Skip to content

Commit 2fa3ef2

Browse files
committed
[core] Garbage collect unused sections in libCling
After inlining and hiding symbols, some of them are not referenced anymore and can be collected by the linker, reducing the library size from 120 MB to 105 MB in a Release configuration with GCC.
1 parent ee8598f commit 2fa3ef2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/metacling/src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,13 @@ if(NOT APPLE AND NOT MSVC)
229229
# and by ALICE in https://github.com/root-project/root/issues/19889
230230
# Only needed for Linux: Mac uses linker namespaces and Windows explicit export/import
231231
target_link_libraries(Cling PRIVATE -Wl,-Bsymbolic)
232+
# We compile with -fvisibility=hidden in interpreter/, but some symbols of
233+
# instantiated templates remain. Use a version script to hide them.
232234
target_link_libraries(Cling PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libCling.script)
233235
set_target_properties(Cling PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libCling.script)
236+
# After inlining and hiding symbols, some of them are not referenced anymore
237+
# and can be collected by the linker, reducing the library size.
238+
target_link_libraries(Cling PRIVATE -Wl,--gc-sections)
234239
endif()
235240

236241
if (CMAKE_SYSTEM_NAME MATCHES FreeBSD)

0 commit comments

Comments
 (0)