commit 8d9a05365da29a065550575619c11147379673f8
parent d65516439b03c3dbabc74141bda1b804af6bc962
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Wed, 24 Dec 2025 01:25:54 +0000
Cross compile for x86_64 and aarch64
Diffstat:
4 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/Tupfile b/Tupfile
@@ -1,7 +1,14 @@
CXXFLAGS = -g -Os -fno-asynchronous-unwind-tables -fno-builtin -fno-pic -fno-pie -fno-stack-protector -fdiagnostics-color=always
LDFLAGS = --gc-sections
-: foreach *.cpp |> clang++ $(CXXFLAGS) -c -o %o %f |> obj/%B.o {objs}
+: foreach *.cpp |> clang++ --target=aarch64 $(CXXFLAGS) -c -o %o %f |> obj/%B.aarch64.o {objs-aarch64}
+: foreach *.cpp |> clang++ --target=x86_64 $(CXXFLAGS) -c -o %o %f |> obj/%B.x86_64.o {objs-x86_64}
+
+: foreach *.s |> clang --target=%B -c -o %o %f |> obj/%B.o
+
+: foreach {objs-aarch64} | aarch64.ld obj/aarch64.o |> ld.lld -m aarch64elf $(LDFLAGS) -o %o --script aarch64.ld obj/aarch64.o %f |> bin/%B {bin-aarch64}
+: foreach {objs-x86_64} | x86_64.ld obj/x86_64.o |> ld.lld -m elf_x86_64 $(LDFLAGS) -o %o --script x86_64.ld obj/x86_64.o %f |> bin/%B
+
run ./gen.sh
.gitignore
diff --git a/aarch64.ld b/aarch64.ld
@@ -7,18 +7,18 @@ PHDRS
MEMORY
{
- userspace (rwx) : ORIGIN = 0x10000, LENGTH = 0x100000 - ORIGIN(userspace)
+ userspace (rwx) : ORIGIN = 0x10000, LENGTH = 0x1000000 - 0x10000 #ORIGIN(userspace)
}
SECTIONS
{
- .rodata (READONLY) :
+ .rodata :
ALIGN(CONSTANT(MAXPAGESIZE))
{
*(.rodata*)
} >userspace :rodata
- .text (READONLY) :
+ .text :
ALIGN(CONSTANT(MAXPAGESIZE))
{
*(.text*)
@@ -30,7 +30,6 @@ SECTIONS
*(.data*)
} >userspace :data
-
.bss (NOLOAD) :
ALIGN(CONSTANT(MAXPAGESIZE))
{
@@ -41,9 +40,9 @@ SECTIONS
ALIGN(CONSTANT(MAXPAGESIZE))
{
*(.mappable*)
- mappable = .;
} >userspace
-
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
+ mappable = .;
}
ENTRY(start)
diff --git a/gen.sh b/gen.sh
@@ -2,5 +2,4 @@
ARCH=`uname -m`
-echo ": $ARCH.s |> as -o %o <%f |> obj/%B.o"
-echo ": foreach {objs} | $ARCH.ld obj/$ARCH.o |> ld "'$(LDFLAGS)'" -o %o -T $ARCH.ld obj/$ARCH.o %f |> %B"
+echo ": foreach {bin-$ARCH} |> ln -s %f %o |> %B"
diff --git a/x86_64.ld b/x86_64.ld
@@ -7,18 +7,18 @@ PHDRS
MEMORY
{
- userspace (rwx) : ORIGIN = 0x10000, LENGTH = 0x7ffff7000000 - ORIGIN(userspace)
+ userspace (rwx) : ORIGIN = 0x10000, LENGTH = 0x7ffff7000000 - 0x10000 #ORIGIN(userspace)
}
SECTIONS
{
- .rodata (READONLY) :
+ .rodata :
ALIGN(CONSTANT(MAXPAGESIZE))
{
*(.rodata*)
} >userspace :rodata
- .text (READONLY) :
+ .text :
ALIGN(CONSTANT(MAXPAGESIZE))
{
*(.text*)
@@ -40,8 +40,9 @@ SECTIONS
ALIGN(CONSTANT(MAXPAGESIZE))
{
*(.mappable*)
- mappable = .;
} >userspace
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
+ mappable = .;
}
ENTRY(start)