mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-26 11:18:59 +00:00
LibC: Modernize and simplify LibC/CMakeLists.txt
This commit is contained in:
parent
ce5813d6ab
commit
e3e98ed3eb
Notes:
sideshowbarker
2024-07-16 23:54:15 +09:00
Author: https://github.com/DanShaders
Commit: e3e98ed3eb
Pull-request: https://github.com/SerenityOS/serenity/pull/24129
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/supercomputer7
2 changed files with 154 additions and 42 deletions
|
@ -1,4 +1,6 @@
|
||||||
set(LIBC_SOURCES
|
set(SOURCES
|
||||||
|
arch/${SERENITY_ARCH}/fenv.cpp
|
||||||
|
arch/${SERENITY_ARCH}/setjmp.S
|
||||||
arpa/inet.cpp
|
arpa/inet.cpp
|
||||||
assert.cpp
|
assert.cpp
|
||||||
ctype.cpp
|
ctype.cpp
|
||||||
|
@ -76,15 +78,152 @@ set(LIBC_SOURCES
|
||||||
wchar.cpp
|
wchar.cpp
|
||||||
wctype.cpp
|
wctype.cpp
|
||||||
wstdio.cpp
|
wstdio.cpp
|
||||||
|
|
||||||
|
${AK_SOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB_RECURSE LIBC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" CONFIGURE_DEPENDS "*.h")
|
if (SERENITY_ARCH STREQUAL "x86_64")
|
||||||
list(APPEND LIBC_HEADERS "../LibELF/ELFABI.h" "../LibRegex/RegexDefs.h")
|
list(APPEND SOURCES
|
||||||
|
arch/x86_64/memset.cpp
|
||||||
|
arch/x86_64/memset.S
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# FIXME: This, ideally, should be an exhaustive list of headers (transitively) used by libc's own
|
||||||
|
# headers. (Like, for example, we shouldn't include AK/Platform.h in them for no reason at
|
||||||
|
# all.)
|
||||||
|
set(HEADERS
|
||||||
|
arch/${SERENITY_ARCH}/fenv.h
|
||||||
|
arch/fenv.h
|
||||||
|
arpa/inet.h
|
||||||
|
bits/dlfcn_integration.h
|
||||||
|
bits/FILE.h
|
||||||
|
bits/getopt.h
|
||||||
|
bits/mutex_locker.h
|
||||||
|
bits/posix1_lim.h
|
||||||
|
bits/pthread_cancel.h
|
||||||
|
bits/pthread_integration.h
|
||||||
|
bits/search.h
|
||||||
|
bits/sighow.h
|
||||||
|
bits/stdint.h
|
||||||
|
bits/stdio_file_implementation.h
|
||||||
|
bits/utimens.h
|
||||||
|
bits/wchar.h
|
||||||
|
bits/wchar_size.h
|
||||||
|
net/if.h
|
||||||
|
net/if_arp.h
|
||||||
|
net/route.h
|
||||||
|
netinet/if_ether.h
|
||||||
|
netinet/in.h
|
||||||
|
netinet/in_systm.h
|
||||||
|
netinet/ip.h
|
||||||
|
netinet/ip_icmp.h
|
||||||
|
netinet/tcp.h
|
||||||
|
sys/arch/${SERENITY_ARCH}/regs.h
|
||||||
|
sys/arch/regs.h
|
||||||
|
sys/archctl.h
|
||||||
|
sys/auxv.h
|
||||||
|
sys/cdefs.h
|
||||||
|
sys/device.h
|
||||||
|
sys/devices/gpu.h
|
||||||
|
sys/file.h
|
||||||
|
sys/internals.h
|
||||||
|
sys/ioctl.h
|
||||||
|
sys/mman.h
|
||||||
|
sys/param.h
|
||||||
|
sys/poll.h
|
||||||
|
sys/prctl.h
|
||||||
|
sys/ptrace.h
|
||||||
|
sys/resource.h
|
||||||
|
sys/select.h
|
||||||
|
sys/socket.h
|
||||||
|
sys/stat.h
|
||||||
|
sys/statvfs.h
|
||||||
|
sys/sysmacros.h
|
||||||
|
sys/time.h
|
||||||
|
sys/times.h
|
||||||
|
sys/ttydefaults.h
|
||||||
|
sys/types.h
|
||||||
|
sys/uio.h
|
||||||
|
sys/un.h
|
||||||
|
sys/utsname.h
|
||||||
|
sys/wait.h
|
||||||
|
alloca.h
|
||||||
|
assert.h
|
||||||
|
byteswap.h
|
||||||
|
complex.h
|
||||||
|
ctype.h
|
||||||
|
dirent.h
|
||||||
|
dlfcn.h
|
||||||
|
elf.h
|
||||||
|
endian.h
|
||||||
|
errno_codes.h
|
||||||
|
errno.h
|
||||||
|
fcntl.h
|
||||||
|
fd_set.h
|
||||||
|
fenv.h
|
||||||
|
float.h
|
||||||
|
fnmatch.h
|
||||||
|
getopt.h
|
||||||
|
glob.h
|
||||||
|
grp.h
|
||||||
|
ifaddrs.h
|
||||||
|
inttypes.h
|
||||||
|
langinfo.h
|
||||||
|
libgen.h
|
||||||
|
limits.h
|
||||||
|
link.h
|
||||||
|
locale.h
|
||||||
|
mallocdefs.h
|
||||||
|
math.h
|
||||||
|
memory.h
|
||||||
|
mntent.h
|
||||||
|
netdb.h
|
||||||
|
nl_types.h
|
||||||
|
paths.h
|
||||||
|
poll.h
|
||||||
|
pthread.h
|
||||||
|
pty.h
|
||||||
|
pwd.h
|
||||||
|
regex.h
|
||||||
|
resolv.h
|
||||||
|
sched.h
|
||||||
|
search.h
|
||||||
|
semaphore.h
|
||||||
|
serenity.h
|
||||||
|
setjmp.h
|
||||||
|
shadow.h
|
||||||
|
signal.h
|
||||||
|
spawn.h
|
||||||
|
stdarg.h
|
||||||
|
stdint.h
|
||||||
|
stdio_ext.h
|
||||||
|
stdio.h
|
||||||
|
stdlib.h
|
||||||
|
string.h
|
||||||
|
strings.h
|
||||||
|
sysexits.h
|
||||||
|
syslog.h
|
||||||
|
termcap.h
|
||||||
|
termios.h
|
||||||
|
time.h
|
||||||
|
ucontext.h
|
||||||
|
ulimit.h
|
||||||
|
unistd.h
|
||||||
|
utime.h
|
||||||
|
utmp.h
|
||||||
|
wchar.h
|
||||||
|
wctype.h
|
||||||
|
|
||||||
|
../LibELF/ELFABI.h
|
||||||
|
../LibRegex/RegexDefs.h
|
||||||
|
)
|
||||||
|
|
||||||
|
# ===== LibC headers =====
|
||||||
add_custom_target(install_libc_headers)
|
add_custom_target(install_libc_headers)
|
||||||
|
|
||||||
# Copy LibC's headers into the sysroot to satisfy libc++'s include priority requirements.
|
# Copy LibC's headers into the sysroot to satisfy libc++'s include priority requirements.
|
||||||
foreach(RELATIVE_HEADER_PATH IN LISTS LIBC_HEADERS)
|
foreach(RELATIVE_HEADER_PATH IN LISTS HEADERS)
|
||||||
get_filename_component(directory ${RELATIVE_HEADER_PATH} DIRECTORY)
|
get_filename_component(directory ${RELATIVE_HEADER_PATH} DIRECTORY)
|
||||||
string(REPLACE "../" "" subdirectory "${directory}")
|
string(REPLACE "../" "" subdirectory "${directory}")
|
||||||
file(MAKE_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${subdirectory}")
|
file(MAKE_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${subdirectory}")
|
||||||
|
@ -97,28 +236,9 @@ foreach(RELATIVE_HEADER_PATH IN LISTS LIBC_HEADERS)
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if ("${SERENITY_ARCH}" STREQUAL "aarch64")
|
# ===== Start files =====
|
||||||
set(LIBC_SOURCES ${LIBC_SOURCES} "arch/aarch64/fenv.cpp")
|
# NOTE: We link all these against NoCoverage so that we don't break ports by requiring coverage
|
||||||
set(ASM_SOURCES "arch/aarch64/setjmp.S")
|
# symbols in runtime/startup objects.
|
||||||
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(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(CRTI_SOURCE "arch/riscv64/crti.S")
|
|
||||||
set(CRTN_SOURCE "arch/riscv64/crtn.S")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
|
|
||||||
|
|
||||||
# Note: We link all these against NoCoverage so that we don't break ports by requiring coverage symbols
|
|
||||||
# in runtime/startup objects.
|
|
||||||
|
|
||||||
add_library(crt0 STATIC crt0.cpp)
|
add_library(crt0 STATIC crt0.cpp)
|
||||||
add_dependencies(crt0 install_libc_headers)
|
add_dependencies(crt0 install_libc_headers)
|
||||||
target_link_libraries(crt0 PRIVATE NoCoverage)
|
target_link_libraries(crt0 PRIVATE NoCoverage)
|
||||||
|
@ -126,6 +246,7 @@ add_custom_command(
|
||||||
TARGET crt0
|
TARGET crt0
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crt0> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o
|
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crt0> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(crt0_shared STATIC crt0_shared.cpp)
|
add_library(crt0_shared STATIC crt0_shared.cpp)
|
||||||
add_dependencies(crt0_shared install_libc_headers)
|
add_dependencies(crt0_shared install_libc_headers)
|
||||||
target_link_libraries(crt0_shared PRIVATE NoCoverage)
|
target_link_libraries(crt0_shared PRIVATE NoCoverage)
|
||||||
|
@ -134,36 +255,35 @@ add_custom_command(
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crt0_shared> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0_shared.o
|
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crt0_shared> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0_shared.o
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(crti STATIC ${CRTI_SOURCE})
|
add_library(crti STATIC arch/${SERENITY_ARCH}/crti.S)
|
||||||
target_link_libraries(crti PRIVATE NoCoverage)
|
target_link_libraries(crti PRIVATE NoCoverage)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET crti
|
TARGET crti
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crti> ${CMAKE_INSTALL_PREFIX}/usr/lib/crti.o
|
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crti> ${CMAKE_INSTALL_PREFIX}/usr/lib/crti.o
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(crtn STATIC ${CRTN_SOURCE})
|
add_library(crtn STATIC arch/${SERENITY_ARCH}/crtn.S)
|
||||||
target_link_libraries(crtn PRIVATE NoCoverage)
|
target_link_libraries(crtn PRIVATE NoCoverage)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET crtn
|
TARGET crtn
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crtn> ${CMAKE_INSTALL_PREFIX}/usr/lib/crtn.o
|
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crtn> ${CMAKE_INSTALL_PREFIX}/usr/lib/crtn.o
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ASM_SOURCES})
|
# ===== LibC =====
|
||||||
|
|
||||||
# Prevent GCC from removing null checks by marking the `FILE*` argument non-null
|
# 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")
|
set_source_files_properties(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.
|
# Prevent naively implemented string functions (like strlen) from being "optimized" into a call to themselves.
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
set_source_files_properties(string.cpp wchar.cpp PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns")
|
set_source_files_properties(string.cpp wchar.cpp PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns")
|
||||||
|
else()
|
||||||
|
set_source_files_properties(string.cpp wchar.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set_source_files_properties(ssp.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nolibc")
|
|
||||||
serenity_libc(LibC c)
|
serenity_libc(LibC c)
|
||||||
add_dependencies(LibC crti crt0 crt0_shared crtn install_libc_headers)
|
add_dependencies(LibC crti crt0 crt0_shared crtn install_libc_headers)
|
||||||
target_link_libraries(LibC PRIVATE LibSystem LibTimeZone)
|
target_link_libraries(LibC PRIVATE LibSystem LibTimeZone)
|
||||||
|
target_link_options(LibC PRIVATE -nolibc)
|
||||||
|
|
||||||
# Provide a linker script instead of various other libraries that tells everything to link against LibC.
|
# Provide a linker script instead of various other libraries that tells everything to link against LibC.
|
||||||
file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libpthread.so" "INPUT(libc.so)")
|
file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libpthread.so" "INPUT(libc.so)")
|
||||||
|
|
|
@ -11,18 +11,10 @@
|
||||||
#include <sys/internals.h>
|
#include <sys/internals.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined __SSP__ || defined __SSP_ALL__
|
extern "C" [[gnu::noreturn, gnu::no_stack_protector]] void __stack_chk_fail()
|
||||||
# error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
__attribute__((noreturn)) void __stack_chk_fail()
|
|
||||||
{
|
{
|
||||||
dbgln("Error: USERSPACE({}) Stack protector failure, stack smashing detected!", getpid());
|
dbgln("Error: USERSPACE({}) Stack protector failure, stack smashing detected!", getpid());
|
||||||
if (__stdio_is_initialized)
|
if (__stdio_is_initialized)
|
||||||
warnln("Error: Stack protector failure, stack smashing detected!");
|
warnln("Error: Stack protector failure, stack smashing detected!");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue