Everywhere: Explicitly link all binaries against the LibC target

Even though the toolchain implicitly links against -lc, it does not know
where it should get LibC from except for the sysroot. In the case of
Clang this causes it to pick up the LibC stub instead, which might be
slightly outdated and feature missing symbols.

This is currently not an issue that manifests because we pass through
the dependency on LibC and other libraries by accident, which causes
CMake to link against the LibC target (instead of just the library),
and thus points the linker at the build output directory.

Since we are looking to fix that in the upcoming commits, let's make
sure that everything will still be able to find the proper LibC first.
This commit is contained in:
Tim Schumacher 2022-10-22 15:13:49 +02:00 committed by Linus Groh
parent 39fca21e11
commit 7834e26ddb
Notes: sideshowbarker 2024-07-17 04:54:41 +09:00
39 changed files with 42 additions and 33 deletions

View file

@ -2,6 +2,15 @@
include(${CMAKE_CURRENT_LIST_DIR}/serenity_components.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/code_generators.cmake)
function(serenity_set_implicit_links target_name)
# Make sure that CMake is aware of the implicit LibC dependency, and ensure
# that we are choosing the correct and updated LibC.
# The latter is a problem with Clang especially, since we might have the
# slightly outdated stub in the sysroot, but have not yet installed the freshly
# built LibC.
target_link_libraries(${target_name} LibC)
endfunction()
function(serenity_install_headers target_name)
file(GLOB_RECURSE headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
foreach(header ${headers})
@ -43,6 +52,7 @@ if (NOT COMMAND serenity_lib)
install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
serenity_generated_sources(${target_name})
serenity_set_implicit_links(${target_name})
endfunction()
endif()
@ -56,6 +66,7 @@ if (NOT COMMAND serenity_lib_static)
install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
serenity_generated_sources(${target_name})
serenity_set_implicit_links(${target_name})
endfunction()
endif()
@ -80,6 +91,7 @@ if (NOT COMMAND serenity_bin)
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL)
serenity_generated_sources(${target_name})
serenity_set_implicit_links(${target_name})
endfunction()
endif()
@ -96,6 +108,7 @@ function(serenity_test test_src sub_dir)
add_executable(${test_name} ${TEST_SOURCES})
add_dependencies(ComponentTests ${test_name})
set_target_properties(${test_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
serenity_set_implicit_links(${test_name})
target_link_libraries(${test_name} LibTest LibCore)
foreach(lib ${SERENITY_TEST_LIBS})
target_link_libraries(${test_name} ${lib})

View file

@ -26,6 +26,7 @@ foreach(source IN LISTS TEST_SOURCES)
get_filename_component(test_name "${source}" NAME_WE)
add_executable("${test_name}" "${source}")
target_link_libraries("${test_name}" LibCore)
serenity_set_implicit_links("${test_name}")
install(TARGETS "${test_name}" RUNTIME DESTINATION usr/Tests/Kernel/Legacy)
endforeach()

View file

@ -4,6 +4,7 @@ macro(add_dlopen_lib NAME FUNCTION)
target_compile_definitions(${NAME} PRIVATE -DFUNCTION=${FUNCTION})
# LibLine is not special, just an "external" dependency
target_link_libraries(${NAME} LibLine)
serenity_set_implicit_links(${NAME})
# Avoid execution by the test runner
install(TARGETS ${NAME}
DESTINATION usr/Tests/LibELF

View file

@ -18,6 +18,7 @@ serenity_component(
)
add_executable(test262-runner test262-runner.cpp)
target_link_libraries(test262-runner LibJS LibCore)
serenity_set_implicit_links(test262-runner)
link_with_locale_data(test262-runner)
install(TARGETS test262-runner RUNTIME DESTINATION bin OPTIONAL)
@ -27,4 +28,5 @@ serenity_component(
)
add_executable(test-test262 test-test262.cpp)
target_link_libraries(test-test262 LibMain LibCore)
serenity_set_implicit_links(test-test262)
install(TARGETS test-test262 RUNTIME DESTINATION bin OPTIONAL)

View file

@ -8,5 +8,6 @@ foreach(source IN LISTS TEST_SOURCES)
get_filename_component(test_name "${source}" NAME_WE)
add_executable("${test_name}" "${source}")
target_link_libraries("${test_name}" LibCore)
serenity_set_implicit_links("${test_name}")
install(TARGETS "${test_name}" RUNTIME DESTINATION usr/Tests/UserEmulator)
endforeach()

View file

@ -9,7 +9,7 @@ set(GENERATED_SOURCES
LanguageServerEndpoint.h)
serenity_lib(LibLanguageServer languageserver)
target_link_libraries(LibLanguageServer LibCodeComprehension LibC)
target_link_libraries(LibLanguageServer LibCodeComprehension)
add_subdirectory(Cpp)
add_subdirectory(Shell)

View file

@ -6,4 +6,4 @@ set(SOURCES
)
serenity_lib(LibCards cards)
target_link_libraries(LibCards LibC LibCore LibConfig LibGUI)
target_link_libraries(LibCards LibCore LibConfig LibGUI)

View file

@ -5,4 +5,4 @@ set(SOURCES
)
serenity_lib(LibChess chess)
target_link_libraries(LibChess LibC LibCore)
target_link_libraries(LibChess LibCore)

View file

@ -4,7 +4,6 @@ set(SOURCES
)
serenity_lib(LibCodeComprehension codecomprehension)
target_link_libraries(LibCodeComprehension LibC)
add_subdirectory(Cpp)
add_subdirectory(Shell)

View file

@ -3,7 +3,7 @@ set(SOURCES
)
serenity_lib(LibCppComprehension cppcomprehension)
target_link_libraries(LibCppComprehension LibCodeComprehension LibC)
target_link_libraries(LibCppComprehension LibCodeComprehension)
serenity_component(
CppComprehensionTests

View file

@ -3,4 +3,4 @@ set(SOURCES
)
serenity_lib(LibShellComprehension shellcomprehension)
target_link_libraries(LibShellComprehension LibCodeComprehension LibC)
target_link_libraries(LibShellComprehension LibCodeComprehension)

View file

@ -7,4 +7,4 @@ set(SOURCES
)
serenity_lib(LibCompress compress)
target_link_libraries(LibCompress LibC LibCrypto)
target_link_libraries(LibCompress LibCrypto)

View file

@ -45,4 +45,4 @@ if (NOT ANDROID AND NOT WIN32)
endif()
serenity_lib(LibCore core)
target_link_libraries(LibCore LibC LibCrypt LibSystem)
target_link_libraries(LibCore LibCrypt LibSystem)

View file

@ -5,4 +5,4 @@ set(SOURCES
)
serenity_lib(LibCoredump coredump)
target_link_libraries(LibCoredump LibC LibCompress LibCore LibDebug)
target_link_libraries(LibCoredump LibCompress LibCore LibDebug)

View file

@ -9,4 +9,4 @@ set(SOURCES
)
serenity_lib(LibCpp cpp)
target_link_libraries(LibCpp LibC LibSyntax LibDiff)
target_link_libraries(LibCpp LibSyntax LibDiff)

View file

@ -11,4 +11,4 @@ set(SOURCES
)
serenity_lib(LibCrypt crypt)
target_link_libraries(LibCrypt LibC LibCryptSHA2)
target_link_libraries(LibCrypt LibCryptSHA2)

View file

@ -33,4 +33,4 @@ set(SOURCES
)
serenity_lib(LibCrypto crypto)
target_link_libraries(LibCrypto LibC LibCore)
target_link_libraries(LibCrypto LibCore)

View file

@ -5,4 +5,4 @@ set(SOURCES
)
serenity_lib(LibDNS dns)
target_link_libraries(LibDNS LibC LibIPC)
target_link_libraries(LibDNS LibIPC)

View file

@ -14,4 +14,4 @@ set(SOURCES
)
serenity_lib(LibDebug debug)
target_link_libraries(LibDebug LibC LibRegex)
target_link_libraries(LibDebug LibRegex)

View file

@ -4,4 +4,4 @@ set(SOURCES
)
serenity_lib(LibDeviceTree DeviceTree)
target_link_libraries(LibDeviceTree LibC LibCore)
target_link_libraries(LibDeviceTree LibCore)

View file

@ -6,4 +6,3 @@ set(SOURCES
)
serenity_lib(LibDiff diff)
target_link_libraries(LibDiff LibC)

View file

@ -8,5 +8,4 @@ set(SOURCES
)
serenity_lib(LibEDID edid)
target_link_libraries(LibEDID LibC)
target_compile_definitions(LibEDID PRIVATE ENABLE_PNP_IDS_DATA=$<BOOL:${ENABLE_PNP_IDS_DOWNLOAD}>)

View file

@ -5,4 +5,4 @@ set(SOURCES
)
serenity_lib(LibIPC ipc)
target_link_libraries(LibIPC LibC LibCore)
target_link_libraries(LibIPC LibCore)

View file

@ -7,4 +7,4 @@ set(SOURCES
)
serenity_lib(LibLine line)
target_link_libraries(LibLine LibC LibCore)
target_link_libraries(LibLine LibCore)

View file

@ -3,4 +3,3 @@ set(SOURCES
)
serenity_lib_static(LibMain main)
target_link_libraries(LibMain LibC)

View file

@ -3,4 +3,3 @@ set(SOURCES
)
serenity_lib(LibPCIDB pcidb)
target_link_libraries(LibPCIDB LibC)

View file

@ -19,4 +19,4 @@ set(SOURCES
)
serenity_lib(LibPDF pdf)
target_link_libraries(LibPDF LibC LibCore LibIPC LibGfx LibTextCodec LibCrypto)
target_link_libraries(LibPDF LibCore LibIPC LibGfx LibTextCodec LibCrypto)

View file

@ -11,4 +11,4 @@ if(SERENITYOS)
endif()
serenity_lib(LibRegex regex)
target_link_libraries(LibRegex LibC LibCore LibUnicode)
target_link_libraries(LibRegex LibCore LibUnicode)

View file

@ -3,4 +3,3 @@ set(SOURCES
)
serenity_lib(LibSyntax syntax)
target_link_libraries(LibSyntax LibC)

View file

@ -6,7 +6,6 @@ set(SOURCES
)
serenity_lib(LibTest test)
target_link_libraries(LibTest LibC)
add_library(LibTestMain OBJECT TestMain.cpp)
add_library(JavaScriptTestRunnerMain OBJECT JavaScriptTestRunnerMain.cpp)

View file

@ -3,4 +3,3 @@ set(SOURCES
)
serenity_lib(LibTextCodec textcodec)
target_link_libraries(LibTextCodec LibC)

View file

@ -4,4 +4,4 @@ set(SOURCES
)
serenity_lib(LibThreading threading)
target_link_libraries(LibThreading LibC LibCore)
target_link_libraries(LibThreading LibCore)

View file

@ -3,4 +3,3 @@ set(SOURCES
)
serenity_lib(LibUSBDB usbdb)
target_link_libraries(LibUSBDB LibC)

View file

@ -11,4 +11,4 @@ set(GENERATED_SOURCES
generate_state_machine(StateMachine.txt EscapeSequenceStateMachine.h)
serenity_lib(LibVT vt)
target_link_libraries(LibVT LibC LibCore LibGUI LibGfx LibDesktop LibConfig)
target_link_libraries(LibVT LibCore LibGUI LibGfx LibDesktop LibConfig)

View file

@ -8,4 +8,4 @@ set(SOURCES
)
serenity_lib(LibWasm wasm)
target_link_libraries(LibWasm LibC LibCore)
target_link_libraries(LibWasm LibCore)

View file

@ -3,4 +3,3 @@ set(SOURCES
)
serenity_lib(LibX86 x86)
target_link_libraries(LibX86 LibC)

View file

@ -4,4 +4,3 @@ set(SOURCES
)
serenity_lib(LibXML xml)
target_link_libraries(LibXML LibC)

View file

@ -9,4 +9,4 @@ set(SOURCES
)
serenity_bin(CrashDaemon)
target_link_libraries(CrashDaemon LibC LibCompress LibCore LibCoredump LibMain)
target_link_libraries(CrashDaemon LibCompress LibCore LibCoredump LibMain)

View file

@ -41,12 +41,14 @@ foreach(CMD_SRC ${CMD_SOURCES})
if (CMD_NAME IN_LIST SPECIAL_TARGETS)
add_executable(${TARGET_NAME} ${CMD_SRC})
target_link_libraries(${TARGET_NAME} LibCore LibMain)
serenity_set_implicit_links(${TARGET_NAME})
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin)
install(CODE "file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME}-bin ${CMAKE_INSTALL_PREFIX}/bin/${CMD_NAME})")
else()
add_executable(${CMD_NAME} ${CMD_SRC})
set_target_properties(${CMD_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries(${CMD_NAME} LibCore)
serenity_set_implicit_links(${TARGET_NAME})
install(TARGETS ${CMD_NAME} RUNTIME DESTINATION bin OPTIONAL)
endif()
endforeach()