2 * Copyright (c) 1998 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
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
26 * $FreeBSD: src/sys/kern/link_elf.c,v 1.24 1999/12/24 15:33:36 bde Exp $
27 * $DragonFly: src/sys/kern/link_elf.c,v 1.3 2003/06/25 03:55:57 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/systm.h>
33 #include <sys/malloc.h>
35 #include <sys/namei.h>
36 #include <sys/fcntl.h>
37 #include <sys/vnode.h>
38 #include <sys/linker.h>
39 #include <machine/elf.h>
42 #include <vm/vm_param.h>
43 #include <vm/vm_zone.h>
46 #include <vm/vm_object.h>
47 #include <vm/vm_kern.h>
48 #include <vm/vm_extern.h>
51 #include <vm/vm_map.h>
53 static int link_elf_load_module(const char*, linker_file_t*);
54 static int link_elf_load_file(const char*, linker_file_t*);
55 static int link_elf_lookup_symbol(linker_file_t, const char*,
57 static int link_elf_symbol_values(linker_file_t, c_linker_sym_t, linker_symval_t*);
58 static int link_elf_search_symbol(linker_file_t, caddr_t value,
59 c_linker_sym_t* sym, long* diffp);
61 static void link_elf_unload_file(linker_file_t);
62 static void link_elf_unload_module(linker_file_t);
64 static struct linker_class_ops link_elf_class_ops = {
68 static struct linker_file_ops link_elf_file_ops = {
69 link_elf_lookup_symbol,
70 link_elf_symbol_values,
71 link_elf_search_symbol,
75 static struct linker_file_ops link_elf_module_ops = {
76 link_elf_lookup_symbol,
77 link_elf_symbol_values,
78 link_elf_search_symbol,
79 link_elf_unload_module,
81 typedef struct elf_file {
82 caddr_t address; /* Relocation address */
84 vm_object_t object; /* VM object to hold file pages */
86 const Elf_Dyn* dynamic; /* Symbol table etc. */
87 Elf_Off nbuckets; /* DT_HASH info */
89 const Elf_Off* buckets;
90 const Elf_Off* chains;
92 caddr_t strtab; /* DT_STRTAB */
93 int strsz; /* DT_STRSZ */
94 const Elf_Sym* symtab; /* DT_SYMTAB */
95 Elf_Addr* got; /* DT_PLTGOT */
96 const Elf_Rel* pltrel; /* DT_JMPREL */
97 int pltrelsize; /* DT_PLTRELSZ */
98 const Elf_Rela* pltrela; /* DT_JMPREL */
99 int pltrelasize; /* DT_PLTRELSZ */
100 const Elf_Rel* rel; /* DT_REL */
101 int relsize; /* DT_RELSZ */
102 const Elf_Rela* rela; /* DT_RELA */
103 int relasize; /* DT_RELASZ */
105 const Elf_Sym* ddbsymtab; /* The symbol table we are using */
106 long ddbsymcnt; /* Number of symbols */
107 caddr_t ddbstrtab; /* String table */
108 long ddbstrcnt; /* number of bytes in string table */
109 caddr_t symbase; /* malloc'ed symbold base */
110 caddr_t strbase; /* malloc'ed string base */
113 static int parse_dynamic(linker_file_t lf);
114 static int load_dependancies(linker_file_t lf);
115 static int relocate_file(linker_file_t lf);
116 static int parse_module_symbols(linker_file_t lf);
119 * The kernel symbol table starts here.
121 extern struct _dynamic _DYNAMIC;
124 link_elf_init(void* arg)
128 caddr_t modptr, baseptr, sizeptr;
133 #if ELF_TARG_CLASS == ELFCLASS32
134 linker_add_class("elf32", NULL, &link_elf_class_ops);
136 linker_add_class("elf64", NULL, &link_elf_class_ops);
140 dp = (Elf_Dyn*) &_DYNAMIC;
142 ef = malloc(sizeof(struct elf_file), M_LINKER, M_NOWAIT);
144 panic("link_elf_init: Can't create linker structures for kernel");
145 bzero(ef, sizeof(*ef));
148 #ifdef SPARSE_MAPPING
153 modptr = preload_search_by_type("elf kernel");
155 modname = (char *)preload_search_info(modptr, MODINFO_NAME);
158 linker_kernel_file = linker_make_file(modname, ef, &link_elf_file_ops);
159 if (linker_kernel_file == NULL)
160 panic("link_elf_init: Can't create linker structures for kernel");
161 parse_dynamic(linker_kernel_file);
162 linker_kernel_file->address = (caddr_t) KERNBASE;
163 linker_kernel_file->size = -(intptr_t)linker_kernel_file->address;
167 baseptr = preload_search_info(modptr, MODINFO_ADDR);
169 linker_kernel_file->address = *(caddr_t *)baseptr;
170 sizeptr = preload_search_info(modptr, MODINFO_SIZE);
172 linker_kernel_file->size = *(size_t *)sizeptr;
174 (void)parse_module_symbols(linker_kernel_file);
175 linker_current_file = linker_kernel_file;
176 linker_kernel_file->flags |= LINKER_FILE_LINKED;
181 SYSINIT(link_elf, SI_SUB_KLD, SI_ORDER_SECOND, link_elf_init, 0);
184 parse_module_symbols(linker_file_t lf)
186 elf_file_t ef = lf->priv;
188 caddr_t ssym, esym, base;
194 if (ef->modptr == NULL)
196 pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_SSYM);
199 ssym = *(caddr_t *)pointer;
200 pointer = preload_search_info(ef->modptr, MODINFO_METADATA|MODINFOMD_ESYM);
203 esym = *(caddr_t *)pointer;
207 symcnt = *(long *)base;
208 base += sizeof(long);
209 symtab = (Elf_Sym *)base;
210 base += roundup(symcnt, sizeof(long));
212 if (base > esym || base < ssym) {
213 printf("Symbols are corrupt!\n");
217 strcnt = *(long *)base;
218 base += sizeof(long);
220 base += roundup(strcnt, sizeof(long));
222 if (base > esym || base < ssym) {
223 printf("Symbols are corrupt!\n");
227 ef->ddbsymtab = symtab;
228 ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
229 ef->ddbstrtab = strtab;
230 ef->ddbstrcnt = strcnt;
236 parse_dynamic(linker_file_t lf)
238 elf_file_t ef = lf->priv;
240 int plttype = DT_REL;
242 for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
246 /* From src/libexec/rtld-elf/rtld.c */
247 const Elf_Off *hashtab = (const Elf_Off *)
248 (ef->address + dp->d_un.d_ptr);
249 ef->nbuckets = hashtab[0];
250 ef->nchains = hashtab[1];
251 ef->buckets = hashtab + 2;
252 ef->chains = ef->buckets + ef->nbuckets;
256 ef->strtab = (caddr_t) (ef->address + dp->d_un.d_ptr);
259 ef->strsz = dp->d_un.d_val;
262 ef->symtab = (Elf_Sym*) (ef->address + dp->d_un.d_ptr);
265 if (dp->d_un.d_val != sizeof(Elf_Sym))
269 ef->got = (Elf_Addr *) (ef->address + dp->d_un.d_ptr);
272 ef->rel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
275 ef->relsize = dp->d_un.d_val;
278 if (dp->d_un.d_val != sizeof(Elf_Rel))
282 ef->pltrel = (const Elf_Rel *) (ef->address + dp->d_un.d_ptr);
285 ef->pltrelsize = dp->d_un.d_val;
288 ef->rela = (const Elf_Rela *) (ef->address + dp->d_un.d_ptr);
291 ef->relasize = dp->d_un.d_val;
294 if (dp->d_un.d_val != sizeof(Elf_Rela))
298 plttype = dp->d_un.d_val;
299 if (plttype != DT_REL && plttype != DT_RELA)
305 if (plttype == DT_RELA) {
306 ef->pltrela = (const Elf_Rela *) ef->pltrel;
308 ef->pltrelasize = ef->pltrelsize;
312 ef->ddbsymtab = ef->symtab;
313 ef->ddbsymcnt = ef->nchains;
314 ef->ddbstrtab = ef->strtab;
315 ef->ddbstrcnt = ef->strsz;
321 link_elf_error(const char *s)
323 printf("kldload: %s\n", s);
327 link_elf_load_module(const char *filename, linker_file_t *result)
329 caddr_t modptr, baseptr, sizeptr, dynptr;
336 /* Look to see if we have the module preloaded */
337 modptr = preload_search_by_name(filename);
339 return (link_elf_load_file(filename, result));
341 /* It's preloaded, check we can handle it and collect information */
342 type = (char *)preload_search_info(modptr, MODINFO_TYPE);
343 baseptr = preload_search_info(modptr, MODINFO_ADDR);
344 sizeptr = preload_search_info(modptr, MODINFO_SIZE);
345 dynptr = preload_search_info(modptr, MODINFO_METADATA|MODINFOMD_DYNAMIC);
346 if (type == NULL || strcmp(type, "elf module") != 0)
348 if (baseptr == NULL || sizeptr == NULL || dynptr == NULL)
351 ef = malloc(sizeof(struct elf_file), M_LINKER, M_WAITOK);
354 bzero(ef, sizeof(*ef));
356 ef->address = *(caddr_t *)baseptr;
357 #ifdef SPARSE_MAPPING
360 dp = (vm_offset_t)ef->address + *(vm_offset_t *)dynptr;
361 ef->dynamic = (Elf_Dyn *)dp;
362 lf = linker_make_file(filename, ef, &link_elf_module_ops);
367 lf->address = ef->address;
368 lf->size = *(size_t *)sizeptr;
370 error = parse_dynamic(lf);
372 linker_file_unload(lf);
375 error = load_dependancies(lf);
377 linker_file_unload(lf);
380 error = relocate_file(lf);
382 linker_file_unload(lf);
385 (void)parse_module_symbols(lf);
386 lf->flags |= LINKER_FILE_LINKED;
392 link_elf_load_file(const char* filename, linker_file_t* result)
395 struct thread *td = curthread; /* XXX */
396 struct proc *p = td->td_proc;
410 Elf_Addr base_vlimit;
425 pathname = linker_search_path(filename);
426 if (pathname == NULL)
429 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, pathname, td);
430 error = vn_open(&nd, FREAD, 0);
431 free(pathname, M_LINKER);
434 NDFREE(&nd, NDF_ONLY_PNBUF);
437 * Read the elf header from the file.
439 firstpage = malloc(PAGE_SIZE, M_LINKER, M_WAITOK);
440 if (firstpage == NULL) {
444 hdr = (Elf_Ehdr *)firstpage;
445 error = vn_rdwr(UIO_READ, nd.ni_vp, firstpage, PAGE_SIZE, 0,
446 UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, td);
447 nbytes = PAGE_SIZE - resid;
456 if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
457 || hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
458 link_elf_error("Unsupported file layout");
462 if (hdr->e_ident[EI_VERSION] != EV_CURRENT
463 || hdr->e_version != EV_CURRENT) {
464 link_elf_error("Unsupported file version");
468 if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
469 link_elf_error("Unsupported file type");
473 if (hdr->e_machine != ELF_TARG_MACH) {
474 link_elf_error("Unsupported machine");
480 * We rely on the program header being in the first page. This is
481 * not strictly required by the ABI specification, but it seems to
482 * always true in practice. And, it simplifies things considerably.
484 if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
485 (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
486 (hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
487 link_elf_error("Unreadable program headers");
490 * Scan the program header entries, and save key information.
492 * We rely on there being exactly two load segments, text and data,
495 phdr = (Elf_Phdr *) (firstpage + hdr->e_phoff);
496 phlimit = phdr + hdr->e_phnum;
500 while (phdr < phlimit) {
501 switch (phdr->p_type) {
505 link_elf_error("Too many sections");
525 link_elf_error("Object is not dynamically-linked");
531 * Allocate the entire address space of the object, to stake out our
532 * contiguous region, and to establish the base address for relocation.
534 base_offset = trunc_page(segs[0]->p_offset);
535 base_vaddr = trunc_page(segs[0]->p_vaddr);
536 base_vlimit = round_page(segs[1]->p_vaddr + segs[1]->p_memsz);
537 mapsize = base_vlimit - base_vaddr;
539 ef = malloc(sizeof(struct elf_file), M_LINKER, M_WAITOK);
540 bzero(ef, sizeof(*ef));
541 #ifdef SPARSE_MAPPING
542 ef->object = vm_object_allocate(OBJT_DEFAULT, mapsize >> PAGE_SHIFT);
543 if (ef->object == NULL) {
548 vm_object_reference(ef->object);
549 ef->address = (caddr_t) vm_map_min(kernel_map);
550 error = vm_map_find(kernel_map, ef->object, 0,
551 (vm_offset_t *) &ef->address,
553 VM_PROT_ALL, VM_PROT_ALL, 0);
555 vm_object_deallocate(ef->object);
560 ef->address = malloc(mapsize, M_LINKER, M_WAITOK);
562 mapbase = ef->address;
565 * Read the text and data sections and zero the bss.
567 for (i = 0; i < 2; i++) {
568 caddr_t segbase = mapbase + segs[i]->p_vaddr - base_vaddr;
569 error = vn_rdwr(UIO_READ, nd.ni_vp,
570 segbase, segs[i]->p_filesz, segs[i]->p_offset,
571 UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, td);
573 #ifdef SPARSE_MAPPING
574 vm_map_remove(kernel_map, (vm_offset_t) ef->address,
575 (vm_offset_t) ef->address
576 + (ef->object->size << PAGE_SHIFT));
577 vm_object_deallocate(ef->object);
579 free(ef->address, M_LINKER);
584 bzero(segbase + segs[i]->p_filesz,
585 segs[i]->p_memsz - segs[i]->p_filesz);
587 #ifdef SPARSE_MAPPING
589 * Wire down the pages
591 vm_map_pageable(kernel_map,
592 (vm_offset_t) segbase,
593 (vm_offset_t) segbase + segs[i]->p_memsz,
598 ef->dynamic = (const Elf_Dyn *) (mapbase + phdyn->p_vaddr - base_vaddr);
600 lf = linker_make_file(filename, ef, &link_elf_file_ops);
602 #ifdef SPARSE_MAPPING
603 vm_map_remove(kernel_map, (vm_offset_t) ef->address,
604 (vm_offset_t) ef->address
605 + (ef->object->size << PAGE_SHIFT));
606 vm_object_deallocate(ef->object);
608 free(ef->address, M_LINKER);
614 lf->address = ef->address;
617 error = parse_dynamic(lf);
620 error = load_dependancies(lf);
623 error = relocate_file(lf);
627 /* Try and load the symbol table if it's present. (you can strip it!) */
628 nbytes = hdr->e_shnum * hdr->e_shentsize;
629 if (nbytes == 0 || hdr->e_shoff == 0)
631 shdr = malloc(nbytes, M_LINKER, M_WAITOK);
637 error = vn_rdwr(UIO_READ, nd.ni_vp,
638 (caddr_t)shdr, nbytes, hdr->e_shoff,
639 UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, td);
644 for (i = 0; i < hdr->e_shnum; i++) {
645 if (shdr[i].sh_type == SHT_SYMTAB) {
647 symstrindex = shdr[i].sh_link;
650 if (symtabindex < 0 || symstrindex < 0)
653 symcnt = shdr[symtabindex].sh_size;
654 ef->symbase = malloc(symcnt, M_LINKER, M_WAITOK);
655 strcnt = shdr[symstrindex].sh_size;
656 ef->strbase = malloc(strcnt, M_LINKER, M_WAITOK);
658 if (ef->symbase == NULL || ef->strbase == NULL) {
662 error = vn_rdwr(UIO_READ, nd.ni_vp,
663 ef->symbase, symcnt, shdr[symtabindex].sh_offset,
664 UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, td);
667 error = vn_rdwr(UIO_READ, nd.ni_vp,
668 ef->strbase, strcnt, shdr[symstrindex].sh_offset,
669 UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, td);
673 ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
674 ef->ddbsymtab = (const Elf_Sym *)ef->symbase;
675 ef->ddbstrcnt = strcnt;
676 ef->ddbstrtab = ef->strbase;
678 lf->flags |= LINKER_FILE_LINKED;
686 linker_file_unload(lf);
688 free(shdr, M_LINKER);
690 free(firstpage, M_LINKER);
691 VOP_UNLOCK(nd.ni_vp, 0, td);
692 vn_close(nd.ni_vp, FREAD, p->p_ucred, td);
698 link_elf_unload_file(linker_file_t file)
700 elf_file_t ef = file->priv;
703 #ifdef SPARSE_MAPPING
705 vm_map_remove(kernel_map, (vm_offset_t) ef->address,
706 (vm_offset_t) ef->address
707 + (ef->object->size << PAGE_SHIFT));
708 vm_object_deallocate(ef->object);
712 free(ef->address, M_LINKER);
715 free(ef->symbase, M_LINKER);
717 free(ef->strbase, M_LINKER);
723 link_elf_unload_module(linker_file_t file)
725 elf_file_t ef = file->priv;
730 preload_delete_name(file->filename);
734 load_dependancies(linker_file_t lf)
736 elf_file_t ef = lf->priv;
743 * All files are dependant on /kernel.
745 if (linker_kernel_file) {
746 linker_kernel_file->refs++;
747 linker_file_add_dependancy(lf, linker_kernel_file);
750 for (dp = ef->dynamic; dp->d_tag != DT_NULL; dp++) {
751 if (dp->d_tag == DT_NEEDED) {
752 name = ef->strtab + dp->d_un.d_val;
754 error = linker_load_file(name, &lfdep);
757 error = linker_file_add_dependancy(lf, lfdep);
768 symbol_name(elf_file_t ef, Elf_Word r_info)
772 if (ELF_R_SYM(r_info)) {
773 ref = ef->symtab + ELF_R_SYM(r_info);
774 return ef->strtab + ref->st_name;
780 relocate_file(linker_file_t lf)
782 elf_file_t ef = lf->priv;
783 const Elf_Rel *rellim;
785 const Elf_Rela *relalim;
786 const Elf_Rela *rela;
789 /* Perform relocations without addend if there are any: */
792 rellim = (const Elf_Rel *)((const char *)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);
803 /* Perform relocations with addend if there are any: */
806 relalim = (const Elf_Rela *)((const char *)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);
817 /* Perform PLT relocations without addend if there are any: */
820 rellim = (const Elf_Rel *)((const char *)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);
831 /* Perform relocations with addend if there are any: */
834 relalim = (const Elf_Rela *)((const char *)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);
849 * Hash function for symbol table lookup. Don't even think about changing
850 * this. It is specified by the System V ABI.
853 elf_hash(const char *name)
855 const unsigned char *p = (const unsigned char *) name;
861 if ((g = h & 0xf0000000) != 0)
869 link_elf_lookup_symbol(linker_file_t lf, const char* name, c_linker_sym_t* sym)
871 elf_file_t ef = lf->priv;
872 unsigned long symnum;
878 /* First, search hashed global symbols */
879 hash = elf_hash(name);
880 symnum = ef->buckets[hash % ef->nbuckets];
882 while (symnum != STN_UNDEF) {
883 if (symnum >= ef->nchains) {
884 printf("link_elf_lookup_symbol: corrupt symbol table\n");
888 symp = ef->symtab + symnum;
889 if (symp->st_name == 0) {
890 printf("link_elf_lookup_symbol: corrupt symbol table\n");
894 strp = ef->strtab + symp->st_name;
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 = (c_linker_sym_t) symp;
906 symnum = ef->chains[symnum];
909 /* If we have not found it, look at the full table (if loaded) */
910 if (ef->symtab == ef->ddbsymtab)
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 = (c_linker_sym_t) symp;
931 link_elf_symbol_values(linker_file_t lf, c_linker_sym_t sym, linker_symval_t* symval)
933 elf_file_t ef = lf->priv;
934 const Elf_Sym* es = (const Elf_Sym*) sym;
936 if (es >= ef->symtab && ((es - ef->symtab) < ef->nchains)) {
937 symval->name = ef->strtab + es->st_name;
938 symval->value = (caddr_t) ef->address + es->st_value;
939 symval->size = es->st_size;
942 if (ef->symtab == ef->ddbsymtab)
944 if (es >= ef->ddbsymtab && ((es - ef->ddbsymtab) < ef->ddbsymcnt)) {
945 symval->name = ef->ddbstrtab + es->st_name;
946 symval->value = (caddr_t) ef->address + es->st_value;
947 symval->size = es->st_size;
954 link_elf_search_symbol(linker_file_t lf, caddr_t value,
955 c_linker_sym_t* sym, long* diffp)
957 elf_file_t ef = lf->priv;
958 u_long off = (uintptr_t) (void *) value;
962 const Elf_Sym* best = 0;
965 for (i = 0, es = ef->ddbsymtab; i < ef->ddbsymcnt; i++, es++) {
966 if (es->st_name == 0)
968 st_value = es->st_value + (uintptr_t) (void *) ef->address;
969 if (off >= st_value) {
970 if (off - st_value < diff) {
971 diff = off - st_value;
975 } else if (off - st_value == diff) {
984 *sym = (c_linker_sym_t) best;