@@ -1263,6 +1263,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
l->l_map_start = l->l_map_end = 0;
goto lose;
}
+ errstring = _dl_finalize_segments (l, type, loadcmds, nloadcmds);
+ if (__glibc_unlikely (errstring != NULL))
+ goto lose;
}
if (l->l_ld != 0)
@@ -120,6 +120,11 @@ static const char *_dl_map_segments (struct link_map *l, int fd,
const size_t maplength,
struct link_map *loader);
+static const char *_dl_finalize_segments (struct link_map *l,
+ int type,
+ const struct loadcmd loadcmds[],
+ size_t nloadcmds);
+
/* All the error message strings _dl_map_segments might return are
listed here so that different implementations in different sysdeps
dl-map-segments.h files all use consistent strings that are
@@ -123,12 +123,10 @@ _dl_map_segments (struct link_map *l, int fd,
while (c < &loadcmds[nloadcmds])
{
- ElfW(Addr) hole_start, hole_size;
-
if (c->mapend > c->mapstart
/* Map the segment contents from the file. */
&& (__mmap ((void *) (l->l_addr + c->mapstart),
- c->mapend - c->mapstart, c->prot,
+ c->mapend - c->mapstart, PROT_READ | PROT_WRITE,
MAP_FIXED|MAP_COPY|MAP_FILE,
fd, c->mapoff)
== MAP_FAILED))
@@ -136,6 +134,34 @@ _dl_map_segments (struct link_map *l, int fd,
_dl_postprocess_loadcmd (l, header, c);
+ ++c;
+ }
+
+ /* Notify ELF_PREFERRED_ADDRESS that we have to load this one
+ fixed. */
+ ELF_FIXED_ADDRESS (loader, c->mapstart);
+
+ return NULL;
+}
+
+static __always_inline const char *
+_dl_finalize_segments (struct link_map *l, int type,
+ const struct loadcmd loadcmds[], size_t nloadcmds)
+{
+ const struct loadcmd *c = loadcmds;
+
+ while (c < &loadcmds[nloadcmds])
+ {
+ ElfW(Addr) hole_start, hole_size;
+
+ if (c->mapend > c->mapstart)
+ {
+ if (__mprotect ((void *) (l->l_addr + c->mapstart),
+ c->mapend - c->mapstart, c->prot) < 0)
+ return DL_MAP_SEGMENTS_ERROR_MPROTECT;
+
+ }
+
if (c->allocend > c->dataend)
{
/* Extra zero pages should appear at the end of this segment,
@@ -208,9 +234,5 @@ _dl_map_segments (struct link_map *l, int fd,
++c;
}
- /* Notify ELF_PREFERRED_ADDRESS that we have to load this one
- fixed. */
- ELF_FIXED_ADDRESS (loader, c->mapstart);
-
return NULL;
}
This is needed so that further patches can move that to the relocation code. The test-suite was run on x86_64/64 and showed no regressions. Signed-off-by: Stas Sergeev <stsp2@yandex.ru> --- elf/dl-load.c | 3 +++ elf/dl-load.h | 5 +++++ elf/dl-map-segments.h | 36 +++++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 7 deletions(-)