diff options
Diffstat (limited to 'elf')
-rw-r--r-- | elf/Makefile | 4 | ||||
-rw-r--r-- | elf/dl-deps.c | 2 | ||||
-rw-r--r-- | elf/dl-minimal.c | 15 | ||||
-rw-r--r-- | elf/do-rel.h | 7 | ||||
-rw-r--r-- | elf/dynamic-link.h | 81 | ||||
-rw-r--r-- | elf/elf.h | 51 | ||||
-rw-r--r-- | elf/link.h | 4 | ||||
-rw-r--r-- | elf/rtld.c | 5 |
8 files changed, 144 insertions, 25 deletions
diff --git a/elf/Makefile b/elf/Makefile index 904099cbeb..f8dc9d0ef2 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -22,13 +22,13 @@ subdir := elf headers = elf.h bits/elfclass.h bits/dlfcn.h link.h dlfcn.h routines = $(dl-routines) dl-open dl-close dl-symbol dl-support \ - dl-version enbl-secure + enbl-secure # The core dynamic linking functions are in libc for the static and # profiled libraries. dl-routines = $(addprefix dl-,load cache lookup object reloc deps \ runtime error init fini debug misc \ - profile) + version profile) # But they are absent from the shared libc, because that code is in ld.so. elide-routines.so = $(dl-routines) dl-support enbl-secure diff --git a/elf/dl-deps.c b/elf/dl-deps.c index e990d6965b..3fbb3dbf92 100644 --- a/elf/dl-deps.c +++ b/elf/dl-deps.c @@ -21,7 +21,7 @@ #include <errno.h> #include <dlfcn.h> #include <stdlib.h> - +#include <string.h> #include <assert.h> /* Whether an shared object references one or more auxiliary objects diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index 486e5bc608..a76e01dcb8 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -23,7 +23,7 @@ #include <assert.h> #include <string.h> #include <link.h> -#include "../stdio-common/_itoa.h" +#include <stdio-common/_itoa.h> /* Minimal `malloc' allocator for use while loading shared libraries. Only small blocks are allocated, and none are ever freed. */ @@ -43,9 +43,6 @@ malloc (size_t n) #define MAP_ANON 0 #endif - if (_dl_pagesize == 0) - _dl_pagesize = __getpagesize (); - if (alloc_end == 0) { /* Consume any unused space in the last page of our data segment. */ @@ -115,10 +112,16 @@ realloc (void *ptr, size_t n) int weak_function __sigjmp_save (sigjmp_buf env, int savemask) -{ env[0].__mask_was_saved = savemask; return 0; } +{ + env[0].__mask_was_saved = savemask; + return 0; +} void weak_function -longjmp (jmp_buf env, int val) { __longjmp (env[0].__jmpbuf, val); } +longjmp (jmp_buf env, int val) +{ + __longjmp (env[0].__jmpbuf, val); +} /* Define our own stub for the localization function used by strerror. English-only in the dynamic linker keeps it smaller. */ diff --git a/elf/do-rel.h b/elf/do-rel.h index 7f4b1259a2..2e0f26bd05 100644 --- a/elf/do-rel.h +++ b/elf/do-rel.h @@ -37,12 +37,11 @@ static inline void elf_dynamic_do_rel (struct link_map *map, - int reltag, int sztag, + ElfW(Addr) reladdr, ElfW(Addr) relsize, int lazy) { - const ElfW(Rel) *r - = (const ElfW(Rel) *) (map->l_addr + map->l_info[reltag]->d_un.d_ptr); - const ElfW(Rel) *end = &r[map->l_info[sztag]->d_un.d_val / sizeof *r]; + const ElfW(Rel) *r = (const ElfW(Rel) *)(map->l_addr + reladdr); + const ElfW(Rel) *end = (const ElfW(Rel) *)(map->l_addr + reladdr + relsize); if (lazy) /* Doing lazy PLT relocations; they need very little info. */ diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h index 4a946f8ad8..64b5f78bc7 100644 --- a/elf/dynamic-link.h +++ b/elf/dynamic-link.h @@ -75,14 +75,75 @@ elf_get_dynamic_info (ElfW(Dyn) *dyn, duplicating their code. It cannot be done in a more general function because we must be able to completely inline. */ +/* On some machines, notably Sparc, DT_REL* includes DT_JMPREL in its + range. Note that according to the ELF spec, this is completely legal! + But conditionally define things so that on machines we know this will + not happen we do something more optimal. */ + +#ifdef ELF_MACHINE_PLTREL_OVERLAP +#define _ELF_DYNAMIC_DO_RELOC(RELOC, reloc, map, lazy) \ + do { \ + ElfW(Addr) r_addr, r_size, p_addr, p_size; \ + if ((map)->l_info[DT_##RELOC]) \ + { \ + r_addr = (map)->l_info[DT_##RELOC]->d_un.d_ptr; \ + r_size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val; \ + if ((map)->l_info[DT_PLTREL] && \ + (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC) \ + { \ + p_addr = (map)->l_info[DT_JMPREL]->d_un.d_ptr; \ + p_size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \ + if (r_addr <= p_addr && r_addr+r_size > p_addr) \ + { \ + ElfW(Addr) r2_addr, r2_size; \ + r2_addr = p_addr+p_size; \ + if (r2_addr < r_addr+r_size) \ + { \ + r2_size = r_addr+r_size - r2_addr; \ + elf_dynamic_do_##reloc ((map), r2_addr, r2_size, 0); \ + } \ + r_size = p_addr - r_addr; \ + } \ + } \ + \ + elf_dynamic_do_##reloc ((map), r_addr, r_size, 0); \ + if (p_addr) \ + elf_dynamic_do_##reloc ((map), p_addr, p_size, (lazy)); \ + } \ + else if ((map)->l_info[DT_PLTREL] && \ + (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC) \ + { \ + p_addr = (map)->l_info[DT_JMPREL]->d_un.d_ptr; \ + p_size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \ + \ + elf_dynamic_do_##reloc ((map), p_addr, p_size, (lazy)); \ + } \ + } while (0) +#else +#define _ELF_DYNAMIC_DO_RELOC(RELOC, reloc, map, lazy) \ + do { \ + if ((map)->l_info[DT_##RELOC]) \ + { \ + ElfW(Addr) r_addr, r_size; \ + r_addr = (map)->l_info[DT_##RELOC]->d_un.d_ptr; \ + r_size = (map)->l_info[DT_##RELOC##SZ]->d_un.d_val; \ + elf_dynamic_do_##reloc ((map), r_addr, r_size, 0); \ + } \ + if ((map)->l_info[DT_PLTREL] && \ + (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC) \ + { \ + ElfW(Addr) p_addr, p_size; \ + p_addr = (map)->l_info[DT_JMPREL]->d_un.d_ptr; \ + p_size = (map)->l_info[DT_PLTRELSZ]->d_un.d_val; \ + elf_dynamic_do_##reloc ((map), p_addr, p_size, (lazy)); \ + } \ + } while (0) +#endif + #if ! ELF_MACHINE_NO_REL #include "do-rel.h" -#define ELF_DYNAMIC_DO_REL(map, lazy) \ - if ((map)->l_info[DT_REL]) \ - elf_dynamic_do_rel ((map), DT_REL, DT_RELSZ, 0); \ - if ((map)->l_info[DT_PLTREL] && \ - (map)->l_info[DT_PLTREL]->d_un.d_val == DT_REL) \ - elf_dynamic_do_rel ((map), DT_JMPREL, DT_PLTRELSZ, (lazy)); +#define ELF_DYNAMIC_DO_REL(map, lazy) \ + _ELF_DYNAMIC_DO_RELOC (REL, rel, map, lazy) #else #define ELF_DYNAMIC_DO_REL(map, lazy) /* Nothing to do. */ #endif @@ -90,12 +151,8 @@ elf_get_dynamic_info (ElfW(Dyn) *dyn, #if ! ELF_MACHINE_NO_RELA #define DO_RELA #include "do-rel.h" -#define ELF_DYNAMIC_DO_RELA(map, lazy) \ - if ((map)->l_info[DT_RELA]) \ - elf_dynamic_do_rela ((map), DT_RELA, DT_RELASZ, 0); \ - if ((map)->l_info[DT_PLTREL] && \ - (map)->l_info[DT_PLTREL]->d_un.d_val == DT_RELA) \ - elf_dynamic_do_rela ((map), DT_JMPREL, DT_PLTRELSZ, (lazy)); +#define ELF_DYNAMIC_DO_RELA(map, lazy) \ + _ELF_DYNAMIC_DO_RELOC (RELA, rela, map, lazy) #else #define ELF_DYNAMIC_DO_RELA(map, lazy) /* Nothing to do. */ #endif @@ -505,6 +505,7 @@ typedef struct entry */ } Elf32_Verdef; +#if 0 /* XXX We have no information what types should be used for 64 bit architectures. What is following is only an intelligent guess. */ typedef struct @@ -518,6 +519,11 @@ typedef struct Elf64_Word vd_next; /* Offset in bytes to next verdef entry */ } Elf64_Verdef; +#else +/* The linker doesn't even parameterize the version info swapping + routines. I wonder if it should or is this good enough. */ +typedef Elf32_Verdef Elf64_Verdef; +#endif /* Legal values for vd_version (version revision). */ #define VER_DEF_NONE 0 /* No version */ @@ -537,6 +543,7 @@ typedef struct entry */ } Elf32_Verdaux; +#if 0 /* XXX We have no information what types should be used for 64 bit architectures. What is following is only an intelligent guess. */ typedef struct @@ -545,6 +552,10 @@ typedef struct Elf64_Word vda_next; /* Offset in bytes to next verdaux entry */ } Elf64_Verdaux; +#else +/* The linker doesn't even parameterize this -- should it? */ +typedef Elf32_Verdaux Elf64_Verdaux; +#endif /* Version dependency section. */ @@ -559,6 +570,7 @@ typedef struct entry */ } Elf32_Verneed; +#if 0 /* XXX We have no information what types should be used for 64 bit architectures. What is following is only an intelligent guess. */ typedef struct @@ -571,6 +583,10 @@ typedef struct Elf64_Word vn_next; /* Offset in bytes to next verneed entry */ } Elf64_Verneed; +#else +/* The linker doesn't even parameterize this -- should it? */ +typedef Elf32_Verneed Elf64_Verneed; +#endif /* Legal values for vn_version (version revision). */ #define VER_NEED_NONE 0 /* No version */ @@ -589,6 +605,7 @@ typedef struct entry */ } Elf32_Vernaux; +#if 0 /* XXX We have no information what types should be used for 64 bit architectures. What is following is only an intelligent guess. */ typedef struct @@ -600,6 +617,10 @@ typedef struct Elf64_Word vna_next; /* Offset in bytes to next vernaux entry */ } Elf64_Vernaux; +#else +/* The linker doesn't even parameterize these -- should it? */ +typedef Elf32_Vernaux Elf64_Vernaux; +#endif /* Legal values for vna_flags. */ #define VER_FLG_WEAK 0x2 /* Weak verison identifier */ @@ -732,6 +753,36 @@ typedef struct #define R_SPARC_RELATIVE 22 /* Adjust by program base */ #define R_SPARC_UA32 23 /* Direct 32 bit unaligned */ +/* Additional Sparc64 relocs. */ + +#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */ +#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */ +#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */ +#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */ +#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */ +#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */ +#define R_SPARC_10 30 /* Direct 10 bit */ +#define R_SPARC_11 31 /* Direct 11 bit */ +#define R_SPARC_64 32 /* Direct 64 bit */ +#define R_SPARC_OLO10 33 /* ?? */ +#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */ +#define R_SPARC_HM10 35 /* High middle 10 bits of ... */ +#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */ +#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */ +#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */ +#define R_SPARC_PC_LM22 39 /* Low miggle 22 bits of ... */ +#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */ +#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */ +#define R_SPARC_GLOB_JMP 42 /* ?? */ +#define R_SPARC_7 43 /* Direct 7 bit */ +#define R_SPARC_5 44 /* Direct 5 bit */ +#define R_SPARC_6 45 /* Direct 6 bit */ + +/* For Sparc64, legal values for d_tag of Elf64_Dyn. */ + +#define DT_SPARC_PLTFMT 0x70000001 /* .plt format version/type */ +#define DT_SPARC_NUM 2 + /* MIPS R3000 specific definitions. */ /* Legal values for e_flags field of Elf32_Ehdr. */ diff --git a/elf/link.h b/elf/link.h index 38a7c88d9a..a90854a2ea 100644 --- a/elf/link.h +++ b/elf/link.h @@ -444,6 +444,10 @@ extern void _dl_start_profile (struct link_map *map, const char *output_dir); /* The actual functions used to keep book on the calls. */ extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc); + +/* Show the member of the auxiliry aray passed up from the kernel. */ +extern void _dl_show_auxv (void); + __END_DECLS #endif /* link.h */ diff --git a/elf/rtld.c b/elf/rtld.c index 726463c882..c3d81e198f 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -261,6 +261,11 @@ dl_main (const ElfW(Phdr) *phdr, char *file; int has_interp = 0; + /* Test whether we want to see the content of the auxiliary array passed + up from the kernel. */ + if (getenv ("LD_SHOW_AUXV") != NULL) + _dl_show_auxv (); + mode = getenv ("LD_TRACE_LOADED_OBJECTS") != NULL ? trace : normal; _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1; |