rtld.c (70677) | rtld.c (76296) |
---|---|
1/*- 2 * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * | 1/*- 2 * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * |
25 * $FreeBSD: head/libexec/rtld-elf/rtld.c 70677 2001-01-05 04:36:17Z jdp $ | 25 * $FreeBSD: head/libexec/rtld-elf/rtld.c 76296 2001-05-05 23:21:05Z jdp $ |
26 */ 27 28/* 29 * Dynamic linker for ELF. 30 * 31 * John Polstra <jdp@polstra.com>. 32 */ 33 --- 388 unchanged lines hidden (view full) --- 422 423 rlock_acquire(); 424 if (obj->pltrel) 425 rel = (const Elf_Rel *) ((caddr_t) obj->pltrel + reloff); 426 else 427 rel = (const Elf_Rel *) ((caddr_t) obj->pltrela + reloff); 428 429 where = (Elf_Addr *) (obj->relocbase + rel->r_offset); | 26 */ 27 28/* 29 * Dynamic linker for ELF. 30 * 31 * John Polstra <jdp@polstra.com>. 32 */ 33 --- 388 unchanged lines hidden (view full) --- 422 423 rlock_acquire(); 424 if (obj->pltrel) 425 rel = (const Elf_Rel *) ((caddr_t) obj->pltrel + reloff); 426 else 427 rel = (const Elf_Rel *) ((caddr_t) obj->pltrela + reloff); 428 429 where = (Elf_Addr *) (obj->relocbase + rel->r_offset); |
430 def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true); | 430 def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true, NULL); |
431 if (def == NULL) 432 die(); 433 434 target = (Elf_Addr)(defobj->relocbase + def->st_value); 435 436 dbg("\"%s\" in \"%s\" ==> %p in \"%s\"", 437 defobj->strtab + def->st_name, basename(obj->path), 438 (void *)target, basename(defobj->path)); --- 377 unchanged lines hidden (view full) --- 816/* 817 * Given a symbol number in a referencing object, find the corresponding 818 * definition of the symbol. Returns a pointer to the symbol, or NULL if 819 * no definition was found. Returns a pointer to the Obj_Entry of the 820 * defining object via the reference parameter DEFOBJ_OUT. 821 */ 822const Elf_Sym * 823find_symdef(unsigned long symnum, const Obj_Entry *refobj, | 431 if (def == NULL) 432 die(); 433 434 target = (Elf_Addr)(defobj->relocbase + def->st_value); 435 436 dbg("\"%s\" in \"%s\" ==> %p in \"%s\"", 437 defobj->strtab + def->st_name, basename(obj->path), 438 (void *)target, basename(defobj->path)); --- 377 unchanged lines hidden (view full) --- 816/* 817 * Given a symbol number in a referencing object, find the corresponding 818 * definition of the symbol. Returns a pointer to the symbol, or NULL if 819 * no definition was found. Returns a pointer to the Obj_Entry of the 820 * defining object via the reference parameter DEFOBJ_OUT. 821 */ 822const Elf_Sym * 823find_symdef(unsigned long symnum, const Obj_Entry *refobj, |
824 const Obj_Entry **defobj_out, bool in_plt) | 824 const Obj_Entry **defobj_out, bool in_plt, SymCache *cache) |
825{ 826 const Elf_Sym *ref; 827 const Elf_Sym *def; 828 const Obj_Entry *defobj; 829 const char *name; 830 unsigned long hash; 831 | 825{ 826 const Elf_Sym *ref; 827 const Elf_Sym *def; 828 const Obj_Entry *defobj; 829 const char *name; 830 unsigned long hash; 831 |
832 /* 833 * If we have already found this symbol, get the information from 834 * the cache. 835 */ 836 if (symnum >= refobj->nchains) 837 return NULL; /* Bad object */ 838 if (cache != NULL && cache[symnum].sym != NULL) { 839 *defobj_out = cache[symnum].obj; 840 return cache[symnum].sym; 841 } 842 |
|
832 ref = refobj->symtab + symnum; 833 name = refobj->strtab + ref->st_name; 834 hash = elf_hash(name); 835 defobj = NULL; 836 837 def = symlook_default(name, hash, refobj, &defobj, in_plt); 838 839 /* 840 * If we found no definition and the reference is weak, treat the 841 * symbol as having the value zero. 842 */ 843 if (def == NULL && ELF_ST_BIND(ref->st_info) == STB_WEAK) { 844 def = &sym_zero; 845 defobj = obj_main; 846 } 847 | 843 ref = refobj->symtab + symnum; 844 name = refobj->strtab + ref->st_name; 845 hash = elf_hash(name); 846 defobj = NULL; 847 848 def = symlook_default(name, hash, refobj, &defobj, in_plt); 849 850 /* 851 * If we found no definition and the reference is weak, treat the 852 * symbol as having the value zero. 853 */ 854 if (def == NULL && ELF_ST_BIND(ref->st_info) == STB_WEAK) { 855 def = &sym_zero; 856 defobj = obj_main; 857 } 858 |
848 if (def != NULL) | 859 if (def != NULL) { |
849 *defobj_out = defobj; | 860 *defobj_out = defobj; |
850 else | 861 /* Record the information in the cache to avoid subsequent lookups. */ 862 if (cache != NULL) { 863 cache[symnum].sym = def; 864 cache[symnum].obj = defobj; 865 } 866 } else |
851 _rtld_error("%s: Undefined symbol \"%s\"", refobj->path, name); 852 return def; 853} 854 855/* 856 * Return the search path from the ldconfig hints file, reading it if 857 * necessary. Returns NULL if there are problems with the hints file, 858 * or if the search path there is empty. --- 1062 unchanged lines hidden (view full) --- 1921 const Elf_Sym *symp; 1922 const char *strp; 1923 1924 if (symnum >= obj->nchains) 1925 return NULL; /* Bad object */ 1926 symp = obj->symtab + symnum; 1927 strp = obj->strtab + symp->st_name; 1928 | 867 _rtld_error("%s: Undefined symbol \"%s\"", refobj->path, name); 868 return def; 869} 870 871/* 872 * Return the search path from the ldconfig hints file, reading it if 873 * necessary. Returns NULL if there are problems with the hints file, 874 * or if the search path there is empty. --- 1062 unchanged lines hidden (view full) --- 1937 const Elf_Sym *symp; 1938 const char *strp; 1939 1940 if (symnum >= obj->nchains) 1941 return NULL; /* Bad object */ 1942 symp = obj->symtab + symnum; 1943 strp = obj->strtab + symp->st_name; 1944 |
1929 if (strcmp(name, strp) == 0) | 1945 if (name[0] == strp[0] && strcmp(name, strp) == 0) |
1930 return symp->st_shndx != SHN_UNDEF || 1931 (!in_plt && symp->st_value != 0 && 1932 ELF_ST_TYPE(symp->st_info) == STT_FUNC) ? symp : NULL; 1933 1934 symnum = obj->chains[symnum]; 1935 } 1936 } 1937 return NULL; --- 159 unchanged lines hidden --- | 1946 return symp->st_shndx != SHN_UNDEF || 1947 (!in_plt && symp->st_value != 0 && 1948 ELF_ST_TYPE(symp->st_info) == STT_FUNC) ? symp : NULL; 1949 1950 symnum = obj->chains[symnum]; 1951 } 1952 } 1953 return NULL; --- 159 unchanged lines hidden --- |