link_elf.c (f822c9e287b88ce01e9c3816700eb7940a2ddc69) link_elf.c (b19c9dea3ec011ea419f91b5489f0572c2169ca5)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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

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

768 break;
769 }
770 return (error);
771#else
772 return (0);
773#endif
774}
775
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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

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

768 break;
769 }
770 return (error);
771#else
772 return (0);
773#endif
774}
775
776#ifdef __arm__
777/*
778 * Locate the ARM exception/unwind table info for DDB and stack(9) use by
779 * searching for the section header that describes it. There may be no unwind
780 * info, for example in a module containing only data.
781 */
782static void
783link_elf_locate_exidx(linker_file_t lf, Elf_Shdr *shdr, int nhdr)
784{
785 int i;
786
787 for (i = 0; i < nhdr; i++) {
788 if (shdr[i].sh_type == SHT_ARM_EXIDX) {
789 lf->exidx_addr = shdr[i].sh_addr + lf->address;
790 lf->exidx_size = shdr[i].sh_size;
791 break;
792 }
793 }
794}
795
796/*
797 * Locate the section headers metadata in a preloaded module, then use it to
798 * locate the exception/unwind table in the module. The size of the metadata
799 * block is stored in a uint32 word immediately before the data itself, and a
800 * comment in preload_search_info() says it is safe to rely on that.
801 */
802static void
803link_elf_locate_exidx_preload(struct linker_file *lf, caddr_t modptr)
804{
805 uint32_t *modinfo;
806 Elf_Shdr *shdr;
807 uint32_t nhdr;
808
809 modinfo = (uint32_t *)preload_search_info(modptr,
810 MODINFO_METADATA | MODINFOMD_SHDR);
811 if (modinfo != NULL) {
812 shdr = (Elf_Shdr *)modinfo;
813 nhdr = modinfo[-1] / sizeof(Elf_Shdr);
814 link_elf_locate_exidx(lf, shdr, nhdr);
815 }
816}
817
818#endif /* __arm__ */
819
776static int
777link_elf_link_preload(linker_class_t cls, const char *filename,
778 linker_file_t *result)
779{
780 Elf_Addr *ctors_addrp;
781 Elf_Size *ctors_sizep;
782 caddr_t modptr, baseptr, sizeptr, dynptr;
783 char *type;

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

823 MODINFO_METADATA | MODINFOMD_CTORS_ADDR);
824 ctors_sizep = (Elf_Size *)preload_search_info(modptr,
825 MODINFO_METADATA | MODINFOMD_CTORS_SIZE);
826 if (ctors_addrp != NULL && ctors_sizep != NULL) {
827 lf->ctors_addr = ef->address + *ctors_addrp;
828 lf->ctors_size = *ctors_sizep;
829 }
830
820static int
821link_elf_link_preload(linker_class_t cls, const char *filename,
822 linker_file_t *result)
823{
824 Elf_Addr *ctors_addrp;
825 Elf_Size *ctors_sizep;
826 caddr_t modptr, baseptr, sizeptr, dynptr;
827 char *type;

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

867 MODINFO_METADATA | MODINFOMD_CTORS_ADDR);
868 ctors_sizep = (Elf_Size *)preload_search_info(modptr,
869 MODINFO_METADATA | MODINFOMD_CTORS_SIZE);
870 if (ctors_addrp != NULL && ctors_sizep != NULL) {
871 lf->ctors_addr = ef->address + *ctors_addrp;
872 lf->ctors_size = *ctors_sizep;
873 }
874
875#ifdef __arm__
876 link_elf_locate_exidx_preload(lf, modptr);
877#endif
878
831 error = parse_dynamic(ef);
832 if (error == 0)
833 error = parse_dpcpu(ef);
834#ifdef VIMAGE
835 if (error == 0)
836 error = parse_vnet(ef);
837#endif
838 if (error == 0)

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

1220 goto out;
1221
1222 ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
1223 ef->ddbsymtab = (const Elf_Sym *)ef->symbase;
1224 ef->ddbstrcnt = strcnt;
1225 ef->ddbstrtab = ef->strbase;
1226
1227nosyms:
879 error = parse_dynamic(ef);
880 if (error == 0)
881 error = parse_dpcpu(ef);
882#ifdef VIMAGE
883 if (error == 0)
884 error = parse_vnet(ef);
885#endif
886 if (error == 0)

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

1268 goto out;
1269
1270 ef->ddbsymcnt = symcnt / sizeof(Elf_Sym);
1271 ef->ddbsymtab = (const Elf_Sym *)ef->symbase;
1272 ef->ddbstrcnt = strcnt;
1273 ef->ddbstrtab = ef->strbase;
1274
1275nosyms:
1276
1277#ifdef __arm__
1278 link_elf_locate_exidx(lf, shdr, hdr->e_shnum);
1279#endif
1280
1228 error = link_elf_link_common_finish(lf);
1229 if (error != 0)
1230 goto out;
1231
1232 *result = lf;
1233
1234out:
1235 VOP_UNLOCK(nd.ni_vp, 0);

--- 608 unchanged lines hidden ---
1281 error = link_elf_link_common_finish(lf);
1282 if (error != 0)
1283 goto out;
1284
1285 *result = lf;
1286
1287out:
1288 VOP_UNLOCK(nd.ni_vp, 0);

--- 608 unchanged lines hidden ---