Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

### Changed

* Each backend archive (`libhipfort-amdgcn.a`, `libhipfort-nvptx.a`) is
compiled with one section per procedure (`-ffunction-sections
-fdata-sections`). A program linked with `-Wl,--gc-sections` keeps only the
wrappers it calls, instead of all of a library's wrappers, and still links
when another wrapper names a C function that the installed library does not
export. The tests link that way. A shared library that links an archive also
needs `-Wl,--exclude-libs,ALL`.
* **Breaking.** The array overloads of `hipMalloc`, `hipMallocManaged`,
`hipHostMalloc`, `hipFree`, `hipHostFree`, the `hipMemcpy` families and the
`hipHostRegister` family are now part of the Fortran 2008 array overloads, like
Expand Down
10 changes: 10 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ if(HIPFORT_ASSUMED_RANK AND NOT (HIPFORT_USE_FPOINTER_INTERFACES AND CMAKE_Fortr
"Use the F2018 assumed-rank array interfaces" FORCE)
endif()

# Each module compiles to one object, and a linker extracts whole objects from an
# archive, so a program that calls one wrapper links all of that module's. One
# section per procedure lets a program linked with -Wl,--gc-sections keep only
# the wrappers it calls; without that flag it changes nothing. Only these
# compilers split the sections (the Intel ones accept the flags but do not).
set(HIPFORT_SECTION_FLAGS
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU,LLVMFlang,Flang,NVHPC>:-ffunction-sections;-fdata-sections>")

if(HIPFORT_BUILD_AMDGCN)
set(HIPFORT_ARCH "amdgcn")
# amdgcn
Expand All @@ -138,6 +146,7 @@ set(HIPFORT_ARCH "amdgcn")
target_compile_definitions(${HIPFORT_LIB} PRIVATE USE_ASSUMED_SHAPE)
ENDIF()
target_compile_definitions(${HIPFORT_LIB} PRIVATE _HIPFORT_ARCH='${HIPFORT_ARCH}')
target_compile_options(${HIPFORT_LIB} PRIVATE "${HIPFORT_SECTION_FLAGS}")
# Install Target hipfort-amdgcn
# CMAKE_INSTALL_LIBDIR/INCLUDEDIR already carry the toolchain-specific
# subdirectory (see HIPFORT_MULTITOOLCHAIN_LAYOUT in the top-level
Expand Down Expand Up @@ -183,6 +192,7 @@ set(HIPFORT_ARCH "nvptx")
ENDIF()
target_compile_definitions(${HIPFORT_LIB} PRIVATE USE_CUDA_NAMES)
target_compile_definitions(${HIPFORT_LIB} PRIVATE _HIPFORT_ARCH='${HIPFORT_ARCH}')
target_compile_options(${HIPFORT_LIB} PRIVATE "${HIPFORT_SECTION_FLAGS}")
# Install Target hipfort-nvptx
rocm_install_targets(
TARGETS ${HIPFORT_LIB}
Expand Down
8 changes: 8 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ if(BUILD_TESTING)
CMAKE_Fortran_PREPROCESS_SOURCE "${CMAKE_Fortran_PREPROCESS_SOURCE}")
endif()

# Keep only the binding wrappers a test calls (the archives are built with one
# section per procedure), so a test links even when another wrapper names a C
# symbol the installed library does not export. Spelled -Wl, rather than
# LINKER:, which CMake 3.27 passes to LLVMFlang as a bare --gc-sections.
if(NOT APPLE AND NOT WIN32)
add_link_options(-Wl,--gc-sections)
endif()

# Which backend the tests link: hipfort::hip carries the archive of the one
# lib/ built the components for (nvptx when HIPFORT_BUILD_AMDGCN is OFF, even on
# an AMD host). On the CUDA backend the symbol tests are compiled with
Expand Down