sys: add ld runtime linker

This commit is contained in:
2026-02-19 19:30:07 +00:00
parent 1e6748b4fc
commit efad96ce63
5 changed files with 83 additions and 0 deletions

24
sys/ld/CMakeLists.txt Normal file
View 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)

View 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)
}
}

View 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
View 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;
}