Deleted Added
full compact
link_elf.c (43185) link_elf.c (43301)
1/*-
2 * Copyright (c) 1998 Doug Rabson
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

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1998 Doug Rabson
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

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: link_elf.c,v 1.11 1998/12/31 09:17:20 peter Exp $
26 * $Id: link_elf.c,v 1.12 1999/01/25 08:42:24 dfr Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/kernel.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/proc.h>
34#include <sys/namei.h>

--- 10 unchanged lines hidden (view full) ---

45#include <vm/vm_kern.h>
46#include <vm/vm_extern.h>
47#include <vm/pmap.h>
48#include <vm/vm_map.h>
49
50static int link_elf_load_module(const char*, linker_file_t*);
51static int link_elf_load_file(const char*, linker_file_t*);
52static int link_elf_lookup_symbol(linker_file_t, const char*,
27 */
28
29#include <sys/param.h>
30#include <sys/kernel.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/proc.h>
34#include <sys/namei.h>

--- 10 unchanged lines hidden (view full) ---

45#include <vm/vm_kern.h>
46#include <vm/vm_extern.h>
47#include <vm/pmap.h>
48#include <vm/vm_map.h>
49
50static int link_elf_load_module(const char*, linker_file_t*);
51static int link_elf_load_file(const char*, linker_file_t*);
52static int link_elf_lookup_symbol(linker_file_t, const char*,
53 linker_sym_t*);
53 c_linker_sym_t*);
54static int link_elf_symbol_values(linker_file_t, linker_sym_t, linker_symval_t*);
55static int link_elf_search_symbol(linker_file_t, caddr_t value,
54static int link_elf_symbol_values(linker_file_t, linker_sym_t, linker_symval_t*);
55static int link_elf_search_symbol(linker_file_t, caddr_t value,
56 linker_sym_t* sym, long* diffp);
56 c_linker_sym_t* sym, long* diffp);
57
58static void link_elf_unload_file(linker_file_t);
59static void link_elf_unload_module(linker_file_t);
60
61static struct linker_class_ops link_elf_class_ops = {
62 link_elf_load_module,
63};
64

--- 719 unchanged lines hidden (view full) ---

