aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/link_elf.c
Commit message (Collapse)AuthorAgeFilesLines
* linker: Improve handling of ifuncs when fetching symbol metadataMark Johnston2025-07-021-4/+34
| | | | | | | | | | | | | | | | | When looking up symbol values, we map ifunc symbols to the value returned by the resolver. However, the returned symbol size is still that of the resolver. Be consistent and provide the size of the implementation symbol as well. This fixes an inconsistency in dtrace's FBT provider, which enumerates all function symbols and disassembles their values, using the symbol size as the bound for the disassembly loop. In particular, for ifuncs, we were not creating return probes. Reviewed by: kib MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D50683
* sys: use globals for the ELF kernel and module type stringsAhmad Khalifa2025-01-241-3/+1
| | | | | | | | | | Initialize the globals with macros so we can use the same values in the loader. Also remove unnecessary "elfN module" checks. Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394
* sys: make the kernel metadata pointer globalAhmad Khalifa2025-01-241-14/+10
| | | | | | | | | | | | | | | | | The way we got the kernel metadata pointer was by calling preload_search_by_type with one of the following three: "elf kernel", "elf32 kernel" and "elf64 kernel". Which one(s) we used wasn't consistent though. Sometimes we would only try "elf kernel", and other times we would try one of the latter two if the first failed. However, the loader only ever sets "elf kernel" as the kernel type. Now, the kmdp is a global, preload_kmdp, and it's initialized using preload_initkmdp in machdep.c (or machdep_boot.c on arm/64). preload_initkmdp takes a single boolean argument that tells us whether not finding the kmdp is fatal or not. Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394
* kern linker: Don't invoke dtors without having invoked ctorsMark Johnston2024-03-311-2/+13
| | | | | | | | | | | | | | | | | | | I have a kernel module which fails to load because of an unrecognized relocation type. link_elf_load_file() fails before the module's ctors are invoked and it calls linker_file_unload(), which causes the module's dtors to be executed, resulting in a kernel panic. Add a flag to the linker file to ensure that dtors are not invoked if unloading due to an error prior to ctors being invoked. At the moment I only implemented this for link_elf_obj.c since link_elf.c doesn't invoke dtors, but I refactored link_elf.c to make them more similar. Fixes: 9e575fadf491 ("link_elf_obj: Invoke fini callbacks") Reviewed by: zlei, kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D44559
* Fix style nits in kern_linker.cBojan Novković2024-03-281-1/+0
| | | | | | Reported by: jrtc27 Fixes: c21bc6f3c242 ("ddb: Add CTF-based pretty printing") Approved by: markj (mentor)
* ddb: Add CTF-based pretty printingBojan Novković2024-03-221-0/+37
| | | | | | | | | | | | | | | | | | | | Add basic CTF support and a CTF-powered pretty-printer to ddb. The db_ctf.* files expose a basic interface for fetching type data for ELF symbols, interacting with the CTF string table, and translating type identifiers to type data. The db_pprint.c file uses those interfaces to implement a pretty-printer for all kernel ELF symbols. The pretty-printer works with symbol names and arbitrary addresses: pprint struct thread 0xffffffff8194ad90 Pretty-printing currently only works after the root filesystem gets mounted because the CTF info is not available during early boot. Differential Revision: https://reviews.freebsd.org/D37899 Approved by: markj (mentor)
* sys/kern: Remove a few sys/cdefs.h around some elf thingsWarner Losh2024-02-211-1/+0
| | | | | | | These sys/cdefs.h are no longer needed. Remove them in advance of other work in this area. Sponsored by: Netflix
* sysctl: Update 'master' copy of vnet SYSCTLs on kernel environment variables ↵Zhenlei Huang2023-09-211-0/+2
| | | | | | | | | | | | | | | | | | | | | | | change Complete phase three of 3da1cf1e88f8. With commit 110113bc086f, vnet sysctl variables can be loader tunable but the feature is limited. When the kernel modules have been initialized, any changes (e.g. via kenv) to kernel environment variable will not affect subsequently created VNETs. This change relexes the limitation by listening on kernel environment variable's set / unset events, and then update the 'master' copy of vnet SYSCTL or restore it to its initial value. With this change, TUNABLE_XXX_FETCH can be greately eliminated for vnet loader tunables. Reviewed by: glebius Fixes: 110113bc086f sysctl(9): Enable vnet sysctl variables to be loader tunable MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D41825
* kernel linker: Eliminate unneeded vnet propagationZhenlei Huang2023-09-091-1/+1
| | | | | | | | | | | | | | | The module preload happens before vnet0 creation, at this moment the vnet list is empty thus invoking vnet_data_copy() during preload is a noop. With recent change 110113bc086f, for dynamic module load, aka via kldload, linker will do vnet propagation right after registering sysctls which happens after module load, then previous propagation (during module load) is redundant. No functional change intended. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D39852
* sysctl(9): Enable vnet sysctl variables to be loader tunableZhenlei Huang2023-09-091-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Complete phase two of 3da1cf1e88f8. In 3da1cf1e88f8, the meaning of the flag CTLFLAG_TUN is extended to automatically check if there is a kernel environment variable which shall initialize the SYSCTL during early boot. It works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTLs which belong to VNETs. This change extends the meaning further, to allow it also works for the SYSCTLs which belong to VNETs. A typical usage is ``` VNET_DEFINE_STATIC(int, foo) = 0; SYSCTL_INT(_net, OID_AUTO, foo, CTLFLAG_RWTUN | CTLFLAG_VNET, &VNET_NAME(foo), 0, "Description of the foo loader tunable"); ``` Note that the implementation has a limitation. It behaves the same way as that of non-vnet loader tunables. That is, after the kernel or modules being initialized, any changes (e.g. via kenv) to kernel environment variable will not affect the corresponding vnet variable of subsequently created VNETs. To overcome it, we can use TUNABLE_XXX_FETCH to fetch the kernel environment variable into those vnet variables during vnet constructing. This change will fix the following SYSCTLs those belong to VNETs and have CTLFLAG_TUN flag: ``` net.add_addr_allfibs net.bpf.optimize_writers net.inet.tcp.fastopen.ccache_buckets net.link.bridge.inherit_mac net.link.bridge.ipfw_arp net.link.bridge.log_stp net.link.bridge.pfil_bridge net.link.bridge.pfil_local_phys net.link.bridge.pfil_member net.link.bridge.pfil_onlyip net.link.lagg.default_use_flowid net.link.lagg.default_use_numa net.link.lagg.default_flowid_shift net.link.lagg.lacp.debug net.link.lagg.lacp.default_strict_mode ``` Although the following vnet SYSCTLs have CTLFLAG_TUN flag, theirs values are re-fetched via TUNABLE_XXX_FETCH, thus are not affected by this change. ``` net.inet.ip.reass_hashsize net.inet.tcp.hostcache.cachelimit net.inet.tcp.hostcache.hashsize net.inet.tcp.hostcache.bucketlimit net.inet.tcp.syncache.bucketlimit net.inet.tcp.syncache.cachelimit net.inet.tcp.syncache.hashsize net.key.spdcache.maxentries net.key.spdcache.threshold ``` In memoriam: hselasky Discussed with: hselasky, glebius Fixes: 3da1cf1e88f8 Extend the meaning of the CTLFLAG_TUN flag ... MFC after: 2 weeks Relnotes: yes Differential Revision: https://reviews.freebsd.org/D39638
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Revert "Revert "tslog: Annotate some early boot functions""Colin Percival2023-06-051-0/+7
| | | | | | | | Now that <sys/tslog.h> is wrapped in #ifdef _KERNEL, it's safe to have tslog annotations in files which might be built from userland (i.e. in subr_boot.c, which is built as part of the boot loader). This reverts commit 59588a546f55523d6fd37ab42eb08b719311d7d6.
* Revert "tslog: Annotate some early boot functions"Colin Percival2023-06-041-7/+0
| | | | | | | | | | | | The change to subr_boot.c broke the libsa build because the TSLOG macros have their own definitions for the boot loader -- I didn't realize that the loader code used subr_boot.c. I'm currently testing a fix and I'll revert this revert once I'm satisfied that everything works, but I don't want to leave the tree broken for too long. This reverts commit 469cfa3c30ee7a5ddeb597d0a8c3e7cac909b27a.
* tslog: Annotate some early boot functionsColin Percival2023-06-041-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Booting an amd64 kernel on Firecracker with 1 CPU and 128 MB of RAM, hammer_time takes roughly 2740 us: * 55 us in xen_pvh_parse_preload_data * 20 us in boot_parse_cmdline_delim * 20 us in boot_env_to_howto * 15 us in identify_hypervisor * 1320 us in link_elf_reloc * 1310 us in relocate_file1 handling ef->rela * 25 us in init_param1 * 30 us in dpcpu_init * 355 us in initializecpu * 255 us in initializecpu calling load_cr4 * 425 us in getmemsize * 280 us in pmap_bootstrap * 205 us in create_pagetables * 10 us in init_param2 * 25 us in pci_early_quirks * 60 us in cninit * 90 us in kdb_init * 105 us in msgbufinit * 20 us in fpuinit * 205 us elsewhere in hammer_time Some of these are unavoidable (e.g. identify_hypervisor uses CPUID and load_cr4 loads the CR4 register, both of which trap to the hypervisor) but others may deserve attention. Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D40325
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* link_elf: fix SysV hash function overflowEd Maste2023-04-121-11/+8
| | | | | | | | | | | | | | | | | | | | | | Quoting from https://maskray.me/blog/2023-04-12-elf-hash-function: The System V Application Binary Interface (generic ABI) specifies the ELF object file format. When producing an output executable or shared object needing a dynamic symbol table (.dynsym), a linker generates a .hash section with type SHT_HASH to hold a symbol hash table. A DT_HASH tag is produced to hold the address of .hash. The function is supposed to return a value no larger than 0x0fffffff. Unfortunately, there is a bug. When unsigned long consists of more than 32 bits, the return value may be larger than UINT32_MAX. For instance, elf_hash((const unsigned char *)"\xff\x0f\x0f\x0f\x0f\x0f\x12") returns 0x100000002, which is clearly unintended, as the function should behave the same way regardless of whether long represents a 32-bit integer or a 64-bit integer. Reviewed by: kib, Fangrui Song Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39517
* Retire broken GPROF support from the kernelMateusz Guzik2022-11-151-11/+0
| | | | | | | | The option is not even recognized and with that patched it does not compile. Even if it did work, it would be prohibitively expensive to use. Interested parties can use pmcstat or dtrace instead.
* vfs: NDFREE(&nd, NDF_ONLY_PNBUF) -> NDFREE_PNBUF(&nd)Mateusz Guzik2022-03-241-1/+1
|
* Kernel linkers: add emergency sysctl to restore old behaviorKonstantin Belousov2021-12-081-0/+9
| | | | | | | | | | | | | allowing linking to static symbols from other files. Default the new settings to true, delaying the change of the kernel linker behavior for other day. Suggested by: emaste PR: 207898 Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32878
* kernel linker: do not read debug symbol tables for non-debug symbolsKonstantin Belousov2021-12-081-16/+63
| | | | | | | | | | | | | In particular, this prevents resolving locals from other files. To access debug symbol tables, add LINKER_LOOKUP_DEBUG_SYMBOL and LINKER_DEBUG_SYMBOL_VALUES kobj methods, which are allowed to use any types of present symbols in all tables. PR: 207898 Reviewed by: emaste, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32878
* vfs: remove the unused thread argument from NDINIT*Mateusz Guzik2021-11-251-1/+1
| | | | | | See b4a58fbf640409a1 ("vfs: remove cn_thread") Bump __FreeBSD_version to 1400043.
* Kernel linkers: some styleKonstantin Belousov2021-11-181-5/+5
| | | | | | | Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 3 days Differential revision: https://reviews.freebsd.org/D32878
* Add pmap_change_prot on arm64Andrew Turner2021-10-111-1/+1
| | | | | | | | | | Support changing the protection of preloaded kernel modules by implementing pmap_change_prot on arm64 and calling it from preload_protect. Reviewed by: alc (previous version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32026
* vm_map_protect: allow to set prot and max_prot in one go.Konstantin Belousov2021-01-121-1/+1
| | | | | | | | | | | | | | This prevents a situation where other thread modifies map entries permissions between setting max_prot, then relocking, then setting prot, confusing the operation outcome. E.g. you can get an error that is not possible if operation is performed atomic. Also enable setting rwx for max_prot even if map does not allow to set effective rwx protection. Reviewed by: brooks, markj (previous version) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28117
* malloc: delegate M_EXEC handling to dedicacted routinesMateusz Guzik2020-10-301-1/+1
| | | | | | | | | | | | It is almost never needed and adds an avoidable branch. While here do minior clean ups in preparation for larger changes. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D27019 Notes: svn path=/head/; revision=367186
* Convert allocations of the phys pager to vm_pager_allocate().Konstantin Belousov2020-09-081-1/+2
| | | | | | | | | | | | | | Future changes would require additional initialization of OBJT_PHYS objects, and vm_object_allocate() is not suitable for it. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24652 Notes: svn path=/head/; revision=365485
* kern: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-1/+0
| | | | Notes: svn path=/head/; revision=365222
* Rerun kernel ifunc resolvers after all CPUs have startedAndrew Turner2020-07-051-0/+14
| | | | | | | | | | | | | | | | | | | On architectures that use RELA relocations it is safe to rerun the ifunc resolvers on after all CPUs have started, but while they are sill parked. On arm64 with big.LITTLE this is needed as some SoCs have shipped with different ID register values the big and little clusters meaning we were unable to rely on the register values from the boot CPU. Add support for rerunning the resolvers on arm64 and amd64 as these are both RELA using architectures. Reviewed by: kib Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D25455 Notes: svn path=/head/; revision=362944
* [PowerPC] More relocation fixesBrandon Bergren2020-06-211-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It turns out relocating the symbol table itself can cause issues, like fbt crashing because it applies the offsets to the kernel twice. This had been previously brought up in rS333447 when the stoffs hack was added, but I had been unaware of this and reimplemented symtab relocation. Instead of relocating the symbol table, keep track of the relocation base in ddb, so the ddb symbols behave like the kernel linker-provided symbols. This is intended to be NFC on platforms other than PowerPC, which do not use fully relocatable kernels. (The relbase will always be 0) * Remove the rest of the stoffs hack. * Remove my half-baked displace_symbol_table() function. * Extend ddb initialization to cope with having a relocation offset on the kernel symbol table. * Fix my kernel-as-initrd hack to work with booke64 by using a temporary mapping to access the data. * Fix another instance of __powerpc__ that is actually RELOCATABLE_KERNEL. * Change the behavior or X_db_symbol_values to apply the relocation base when updating valp, to match link_elf_symbol_values() behavior. Reviewed by: jhibbits Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D25223 Notes: svn path=/head/; revision=362458
* [PowerPC] kernel ifunc support for powerpc*, fix ppc64 relocation oddities.Brandon Bergren2020-05-071-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a general cleanup of the relocatable kernel support on powerpc, needed to enable kernel ifuncs. * Fix some relocatable issues in the kernel linker, and change to using a RELOCATABLE_KERNEL #define instead of #ifdef __powerpc__ for parts that other platforms can use in the future if they wish to have ET_DYN kernels. * Get rid of the DB_STOFFS hack now that the kernel is relocated to the DMAP properly across the board on powerpc64. * Add powerpc64 and powerpc32 ifunc functionality. * Allow AIM64 virtual mode OF kernels to run from the DMAP like other AIM64 by implementing a virtual mode restart. This fixes the runtime address on PowerMac G5. * Fix symbol relocation problems on post-relocation kernels by relocating the symbol table. * Add an undocumented method for supplying kernel symbols on powernv and other powerpc machines using linux-style kernel/initrd loading -- If you pass the kernel in as the initrd as well, the copy resident in initrd will be used as a source for symbols when initializing the debugger. This method is subject to removal once we have a better way of doing this. Approved by: jhibbits Relnotes: yes Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D23156 Notes: svn path=/head/; revision=360794
* [PowerPC][Book-E] Fix missing load base in elf_cpu_parse_dynamic().Brandon Bergren2020-03-181-1/+1
| | | | | | | | | | | | | | | | | | | | | When I implemented MD DYNAMIC parsing, I was originally passing a linker_file_t so that the MD code could relocate pointers. However, it turns out this isn't even filled in until later, so it was always 0. Just pass the load base (ef->address) directly, as that's really the only thing we were interested in in the first place. This fixes a crash on RB800 where it was trying to write to an unmapped address when updating the GOT. Reviewed by: jhibbits Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D24105 Notes: svn path=/head/; revision=359062
* sys/kern: quiet -Wwrite-stringsRyan Libby2020-02-231-1/+1
| | | | | | | | | | | | Quiet a variety of Wwrite-strings warnings in sys/kern at low-impact sites. This patch avoids addressing certain others which would need to plumb const through structure definitions. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D23798 Notes: svn path=/head/; revision=358258
* Add SYSCTL to get KERNBASE and relocated KERNBASELeandro Lupori2020-02-051-0/+9
| | | | | | | | | | | | | | | | This change adds 2 new SYSCTLs, to retrieve the original and relocated KERNBASE values. This provides an easy, architecture independent way to calculate the running kernel displacement (current/load address minus original base address). The initial goal for this change is to add a new libkvm function that returns the kernel displacement, both for live kernels and crashdumps. This would in turn be used by kgdb to find out how to relocate kernel symbols (if needed). Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D23284 Notes: svn path=/head/; revision=357570
* Remove duplicated empty lines from kern/*.cMateusz Guzik2020-01-301-1/+0
| | | | | | | No functional changes. Notes: svn path=/head/; revision=357312
* vfs: drop the mostly unused flags argument from VOP_UNLOCKMateusz Guzik2020-01-031-2/+2
| | | | | | | | | | | Filesystems which want to use it in limited capacity can employ the VOP_UNLOCK_FLAGS macro. Reviewed by: kib (previous version) Differential Revision: https://reviews.freebsd.org/D21427 Notes: svn path=/head/; revision=356337
* [PowerPC] Implement Secure-PLT jump table processing for ppc32.Brandon Bergren2019-12-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Due to clang and LLD's tendency to use a PLT for builtins, and as they don't have full support for EABI, we sometimes have to deal with a PLT in .ko files in a clang-built kernel. As such, augment the in-kernel linker to support jump table processing. As there is no particular reason to support lazy binding in kernel modules, only implement Secure-PLT immediate binding. As part of these changes, add elf_cpu_parse_dynamic() to the MD API of the in-kernel linker (except on platforms that use raw object files.) The new function will allow MD code to act on MD tags in _DYNAMIC. Use this new function in the PowerPC MD code to ensure BSS-PLT modules using PLT will be rejected during insertion, and to poison the runtime resolver to ensure we get a clear panic reason if a call is made to the resolver. Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D22608 Notes: svn path=/head/; revision=356053
* Rewrite arm kernel stack unwind code to work when unwinding through modules.Ian Lepore2019-12-151-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | The arm kernel stack unwinder has apparently never been able to unwind when the path of execution leads through a kernel module. There was code that tried to handle modules by looking for the unwind data in them, but it did so by trying to find symbols which have never existed in arm kernel modules. That caused the unwind code to panic, and because part of panic handling calls into the unwind code, that just created a recursion loop. Locating the unwind data in a loaded module requires accessing the Elf section headers to find the SHT_ARM_EXIDX section. For preloaded modules those headers are present in a metadata blob. For dynamically loaded modules, the headers are present only while the loading is in progress; the memory is freed once the module is ready to use. For that reason, there is new code in kern/link_elf.c, wrapped in #ifdef __arm__, to extract the unwind info while the headers are loaded. The values are saved into new fields in the linker_file structure which are also conditional on __arm__. In arm/unwind.c there is new code to locally cache the per-module info needed to find the unwind tables. The local cache is crafted for lockless read access, because the unwind code often needs to run in context where sleeping is not allowed. A large comment block describes the local cache list, so I won't repeat it all here. Notes: svn path=/head/; revision=355780
* Apply mapping protections to preloaded kernel modules on amd64.Mark Johnston2019-10-181-2/+44
| | | | | | | | | | | | | | With an upcoming change the amd64 kernel will map preloaded files RW instead of RWX, so the kernel linker must adjust protections appropriately using pmap_change_prot(). Reviewed by: kib MFC after: 1 month Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D21860 Notes: svn path=/head/; revision=353730
* Use KOBJMETHOD_END in the kernel linker.Mark Johnston2019-10-161-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=353671
* Use OBJT_PHYS VM objects for kernel modules.Mark Johnston2019-10-021-1/+1
| | | | | | | | | | | | | OBJT_DEFAULT incurs some unnecessary overhead given that kernel module pages cannot be paged out. Reviewed by: alc, kib MFC after: 1 week Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D21862 Notes: svn path=/head/; revision=353014
* Fix some problems with the SPARSE_MAPPING option in the kernel linker.Mark Johnston2019-09-281-21/+66
| | | | | | | | | | | | | | | | | | - Ensure that the end of the mapping passed to vm_page_wire() is page-aligned. vm_page_wire() expects this. - Wire pages before reading data into them. - Apply protections specified in the segment descriptor using vm_map_protect() once relocation processing is done. - On amd64, ensure that we load KLDs above KERNBASE, since they are compiled with the "kernel" memory model by default. Reviewed by: kib MFC after: 2 weeks Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D21756 Notes: svn path=/head/; revision=352829
* Use elf_relocaddr() when handling R_X86_64_RELATIVE relocations.Mark Johnston2019-09-231-0/+3
| | | | | | | | | | | | | | This is required for DPCPU and VNET data variable definitions to work when KLDs are linked as DSOs. R_X86_64_RELATIVE relocations should not appear in object files, so assert this in elf_relocaddr(). Reviewed by: kib MFC after: 1 month Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D21755 Notes: svn path=/head/; revision=352623
* Convert DDB_CTF to use newer version of ZLIB.Xin LI2019-08-081-4/+0
| | | | | | | | | PR: 229763 Submitted by: Yoshihiro Ota <ota j email ne jp> Differential Revision: https://reviews.freebsd.org/D21176 Notes: svn path=/head/; revision=350744
* Fix dpcpu and vnet panics with complex types at the end of the section.Bjoern A. Zeeb2019-06-081-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Apply a linker script when linking i386 kernel modules to apply padding to a set_pcpu or set_vnet section. The padding value is kind-of random and is used to catch modules not compiled with the linker-script, so possibly still having problems leading to kernel panics. This is needed as the code generated on certain architectures for non-simple-types, e.g., an array can generate an absolute relocation on the edge (just outside) the section and thus will not be properly relocated. Adding the padding to the end of the section will ensure that even absolute relocations of complex types will be inside the section, if they are the last object in there and hence relocation will work properly and avoid panics such as observed with carp.ko or ipsec.ko. There is a rather lengthy discussion of various options to apply in the mentioned PRs and their depends/blocks, and the review. There seems no best solution working across multiple toolchains and multiple version of them, so I took the liberty of taking one, as currently our users (and our CI system) are hitting this on just i386 and we need some solution. I wish we would have a proper fix rather than another "hack". Also backout r340009 which manually, temporarily fixed CARP before 12.0-R "by chance" after a lead-up of various other link-elf.c and related fixes. PR: 230857,238012 With suggestions from: arichardson (originally last year) Tested by: lwhsu Event: Waterloo Hackathon 2019 Reported by: lwhsu, olivier MFC after: 6 weeks Differential Revision: https://reviews.freebsd.org/D17512 Notes: svn path=/head/; revision=348808
* As a follow-up to r339930 and various reports implement logging in caseBjoern A. Zeeb2018-10-301-2/+10
| | | | | | | | | | | | | | | | we fail during module load because the pcpu or vnet module sections are full. We did return a proper error but not leaving any indication to the user as to what the actual problem was. Even worse, on 12/13 currently we are seeing an unrelated error (ENOSYS instead of ENOSPC, which gets skipped over in kern_linker.c) to be printed which made problem diagnostics even harder. PR: 228854 MFC after: 3 days Notes: svn path=/head/; revision=339931
* In r78161 the lookup_set linker method was introduced which optionallyBjoern A. Zeeb2018-10-181-14/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | returns the section start and stop locations as well as a count if the caller asks for them. There was only one out-of-file consumer of count which did not actually use it and hence was eliminated in r339407. In r194784 parse_dpcpu(), and in r195699 parse_vnet() (a copy of the former) started to use the link_elf_lookup_set() interface internally also asking for the count. count is computed as the difference of the void **stop - void **start locations and as such, if the absoulte numbers (stop - start) % sizeof(void *) != 0 a round-down happens, e.g., **stop 0x1003 - **start 0x1000 => count 0. To get the section size instead of "count is the number of pointer elements in the section", the parse_*() functions do a count *= sizeof(void *). They use the result to allocate memory and copy the section data into the "master" and per-instance memory regions with a size of count. As a result of count possibly round-down this can miss the last bytes of the section. The good news is that we do not touch out of bounds memory during these operations (we may at a later stage if the last bytes would overflow the master sections). Given relocation in elf_relocaddr() works based on the absolute numbers of start and stop, this means that we can possibly try to access relocated data which was never copied and hence we get random garbage or at best zeroed memory. Stop the two (last) consumers of count (the parse_*() functions) from using count as well, and calculate the section size based on the absolute numbers of stop and start and use the proper size for the memory allocation and data copies. This will make the symbols in the last bytes of the pcpu or vnet sections be presented as expected. PR: 232289 Approved by: re (gjb) MFC after: 2 weeks Notes: svn path=/head/; revision=339431
* Provide string functions for use before ifuncs get resolved.Mateusz Guzik2018-10-111-5/+1
| | | | | | | | | | | | | | | The change is a no-op for architectures which don't ifunc memset, memcpy nor memmove. Convert places which need them. Xen bits by royger. Reviewed by: kib Approved by: re (gjb) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17487 Notes: svn path=/head/; revision=339321
* Add kernel ifunc support on arm64.Andrew Turner2018-10-011-1/+1
| | | | | | | | | | | | Tested with ifunc resolvers in the kernel and module with calls from kernel to kernel, module to kernel, and module to module. Reviewed by: kib (previous version) Approved by: re (gjb) Differential Revision: https://reviews.freebsd.org/D17370 Notes: svn path=/head/; revision=339074
* Prepare the kernel linker to handle PC-relative ifunc relocations.Mark Johnston2018-08-221-81/+71
| | | | | | | | | | | | | | | | | | | | | | The boot-time ifunc resolver assumes that it only needs to apply IRELATIVE relocations to PLT entries. With an upcoming optimization, this assumption no longer holds, so add the support required to handle PC-relative relocations targeting GNU_IFUNC symbols. - Provide a custom symbol lookup routine that can be used in early boot. The default lookup routine uses kobj, which is not functional at that point. - Apply all existing relocations during boot rather than filtering IRELATIVE relocations. - Ensure that we continue to apply ifunc relocations in a second pass when loading a kernel module. Reviewed by: kib MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D16749 Notes: svn path=/head/; revision=338211
* Provide the full module path to preload_delete_name().Mark Johnston2018-07-191-2/+2
| | | | | | | | | | | | | The basename will never match against the preload metadata, so these calls previously had no effect. Reviewed by: kib, royger MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D16330 Notes: svn path=/head/; revision=336504