mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
* dmabuf: export RM video memory by handle
NV_ESC_EXPORT_TO_DMABUF_FD (0xd9) only exported a raw BAR1 range, for
CAP_SYS_ADMIN, ignoring the RM handles in the request. Implement the
stock ABI (nv_ioctl_export_to_dma_buf_fd_t, 2608 bytes):
- resolve each (hClient, hMemory, offset, size) to its VRAM with
nv_rs_rmapi_resolve_dmabuf_object(), authorized like the original:
the client belongs to the caller's file or its control file
(CAP_SYS_ADMIN may export any);
- a non-contiguous allocation (scatter_id != 0) is walked segment by
segment, each piece of the requested range becoming its own BAR1
extent, so an export never covers the VRAM between two segments;
- up to 128 objects per call, batched calls (index > 0) for larger
VMM exports, contiguous extents coalesced, segments capped at 1 GiB,
at most 2^20 extents per dma-buf; its kernel memory (pins, extents)
grows with the objects appended, not the declared total, and is
charged to the caller's memory cgroup;
- the dma-buf is BAR1-backed (the GA10x BAR1 maps VRAM 1:1), mapped for
importers with dma_map_resource(); bAllowMmap allows a write-combined
CPU mmap, shared only (a private, copy-on-write mapping of PFN-mapped
memory is refused: vmf_insert_pfn() BUG()s on one). The raw BAR1
export stays for h_client == 0 (admin only);
- only GSP-RM GPUs export: their BAR1 maps VRAM 1:1 for as long as the
GPU is in the RM. A pre-GSP GPU's BAR1 window belongs to the runtime
engines, which clear it when they stop (suspend, AER) while an export
would keep its offsets, so those GPUs refuse (NV_ERR_NOT_SUPPORTED);
- the fd is reserved, and installed only once the reply carrying it has
been copied to the caller: a reply that does not arrive leaves no fd,
and no pin, behind (the raw BAR1 export included).
A dma-buf must not outlive its memory: once the VRAM is freed it can be
handed to another allocation, and a peer still DMAing into the old
range would write into it. The dma-buf therefore holds the memory, as
the stock driver's exports do. Each exported object's backing is pinned
in the RM memory table (Table::pin_export, the reference the FD exports
already take), and every route that frees memory honours it:
NV_ESC_RM_FREE, NVOS32_FUNCTION_FREE (NV_ESC_RM_VID_HEAP_CONTROL),
freeing a parent or the whole client, file release, and channel USERD
orphan cleanup drop the handle but leave the VRAM, and a non-contiguous
allocation's segment chain, allocated while a pin exists. (The orphan
cleanup released a segment chain without that check; it now has it.)
When the dma-buf is released, a work item drops its pins under the RM
API lock and frees whatever nothing else references; a dma-buf can be
released with that lock held, so its release callback does not take it.
Module unload flushes the work item. Exports resolve their handles and
take their pins under the same lock, so a concurrent free either runs
first, and the export fails, or finds the pin.
Only GPU removal still revokes, as the memory goes away regardless.
It first marks the device as going away: from then until the GPU has
left the RM no dma-buf is created over it (the check and the insertion
into the export list are under one lock hold, so an export is either
listed or refused). Before taking the RM API lock, so that RM calls do
not wait behind the importers, every dma-buf over the device is first
marked revoked (attach, map and mmap then fail with -ENODEV) and its
CPU mappings are zapped; then its importers' mappings are invalidated
(dma_buf_invalidate_mappings), those whose reservation object is free
first; only then are the two waits the kernel-doc asks for done for
each: until the fences on the reservation object retire, and until
every importer mapping has been unmapped. An importer slow to retire
its fences, or holding a reservation object, thus leaves no other
dma-buf readable. A dma-buf whose last reference is already going is
waited for until its release has queued its pins, which are then
flushed, so none is dropped after the GPU is gone. Then,
under the lock and before the GPU leaves the RM, the pins are dropped;
nothing waits there. The CPU zap is unmap_mapping_range(); CPU mappings
are filled in at fault time
(vmf_insert_pfn after checking `revoked` under the dma-buf's lock), not
in .mmap, because the kernel links a new VMA into the file's i_mmap
only after .mmap returns and pages inserted there could escape a racing
zap. After a revoke a CPU access gets SIGBUS.
Only importers that can honour a revoke may attach: peer-to-peer
capable (allow_peer2peer, the scatterlist has BAR1 bus addresses and no
struct pages) and revocable (dma_buf_attach_revocable(): they
invalidate and unmap in bounded time). The NVMe dma-buf I/O path is
both. Kernels without dma_buf_attach_revocable() have no such contract
(move_notify only asks importers to remap as soon as possible), so
there the dma-buf has no importers, only the CPU mmap. The exporter is
dynamic (pin/unpin, a no-op: BAR1 memory never moves), so that no
kernel caches an importer's mapping at attach time, where its unmap
would not reach the exporter.
Built against 7.4 only. dma_buf_attach_revocable(), the
invalidate_mappings rename and enum dma_resv_usage are probed in Kbuild
with fallbacks for older kernels, which have not been compiled.
Tested on an RTX 3050 Laptop (GA107), on a 7.4-rc2 kernel with KASAN
and lockdep, IOMMU in identity mode, with io_uring + NVMe dma-buf reads,
through the export by CUDA address added later in this series. That
shares the dma-buf creation, mapping, pinning and release code with
this ioctl but not its handle loop: libcuda does not issue
NV_ESC_EXPORT_TO_DMABUF_FD on this GPU, so multi-object and batched
exports have not run on hardware. NVMe -> VRAM reads were verified
byte for byte. With the memory freed (cuMemFree, cuMemRelease) while
128 reads were queued, or at points in the middle of a stream, every
read completed without error, and the freed VRAM was not reused: a new
allocation filled before the free stayed untouched. The VRAM stays
allocated while the dma-buf is open (free VRAM did not come back after
the RM free) and is returned when it is closed. A dma-buf whose
exporter exited keeps working, and killing a reader mid-I/O tears it
down. No KASAN or lockdep report. GPU removal (the remaining revoke)
is run on hardware by the test added in the third commit.
These runs used the gpu-prio `preempt 0` policy: on this GPU, master's
default CILP/GFXP preemption policy makes cuCtxCreate fail before any
export (the second channel's compute object allocation returns
NV_ERR_INSUFFICIENT_RESOURCES), with or without this series.
* gsp_route: answer GPU_GET_INFO DMABUF_CAPABILITY as kernel RM does
NV2080_CTRL_GPU_INFO_INDEX_DMABUF_CAPABILITY (0x3d) is answered by
NVIDIA's kernel-side RM, not by GSP-RM: subdevice_ctrl_gpu_kernel.c
returns YES when osDmabufIsSupported(). GSP-RM has no dma-buf and
answers NO, and the GA10x routing passed that through. nvdriver exports
dma-bufs itself (NV_ESC_EXPORT_TO_DMABUF_FD), so answer YES like the
kernel-side RM, on every path that answers the index: GSP-RM's V2
reply, the V2 reply a V1 GET_INFO is translated to, an R620-sized V2
query translated to 580 batches, and nvdriver's native GET_INFO_V2
table.
libcuda 580.178.04 queries this index, but on a GeForce laptop GPU it
still reports CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED=0 afterwards and
never issues the export ioctl: its decision depends on more than this
answer. This only makes the answer correct.
* uvm: export a CUDA allocation as a dma-buf by GPU address
libcuda only exports a dma-buf through cuMemGetHandleForAddressRange,
and on GPUs it reports CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED=0 for (a
GeForce RTX 3050 Laptop here) it refuses in user space with
CUDA_ERROR_NOT_SUPPORTED, before asking the kernel. The RM handles that
NV_ESC_EXPORT_TO_DMABUF_FD needs live inside libcuda, so an application
cannot call the ioctl itself.
The UVM node knows them: UVM_MAP_EXTERNAL_ALLOCATION maps (hClient,
hMemory, offset) at a GPU virtual address. Record them in each
ExternalMap (and carry them through uvm_ext_gpu_map_split, the piece
after a hole moving its offset along), and add an nvidia_rs ioctl on
the process's own /dev/nvidia-uvm VA-space fd:
NV_RS_UVM_EXPORT_DMABUF (0x4e520001)
{ u64 va; u64 size; u32 flags; s32 fd; u32 status; s32 rm_fd; }
[va, va + size) must be page aligned and lie inside one external
mapping; flags bit 0 allows a (shared) CPU mmap. The range resolves to
its RM memory and goes through the same export as
NV_ESC_EXPORT_TO_DMABUF_FD (nv_rs_rmapi_export_dmabuf_object(), a single
extent), so it gets the same lifetime (the dma-buf pins the memory)
and the same authorization: the memory's client must belong to rm_fd,
an RM file the caller holds (or to its control file), the way UVM's
rmCtrlFd names it. The UVM mapping is
not enough on its own: UVM_MAP_EXTERNAL_ALLOCATION also accepts objects
shared through NV_ESC_RM_SHARE, which this export does not. If GPUs'
mappings of the range name different memory, the address is ambiguous
and refused. The lookup takes only the UVM lock (it reads this file's VA
space); the export then resolves the memory again under the RM API lock,
so a mapping changed in between exports memory the caller still owns, or
fails. As for NV_ESC_EXPORT_TO_DMABUF_FD, the fd is installed only once
the reply has been copied out.
tools/nv_rs_dmabuf.h wraps it (nv_rs_export_dmabuf(ptr, size, flags,
&status) finds the UVM and RM fds in /proc/self/fd); tools/
cuda_dmabuf_uvm_export_test.c checks that the dma-buf is the
allocation's VRAM (CPU mmap reads what cuMemcpyHtoD wrote and
cuMemcpyDtoH reads what it wrote, whole and for a sub-range), that bad
ranges and private mmaps are refused, that an export whose reply cannot
be copied back leaves no fd, and that the dma-buf keeps a
freed cuMemMap allocation: an existing CPU mapping still reads its
data, and writes through it never reach a new allocation.
On the RTX 3050 Laptop with io_uring + NVMe dma-buf reads (block layer
support from the io_uring dma-buf series in 7.4; ext4 needs out-of-tree
patches, device-mapper is refused), NVMe reads land in VRAM at the speed
they land in host memory on a Gen3 x4 drive (3.2 GB/s), and at ~75% of
it from a Gen4 x4 drive on another root port (5.1 vs 6.8 GB/s).
tools/dmabuf_unbind_race_test.py (run by tools/dmabuf_unbind_race_run.sh)
exercises the GPU-removal revoke from commit 1 through this export: it
unbinds nvidia_rs from the GPU while an io_uring reader keeps 32 NVMe
reads in flight into an exported buffer, another export carries an
unsignaled sw_sync write fence (signaled HOLD seconds into the unbind),
an RM-call loop runs, and an export loop runs. Its io_uring side is fastsafetensors' io_uring
dma-buf layer (IoUring); the export is its own, the ioctl of
tools/nv_rs_dmabuf.h. The reader exports after the
fenced buffer, so the revoke meets the fence first. On the RTX 3050
Laptop with a 5 s hold (three runs), exports were refused from 9-29 ms
into the unbind, every in-flight read completed with -ENODEV by
24-51 ms (the fenced buffer did not keep the reader's readable), RM
calls kept completing without a failure (slowest call 182 ms) while the revoke waited
for the fence, and the GPU teardown under the RM API lock started right
after the fence was signaled. Lockdep stayed on through the run, with no
KASAN or lockdep report.
---------
Co-authored-by: Arsenova <arsenova@a7snv.com>
16 KiB
16 KiB
Kernel-version compat guards
Conditional compile guards and version-independent stock-parity patterns in the kernel-open C shims for Linux 5.15 through 7.3+.
Stock-parity version-independent patterns
Where stock NVIDIA 580.178.04 avoids #if LINUX_VERSION_CODE guards altogether, we mirror stock directly:
.llseekomitted (NULL) acrossdiagnostic.c,gpu_owner.c,uvm_node.c, andrmapi_node.c(×2): matches stocknvidia_fops(nv.c:227) anduvm_fops(uvm.c:1076). Returns-ESPIPEon every kernel version (5.15–7.3+) without referencing the removedno_llseekmacro (gone in v6.12).container_of()forstruct timer_listinnano_timer_adapter.c: matches stockcommon/inc/nv-timer.h:39and works on every kernel version withoutfrom_timer/timer_container_of(v6.16) guards.#if defined(MAX_PAGE_ORDER)inrom_fw_adapter.c: matches stockcommon/inc/nv-linux.h:335(order > MAX_PAGE_ORDERon ≥6.8,order >= MAX_ORDERon older kernels and distro backports).
Version guards
| Symbol | Boundary | Site |
|---|---|---|
vma->vm_flags const (vm_flags_set/vm_flags_clear) |
6.3 (or RHEL_RELEASE_CODE) |
rmapi_node.c ×4, uvm_node.c ×1, nvidia_rs_drm.c ×2 |
PCI_IRQ_LEGACY → PCI_IRQ_INTX |
#ifndef PCI_IRQ_INTX (6.10 & RHEL 9.8) |
irq_adapter.c ×2 (via NV_RS_PCI_IRQ_INTX) |
MODULE_IMPORT_NS (DMA_BUF / "DMA_BUF") |
5.16 / RHEL_RELEASE_CODE (ident), 6.13 (string) |
dmabuf_p2p.c, nvidia_rs_drm.c |
hrtimer_init → hrtimer_setup |
6.15 | nano_timer_adapter.c |
class_create(owner, name) → class_create(name); class.devnode const struct device * |
declarations in device/class.h (6.4 / 6.2; RHEL 9 backports both to 5.14) |
rmapi_node.c (via NV_RS_CLASS_CREATE_NO_OWNER / NV_RS_CLASS_DEVNODE_CONST_DEV from kernel-open/compat_probes.mk) |
fb_is_primary_device() → video_is_primary_device() in <asm/video.h> |
declaration in asm/video.h (6.9); before it vga_default_device() |
ga10x_adapter.c (via NV_RS_HAVE_VIDEO_IS_PRIMARY_DEVICE from kernel-open/Kbuild) |
pci_resize_resource(..., exclude_bars) |
declaration in pci.h (6.19, backported to 6.18 stable), else 6.19 / UTS_UBUNTU_RELEASE_ABI |
pci_adapter.c ×2 (via NV_RS_PCI_RESIZE_EXCLUDE_BARS from kernel-open/Kbuild) |
drm_driver.date (field removed) |
6.14 | nvidia-drm/nvidia_rs_drm.c |
<linux/aperture.h> vs <drm/drm_aperture.h> (aperture_remove_conflicting_pci_devices) |
6.2 | nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_LINUX_APERTURE_H / NV_RS_HAVE_DRM_APERTURE_H) |
drm_client_setup (<drm/clients/drm_client_setup.h> / <drm/drm_client_setup.h> vs drm_fbdev_ttm_setup / drm_fbdev_generic_setup) |
6.12 / 6.13 | nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_CLIENTS_CLIENT_SETUP_H, etc.) |
drm_mode_config_funcs.fb_create & drm_helper_mode_fill_fb_struct info parameter |
6.17 | nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_FB_CREATE_FORMAT_INFO) |
drm_gem_object_funcs.vmap struct iosys_map / <linux/iosys-map.h> |
5.18 | nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_IOSYS_MAP / NV_RS_HAVE_LINUX_IOSYS_MAP_H) |
struct drm_atomic_state → struct drm_atomic_commit in the plane / CRTC atomic helper callbacks |
definition in drm_atomic.h (seen in 7.3) |
nvidia-drm/nvidia_rs_drm.c ×5 (via NV_RS_HAVE_DRM_ATOMIC_COMMIT from kernel-open/compat_probes.mk) |
drm_edid_read_custom / drm_edid_connector_add_modes |
6.3 | nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DRM_EDID_READ_CUSTOM) |
pin_user_pages(..., vmas) → without vmas |
declaration in mm.h (6.5), as stock's NV_PIN_USER_PAGES_HAS_ARGS_VMAS |
rmapi_node.c (via NV_RS_PIN_USER_PAGES_HAS_VMAS from kernel-open/compat_probes.mk) |
MAX_ORDER → MAX_PAGE_ORDER |
#if defined(MAX_PAGE_ORDER) (6.8) |
rmapi_node.c, rom_fw_adapter.c |
dma_resv_reserve_shared / dma_resv_add_{shared,excl}_fence → dma_resv_reserve_fences / dma_resv_add_fence |
declarations in dma-resv.h (5.19; Ubuntu 5.15 backported dma_resv_reserve_fences independently) |
nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DMA_RESV_RESERVE_FENCES / NV_RS_HAVE_DMA_RESV_ADD_FENCE from kernel-open/compat_probes.mk) |
dma_fence_ops.use_64bit_seqno → dma_fence_init64 |
declaration in dma-fence.h (6.17) |
nvidia-drm/nvidia_rs_drm.c (via NV_RS_HAVE_DMA_FENCE_INIT64 from kernel-open/compat_probes.mk) |
DRM_PLANE_HELPER_NO_SCALING → DRM_PLANE_NO_SCALING |
#ifndef DRM_PLANE_NO_SCALING (6.1) |
nvidia-drm/nvidia_rs_drm.c |
platform_driver.remove (int → void) |
6.11 | nvidia/platform_driver.c |
struct file::f_count → f_ref / file_ref_get() |
6.13 (or NV_RS_HAVE_FILE_REF from kernel-open/compat_probes.mk for distro backports) |
nvidia/rmapi_plat_io.h |
dma_buf_move_notify → dma_buf_invalidate_mappings |
declaration in dma-buf.h (7.x) |
dmabuf_p2p.c (via NV_RS_HAVE_DMABUF_INVALIDATE_MAPPINGS from kernel-open/compat_probes.mk) |
file->f_count → get_file_active() |
declaration in fs.h (6.8+, required on 6.12+ file_ref_t f_ref) |
dmabuf_p2p.c (via NV_RS_HAVE_GET_FILE_ACTIVE from kernel-open/compat_probes.mk) |
dma_buf_attach_revocable() (without it importers cannot attach: CPU mmap only) |
declaration in dma-buf.h (7.x) |
dmabuf_p2p.c (via NV_RS_HAVE_DMABUF_ATTACH_REVOCABLE from kernel-open/compat_probes.mk) |
dma_resv_wait_timeout(obj, bool wait_all, …) → (obj, enum dma_resv_usage, …) |
enum dma_resv_usage in dma-resv.h (5.19) |
dmabuf_p2p.c (via NV_RS_HAVE_DMA_RESV_USAGE from kernel-open/compat_probes.mk) |
- Host-fixture builds (
NV_RS_*_HOST_FIXTURE) do not pull<linux/version.h>.tests/irq-mock/irq_mock.handtests/rom-fw-mock/rom_fw_mock.hdefineLINUX_VERSION_CODE 0andKERNEL_VERSION(a,b,c)so the guards preprocess cleanly on the host-fixture side.
ENDBR / IBT (CONFIG_X86_KERNEL_IBT=y + CONFIG_OBJTOOL_WERROR=y)
- Stock
nv-kernel.o_binaryemitsendbr64(f3 0f 1e fa) at indirect-call/vtable entries and omits it on direct-only internal functions. utils.mkauto-detectsCONFIG_X86_KERNEL_IBT=yin$(KERNEL_OUTPUT)/.config(overridable viaNV_RS_KERNEL_IBT=1/NV_RS_KERNEL_IBT=0). When enabled onx86_64,RUST_KERNEL_FLAGSadds-Z cf-protection=branch -C jump-tables=no(-C jump-tables=noavoids per-function.rodata.<sym>switch tables that objtool rejects with--werror).- Because
-Z cf-protection=branchis an unstablerustcflag,utils.mkautomatically exportsRUSTC_BOOTSTRAP=1wheneverNV_RS_KERNEL_IBT=1. This allows both the pinned stable toolchain inrust-toolchain.toml(1.100.0) and distro-packaged stablerustc(Arch, Gentoo, Fedora, etc.) to emitENDBR64prologues without requiring a nightly toolchain. tools/check_kernel_module.pyenforcesendbr64_at_data_relocation_targetsonx86_64wheneverCONFIG_X86_KERNEL_IBT=y,NV_RS_KERNEL_IBT=1, or the built object emitsendbr64entries.NV_RS_KERNEL_IBT=0suppresses only the config-based trigger, so the object's ownendbr64entry evidence still enforces the rule; the check reports green from the skip only when neither the config nor the object provides evidence. Both symbol and section-symbol relocations are resolved through the ELF tables, not from printed names, and a target passes only when the instruction at the resolved address isendbr64and the relocation addend is zero; the resolved address is the symbol's value plus the addend, so the sameendbr64is judged twice: measured on one instruction at offset 5, the addend-5 form through the section symbol fails and the addend-0 form through the symbol passes. A target inside a disassembled block fails, but a label inside a function does not: objdump prints each labelled symbol as its own block header, so a label on a mid-functionendbr64is a block entry and passes (measured with addend 0), which is also whyduplicate-symbol-prefix.s, whose relocated symbol starts at offset 1, is recorded as an entry pad. The check cannot call that a function entry, and aSTT_FUNCboundary rule is not an option (measured locally on the current build, all 205 recorded targets came from symbols that are notSTT_FUNC, so such a rule would refuse the current build; report card left untouched (local results should not be committed to the tree)). ARM64 objects are exempt from the x86endbr64rule.- The pass condition is stricter than objtool's rule, not the same rule.
validate_ibt_data_reloc(verified at the v6.12 tag) accepts a data relocation to any instruction it has markednoendbr, accepts anENDBRinstruction without asking whether it is a function entry, and accepts a target it cannot locate as an instruction at all. The checker additionally requires a recorded instruction boundary,endbr64at the resolved address itself (a block entry as objdump prints it, which for a labelled symbol inside a function is that symbol's own header), addend 0, andendbr64whatever objtool would have marked it, so a checker failure reads as 'this data pointer is not anendbr64at offset 0' — objtool can exit 0 on an object the check refuses. The reverse does not hold either, so a green check is not a guarantee that objtool accepts the object: the checker only judges relocations from allocatable, non-executable sections (if not sections[sec][1]&ALLOC or sections[sec][1]&EXEC:continue), whilevalidate_ibt()at the same tag iterates every non-executable section that has a reloc section, skipping only a named list (.discard*,.debug*,.altinstructions,.orc_unwind_ip,__ex_table, …) and nothing incheck.ctestsSHF_ALLOCat all. Measured on one object with aretentry relocated from both.rodataand a non-allocatable.note.mine: the checker sees 1 recorded target and refuses that one, and reports nothing about the other; objtool's path warns on both because.note.mineis not in its exclusion list. - Module-only checks (GOT relocations, runtime symbols, module name, PCI aliases) belong to default validation, and default validation requires
nvidia_rs.ko:--object-onlyis the only mode that skips them, so fixtures are still assertable without a build while a default run with no module fails instead of reporting green with those checks skipped. - The checker honours
NV_RS_KERNEL_IBT=0as an explicit override, the same overrideutils.mkdocuments, so both sides of the IBT rule are assertable without a host kernel config.test_gate_cases.pysets NV_RS_KERNEL_IBT=1 for its expectations instead of reading the host's config, and asserts the disabled side separately: a recorded target that is not an entry pad with the ENDBR rule green means the rule was skipped, not that the target passed. - Identity is taken from the ELF tables, not from printed names: the section header table, the symbol table and the relocation entries give the target section, the symbol's value and the addend, so a printed string of exactly 256 characters that is also another entity's truncation decides nothing — a relocation to the entity whose name is longer is judged against that entity, not against the shorter one that shares the printed prefix. objdump is still the source of instruction boundaries, so its disassembly has to be attributed to a section, and a header whose printed form belongs to two sections cannot be attributed: the prefix is recorded as ambiguous and every target in it is refused instead of judged against whichever entity was disassembled last. Which names arrive truncated is implementation-dependent (readelf 2.47 here truncates names from the section string table, objdump prints them in full, llvm-readelf 23 truncates neither), so
test_gate_cases.pytakes the shared-prefix case's expectation from the printing objdump actually showed and records it; no name on the current object shares a prefix, so the resolved branch is the one that runs. - The export set is built from the symbol table and counts only defined entries:
st_shndx == SHN_UNDEFmeans the name is referenced, not exported, so an object that references all nine protocol names without defining any failsprotocol_exports_presentrather than passing (thenm --defined-onlycheck it replaced rejected this case, and--object-onlyhas no module undefined-symbol check to catch it). Undefined symbols stay in the symbol table for relocation analysis, sotest_gate_cases.pyasserts both sides withundefined-exports.sanddefined-exports.s. - A section name that appears twice in the section header table is not an identity either: it is recorded as a duplicate, every section sharing it is unattributable, and a relocation into one of them is refused instead of judged against whichever section objdump happened to disassemble first. GNU as merges sections with the same name (it warns "ignoring changed section attributes"), so the shape reaches the checker only through a linker that keeps two output sections under one name;
test_gate_cases.pybuilds it withld -rand counts duplicates separately from the shared-prefix counter. The current object has no duplicate section names. - Entry evidence is recorded whether or not the disassembly can be attributed to a section, so an
endbr64pad inside a duplicate-name section still enables the object-based IBT fallback. Before this, the only entry pad in a fixture whose name could not be attributed was lost, enforcement then came from the host config alone, and a data pointer to an empty section passed both checks. - Extended section numbering is read from the escape fields rather than from the header counters: when
e_shnumisSHN_UNDEFthe real count is insh_sizeof header 0, and whene_shstrndxis an escape value the real string table index is insh_linkof header 0 (spec Table 3.5, verified at gabi.xinuos.com/elf/03-sheader.html); a symbol whosest_shndxisSHN_XINDEXgets its index from the associatedSHT_SYMTAB_SHNDX(type 18) section. Before this the checker saw no sections on such an object and reported green over an empty set although both data relocations pointed at aretentry.test_gate_cases.pybuilds the object itself becauseasandldcannot emit it. If the escape value has no associated table objdump refuses the file, so the run exits nonzero instead of passing. - A raw
st_shndxin the reserved rangeSHN_LORESERVE..0xfffeis a special value, not a section reference, so it is skipped before the section-bounds check;SHN_XINDEXcan still resolve to a real section index that is numerically inside that range. In the built object 65521 is bothSHN_ABS's value and a real section, so the two cases are distinguishable only by reading the value as written. Before this the checker stored the symbol's index only after expansion, so the absolute symbol resolved through the section header table at 65521: measured, the run reported green with 2 recorded targets, one of them a symbol that names no section. The export set keys on the raw value, so absolute protocol names are still counted as defined exports.test_gate_cases.pybuilds the object; the symbol over the code needs a size that spans the section, otherwise objdump prints the whole section as one undecodable blob instead of theendbr64entry (measured with symbol size 1, 5 and 14). - Code symbols that share an address are recorded through the symbol table, because objdump prints only one symbol per address. A data relocation naming an alias of a symbol objdump already displayed had nothing to match against and was dropped without being recorded, so the ENDBR rule passed over an empty set.
test_gate_cases.pyasserts both alias targets are recorded: the one at the entry is an entry pad, the one inside a multi-byte instruction is recorded as a target that is not one. The entry flag is the symbol's own address (addend 0), not objdump's block header, so an alias is an entry when the symbol it names is one.