Skip to content

build: compile each backend archive with one section per procedure - #615

Merged
amontoison merged 1 commit into
developfrom
build/function-sections
Oct 20, 2026
Merged

amontoison merged 1 commit into
developfrom
build/function-sections

Conversation

@amontoison

@amontoison amontoison commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Each hipfort module compiles to one object, and a linker extracts whole objects from an archive, not single symbols. A program that calls one rocBLAS wrapper therefore links all of them, and a wrapper naming a C function the installed library does not export (bindings generated from headers newer than the library) breaks every link of that library, whatever the program calls.

  • lib/CMakeLists.txt: compile libhipfort-amdgcn.a and libhipfort-nvptx.a with -ffunction-sections -fdata-sections, for the compilers that split the sections (GNU, LLVMFlang, Flang, NVHPC). The Intel compilers accept the flags but emit a single section, so they are left out. Without --gc-sections at link time this changes nothing.
  • test/CMakeLists.txt: link the tests with -Wl,--gc-sections (not on Apple or Windows). Spelled -Wl, rather than LINKER:, which CMake 3.27 passes to LLVMFlang as a bare --gc-sections.
  • CHANGELOG.md: note the change, and that a shared library linking an archive also needs -Wl,--exclude-libs,ALL.

The same change is in the per-library sandbox (#540), where it lets the tests link against a ROCm older than the develop headers.

Each module compiles to one object, and a linker extracts whole objects
from an archive, so a program calling one rocBLAS wrapper linked all of
them, and a wrapper naming a C function the installed library does not
export broke every link of that library. Compile libhipfort-amdgcn.a and
libhipfort-nvptx.a with -ffunction-sections -fdata-sections (GNU,
LLVMFlang, Flang, NVHPC; the Intel compilers do not split the sections),
and link the tests with -Wl,--gc-sections, spelled -Wl, because CMake
3.27 passes LINKER:--gc-sections to LLVMFlang as a bare flag.
@amontoison
amontoison requested a review from a team as a code owner October 20, 2026 22:40
@amontoison
amontoison merged commit 53bc827 into develop Oct 20, 2026
1 check was pending
@amontoison
amontoison deleted the build/function-sections branch October 20, 2026 22:50
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