Deleted Added
full compact
link_elf.c (40397) link_elf.c (40435)
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.5 1998/10/13 09:27:00 peter Exp $
26 * $Id: link_elf.c,v 1.6 1998/10/15 17:16:24 peter 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>

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

766 }
767 }
768
769out:
770 return error;
771}
772
773static 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>

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

766 }
767 }
768
769out:
770 return error;
771}
772
773static const char *
774symbol_name(elf_file_t ef, const Elf_Rela *rela)
774symbol_name(elf_file_t ef, Elf_Word r_info)
775{
776 const Elf_Sym *ref;
777
775{
776 const Elf_Sym *ref;
777
778 if (ELF_R_SYM(rela->r_info)) {
779 ref = ef->symtab + ELF_R_SYM(rela->r_info);
778 if (ELF_R_SYM(r_info)) {
779 ref = ef->symtab + ELF_R_SYM(r_info);
780 return ef->strtab + ref->st_name;
781 } else
782 return NULL;
783}
784
785static int
786relocate_file(linker_file_t lf)
787{
788 elf_file_t ef = lf->priv;
789 const Elf_Rel *rellim;
790 const Elf_Rel *rel;
791 const Elf_Rela *relalim;
792 const Elf_Rela *rela;
780 return ef->strtab + ref->st_name;
781 } else
782 return NULL;
783}
784
785static int
786relocate_file(linker_file_t lf)
787{
788 elf_file_t ef = lf->priv;
789 const Elf_Rel *rellim;
790 const Elf_Rel *rel;
791 const Elf_Rela *relalim;
792 const Elf_Rela *rela;
793 const char *symname;
793
794 /* Perform relocations without addend if there are any: */
794
795 /* Perform relocations without addend if there are any: */
795 rellim = (const Elf_Rel *) ((caddr_t) ef->rel + ef->relsize);
796 for (rel = ef->rel; ef->rel != NULL && rel < rellim; rel++) {
797 Elf_Rela locrela;
798
799 locrela.r_info = rel->r_info;
800 locrela.r_offset = rel->r_offset;
801 locrela.r_addend = 0;
802 if (elf_reloc(lf, &locrela, symbol_name(ef, &locrela)))
803 return ENOENT;
796 rel = ef->rel;
797 if (rel) {
798 rellim = (const Elf_Rel *) ((caddr_t) ef->rel + ef->relsize);
799 while (rel < rellim) {
800 symname = symbol_name(ef, rel->r_info);
801 if (elf_reloc(lf, rel, ELF_RELOC_REL, symname))
802 return ENOENT;
803 rel++;
804 }
804 }
805
806 /* Perform relocations with addend if there are any: */
805 }
806
807 /* Perform relocations with addend if there are any: */
807 relalim = (const Elf_Rela *) ((caddr_t) ef->rela + ef->relasize);
808 for (rela = ef->rela; ef->rela != NULL && rela < relalim; rela++) {
809 if (elf_reloc(lf, rela, symbol_name(ef, rela)))
810 return ENOENT;
808 rela = ef->rela;
809 if (rela) {
810 relalim = (const Elf_Rela *) ((caddr_t) ef->rela + ef->relasize);
811 while (rela < relalim) {
812 symname = symbol_name(ef, rela->r_info);
813 if (elf_reloc(lf, rela, ELF_RELOC_RELA, symname))
814 return ENOENT;
815 rela++;
816 }
811 }
812
813 /* Perform PLT relocations without addend if there are any: */
817 }
818
819 /* Perform PLT relocations without addend if there are any: */
814 rellim = (const Elf_Rel *) ((caddr_t) ef->pltrel + ef->pltrelsize);
815 for (rel = ef->pltrel; ef->pltrel != NULL && rel < rellim; rel++) {
816 Elf_Rela locrela;
817
818 locrela.r_info = rel->r_info;
819 locrela.r_offset = rel->r_offset;
820 locrela.r_addend = 0;
821 if (elf_reloc(lf, &locrela, symbol_name(ef, &locrela)))
822 return ENOENT;
820 rel = ef->pltrel;
821 if (rel) {
822 rellim = (const Elf_Rel *) ((caddr_t) ef->pltrel + ef->pltrelsize);
823 while (rel < rellim) {
824 symname = symbol_name(ef, rel->r_info);
825 if (elf_reloc(lf, rel, ELF_RELOC_REL, symname))
826 return ENOENT;
827 rel++;
828 }
823 }
824
825 /* Perform relocations with addend if there are any: */
829 }
830
831 /* Perform relocations with addend if there are any: */
826 relalim = (const Elf_Rela *) ((caddr_t) ef->pltrela + ef->pltrelasize);
827 for (rela = ef->pltrela; ef->pltrela != NULL && rela < relalim; rela++) {
828 if (elf_reloc(lf, rela, symbol_name(ef, rela)))
829 return ENOENT;
832 rela = ef->pltrela;
833 if (rela) {
834 relalim = (const Elf_Rela *) ((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 return ENOENT;
839 rela++;
840 }
830 }
831
832 return 0;
833}
834
835/*
836 * Hash function for symbol table lookup. Don't even think about changing
837 * this. It is specified by the System V ABI.

--- 135 unchanged lines hidden ---
841 }
842
843 return 0;
844}
845
846/*
847 * Hash function for symbol table lookup. Don't even think about changing
848 * this. It is specified by the System V ABI.

--- 135 unchanged lines hidden ---