link_elf.c (59588a546f55523d6fd37ab42eb08b719311d7d6) link_elf.c (9d6ae1e3c26a0c3334a268b587f17dccb9a503d7)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 1998-2000 Doug Rabson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

44#include <sys/mount.h>
45#include <sys/pcpu.h>
46#include <sys/proc.h>
47#include <sys/namei.h>
48#include <sys/fcntl.h>
49#include <sys/vnode.h>
50#include <sys/linker.h>
51#include <sys/sysctl.h>
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 1998-2000 Doug Rabson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

44#include <sys/mount.h>
45#include <sys/pcpu.h>
46#include <sys/proc.h>
47#include <sys/namei.h>
48#include <sys/fcntl.h>
49#include <sys/vnode.h>
50#include <sys/linker.h>
51#include <sys/sysctl.h>
52#include <sys/tslog.h>
52
53#include <machine/elf.h>
54
55#include <net/vnet.h>
56
57#include <security/mac/mac_framework.h>
58
59#include <vm/vm.h>

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

1426static int
1427relocate_file1(elf_file_t ef, elf_lookup_fn lookup, elf_reloc_fn reloc,
1428 bool ifuncs)
1429{
1430 const Elf_Rel *rel;
1431 const Elf_Rela *rela;
1432 const char *symname;
1433
53
54#include <machine/elf.h>
55
56#include <net/vnet.h>
57
58#include <security/mac/mac_framework.h>
59
60#include <vm/vm.h>

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

1427static int
1428relocate_file1(elf_file_t ef, elf_lookup_fn lookup, elf_reloc_fn reloc,
1429 bool ifuncs)
1430{
1431 const Elf_Rel *rel;
1432 const Elf_Rela *rela;
1433 const char *symname;
1434
1435 TSENTER();
1434#define APPLY_RELOCS(iter, tbl, tblsize, type) do { \
1435 for ((iter) = (tbl); (iter) != NULL && \
1436 (iter) < (tbl) + (tblsize) / sizeof(*(iter)); (iter)++) { \
1437 if ((symbol_type(ef, (iter)->r_info) == \
1438 STT_GNU_IFUNC || \
1439 elf_is_ifunc_reloc((iter)->r_info)) != ifuncs) \
1440 continue; \
1441 if (reloc(&ef->lf, (Elf_Addr)ef->address, \
1442 (iter), (type), lookup)) { \
1443 symname = symbol_name(ef, (iter)->r_info); \
1444 printf("link_elf: symbol %s undefined\n", \
1445 symname); \
1446 return (ENOENT); \
1447 } \
1448 } \
1449} while (0)
1450
1451 APPLY_RELOCS(rel, ef->rel, ef->relsize, ELF_RELOC_REL);
1436#define APPLY_RELOCS(iter, tbl, tblsize, type) do { \
1437 for ((iter) = (tbl); (iter) != NULL && \
1438 (iter) < (tbl) + (tblsize) / sizeof(*(iter)); (iter)++) { \
1439 if ((symbol_type(ef, (iter)->r_info) == \
1440 STT_GNU_IFUNC || \
1441 elf_is_ifunc_reloc((iter)->r_info)) != ifuncs) \
1442 continue; \
1443 if (reloc(&ef->lf, (Elf_Addr)ef->address, \
1444 (iter), (type), lookup)) { \
1445 symname = symbol_name(ef, (iter)->r_info); \
1446 printf("link_elf: symbol %s undefined\n", \
1447 symname); \
1448 return (ENOENT); \
1449 } \
1450 } \
1451} while (0)
1452
1453 APPLY_RELOCS(rel, ef->rel, ef->relsize, ELF_RELOC_REL);
1454 TSENTER2("ef->rela");
1452 APPLY_RELOCS(rela, ef->rela, ef->relasize, ELF_RELOC_RELA);
1455 APPLY_RELOCS(rela, ef->rela, ef->relasize, ELF_RELOC_RELA);
1456 TSEXIT2("ef->rela");
1453 APPLY_RELOCS(rel, ef->pltrel, ef->pltrelsize, ELF_RELOC_REL);
1454 APPLY_RELOCS(rela, ef->pltrela, ef->pltrelasize, ELF_RELOC_RELA);
1455
1456#undef APPLY_RELOCS
1457
1457 APPLY_RELOCS(rel, ef->pltrel, ef->pltrelsize, ELF_RELOC_REL);
1458 APPLY_RELOCS(rela, ef->pltrela, ef->pltrelasize, ELF_RELOC_RELA);
1459
1460#undef APPLY_RELOCS
1461
1462 TSEXIT();
1458 return (0);
1459}
1460
1461static int
1462relocate_file(elf_file_t ef)
1463{
1464 int error;
1465

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

1945}
1946
1947void
1948link_elf_ireloc(caddr_t kmdp)
1949{
1950 struct elf_file eff;
1951 elf_file_t ef;
1952
1463 return (0);
1464}
1465
1466static int
1467relocate_file(elf_file_t ef)
1468{
1469 int error;
1470

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

1950}
1951
1952void
1953link_elf_ireloc(caddr_t kmdp)
1954{
1955 struct elf_file eff;
1956 elf_file_t ef;
1957
1958 TSENTER();
1953 ef = &eff;
1954
1955 bzero_early(ef, sizeof(*ef));
1956
1957 ef->modptr = kmdp;
1958 ef->dynamic = (Elf_Dyn *)&_DYNAMIC;
1959
1960#ifdef RELOCATABLE_KERNEL
1961 ef->address = (caddr_t) (__startkernel - KERNBASE);
1962#else
1963 ef->address = 0;
1964#endif
1965 parse_dynamic(ef);
1966
1967 link_elf_preload_parse_symbols(ef);
1968 relocate_file1(ef, elf_lookup_ifunc, elf_reloc, true);
1959 ef = &eff;
1960
1961 bzero_early(ef, sizeof(*ef));
1962
1963 ef->modptr = kmdp;
1964 ef->dynamic = (Elf_Dyn *)&_DYNAMIC;
1965
1966#ifdef RELOCATABLE_KERNEL
1967 ef->address = (caddr_t) (__startkernel - KERNBASE);
1968#else
1969 ef->address = 0;
1970#endif
1971 parse_dynamic(ef);
1972
1973 link_elf_preload_parse_symbols(ef);
1974 relocate_file1(ef, elf_lookup_ifunc, elf_reloc, true);
1975 TSEXIT();
1969}
1970
1971#if defined(__aarch64__) || defined(__amd64__)
1972void
1973link_elf_late_ireloc(void)
1974{
1975 elf_file_t ef;
1976
1977 KASSERT(linker_kernel_file != NULL,
1978 ("link_elf_late_ireloc: No kernel linker file found"));
1979 ef = (elf_file_t)linker_kernel_file;
1980
1981 relocate_file1(ef, elf_lookup_ifunc, elf_reloc_late, true);
1982}
1983#endif
1984#endif
1976}
1977
1978#if defined(__aarch64__) || defined(__amd64__)
1979void
1980link_elf_late_ireloc(void)
1981{
1982 elf_file_t ef;
1983
1984 KASSERT(linker_kernel_file != NULL,
1985 ("link_elf_late_ireloc: No kernel linker file found"));
1986 ef = (elf_file_t)linker_kernel_file;
1987
1988 relocate_file1(ef, elf_lookup_ifunc, elf_reloc_late, true);
1989}
1990#endif
1991#endif