feat: revamp libraries to use ELF shared objects
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Makefile for libhello shared library
|
||||
# Builds libhello.lib at fixed address 0x400000 (relocated at load time)
|
||||
# Builds libhello.lib as an ELF shared object (ET_DYN).
|
||||
|
||||
# Target architecture.
|
||||
ARCH := x86_64
|
||||
@@ -7,12 +7,12 @@ ARCH := x86_64
|
||||
# Toolchain
|
||||
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
|
||||
CXX := $(TOOLCHAIN_PREFIX)g++
|
||||
LD := $(TOOLCHAIN_PREFIX)ld
|
||||
NM := $(TOOLCHAIN_PREFIX)nm
|
||||
STRIP := $(TOOLCHAIN_PREFIX)strip
|
||||
|
||||
# Compiler flags: freestanding, no stdlib
|
||||
# Build as PIE so library-internal data references remain valid after the
|
||||
# kernel maps the image into a per-process library slot.
|
||||
# Build as PIC so the final ET_DYN image can be relocated by the kernel loader.
|
||||
override CXXFLAGS := \
|
||||
-std=gnu++20 \
|
||||
-g -O2 -pipe \
|
||||
@@ -22,7 +22,7 @@ override CXXFLAGS := \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fPIE \
|
||||
-fPIC \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-ffunction-sections \
|
||||
@@ -40,14 +40,13 @@ override CXXFLAGS := \
|
||||
-isystem ../../../kernel/freestnd-c-hdrs/x86_64/include \
|
||||
-isystem ../../../kernel/freestnd-cxx-hdrs/x86_64/include
|
||||
|
||||
# Linker flags: freestanding static ELF at fixed address
|
||||
# Note: NOT using --gc-sections so all functions are kept
|
||||
# Linker flags for a bare-metal ELF shared object.
|
||||
override LDFLAGS := \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-Wl,--build-id=none \
|
||||
-Wl,-m,elf_x86_64 \
|
||||
-T link.ld
|
||||
-shared \
|
||||
--build-id=none \
|
||||
--hash-style=sysv \
|
||||
-m elf_x86_64 \
|
||||
-z max-page-size=0x1000
|
||||
|
||||
# Output
|
||||
OUTDIR := ../../bin/os
|
||||
@@ -56,7 +55,7 @@ LIBSRC := src/libhello.cpp
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OUTDIR)/$(LIBNAME).lib $(OUTDIR)/$(LIBNAME).lib.sym
|
||||
all: $(OUTDIR)/$(LIBNAME).lib
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir -p $@
|
||||
@@ -68,16 +67,8 @@ src/stb_truetype_impl.o: src/stb_truetype_impl.cpp Makefile | $(OUTDIR)
|
||||
$(CXX) $(CXXFLAGS) -c src/stb_truetype_impl.cpp -o $@
|
||||
|
||||
$(OUTDIR)/$(LIBNAME).lib: src/libhello.o src/stb_truetype_impl.o
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) src/libhello.o src/stb_truetype_impl.o -o $@
|
||||
|
||||
# Generate symbol file from nm output
|
||||
# Format: "symbol_name,offset_in_hex"
|
||||
$(OUTDIR)/$(LIBNAME).lib.sym: $(OUTDIR)/$(LIBNAME).lib
|
||||
@mkdir -p $(OUTDIR)
|
||||
@echo "# Symbol table for $(LIBNAME)" > $@
|
||||
@echo "# This file maps symbol names to offsets from library base" >> $@
|
||||
@$(NM) $(OUTDIR)/$(LIBNAME).lib | grep ' T ' | awk '{printf "%s,0x%x\n", $$3, strtonum("0x" $$1) - 0x400000}' >> $@
|
||||
@echo "Generated symbol file: $@"
|
||||
rm -f $(OUTDIR)/$(LIBNAME).lib.sym
|
||||
$(LD) $(LDFLAGS) src/libhello.o src/stb_truetype_impl.o -o $@
|
||||
|
||||
clean:
|
||||
rm -rf ../../bin/os/$(LIBNAME).lib ../../bin/os/$(LIBNAME).lib.sym src/libhello.o src/stb_truetype_impl.o
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user