diff options
author | Rich Felker <dalias@aerifal.cx> | 2015-09-12 03:10:44 +0000 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-09-12 03:10:44 +0000 |
commit | 6d03c4ee586576bf199cf8d6dc86ba4cd54e4186 (patch) | |
tree | 2bd7197c16633f897d1e13a162ed2321efede9c4 /src | |
parent | 234c58467c3709bafdd3ffa6ac73655e1dfd9ddb (diff) | |
download | musl-6d03c4ee586576bf199cf8d6dc86ba4cd54e4186.zip musl-6d03c4ee586576bf199cf8d6dc86ba4cd54e4186.tar.gz musl-6d03c4ee586576bf199cf8d6dc86ba4cd54e4186.tar.bz2 |
provide arch-generic fdpic self-relocation code for crt1 to use
this file is intended to be included by crt_arch.h on fdpic-based
targets and needs to be called from the entry point asm.
Diffstat (limited to 'src')
-rw-r--r-- | src/internal/fdpic_crt.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/internal/fdpic_crt.h b/src/internal/fdpic_crt.h new file mode 100644 index 0000000..7eb50c6 --- /dev/null +++ b/src/internal/fdpic_crt.h @@ -0,0 +1,28 @@ +#include <stdint.h> + +__attribute__((__visibility__("hidden"))) +void *__fdpic_fixup(void *map, uintptr_t *a, uintptr_t *z) +{ + /* If map is a null pointer, the program was loaded by a + * non-FDPIC-aware ELF loader, and fixups are not needed, + * but the value for the GOT pointer is. */ + if (!map) return (void *)z[-1]; + + struct { + unsigned short version, nsegs; + struct fdpic_loadseg { + uintptr_t addr, p_vaddr, p_memsz; + } segs[]; + } *lm = map; + int nsegs = lm->nsegs, rseg = 0, vseg = 0; + for (;;) { + while (*a-lm->segs[rseg].p_vaddr >= lm->segs[rseg].p_memsz) + if (++rseg == nsegs) rseg = 0; + uintptr_t *r = (uintptr_t *) + (*a + lm->segs[rseg].addr - lm->segs[rseg].p_vaddr); + if (++a == z) return r; + while (*r-lm->segs[vseg].p_vaddr >= lm->segs[vseg].p_memsz) + if (++vseg == nsegs) vseg = 0; + *r += lm->segs[vseg].addr - lm->segs[vseg].p_vaddr; + } +} |