Skip to content

fix: emit _metaptr section writable to avoid text relocations - #46

Merged
Jo5ta merged 1 commit into
mainfrom
fix/textrel-shared-library
Jul 21, 2026
Merged

fix: emit _metaptr section writable to avoid text relocations#46
Jo5ta merged 1 commit into
mainfrom
fix/textrel-shared-library

Conversation

@Jo5ta

@Jo5ta Jo5ta commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

A tracepoint compiled into a shared library (a plugin/driver .so) expands _CLLTK_EMIT_META_PTR, which emits absolute pointer pairs into the _clltk_<buffer>_metaptr section. That section was flagged read-only ("a"), so on a PIC/PIE object the dynamic linker must patch a read-only page at load time — a text relocation (DT_TEXTREL). -fPIC cannot avoid it (the relocation is structurally absolute), PIE/hardened targets such as AArch64 reject it at load time, and packaging QA (do_package_qa) fails on it.

Fix

Flag the section writable ("aw"). Its pointers then land in the data segment and are applied as ordinary RELATIVE relocations — matching how the compiler already emits the sibling _clltk_tracebuffer_handler_ptr section. No API or ABI change; consumers just recompile against the updated header.

Verified on x86_64 (gcc) and aarch64 (clang/lld): old flag → DT_TEXTREL; new flag → clean RELATIVE relocations.

Why CI missed it, and the guards added

The failing shape was built in CI, but only ever as a linker warning on a green build — nothing inspected the produced binary. Guards so it cannot return:

  • test — a packaging consumer test builds a shared library against the installed headers and asserts the produced .so is free of text relocations and an executable stack (the do_package_qa check). This is the shape the pre-existing consumer test (an executable) never exercised.
  • ci — the compiler-compat matrix links a tracepoint-bearing shared object with -z text on every compiler and architecture (incl. arm64/s390x under QEMU), so a text-relocation regression is a hard link error.
  • build — the tracing library and example shared libraries link with --fatal-warnings (gated off under sanitizers), so a "creating DT_TEXTREL" linker warning fails the build instead of scrolling past unread.

A tracepoint compiled into a shared library expands the discovery macro
_CLLTK_EMIT_META_PTR, which emits absolute pointer pairs into the
_clltk_<buffer>_metaptr section. The section was flagged read-only ("a"),
so on a PIC/PIE object the dynamic linker had to patch a read-only page at
load time: a text relocation (DT_TEXTREL). -fPIC cannot avoid it (the
relocation is structurally absolute), PIE/hardened targets such as AArch64
reject it at load time, and packaging QA (do_package_qa) fails on it.

Flag the section writable ("aw"). Its pointers then land in the data
segment and are applied as ordinary RELATIVE relocations - matching how the
compiler already emits the sibling _clltk_tracebuffer_handler_ptr section.
No API or ABI change; recompile against the updated header.

The regression was invisible because CI only ever built this shape as a
warning-not-error link. Add guards so it cannot return:

- test: a packaging consumer test builds a shared library against the
  installed headers and asserts the produced .so is free of text
  relocations and an executable stack (the do_package_qa check).
- ci: the compiler-compat matrix links a tracepoint-bearing shared object
  with -z text on every compiler and architecture (incl. arm64/s390x), so
  a text-relocation regression is a hard link error.
- build: the tracing library and example shared libraries link with
  --fatal-warnings (gated off under sanitizers), so a "creating DT_TEXTREL"
  linker warning fails the build instead of scrolling past unread.

Signed-off-by: Jo5ta <Jo5ta@mail.de>
@Jo5ta
Jo5ta force-pushed the fix/textrel-shared-library branch from 3fa6cd5 to 66ca532 Compare July 21, 2026 09:33
@Jo5ta
Jo5ta merged commit 3b94af2 into main Jul 21, 2026
44 of 45 checks passed
@Jo5ta
Jo5ta deleted the fix/textrel-shared-library branch July 21, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant