sys: add ld runtime linker
This commit is contained in:
@@ -0,0 +1 @@
|
||||
add_subdirectory(ld)
|
||||
|
||||
24
sys/ld/CMakeLists.txt
Normal file
24
sys/ld/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
file(GLOB c_sources *.c *.h)
|
||||
file(GLOB arch_sources arch/${CMAKE_SYSTEM_PROCESSOR}/*.S)
|
||||
|
||||
set_property(SOURCE ${arch_sources} PROPERTY LANGUAGE C)
|
||||
|
||||
add_executable(ld ${c_sources} ${arch_sources})
|
||||
set_target_properties(ld PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
OUTPUT_NAME "ld64"
|
||||
SUFFIX ".so")
|
||||
|
||||
target_link_libraries(ld ulibc libmango)
|
||||
|
||||
target_compile_options(ld PRIVATE
|
||||
-fPIC -fno-stack-protector -nostdlib -ffreestanding)
|
||||
target_link_options(ld PRIVATE
|
||||
-fPIC -nostdlib -ffreestanding -Wl,-shared)
|
||||
|
||||
sysroot_add_program(
|
||||
NAME ld
|
||||
BIN_DIR /lib)
|
||||
bsp_add_program(
|
||||
NAME ld
|
||||
BIN_DIR /lib)
|
||||
30
sys/ld/arch/x86_64/layout.ld
Normal file
30
sys/ld/arch/x86_64/layout.ld
Normal file
@@ -0,0 +1,30 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS {
|
||||
.text ALIGN(4K) : {
|
||||
*(.text)
|
||||
*(.rodata)
|
||||
}
|
||||
|
||||
.rodata ALIGN(4K) : {
|
||||
|
||||
}
|
||||
|
||||
.data ALIGN(4K) : {
|
||||
*(.data)
|
||||
*(.bss)
|
||||
*(.dynamic)
|
||||
}
|
||||
|
||||
.dynamic ALIGN(8) : {
|
||||
*(.dynamic)
|
||||
}
|
||||
|
||||
.got.plt ALIGN(4K) : {
|
||||
*(.got.plt)
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.interp)
|
||||
}
|
||||
}
|
||||
15
sys/ld/arch/x86_64/start.S
Normal file
15
sys/ld/arch/x86_64/start.S
Normal file
@@ -0,0 +1,15 @@
|
||||
.code64
|
||||
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
.extern main
|
||||
.type main, @function
|
||||
|
||||
.extern exit
|
||||
.type exit, @function
|
||||
|
||||
_start:
|
||||
call main
|
||||
1: pause
|
||||
jmp 1b
|
||||
13
sys/ld/main.c
Normal file
13
sys/ld/main.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <mango/log.h>
|
||||
#include <mango/types.h>
|
||||
|
||||
int main(
|
||||
int argc,
|
||||
const char **argv,
|
||||
kern_handle_t task,
|
||||
kern_handle_t address_space,
|
||||
uintptr_t bsp_base)
|
||||
{
|
||||
kern_log("ld!");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user