[klibc] [klibc:master] arm: Move shared library below executables

klibc-bot for Ben Hutchings ben at decadent.org.uk
Sun Jul 23 13:27:07 PDT 2023

Commit-ID:  78279e5b41c6958882d7e258edf457f74c515f34
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=78279e5b41c6958882d7e258edf457f74c515f34
Author:     Ben Hutchings <ben at decadent.org.uk>
AuthorDate: Sun, 16 Jul 2023 12:27:49 +0200
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sun, 16 Jul 2023 17:50:44 +0200

[klibc] arm: Move shared library below executables

The default base address for arm executables is 64 kiB, and the base
address for the shared library is 3.5 MiB when generating Thumb
instructions.  This limits the size of executables using it to be
< 3.5 MiB, and it also interacts with a bug in QEMU's user-mode
emulation, causing executables to immediately crash.

Moving the shared library to the end of the 16 MiB range didn't help.
Instead, move the shared library to 2 MiB and executables to 4 MiB.
This works for both Thumb and non-Thumb configurations, so make it

References: https://bugs.debian.org/1040981
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

 usr/klibc/arch/arm/MCONFIG | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/usr/klibc/arch/arm/MCONFIG b/usr/klibc/arch/arm/MCONFIG
index 41f39a0e..db5b14ac 100644
--- a/usr/klibc/arch/arm/MCONFIG
+++ b/usr/klibc/arch/arm/MCONFIG
@@ -19,12 +19,8 @@ ifeq ($(CONFIG_KLIBC_THUMB),y)
 KLIBCREQFLAGS += -mabi=aapcs-linux
 # Extra linkflags when building the shared version of the library
-# This address needs to be reachable using normal inter-module
-# calls, and work on the memory models for this architecture
 ifeq ($(CONFIG_AEABI),y)
 KLIBCREQFLAGS += -mabi=aapcs-linux -mno-thumb-interwork
@@ -32,5 +28,13 @@ KLIBCREQFLAGS += -mabi=apcs-gnu -mno-thumb-interwork
+# Normal binaries start at 64 kiB. A32 branch instructions have a
+# range of ±32 MiB and T32 branch instructions only ±16 MiB, so we
+# have to put klibc.so in that range. Putting it close above the
+# executable can cause breakage, so instead swap them around:
+# klibc.so at 2 MiB and executable at 4 MiB.
 # Kernel uses dedicated page or vDSO for signal return since 2.6.13

More information about the klibc mailing list