mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
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.
This commit is contained in:
parent
7f2eb2f332
commit
a88f7c99fe
Notes:
sideshowbarker
2024-07-18 09:04:40 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/a88f7c99fe7 Pull-request: https://github.com/SerenityOS/serenity/pull/8696 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/gunnarbeutner ✅ Reviewed-by: https://github.com/networkException
|
@ -150,10 +150,4 @@ void _entry(int argc, char** argv, char** envp)
|
|||
ELF::DynamicLinker::linker_main(move(main_program_name), main_program_fd, is_secure, argc, argv, envp);
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
void _fini();
|
||||
|
||||
void _fini()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
23
Userland/Libraries/LibC/arch/i386/crti.S
Normal file
23
Userland/Libraries/LibC/arch/i386/crti.S
Normal file
|
@ -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
|
15
Userland/Libraries/LibC/arch/i386/crtn.S
Normal file
15
Userland/Libraries/LibC/arch/i386/crtn.S
Normal file
|
@ -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
|
23
Userland/Libraries/LibC/arch/x86_64/crti.S
Normal file
23
Userland/Libraries/LibC/arch/x86_64/crti.S
Normal file
|
@ -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
|
15
Userland/Libraries/LibC/arch/x86_64/crtn.S
Normal file
15
Userland/Libraries/LibC/arch/x86_64/crtn.S
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue