diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-07-12 20:37:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 13:12:25 +0200 |
commit | a88f7c99fe7026ee6e0c0a2b2385e767c04133c2 (patch) | |
tree | 75c351faa2378366d3f9fcddf4b2e94ea537cddc /Userland/Libraries | |
parent | 7f2eb2f33280a44fead28b5416c10b64521f7704 (diff) | |
download | serenity-a88f7c99fe7026ee6e0c0a2b2385e767c04133c2.zip |
LibC: Use our implementation of `crti.o` and `crtn.o`
We have had these for quite a while, but we didn't compile them, and
used GCC's version instead. Clang does not come with these, so we have
to provide our own implementation.
Our implementation follows what `musl` and `FreeBSD` do, so this should
work fine, even if documentation can hardly be found for them.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibC/CMakeLists.txt | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibC/arch/i386/crti.S | 23 | ||||
-rw-r--r-- | Userland/Libraries/LibC/arch/i386/crtn.S | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibC/arch/x86_64/crti.S | 23 | ||||
-rw-r--r-- | Userland/Libraries/LibC/arch/x86_64/crtn.S | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibC/crti.S | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibC/crtn.S | 13 |
7 files changed, 93 insertions, 29 deletions
diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index defdeaf701..ab1288a007 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -65,9 +65,13 @@ file(GLOB ELF_SOURCES CONFIGURE_DEPENDS "../LibELF/*.cpp") if ("${SERENITY_ARCH}" STREQUAL "i686") set(ASM_SOURCES "arch/i386/setjmp.S") set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/i386/entry.S ../LibELF/Arch/i386/plt_trampoline.S) + set(CRTI_SOURCE "arch/i386/crti.S") + set(CRTN_SOURCE "arch/i386/crtn.S") elseif ("${SERENITY_ARCH}" STREQUAL "x86_64") set(ASM_SOURCES "arch/x86_64/setjmp.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") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -DSERENITY_LIBC_BUILD") @@ -83,6 +87,18 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:crt0_shared> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0_shared.o ) +add_library(crti STATIC ${CRTI_SOURCE}) +add_custom_command( + TARGET crti + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:crti> ${CMAKE_INSTALL_PREFIX}/usr/lib/crti.o +) + +add_library(crtn STATIC ${CRTN_SOURCE}) +add_custom_command( + TARGET crtn + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:crtn> ${CMAKE_INSTALL_PREFIX}/usr/lib/crtn.o +) + set_source_files_properties (ssp.cpp PROPERTIES COMPILE_FLAGS "-fno-stack-protector") add_library(ssp STATIC ssp.cpp) @@ -118,7 +134,7 @@ set_property( set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++") serenity_libc(LibC c) -add_dependencies(LibC crt0 crt0_shared) +add_dependencies(LibC crti crt0 crt0_shared crtn) target_link_libraries(LibC ssp system) # We mark LibCStatic as a dependency of LibC because this triggers the build of the LibCStatic target diff --git a/Userland/Libraries/LibC/arch/i386/crti.S b/Userland/Libraries/LibC/arch/i386/crti.S new file mode 100644 index 0000000000..a5cd2f46c0 --- /dev/null +++ b/Userland/Libraries/LibC/arch/i386/crti.S @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +.section .init, "ax", @progbits +.align 4 +.global _init +.type _init, @function +_init: + pushl %ebp + movl %esp, %ebp + andl $-16, %esp + +.section .fini, "ax", @progbits +.align 4 +.global _fini +.type _fini, @function +_fini: + pushl %ebp + movl %esp, %ebp + andl $-16, %esp diff --git a/Userland/Libraries/LibC/arch/i386/crtn.S b/Userland/Libraries/LibC/arch/i386/crtn.S new file mode 100644 index 0000000000..1861755c74 --- /dev/null +++ b/Userland/Libraries/LibC/arch/i386/crtn.S @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +.section .init, "ax", @progbits + movl %ebp, %esp + popl %ebp + retl + +.section .fini, "ax", @progbits + movl %ebp, %esp + popl %ebp + retl diff --git a/Userland/Libraries/LibC/arch/x86_64/crti.S b/Userland/Libraries/LibC/arch/x86_64/crti.S new file mode 100644 index 0000000000..af58391ae8 --- /dev/null +++ b/Userland/Libraries/LibC/arch/x86_64/crti.S @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, Daniel Bertalan <dani@danielbertalan.dev> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +.section .init, "ax", @progbits +.align 4 +.global _init +.type _init, @function +_init: + pushq %rbp + movq %rsp, %rbp + andq $-16, %rsp + +.section .fini, "ax", @progbits +.align 4 +.global _fini +.type _fini, @function +_fini: + pushq %rbp + movq %rsp, %rbp + andq $-16, %rsp diff --git a/Userland/Libraries/LibC/arch/x86_64/crtn.S b/Userland/Libraries/LibC/arch/x86_64/crtn.S new file mode 100644 index 0000000000..71d6b29b54 --- /dev/null +++ b/Userland/Libraries/LibC/arch/x86_64/crtn.S @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021, Daniel Bertalan <dani@danielbertalan.dev> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +.section .init, "ax", @progbits + movq %rbp, %rsp + popq %rbp + retq + +.section .fini, "ax", @progbits + movq %rbp, %rsp + popq %rbp + retq diff --git a/Userland/Libraries/LibC/crti.S b/Userland/Libraries/LibC/crti.S deleted file mode 100644 index 5c05ad34ea..0000000000 --- a/Userland/Libraries/LibC/crti.S +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -.global _init -.section .init -_init: - push %ebp - -.global _fini -.section .fini -_fini: - push %ebp diff --git a/Userland/Libraries/LibC/crtn.S b/Userland/Libraries/LibC/crtn.S deleted file mode 100644 index 9e45e1e346..0000000000 --- a/Userland/Libraries/LibC/crtn.S +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -.section .init - pop %ebp - ret - -.section .fini - pop %ebp - ret |