ladybird/Toolchain/Patches/binutils.patch
Tim Schumacher 292398b585 Toolchain: Load x64 executables at a higher address
Serenity defines a protected range of memory that must not be mmapped,
and is apparently reserved for kernel tasks. In this case, the protected
range is anything below 0x800000.

However, in its default setting, binutils chooses the memory address
0x400000 as the mapping address for executables that do not have PIE
enabled, resulting in mmap being unable to map the file unless the load
address has been overwritten at link time or if it's a PIE.

To mitigate this, move the default base address somewhere outside of
that range (and preferably not anywhere close near the beginning of the
useable virtual memory space, to avoid running into it during sequential
allocations).
2021-11-14 22:25:15 +01:00

194 lines
5.7 KiB
Diff

diff --git a/bfd/config.bfd b/bfd/config.bfd
index 30087e3b..8b192b2e 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -223,7 +223,29 @@ esac
case "${targ}" in
# START OF targmatch.h
+
+ i[3-7]86-*-serenity*)
+ targ_defvec=i386_elf32_vec
+ targ_selvecs=
+ ;;
#ifdef BFD64
+ x86_64-*-serenity*)
+ targ_defvec=x86_64_elf64_vec
+ targ_selvecs=i386_elf32_vec
+ want64=true
+ ;;
+
+ arm-*-serenity*)
+ targ_defvec=arm_elf32_le_vec
+ targ_selvecs=
+ targ64_selvecs=
+ ;;
+ aarch64-*-serenity*)
+ targ_defvec=aarch64_elf64_le_vec
+ targ_selvecs=
+ want64=true
+ ;;
+
aarch64-*-darwin*)
targ_defvec=aarch64_mach_o_vec
targ_selvecs="arm_mach_o_vec mach_o_le_vec mach_o_be_vec mach_o_fat_vec"
diff --git a/config.sub b/config.sub
index 7384e919..aa02c3f6 100755
--- a/config.sub
+++ b/config.sub
@@ -1700,6 +1700,7 @@ case $os in
# The portable systems comes first.
# Each alternative MUST end in a * to match a version number.
gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
+ | serenity* \
| *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \
| hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
| sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 338892ad..3c03ee8b 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -123,6 +123,9 @@ esac
generic_target=${cpu_type}-$vendor-$os
# Note: This table is alpha-sorted, please try to keep it that way.
case ${generic_target} in
+ i386-*-serenity*) fmt=elf;;
+ arm-*-serenity*) fmt=elf;;
+ aarch64-*-serenity*) fmt=elf;;
aarch64*-*-elf*) fmt=elf;;
aarch64*-*-fuchsia*) fmt=elf;;
aarch64*-*-genode*) fmt=elf;;
diff --git a/ld/Makefile.am b/ld/Makefile.am
index f8e99325..bc55fd2b 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -174,6 +174,7 @@ ALL_EMULATION_SOURCES = \
earmelf_nbsd.c \
earmelf_phoenix.c \
earmelf_vxworks.c \
+ earmelf_serenity.c \
earmelfb.c \
earmelfb_fbsd.c \
earmelfb_fuchsia.c \
diff --git a/ld/Makefile.in b/ld/Makefile.in
index ef2e99e0..657d24a2 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -664,6 +664,7 @@ ALL_EMULATION_SOURCES = \
earmelf_nbsd.c \
earmelf_phoenix.c \
earmelf_vxworks.c \
+ earmelf_serenity.c \
earmelfb.c \
earmelfb_fbsd.c \
earmelfb_fuchsia.c \
@@ -774,6 +775,7 @@ ALL_EMULATION_SOURCES = \
eelf_i386_vxworks.c \
eelf_iamcu.c \
eelf_s390.c \
+ eelf_i386_serenity.c \
eh8300elf.c \
eh8300elf_linux.c \
eh8300helf.c \
@@ -945,6 +947,7 @@ ALL_64_EMULATION_SOURCES = \
eelf_x86_64_cloudabi.c \
eelf_x86_64_fbsd.c \
eelf_x86_64_sol2.c \
+ eelf_x86_64_serenity.c \
ehppa64linux.c \
ei386pep.c \
emmo.c
diff --git a/ld/configure.tgt b/ld/configure.tgt
index 6205d7c9..00d97c37 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -43,6 +43,23 @@ targ64_extra_libpath=
# Please try to keep this table more or less in alphabetic order - it
# makes it much easier to lookup a specific archictecture.
case "${targ}" in
+i[3-7]86-*-serenity*)
+ targ_emul=elf_i386_serenity
+ targ_extra_emuls=elf_i386
+ targ64_extra_emuls="elf_x86_64_serenity elf_x86_64"
+ ;;
+x86_64-*-serenity*)
+ targ_emul=elf_x86_64_serenity
+ targ_extra_emuls="elf_i386_serenity elf_x86_64 elf_i386"
+ ;;
+arm-*-serenity*)
+ targ_emul=armelf_serenity
+ targ_extra_emuls="armelf_serenity armelf"
+ ;;
+aarch64-*-serenity*)
+ targ_emul=aarch64elf
+ targ_extra_emuls=
+ ;;
aarch64_be-*-elf) targ_emul=aarch64elfb
targ_extra_emuls="aarch64elf aarch64elf32 aarch64elf32b armelfb armelf"
;;
diff --git a/ld/emulparams/armelf_serenity.sh b/ld/emulparams/armelf_serenity.sh
new file mode 100644
index 00000000..517cd626
--- /dev/null
+++ b/ld/emulparams/armelf_serenity.sh
@@ -0,0 +1,7 @@
+. ${srcdir}/emulparams/armelf.sh
+MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
+TEXT_START_ADDR=0x00008000
+TARGET2_TYPE=got-rel
+
+unset STACK_ADDR
+unset EMBEDDED
diff --git a/ld/emulparams/elf_aarch64_serenity.sh b/ld/emulparams/elf_aarch64_serenity.sh
new file mode 100644
index 00000000..45a05bf4
--- /dev/null
+++ b/ld/emulparams/elf_aarch64_serenity.sh
@@ -0,0 +1 @@
+. ${srcdir}/emulparams/elf_aarch64.sh
diff --git a/ld/emulparams/elf_i386_serenity.sh b/ld/emulparams/elf_i386_serenity.sh
new file mode 100644
index 00000000..342d5298
--- /dev/null
+++ b/ld/emulparams/elf_i386_serenity.sh
@@ -0,0 +1,3 @@
+. ${srcdir}/emulparams/elf_i386.sh
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
diff --git a/ld/emulparams/elf_x86_64_serenity.sh b/ld/emulparams/elf_x86_64_serenity.sh
new file mode 100644
index 00000000..a2af90a6
--- /dev/null
+++ b/ld/emulparams/elf_x86_64_serenity.sh
@@ -0,0 +1 @@
+. ${srcdir}/emulparams/elf_x86_64.sh
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
index df09b7b8..21566f5f 100644
--- a/libiberty/rust-demangle.c
+++ b/libiberty/rust-demangle.c
@@ -75,10 +75,10 @@ struct rust_demangler
int version;
/* Recursion depth. */
- uint recursion;
+ unsigned int recursion;
/* Maximum number of times demangle_path may be called recursively. */
#define RUST_MAX_RECURSION_COUNT 1024
-#define RUST_NO_RECURSION_LIMIT ((uint) -1)
+#define RUST_NO_RECURSION_LIMIT ((unsigned int) -1)
uint64_t bound_lifetime_depth;
};
diff -ur a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
--- a/ld/emulparams/elf_x86_64.sh 2021-07-08 13:37:20.000000000 +0200
+++ b/ld/emulparams/elf_x86_64.sh 2021-11-13 17:52:50.396490742 +0100
@@ -12,7 +12,7 @@
ELFSIZE=64
OUTPUT_FORMAT="elf64-x86-64"
NO_REL_RELOCS=yes
-TEXT_START_ADDR=0x400000
+TEXT_START_ADDR=0x08200000
MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
ARCH="i386:x86-64"