784 const Elf_Rel *rel;
785 const Elf_Rela *relalim;
786 const Elf_Rela *rela;
787 const char *symname;
788
789 /* Perform relocations without addend if there are any: */
790 rel = ef->rel;
791 if (rel) {
57
58static void link_elf_unload_file(linker_file_t);
59static void link_elf_unload_module(linker_file_t);
60
61static struct linker_class_ops link_elf_class_ops = {
62 link_elf_load_module,
63};
64

--- 719 unchanged lines hidden (view full) ---

784 const Elf_Rel *rel;
785 const Elf_Rela *relalim;
786 const Elf_Rela *rela;
787 const char *symname;
788
789 /* Perform relocations without addend if there are any: */
790 rel = ef->rel;
791 if (rel) {
792 rellim = (const Elf_Rel *) ((caddr_t) ef->rel + ef->relsize);
792 rellim = (const Elf_Rel *) ((c_caddr_t) ef->rel + ef->relsize);
793 while (rel < rellim) {
794 symname = symbol_name(ef, rel->r_info);
795 if (elf_reloc(lf, rel, ELF_RELOC_REL, symname)) {
796 printf("link_elf: symbol %s undefined\n", symname);
797 return ENOENT;
798 }
799 rel++;
800 }
801 }
802
803 /* Perform relocations with addend if there are any: */
804 rela = ef->rela;
805 if (rela) {
793 while (rel < rellim) {
794 symname = symbol_name(ef, rel->r_info);
795 if (elf_reloc(lf, rel, ELF_RELOC_REL, symname)) {
796 printf("link_elf: symbol %s undefined\n", symname);
797 return ENOENT;
798 }
799 rel++;
800 }
801 }
802
803 /* Perform relocations with addend if there are any: */
804 rela = ef->rela;
805 if (rela) {
806 relalim = (const Elf_Rela *) ((caddr_t) ef->rela + ef->relasize);
806 relalim = (const Elf_Rela *) ((c_caddr_t) ef->rela + ef->relasize);
807 while (rela < relalim) {
808 symname = symbol_name(ef, rela->r_info);
809 if (elf_reloc(lf, rela, ELF_RELOC_RELA, symname)) {
810 printf("link_elf: symbol %s undefined\n", symname);
811 return ENOENT;
812 }
813 rela++;
814 }
815 }
816
817 /* Perform PLT relocations without addend if there are any: */
818 rel = ef->pltrel;
819 if (rel) {
807 while (rela < relalim) {
808 symname = symbol_name(ef, rela->r_info);
809 if (elf_reloc(lf, rela, ELF_RELOC_RELA, symname)) {
810 printf("link_elf: symbol %s undefined\n", symname);
811 return ENOENT;
812 }
813 rela++;
814 }
815 }
816
817 /* Perform PLT relocations without addend if there are any: */
818 rel = ef->pltrel;
819 if (rel) {
820 rellim = (const Elf_Rel *) ((caddr_t) ef->pltrel + ef->pltrelsize);
820 rellim = (const Elf_Rel *) ((c_caddr_t) ef->pltrel + ef->pltrelsize);
821 while (rel < rellim) {
822 symname = symbol_name(ef, rel->r_info);
823 if (elf_reloc(lf, rel, ELF_RELOC_REL, symname)) {
824 printf("link_elf: symbol %s undefined\n", symname);
825 return ENOENT;
826 }
827 rel++;
828 }
829 }
830
831 /* Perform relocations with addend if there are any: */
832 rela = ef->pltrela;
833 if (rela) {
821 while (rel < rellim) {
822 symname = symbol_name(ef, rel->r_info);
823 if (elf_reloc(lf, rel, ELF_RELOC_REL, symname)) {
824 printf("link_elf: symbol %s undefined\n", symname);
825 return ENOENT;
826 }
827 rel++;
828 }
829 }
830
831 /* Perform relocations with addend if there are any: */
832 rela = ef->pltrela;
833 if (rela) {
834 relalim = (const Elf_Rela *) ((caddr_t) ef->pltrela + ef->pltrelasize);
834 relalim = (const Elf_Rela *) ((c_caddr_t) ef->pltrela + ef->pltrelasize);
835 while (rela < relalim) {
836 symname = symbol_name(ef, rela->r_info);
837 if (elf_reloc(lf, rela, ELF_RELOC_RELA, symname)) {
838 printf("link_elf: symbol %s undefined\n", symname);
839 return ENOENT;
840 }
841 rela++;
842 }

--- 18 unchanged lines hidden (view full) ---

861 if ((g = h & 0xf0000000) != 0)
862 h ^= g >> 24;
863 h &= ~g;
864 }
865 return h;
866}
867
868int
835 while (rela < relalim) {
836 symname = symbol_name(ef, rela->r_info);
837 if (elf_reloc(lf, rela, ELF_RELOC_RELA, symname)) {
838 printf("link_elf: symbol %s undefined\n", symname);
839 return ENOENT;
840 }
841 rela++;
842 }

--- 18 unchanged lines hidden (view full) ---

