From 22bc6531faadb9070836ed14b715b8f2ba516588 Mon Sep 17 00:00:00 2001 From: Mark Seaborn Date: Wed, 20 Jan 2010 17:11:56 +0000 Subject: [PATCH] Remove non-standard PT_LOAD segment containing ELF headers from libraries PHDRs will not be mapped. It turns out ld.so is fine with this. This means we can remove the support for this segment from sel_ldr. First segment is now PROT_EXEC. Change ld.so to cope with this. It wants to map a larger area as PROT_EXEC in order to reserve the address space, but we cannot do this under NaCl. --- elf/dl-load.c | 8 ++++++-- ld/ldscripts/elf_nacl.xs | 7 ++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 716a6f3485..aaf39f7ebf 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1202,8 +1202,10 @@ cannot allocate TLS data structures for initial thread"); - MAP_BASE_ADDR (l)); /* Remember which part of the address space this object uses. */ + /* On NaCl, we cannot map the whole file with PROT_EXEC, so + use PROT_NONE. */ l->l_map_start = (ElfW(Addr)) __mmap ((void *) mappref, maplength, - c->prot, + PROT_NONE, /* c->prot, */ MAP_COPY|MAP_FILE, fd, c->mapoff); if (__builtin_expect ((void *) l->l_map_start == MAP_FAILED, 0)) @@ -1228,7 +1230,8 @@ cannot allocate TLS data structures for initial thread"); l->l_contiguous = 1; - goto postmap; + /* goto postmap; */ + goto start_mapping; } /* This object is loaded at a fixed address. This must never @@ -1249,6 +1252,7 @@ cannot allocate TLS data structures for initial thread"); l->l_map_end = l->l_map_start + maplength; l->l_contiguous = !has_holes; + start_mapping: while (c < &loadcmds[nloadcmds]) { if (c->mapend > c->mapstart diff --git a/ld/ldscripts/elf_nacl.xs b/ld/ldscripts/elf_nacl.xs index 19b80e5116..04515add73 100644 --- a/ld/ldscripts/elf_nacl.xs +++ b/ld/ldscripts/elf_nacl.xs @@ -6,22 +6,19 @@ ENTRY(_start) SEARCH_DIR("/usr/i386-linux-gnu/lib32"); SEARCH_DIR("/usr/local/lib32"); SEARCH_DIR("/lib32"); SEARCH_DIR("/usr/lib32"); SEARCH_DIR("/usr/i386-linux-gnu/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib"); PHDRS { - /* TODO: put headers in a separate, non-executable PT_LOAD segment. */ - segheaders PT_LOAD FLAGS(4) FILEHDR PHDRS ; /* read */ segtext PT_LOAD FLAGS(5) ; /* read + execute */ segrodata PT_LOAD FLAGS(4) ; /* read */ segdata PT_LOAD FLAGS(6) ; /* read + write */ dynamic PT_DYNAMIC FLAGS(6) ; stack PT_GNU_STACK FLAGS(6) ; tls PT_TLS FLAGS(4) ; - /* TODO: do we need a stack? */ } SECTIONS { /* Read-only sections, merged into text segment: */ _begin = 0x0; - . = 0x0 + SIZEOF_HEADERS; - . = ALIGN(CONSTANT (MAXPAGESIZE)); /* nacl wants page alignment */ + /* ELF headers are not included in any PT_LOAD segment */ + . = 0; .init : SUBALIGN(32) { KEEP (*(.init)) -- 2.11.4.GIT