mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 02:50:26 +00:00
5dfe2eb389
Since https://reviews.llvm.org/D131441, libc++ must be included before LibC. As clang includes libc++ as one of the system includes, LibC must be included after those, and the only correct way to do that is to install LibC's headers into the sysroot. Targets that don't link with LibC yet require its headers for one reason or another must add install_libc_headers as a dependency to ensure that the correct headers have been (re)installed into the sysroot. LibC/stddef.h has been dropped since the built-in stddef.h receives a higher include priority. In addition, string.h and wchar.h must define __CORRECT_ISO_CPP_STRING_H_PROTO and _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS respectively in order to tell libc++ to not try to define methods implemented by LibC.
61 lines
2.7 KiB
CMake
61 lines
2.7 KiB
CMake
set(LOADER_SOURCES
|
|
main.cpp
|
|
misc.cpp
|
|
)
|
|
|
|
file(GLOB ELF_SOURCES "../Libraries/LibELF/*.cpp")
|
|
file(GLOB LIBC_SOURCES1 "../Libraries/LibC/*.cpp")
|
|
file(GLOB LIBC_SOURCES2 "../Libraries/LibC/*/*.cpp")
|
|
|
|
set(ARCH_FOLDER "${SERENITY_ARCH}")
|
|
|
|
file(GLOB LIBC_SOURCES3 "../Libraries/LibC/arch/${ARCH_FOLDER}/*.S")
|
|
set(ELF_SOURCES ${ELF_SOURCES} "../Libraries/LibELF/Arch/${ARCH_FOLDER}/entry.S" "../Libraries/LibELF/Arch/${ARCH_FOLDER}/plt_trampoline.S")
|
|
if ("${SERENITY_ARCH}" STREQUAL "x86_64")
|
|
set(LIBC_SOURCES3 ${LIBC_SOURCES3} "../Libraries/LibC/arch/x86_64/memset.cpp")
|
|
endif()
|
|
|
|
file(GLOB LIBSYSTEM_SOURCES "../Libraries/LibSystem/*.cpp")
|
|
|
|
if (ENABLE_UNDEFINED_SANITIZER)
|
|
set(LOADER_SOURCES ${LOADER_SOURCES} ../Libraries/LibSanitizer/UBSanitizer.cpp)
|
|
endif()
|
|
|
|
# pthread requires thread local storage, which DynamicLoader does not have.
|
|
list(FILTER LIBC_SOURCES1 EXCLUDE REGEX ".*/LibC/(pthread|semaphore)\\.cpp")
|
|
|
|
add_definitions(-D_DYNAMIC_LOADER)
|
|
|
|
set(SOURCES ${LOADER_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${LIBC_SOURCES1} ${LIBC_SOURCES2} ${LIBC_SOURCES3} ${LIBSYSTEM_SOURCES})
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -nostdlib -pie -fpic -DNO_TLS")
|
|
|
|
if ("${SERENITY_ARCH}" STREQUAL "aarch64")
|
|
# On aarch64 the stack protector would be accessed before the Loader can relocate itself.
|
|
set_source_files_properties(main.cpp ../Libraries/LibELF/Relocation.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
|
|
endif()
|
|
|
|
set_source_files_properties(../Libraries/LibC/ssp.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
|
|
set_source_files_properties(../Libraries/LibC/ssp_nonshared.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
|
|
# Prevent GCC from removing null checks by marking the `FILE*` argument non-null
|
|
set_source_files_properties(../Libraries/LibC/stdio.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-fputc -fno-builtin-fputs -fno-builtin-fwrite")
|
|
|
|
# Prevent naively implemented string functions (like strlen) from being "optimized" into a call to themselves.
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
set_source_files_properties(../Libraries/LibC/string.cpp ../Libraries/LibC/wchar.cpp
|
|
PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns")
|
|
endif()
|
|
|
|
add_executable(Loader.so ${SOURCES})
|
|
add_dependencies(Loader.so install_libc_headers)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
target_link_libraries(Loader.so PRIVATE gcc)
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
|
target_link_libraries(Loader.so PRIVATE clang_rt.builtins)
|
|
endif ()
|
|
|
|
# Note: Don't confuse the coverage results by instrumenting Loader
|
|
target_link_libraries(Loader.so PRIVATE LibTimeZone NoCoverage)
|
|
target_link_options(Loader.so PRIVATE LINKER:--no-dynamic-linker)
|
|
install(TARGETS Loader.so RUNTIME DESTINATION usr/lib/)
|