History log of /src/sys/kern/link_elf_obj.c (Results 1 – 25 of 709)
Revision Date Author Comments
# 2ce028e8 04-Feb-2026 Olivier Certner <olce@FreeBSD.org>

sys: ELF: Rename SHN_FBSD_CACHED => SHN_FREEBSD_CACHED

All other FreeBSD-specific constants have FREEBSD fully spelled out in
their names. Be consistent.

No functional change (intended).

Reviewed

sys: ELF: Rename SHN_FBSD_CACHED => SHN_FREEBSD_CACHED

All other FreeBSD-specific constants have FREEBSD fully spelled out in
their names. Be consistent.

No functional change (intended).

Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D55224

show more ...


# 203e5a1e 06-Jan-2026 Mark Johnston <markj@FreeBSD.org>

linker: Reset DMAP protections in link_elf_unload_file()

On x86, when a preloaded kernel module is unloaded, we free the backing
(physically contiguous) pages. The ET_REL linker will have adjusted

linker: Reset DMAP protections in link_elf_unload_file()

On x86, when a preloaded kernel module is unloaded, we free the backing
(physically contiguous) pages. The ET_REL linker will have adjusted
protections on segments of the preloaded file, which updates the direct
map, so the original protections must be restored when unloading the
module.

Previously this was handled in kmem_bootstrap_free(), but there is no
apparent reason not to handle this within the kernel linker. Moreover,
we were not resetting permissions in the kernel map on arm64.

Reviewed by: alc, kib
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D54438

show more ...


# fad4c92b 25-Nov-2025 Ed Maste <emaste@FreeBSD.org>

Revert "kernel linker: Disable local sym resolution by default"

I've received a report of a failure from resolving kern_kmq_open.
Revert for now as we are currently in stabweek.

This reverts commit

Revert "kernel linker: Disable local sym resolution by default"

I've received a report of a failure from resolving kern_kmq_open.
Revert for now as we are currently in stabweek.

This reverts commit 9562994a7aacee2baae6ddee1a7b558b48ae39ef.

Reported by: mav

show more ...


# 9562994a 25-Nov-2024 Ed Maste <emaste@FreeBSD.org>

kernel linker: Disable local sym resolution by default

In 95c20faf11a1 and ecd8245e0d77 kib introduced support to have the
kernel linker stop resolving local symbols from other files, but did
not en

kernel linker: Disable local sym resolution by default

In 95c20faf11a1 and ecd8245e0d77 kib introduced support to have the
kernel linker stop resolving local symbols from other files, but did
not enable it by default to avoid surprises. Flip the default now,
before FreeBSD 16.0.

The debug.link_elf_leak_locals and debug.link_elf_obj_leak_locals
sysctls are available to revert to the previous behaviour if necessary.

PR: 207898
Reviewed by: bz
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47742

show more ...


# 07747afd 03-Oct-2025 Mark Johnston <markj@FreeBSD.org>

linker: Make it easier to find the VNET section layout

When trying to find the address of a VNET variable from a debugger, it
helps to have the original address of the VNET section. In particular,

linker: Make it easier to find the VNET section layout

When trying to find the address of a VNET variable from a debugger, it
helps to have the original address of the VNET section. In particular,
given the address of a vnet_entry_foo symbol, one wants to easily find
the linker file that the symbol belongs to.

In link_elf_obj.c, the section address for VNET and DPCPU sections is
overwritten in link_elf_link_preload() and link_elf_load_file(). Add an
"origaddr" field to store the original absolute address of the section
base.

In link_elf.c the elf_file_t already has the fields we want, but they
were not getting filled out for the kernel itself. Fix that too, since
that simplifies things for debuggers and improves consistency.

Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D52730

show more ...


# 79dea0c8 02-Jul-2025 Mark Johnston <markj@FreeBSD.org>

linker: Fix the ifunc symbol value calculation for ET_REL files

Reported by: cy
Fixes: aefae931820f ("linker: Improve handling of ifuncs when fetching symbol metadata")


# aefae931 02-Jul-2025 Mark Johnston <markj@FreeBSD.org>

linker: Improve handling of ifuncs when fetching symbol metadata

When looking up symbol values, we map ifunc symbols to the value
returned by the resolver. However, the returned symbol size is stil

linker: Improve handling of ifuncs when fetching symbol metadata

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

show more ...


# 4d213c59 24-Aug-2024 Ahmad Khalifa <ahmadkhalifa570@gmail.com>

sys: use globals for the ELF kernel and module type strings

Initialize the globals with macros so we can use the same values in the
loader.

Also remove unnecessary "elfN module" checks.

Reviewed b

sys: use globals for the ELF kernel and module type strings

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

show more ...


# 7ef5c19b 31-Mar-2024 Mark Johnston <markj@FreeBSD.org>

