summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-09-17 06:30:55 +0000
committerRich Felker <dalias@aerifal.cx>2015-09-17 06:30:55 +0000
commit2907afb8dbd4c1d34825c3c9bd2b41564baca210 (patch)
tree60ee15a829cd0cee1e02007704acff9bf9f1c6e1 /src
parenta603a75a72bb469c6be4963ed1b55fabe675fe15 (diff)
downloadmusl-2907afb8dbd4c1d34825c3c9bd2b41564baca210.tar.gz
musl-2907afb8dbd4c1d34825c3c9bd2b41564baca210.tar.bz2
musl-2907afb8dbd4c1d34825c3c9bd2b41564baca210.tar.xz
musl-2907afb8dbd4c1d34825c3c9bd2b41564baca210.zip
introduce new symbol-lookup-free rcrt1/dlstart stage chaining
previously, the call into stage 2 was made by looking up the symbol name "__dls2" (which was chosen short to be easy to look up) from the dynamic symbol table. this was no problem for the dynamic linker, since it always exports all its symbols. in the case of the static pie entry point, however, the dynamic symbol table does not contain the necessary symbol unless -rdynamic/-E was used when linking. this linking requirement is a major obstacle both to practical use of static-pie as a nommu binary format (since it greatly enlarges the file) and to upstream toolchain support for static-pie (adding -E to default linking specs is not reasonable). this patch replaces the runtime symbolic lookup with a link-time lookup via an inline asm fragment, which reloc.h is responsible for providing. in this initial commit, the asm is provided only for i386, and the old lookup code is left in place as a fallback for archs that have not yet transitioned. modifying crt_arch.h to pass the stage-2 function pointer as an argument was considered as an alternative, but such an approach would not be compatible with fdpic, where it's impossible to compute function pointers without already having performed relocations. it was also deemed desirable to keep crt_arch.h as simple/minimal as possible. in principle, archs with pc-relative or got-relative addressing of static variables could instead load the stage-2 function pointer from a static volatile object. that does not work for fdpic, and is not safe against reordering on mips-like archs that use got slots even for static functions, but it's a valid on i386 and many others, and could provide a reasonable default implementation in the future.
Diffstat (limited to 'src')
-rw-r--r--src/ldso/dlstart.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/ldso/dlstart.c b/src/ldso/dlstart.c
index 3aaa200f..eb919ab4 100644
--- a/src/ldso/dlstart.c
+++ b/src/ldso/dlstart.c
@@ -74,6 +74,7 @@ void _dlstart_c(size_t *sp, size_t *dynv)
*rel_addr = (size_t)base + rel[2];
}
+#ifndef GETFUNCSYM
const char *strings = (void *)(base + dyn[DT_STRTAB]);
const Sym *syms = (void *)(base + dyn[DT_SYMTAB]);
@@ -85,6 +86,11 @@ void _dlstart_c(size_t *sp, size_t *dynv)
break;
}
((stage2_func)(base + syms[i].st_value))(base, sp);
+#else
+ stage2_func dls2;
+ GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
+ dls2(base, sp);
+#endif
}
#endif