861 if ((g = h & 0xf0000000) != 0)
862 h ^= g >> 24;
863 h &= ~g;
864 }
865 return h;
866}
867
868int
869link_elf_lookup_symbol(linker_file_t lf, const char* name, linker_sym_t* sym)
869link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
870{
871 elf_file_t ef = lf->priv;
872 unsigned long symnum;
873 const Elf_Sym* symp;
874 const char *strp;
875 unsigned long hash;
876 int i;
877

--- 14 unchanged lines hidden (view full) ---

892 }
893
894 strp = ef->strtab + symp->st_name;
895
896 if (strcmp(name, strp) == 0) {
897 if (symp->st_shndx != SHN_UNDEF ||
898 (symp->st_value != 0 &&
899 ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
870{
871 elf_file_t ef = lf->priv;
872 unsigned long symnum;
873 const Elf_Sym* symp;
874 const char *strp;
875 unsigned long hash;
876 int i;
877

--- 14 unchanged lines hidden (view full) ---

892 }
893
894 strp = ef->strtab + symp->st_name;
895
896 if (strcmp(name, strp) == 0) {
897 if (symp->st_shndx != SHN_UNDEF ||
898 (symp->st_value != 0 &&
899 ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
900 *sym = (linker_sym_t) symp;
900 *sym = (c_linker_sym_t) symp;
901 return 0;
902 } else
903 return ENOENT;
904 }
905
906 symnum = ef->chains[symnum];
907 }
908
909 /* If we have not found it, look at the full table (if loaded) */
910 if (ef->symtab == ef->ddbsymtab)
911 return ENOENT;
912
913 /* Exhaustive search */
914 for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
915 strp = ef->ddbstrtab + symp->st_name;
916 if (strcmp(name, strp) == 0) {
917 if (symp->st_shndx != SHN_UNDEF ||
918 (symp->st_value != 0 &&
919 ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
901 return 0;
902 } else
903 return ENOENT;
904 }
905
906 symnum = ef->chains[symnum];
907 }
908
909 /* If we have not found it, look at the full table (if loaded) */
910 if (ef->symtab == ef->ddbsymtab)
911 return ENOENT;
912
913 /* Exhaustive search */
914 for (i = 0, symp = ef->ddbsymtab; i < ef->ddbsymcnt; i++, symp++) {
915 strp = ef->ddbstrtab + symp->st_name;
916 if (strcmp(name, strp) == 0) {
917 if (symp->st_shndx != SHN_UNDEF ||
918 (symp->st_value != 0 &&
919 ELF_ST_TYPE(symp->st_info) == STT_FUNC)) {
920 *sym = (linker_sym_t) symp;
920 *sym = (c_linker_sym_t) symp;
921 return 0;
922 } else
923 return ENOENT;
924 }
925 }
926
927 return ENOENT;
928}

--- 18 unchanged lines hidden (view full) ---

947 symval->size = es->st_size;
948 return 0;
949 }
950 return ENOENT;
951}
952
953static int
954link_elf_search_symbol(linker_file_t lf, caddr_t value,
921 return 0;
922 } else
923 return ENOENT;
924 }
925 }
926
927 return ENOENT;
928}

--- 18 unchanged lines hidden (view full) ---

947 symval->size = es->st_size;
948 return 0;
949 }
950 return ENOENT;
951}
952
953static int
954link_elf_search_symbol(linker_file_t lf, caddr_t value,
955 linker_sym_t* sym, long* diffp)
955 c_linker_sym_t* sym, long* diffp)
956{
957 elf_file_t ef = lf->priv;
958 u_long off = (u_long) value;
959 u_long diff = off;
960 const Elf_Sym* es;
961 const Elf_Sym* best = 0;
962 int i;
963

--- 10 unchanged lines hidden (view full) ---

974 best = es;
975 }
976 }
977 }
978 if (best == 0)
979 *diffp = off;
980 else
981 *diffp = diff;
956{
957 elf_file_t ef = lf->priv;
958 u_long off = (u_long) value;
959 u_long diff = off;
960 const Elf_Sym* es;
961 const Elf_Sym* best = 0;
962 int i;
963

--- 10 unchanged lines hidden (view full) ---

974 best = es;
975 }
976 }
977 }
978 if (best == 0)
979 *diffp = off;
980 else
981 *diffp = diff;
982 *sym = (linker_sym_t) best;
982 *sym = (c_linker_sym_t) best;
983
984 return 0;
985}
983
984 return 0;
985}