kern linker: Don't invoke dtors without having invoked ctors

I have a kernel module which fails to load because of an unrecognized
relocation type. link_elf_load_file() fails before the module's ct

kern linker: Don't invoke dtors without having invoked ctors

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

show more ...


# c21bc6f3 22-Mar-2024 Bojan Novković <bnovkov@FreeBSD.org>

ddb: Add CTF-based pretty printing

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 wit

ddb: Add CTF-based pretty printing

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)

show more ...


# eccde5f4 21-Feb-2024 Warner Losh <imp@FreeBSD.org>

sys/kern: Remove a few sys/cdefs.h around some elf things

These sys/cdefs.h are no longer needed. Remove them in advance of
other work in this area.

Sponsored by: Netflix


# cf7974fd 21-Sep-2023 Zhenlei Huang <zlei@FreeBSD.org>

sysctl: Update 'master' copy of vnet SYSCTLs on kernel environment variables change

Complete phase three of 3da1cf1e88f8.

With commit 110113bc086f, vnet sysctl variables can be loader tunable
but t

sysctl: Update 'master' copy of vnet SYSCTLs on kernel environment variables 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

show more ...


# 205821a7 09-Sep-2023 Zhenlei Huang <zlei@FreeBSD.org>

kernel linker: Eliminate unneeded vnet propagation

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.

W

kernel linker: Eliminate unneeded vnet propagation

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

show more ...


# 110113bc 09-Sep-2023 Zhenlei Huang <zlei@FreeBSD.org>

sysctl(9): Enable vnet sysctl variables to be loader tunable

Complete phase two of 3da1cf1e88f8.

In 3da1cf1e88f8, the meaning of the flag CTLFLAG_TUN is extended to
automatically check if there is

sysctl(9): Enable vnet sysctl variables to be loader tunable

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

show more ...


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

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

show more ...


# bb92cd7b 24-Mar-2022 Mateusz Guzik <mjg@FreeBSD.org>

vfs: NDFREE(&nd, NDF_ONLY_PNBUF) -> NDFREE_PNBUF(&nd)


# ecd8245e 07-Nov-2021 Konstantin Belousov <kib@FreeBSD.org>

Kernel linkers: add emergency sysctl to restore old behavior

allowing linking to static symbols from other files. Default the new
settings to true, delaying the change of the kernel linker behavior

Kernel linkers: add emergency sysctl to restore old behavior

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

show more ...


# 95c20faf 07-Nov-2021 Konstantin Belousov <kib@FreeBSD.org>

kernel linker: do not read debug symbol tables for non-debug symbols

In particular, this prevents resolving locals from other files.
To access debug symbol tables, add LINKER_LOOKUP_DEBUG_SYMBOL and

kernel linker: do not read debug symbol tables for non-debug symbols

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

show more ...


# c37c6f99 08-Dec-2021 Konstantin Belousov <kib@FreeBSD.org>

Style

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D32878


# 7e1d3eef 25-Nov-2021 Mateusz Guzik <mjg@FreeBSD.org>

vfs: remove the unused thread argument from NDINIT*

See b4a58fbf640409a1 ("vfs: remove cn_thread")

Bump __FreeBSD_version to 1400043.


# b11e6fd7 25-Nov-2021 Mark Johnston <markj@FreeBSD.org>

link_elf_obj: Process global ifunc relocs after other global relocs

This is needed to ensure that resolvers that reference global symbols
return correct results.

Reviewed by: kib
MFC after: 1 week

link_elf_obj: Process global ifunc relocs after other global relocs

This is needed to ensure that resolvers that reference global symbols
return correct results.

Reviewed by: kib
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33120

show more ...


# a7e4eb14 07-Nov-2021 Konstantin Belousov <kib@FreeBSD.org>

Kernel linkers: some style

Reviewed by: emaste
Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Differential revision: https://reviews.freebsd.org/D32878


# 9e575fad 29-Jul-2021 Mark Johnston <markj@FreeBSD.org>

link_elf_obj: Invoke fini callbacks

This is required for KASAN: when a module is unloaded, poisoned regions
(e.g., pad areas between global variables) are left as such, so if they
are reused as KLDs

link_elf_obj: Invoke fini callbacks

This is required for KASAN: when a module is unloaded, poisoned regions
(e.g., pad areas between global variables) are left as such, so if they
are reused as KLDs are loaded, false positives can arise.

Reported by: pho, Jenkins
Reviewed by: kib
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31339

show more ...


# 4aa157dd 16-Mar-2021 Mark Johnston <markjdb@gmail.com>

link_elf_obj: Add a case missing from 5e6989ba4f26

Fixes: 5e6989ba4f26
MFC after: 3 days
Sponsored by: The FreeBSD Foundation


12345678910>>...29