From 7b8836349021e47a831ce5ca48073f1a82242251 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Wed, 24 Apr 2024 16:23:57 -0400 Subject: [PATCH] Meta+Userland: Make LibELF a proper library on Serenity Dynamically loaded LibC doesn't need LibELF definitions, so let's not put them there. --- .../Applications/CrashReporter/CMakeLists.txt | 2 +- Userland/BuggieBox/CMakeLists.txt | 2 +- Userland/DevTools/HackStudio/CMakeLists.txt | 2 +- Userland/DevTools/Profiler/CMakeLists.txt | 2 +- Userland/Libraries/LibC/CMakeLists.txt | 7 +--- Userland/Libraries/LibCoredump/CMakeLists.txt | 2 +- Userland/Libraries/LibDebug/CMakeLists.txt | 2 +- Userland/Libraries/LibELF/CMakeLists.txt | 38 +++++++++++++++++-- Userland/Libraries/LibGUI/CMakeLists.txt | 2 +- .../Libraries/LibSymbolication/CMakeLists.txt | 2 +- Userland/Utilities/CMakeLists.txt | 11 ++++-- 11 files changed, 51 insertions(+), 21 deletions(-) diff --git a/Userland/Applications/CrashReporter/CMakeLists.txt b/Userland/Applications/CrashReporter/CMakeLists.txt index 4c6a8f6c305..c6f111d1639 100644 --- a/Userland/Applications/CrashReporter/CMakeLists.txt +++ b/Userland/Applications/CrashReporter/CMakeLists.txt @@ -13,4 +13,4 @@ set(SOURCES ) serenity_app(CrashReporter ICON app-crash-reporter) -target_link_libraries(CrashReporter PRIVATE LibCore LibCoredump LibDebug LibDesktop LibFileSystem LibFileSystemAccessClient LibGfx LibGUI LibMain LibThreading LibURL) +target_link_libraries(CrashReporter PRIVATE LibCore LibCoredump LibDebug LibDesktop LibELF LibFileSystem LibFileSystemAccessClient LibGfx LibGUI LibMain LibThreading LibURL) diff --git a/Userland/BuggieBox/CMakeLists.txt b/Userland/BuggieBox/CMakeLists.txt index 9f36bedb5b8..393ebb79c84 100644 --- a/Userland/BuggieBox/CMakeLists.txt +++ b/Userland/BuggieBox/CMakeLists.txt @@ -41,7 +41,7 @@ set(utility_srcs serenity_bin(BuggieBox) target_sources(BuggieBox PRIVATE main.cpp) -target_link_libraries(BuggieBox PRIVATE LibMain LibShell LibArchive LibCompress LibCore LibCrypto LibFileSystem LibGfx LibLine LibRegex LibAudio LibURL) +target_link_libraries(BuggieBox PRIVATE LibMain LibShell LibArchive LibCompress LibCore LibCrypto LibELF LibFileSystem LibGfx LibLine LibRegex LibAudio LibURL) foreach(file IN LISTS utility_srcs) buggiebox_utility(${file}) diff --git a/Userland/DevTools/HackStudio/CMakeLists.txt b/Userland/DevTools/HackStudio/CMakeLists.txt index 65f95da95d0..01f25187ccc 100644 --- a/Userland/DevTools/HackStudio/CMakeLists.txt +++ b/Userland/DevTools/HackStudio/CMakeLists.txt @@ -55,5 +55,5 @@ set(GENERATED_SOURCES ) serenity_app(HackStudio ICON app-hack-studio) -target_link_libraries(HackStudio PRIVATE LibWebView LibWeb LibMarkdown LibGUI LibCpp LibCMake LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell LibSymbolication LibSyntax LibRegex LibSQL LibConfig LibCore LibCoredump LibDesktop LibFileSystem LibIPC LibJS LibMain LibThreading LibURL) +target_link_libraries(HackStudio PRIVATE LibELF LibWebView LibWeb LibMarkdown LibGUI LibCpp LibCMake LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell LibSymbolication LibSyntax LibRegex LibSQL LibConfig LibCore LibCoredump LibDesktop LibFileSystem LibIPC LibJS LibMain LibThreading LibURL) add_dependencies(HackStudio CppLanguageServer) diff --git a/Userland/DevTools/Profiler/CMakeLists.txt b/Userland/DevTools/Profiler/CMakeLists.txt index bce613fd9e9..a61a77392eb 100644 --- a/Userland/DevTools/Profiler/CMakeLists.txt +++ b/Userland/DevTools/Profiler/CMakeLists.txt @@ -24,4 +24,4 @@ set(SOURCES ) serenity_app(Profiler ICON app-profiler) -target_link_libraries(Profiler PRIVATE LibCore LibDebug LibFileSystem LibGfx LibGUI LibDesktop LibX86 LibSymbolication LibMain LibURL) +target_link_libraries(Profiler PRIVATE LibCore LibDebug LibELF LibFileSystem LibGfx LibGUI LibDesktop LibX86 LibSymbolication LibMain LibURL) diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index 74398d0f185..49f4b059ddb 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -97,24 +97,19 @@ foreach(RELATIVE_HEADER_PATH IN LISTS LIBC_HEADERS) ) endforeach() -file(GLOB ELF_SOURCES CONFIGURE_DEPENDS "../LibELF/*.cpp" "../LibELF/Arch/${SERENITY_ARCH}/*.cpp") - if ("${SERENITY_ARCH}" STREQUAL "aarch64") set(LIBC_SOURCES ${LIBC_SOURCES} "arch/aarch64/fenv.cpp") set(ASM_SOURCES "arch/aarch64/setjmp.S") - set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/aarch64/entry.S ../LibELF/Arch/aarch64/plt_trampoline.S ../LibELF/Arch/aarch64/tls.S) set(CRTI_SOURCE "arch/aarch64/crti.S") set(CRTN_SOURCE "arch/aarch64/crtn.S") elseif ("${SERENITY_ARCH}" STREQUAL "x86_64") set(LIBC_SOURCES ${LIBC_SOURCES} "arch/x86_64/memset.cpp" "arch/x86_64/fenv.cpp") set(ASM_SOURCES "arch/x86_64/setjmp.S" "arch/x86_64/memset.S") - set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/x86_64/entry.S ../LibELF/Arch/x86_64/plt_trampoline.S) set(CRTI_SOURCE "arch/x86_64/crti.S") set(CRTN_SOURCE "arch/x86_64/crtn.S") elseif ("${SERENITY_ARCH}" STREQUAL "riscv64") set(LIBC_SOURCES ${LIBC_SOURCES} "arch/riscv64/fenv.cpp") set(ASM_SOURCES "arch/riscv64/setjmp.S") - set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/riscv64/entry.S ../LibELF/Arch/riscv64/plt_trampoline.S) set(CRTI_SOURCE "arch/riscv64/crti.S") set(CRTN_SOURCE "arch/riscv64/crtn.S") endif() @@ -160,7 +155,7 @@ add_dependencies(ssp_nonshared install_libc_headers) target_link_libraries(ssp_nonshared PRIVATE NoCoverage) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libssp_nonshared.a DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/lib/) -set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${ASM_SOURCES}) +set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ASM_SOURCES}) # Prevent GCC from removing null checks by marking the `FILE*` argument non-null set_source_files_properties(stdio.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-fputc -fno-builtin-fputs -fno-builtin-fwrite") diff --git a/Userland/Libraries/LibCoredump/CMakeLists.txt b/Userland/Libraries/LibCoredump/CMakeLists.txt index 62aba7bac8d..b87905bb2b5 100644 --- a/Userland/Libraries/LibCoredump/CMakeLists.txt +++ b/Userland/Libraries/LibCoredump/CMakeLists.txt @@ -5,4 +5,4 @@ set(SOURCES ) serenity_lib(LibCoredump coredump) -target_link_libraries(LibCoredump PRIVATE LibCompress LibCore LibDebug LibFileSystem) +target_link_libraries(LibCoredump PRIVATE LibCompress LibCore LibDebug LibELF LibFileSystem) diff --git a/Userland/Libraries/LibDebug/CMakeLists.txt b/Userland/Libraries/LibDebug/CMakeLists.txt index b708019722b..e282eb2ad7f 100644 --- a/Userland/Libraries/LibDebug/CMakeLists.txt +++ b/Userland/Libraries/LibDebug/CMakeLists.txt @@ -13,4 +13,4 @@ set(SOURCES ) serenity_lib(LibDebug debug) -target_link_libraries(LibDebug PRIVATE LibCore LibFileSystem LibRegex) +target_link_libraries(LibDebug PRIVATE LibCore LibELF LibFileSystem LibRegex) diff --git a/Userland/Libraries/LibELF/CMakeLists.txt b/Userland/Libraries/LibELF/CMakeLists.txt index 3f22b1dbb08..ed9d3543f22 100644 --- a/Userland/Libraries/LibELF/CMakeLists.txt +++ b/Userland/Libraries/LibELF/CMakeLists.txt @@ -1,6 +1,38 @@ -# LibELF is included within LibC on Serenity and defined as a target in a different place for Lagom, -# so add a dummy interface library for platform-agnosticism. -add_library(LibELF INTERFACE) +# This is here just to not make any changes to Lagom CMakeLists in this commit. +if (NOT SERENITYOS) + add_library(LibELF INTERFACE) + serenity_install_headers("LibELF") + serenity_install_sources("Userland/Libraries/LibELF") + + return() +endif() + +set(SOURCES + Image.cpp + Validation.cpp +) serenity_install_headers("LibELF") serenity_install_sources("Userland/Libraries/LibELF") + +if (SERENITYOS) + list(APPEND SOURCES + Arch/${SERENITY_ARCH}/entry.S + Arch/${SERENITY_ARCH}/plt_trampoline.S + Arch/${SERENITY_ARCH}/tls.cpp + DynamicLinker.cpp + DynamicLoader.cpp + DynamicObject.cpp + ELFBuild.cpp + Relocation.cpp + ) + + if (SERENITY_ARCH STREQUAL "aarch64") + list(APPEND SOURCES + Arch/aarch64/tls.S + ) + endif() +endif() + +serenity_lib(LibELF elf ${SOURCES}) +target_link_libraries(LibELF PRIVATE LibSystem) diff --git a/Userland/Libraries/LibGUI/CMakeLists.txt b/Userland/Libraries/LibGUI/CMakeLists.txt index 9ead8a819ab..d20bbc80d45 100644 --- a/Userland/Libraries/LibGUI/CMakeLists.txt +++ b/Userland/Libraries/LibGUI/CMakeLists.txt @@ -156,5 +156,5 @@ set(GENERATED_SOURCES ) serenity_lib(LibGUI gui) -target_link_libraries(LibGUI PRIVATE LibCore LibFileSystem LibGfx LibImageDecoderClient LibIPC LibThreading LibRegex LibConfig LibUnicode LibURL) +target_link_libraries(LibGUI PRIVATE LibCore LibELF LibFileSystem LibGfx LibImageDecoderClient LibIPC LibThreading LibRegex LibConfig LibUnicode LibURL) target_link_libraries(LibGUI PUBLIC LibSyntax) diff --git a/Userland/Libraries/LibSymbolication/CMakeLists.txt b/Userland/Libraries/LibSymbolication/CMakeLists.txt index a5cdb4e4dbd..02ecbb0abd2 100644 --- a/Userland/Libraries/LibSymbolication/CMakeLists.txt +++ b/Userland/Libraries/LibSymbolication/CMakeLists.txt @@ -3,4 +3,4 @@ set(SOURCES ) serenity_lib(LibSymbolication symbolication) -target_link_libraries(LibSymbolication PRIVATE LibCore LibDebug LibFileSystem) +target_link_libraries(LibSymbolication PRIVATE LibCore LibDebug LibELF LibFileSystem) diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index efcd7812d4d..12b8ef0ec9e 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -88,13 +88,13 @@ target_link_libraries(cpp-lexer PRIVATE LibCpp) target_link_libraries(cpp-parser PRIVATE LibCpp) target_link_libraries(cpp-preprocessor PRIVATE LibCpp) target_link_libraries(diff PRIVATE LibDiff) -target_link_libraries(disasm PRIVATE LibX86) +target_link_libraries(disasm PRIVATE LibELF LibX86) target_link_libraries(drain PRIVATE LibFileSystem) target_link_libraries(expr PRIVATE LibRegex) target_link_libraries(fdtdump PRIVATE LibDeviceTree) -target_link_libraries(file PRIVATE LibGfx LibIPC LibArchive LibCompress LibAudio) +target_link_libraries(file PRIVATE LibELF LibGfx LibIPC LibArchive LibCompress LibAudio) target_link_libraries(find PRIVATE LibFileSystem LibRegex LibURL) -target_link_libraries(functrace PRIVATE LibDebug LibX86) +target_link_libraries(functrace PRIVATE LibDebug LibELF LibX86) target_link_libraries(glsl-compiler PRIVATE LibGLSL) target_link_libraries(gml-format PRIVATE LibGUI) target_link_libraries(grep PRIVATE LibFileSystem LibRegex LibURL) @@ -109,6 +109,7 @@ target_link_libraries(install-bin PRIVATE LibFileSystem) target_link_libraries(isobmff PRIVATE LibGfx) target_link_libraries(js PRIVATE LibCrypto LibJS LibLine LibLocale LibTextCodec) target_link_libraries(keymap PRIVATE LibKeyboard) +target_link_libraries(ldd PRIVATE LibELF) target_link_libraries(less PRIVATE LibLine) target_link_libraries(ls PRIVATE LibFileSystem LibURL) target_link_libraries(lspci PRIVATE LibPCIDB) @@ -130,11 +131,13 @@ target_link_libraries(pdf PRIVATE LibGfx LibPDF) target_link_libraries(pgrep PRIVATE LibRegex) target_link_libraries(pixelflut PRIVATE LibImageDecoderClient LibIPC LibGfx) target_link_libraries(pkill PRIVATE LibRegex) +target_link_libraries(pledge PRIVATE LibELF) target_link_libraries(pls PRIVATE LibCrypt) target_link_libraries(pro PRIVATE LibFileSystem LibProtocol LibHTTP LibURL) +target_link_libraries(readelf PRIVATE LibELF) target_link_libraries(readlink PRIVATE LibFileSystem) target_link_libraries(realpath PRIVATE LibFileSystem) -target_link_libraries(run-tests PRIVATE LibCoredump LibDebug LibFileSystem LibRegex) +target_link_libraries(run-tests PRIVATE LibCoredump LibDebug LibELF LibFileSystem LibRegex) target_link_libraries(rm PRIVATE LibFileSystem) target_link_libraries(sed PRIVATE LibRegex LibFileSystem) target_link_libraries(shot PRIVATE LibFileSystem LibGfx LibGUI LibIPC LibURL)