serenity/Toolchain/Patches/binutils/0001-Add-support-for-SerenityOS.patch
Daniel Bertalan 4defa401d3 Toolchain+Ports: Update binutils to 2.41
Aside from a straightforward rebase, this contains an out-of-tree patch
from MaskRay which adds the `-Bsymbolic-non-weak-functions` flag to ld.
2023-09-18 10:26:42 +02:00

309 lines
14 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan <dani@danielbertalan.dev>
Date: Mon, 27 Mar 2023 19:24:04 +1100
Subject: [PATCH] Add support for SerenityOS
Teaches the assembler, BFD, and the linker about the SerenityOS target
triple.
We set '/' to not start a comment in GAS, as the QEMU port uses it for
division in constant expressions in assembly files (cf. as --divide).
`/usr/lib/Loader.so` is set as the default ELF interpreter.
On AArch64, we set `COMMONPAGESIZE` to enable RELRO support.
---
bfd/config.bfd | 10 ++++++++++
gas/config/tc-i386.c | 3 ++-
gas/config/te-serenity.h | 3 +++
gas/configure.tgt | 3 +++
ld/Makefile.am | 6 ++++++
ld/Makefile.in | 9 +++++++++
ld/configure.tgt | 9 +++++++++
ld/emulparams/aarch64serenity.sh | 5 +++++
ld/emulparams/elf64lriscvserenity.sh | 2 ++
ld/emulparams/elf_serenity.sh | 1 +
ld/emulparams/elf_x86_64_serenity.sh | 2 ++
11 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 gas/config/te-serenity.h
create mode 100644 ld/emulparams/aarch64serenity.sh
create mode 100644 ld/emulparams/elf64lriscvserenity.sh
create mode 100644 ld/emulparams/elf_serenity.sh
create mode 100644 ld/emulparams/elf_x86_64_serenity.sh
diff --git a/bfd/config.bfd b/bfd/config.bfd
index bdee53957c0ca034161715f86e84fcc950d7b625..dc97a5e4a57709736c62f4f4555dd92c0cabd507 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -283,6 +283,11 @@ case "${targ}" in
targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec"
want64=true
;;
+ aarch64-*-serenity*)
+ targ_defvec=aarch64_elf64_le_vec
+ targ_selvecs=
+ want64=true
+ ;;
aarch64-*-linux* | aarch64-*-netbsd* | aarch64-*-nto*)
targ_defvec=aarch64_elf64_le_vec
targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec aarch64_pei_le_vec aarch64_pe_le_vec"
@@ -734,6 +739,11 @@ case "${targ}" in
targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec"
want64=true
;;
+ x86_64-*-serenity*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs=i386_elf32_vec
+ want64=true
+ ;;
#endif
i[3-7]86-*-lynxos*)
targ_defvec=i386_elf32_vec
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index de35ee2a2c6952e596e2f5092a22dee5cc54d92c..7f9c91019432a86d4eb1e94bfe7b9ffd6976057a 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -501,7 +501,8 @@ const char extra_symbol_chars[] = "*%-([{}"
&& !defined (TE_Haiku) \
&& !defined (TE_FreeBSD) \
&& !defined (TE_DragonFly) \
- && !defined (TE_NetBSD))
+ && !defined (TE_NetBSD) \
+ && !defined (TE_SerenityOS))
/* This array holds the chars that always start a comment. If the
pre-processor is disabled, these aren't very useful. The option
--divide will remove '/' from this list. */
diff --git a/gas/config/te-serenity.h b/gas/config/te-serenity.h
new file mode 100644
index 0000000000000000000000000000000000000000..f38faf598cba7f561ed9528ee37328228ee55bdc
--- /dev/null
+++ b/gas/config/te-serenity.h
@@ -0,0 +1,3 @@
+#include "te-generic.h"
+
+#define TE_SerenityOS 1
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 3429f850d05a23783d6736d875c649f5acf48afa..cc83c4d94da21fa278f7f2bdd32b436bd4b540a3 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -137,6 +137,7 @@ case ${generic_target} in
aarch64*-*-nto*) fmt=elf;;
aarch64*-*-openbsd*) fmt=elf;;
aarch64*-*-pe* | aarch64*-*-mingw*) fmt=coff em=pepaarch64 ;;
+ aarch64*-*-serenity*) fmt=elf em=serenity ;;
alpha-*-*vms*) fmt=evax ;;
alpha-*-osf*) fmt=ecoff ;;
alpha-*-linux*ecoff*) fmt=ecoff ;;
@@ -265,6 +266,7 @@ case ${generic_target} in
i386-*-*nt*) fmt=coff em=pe ;;
i386-*-rdos*) fmt=elf ;;
i386-*-darwin*) fmt=macho ;;
+ i386-*-serenity) fmt=elf em=serenity ;;
ia16-*-elf*) fmt=elf ;;
@@ -370,6 +372,7 @@ case ${generic_target} in
pru-*-*) fmt=elf ;;
+ riscv64-*-serenity*) fmt=elf endian=little em=serenity ;;
riscv*-*-haiku*) fmt=elf endian=little em=haiku ;;
riscv*-*-*) fmt=elf ;;
diff --git a/ld/Makefile.am b/ld/Makefile.am
index c3adbb0ccadacb5060988fe0aa24700b7cb489b4..5bbb3a61738a4cce09ba9b8b58d329c3bd5a36ec 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -390,6 +390,7 @@ ALL_64_EMULATION_SOURCES = \
eaarch64linuxb.c \
eaarch64nto.c \
eaarch64pe.c \
+ eaarch64serenity.c \
earm64pe.c \
eelf32_x86_64.c \
eelf32b4300.c \
@@ -444,6 +445,7 @@ ALL_64_EMULATION_SOURCES = \
eelf64lppc.c \
eelf64lppc_fbsd.c \
eelf64lriscv.c \
+ eelf64lriscvserenity.c \
eelf64lriscv_lp64.c \
eelf64lriscv_lp64f.c \
eelf64ltsmip.c \
@@ -459,6 +461,7 @@ ALL_64_EMULATION_SOURCES = \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
+ eelf_x86_64_serenity.c \
eelf_x86_64_sol2.c \
ehppa64linux.c \
ei386pep.c \
@@ -885,6 +888,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64linuxb.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64nto.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64pe.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64serenity.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earm64pe.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32_x86_64.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32b4300.Pc@am__quote@
@@ -939,6 +943,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lppc_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64loongarch.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscvserenity.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64f.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip.Pc@am__quote@
@@ -954,6 +959,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_serenity.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_sol2.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ehppa64linux.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ei386pep.Pc@am__quote@
diff --git a/ld/Makefile.in b/ld/Makefile.in
index d1a5602643787c240b5323c6c09b9d2bbc813e79..b18a0ed9cede77b1665bb0716176091ac02f5fe9 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -890,6 +890,7 @@ ALL_64_EMULATION_SOURCES = \
eaarch64linuxb.c \
eaarch64nto.c \
eaarch64pe.c \
+ eaarch64serenity.c \
earm64pe.c \
eelf32_x86_64.c \
eelf32b4300.c \
@@ -944,6 +945,7 @@ ALL_64_EMULATION_SOURCES = \
eelf64lppc.c \
eelf64lppc_fbsd.c \
eelf64lriscv.c \
+ eelf64lriscvserenity.c \
eelf64lriscv_lp64.c \
eelf64lriscv_lp64f.c \
eelf64ltsmip.c \
@@ -959,6 +961,7 @@ ALL_64_EMULATION_SOURCES = \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_haiku.c \
+ eelf_x86_64_serenity.c \
eelf_x86_64_sol2.c \
ehppa64linux.c \
ei386pep.c \
@@ -1271,6 +1274,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64linuxb.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64nto.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64pe.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64serenity.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaix5ppc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaix5rs6.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaixppc.Po@am__quote@
@@ -1447,6 +1451,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lppc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lppc_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscvserenity.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64f.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip.Po@am__quote@
@@ -1471,6 +1476,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_serenity.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_sol2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eh8300elf.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eh8300elf_linux.Po@am__quote@
@@ -2602,6 +2608,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64linuxb.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64nto.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64pe.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eaarch64serenity.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earm64pe.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32_x86_64.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32b4300.Pc@am__quote@
@@ -2656,6 +2663,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lppc_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64loongarch.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscvserenity.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64f.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip.Pc@am__quote@
@@ -2671,6 +2679,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_cloudabi.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_fbsd.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_haiku.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_serenity.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf_x86_64_sol2.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ehppa64linux.Pc@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ei386pep.Pc@am__quote@
diff --git a/ld/configure.tgt b/ld/configure.tgt
index c62b9581d9b8bb0bb000ff83247baa6144b9921b..6d0d7b2e0dee06be5c808aa933643e4c9eff0a7a 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -97,6 +97,9 @@ aarch64-*-freebsd*) targ_emul=aarch64fbsd
aarch64-*-fuchsia*) targ_emul=aarch64elf
targ_extra_emuls="aarch64elfb armelf armelfb"
;;
+aarch64-*-serenity*) targ_emul=aarch64serenity
+ targ_extra_emuls=aarch64elf
+ ;;
aarch64_be-*-linux-gnu_ilp32)
targ_emul=aarch64linux32b
targ_extra_libpath="aarch64linuxb aarch64linux aarch64linux32 armelfb_linux_eabi armelf_linux_eabi"
@@ -825,6 +828,9 @@ riscv64*-*-linux*) targ_emul=elf64lriscv
targ_extra_emuls="elf64lriscv_lp64f elf64lriscv_lp64 elf32lriscv elf32lriscv_ilp32f elf32lriscv_ilp32 elf64briscv elf64briscv_lp64f elf64briscv_lp64 elf32briscv elf32briscv_ilp32f elf32briscv_ilp32"
targ_extra_libpath=$targ_extra_emuls
;;
+riscv64-*-serenity*) targ_emul=elf64lriscvserenity
+ targ_extra_emuls=elf64lriscv
+ ;;
riscv64be*-*-*) targ_emul=elf64briscv
targ_extra_emuls="elf32briscv elf64lriscv elf32lriscv"
targ_extra_libpath=$targ_extra_emuls
@@ -1011,6 +1017,9 @@ x86_64-*-linux-*) targ_emul=elf_x86_64
x86_64-*-redox*) targ_emul=elf_x86_64
targ_extra_emuls=elf_i386
;;
+x86_64-*-serenity*) targ_emul=elf_x86_64_serenity
+ targ_extra_emuls="elf_x86_64 elf_i386"
+ ;;
x86_64-*-solaris2*) targ_emul=elf_x86_64_sol2
targ_extra_emuls="elf_x86_64 elf_i386_sol2 elf_i386_ldso elf_i386 elf_iamcu"
targ_extra_libpath=$targ_extra_emuls
diff --git a/ld/emulparams/aarch64serenity.sh b/ld/emulparams/aarch64serenity.sh
new file mode 100644
index 0000000000000000000000000000000000000000..23aed1440a033e2ac06536f43c1bacaf98832b92
--- /dev/null
+++ b/ld/emulparams/aarch64serenity.sh
@@ -0,0 +1,5 @@
+source_sh ${srcdir}/emulparams/aarch64elf.sh
+source_sh ${srcdir}/emulparams/elf_serenity.sh
+
+COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
+unset EMBEDDED
diff --git a/ld/emulparams/elf64lriscvserenity.sh b/ld/emulparams/elf64lriscvserenity.sh
new file mode 100644
index 0000000000000000000000000000000000000000..8bcbea812b49363cf4e2e94e1554998277b21cb1
--- /dev/null
+++ b/ld/emulparams/elf64lriscvserenity.sh
@@ -0,0 +1,2 @@
+source_sh ${srcdir}/emulparams/elf64lriscv.sh
+source_sh ${srcdir}/emulparams/elf_serenity.sh
diff --git a/ld/emulparams/elf_serenity.sh b/ld/emulparams/elf_serenity.sh
new file mode 100644
index 0000000000000000000000000000000000000000..c434bacaa7fa16a9bb1c4934ad061230fbf56825
--- /dev/null
+++ b/ld/emulparams/elf_serenity.sh
@@ -0,0 +1 @@
+ELF_INTERPRETER_NAME=\"/usr/lib/Loader.so\"
diff --git a/ld/emulparams/elf_x86_64_serenity.sh b/ld/emulparams/elf_x86_64_serenity.sh
new file mode 100644
index 0000000000000000000000000000000000000000..536af1e31d761b22e3e40cafd339d5bf7a285756
--- /dev/null
+++ b/ld/emulparams/elf_x86_64_serenity.sh
@@ -0,0 +1,2 @@
+source_sh ${srcdir}/emulparams/elf_x86_64.sh
+source_sh ${srcdir}/emulparams/elf_serenity.sh