Ben Hutchings
2023-Jul-16 16:12 UTC
[klibc] [PATCH klibc 3/3] riscv64: Move shared library below executables
The default base address for riscv64 executables is 64 kiB, and I originally selected a base address for the shared library of 2 MiB. This limits the size of executables using it to be < 2 MiB, and it also interacts with a bug in QEMU's user-mode emulation, causing executables to immediately crash. It doesn't help code generation, because single-instruction jumps have a range of only ?1 MiB and two-instruction jumps have a range of ?2 GiB. Move the shared library to 64 kiB and executables to 576 kiB, to allow for generation of single-instruction jumps. (klibc.so is currently much smaller than the 512 kiB this allows for.) References: https://bugs.debian.org/1040981 Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/klibc/arch/riscv64/MCONFIG | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/usr/klibc/arch/riscv64/MCONFIG b/usr/klibc/arch/riscv64/MCONFIG index 34061086..717aedaa 100644 --- a/usr/klibc/arch/riscv64/MCONFIG +++ b/usr/klibc/arch/riscv64/MCONFIG @@ -13,8 +13,13 @@ KLIBCOPTFLAGS += -g endif KLIBCBITSIZE = 64 -# Normal binaries start at 64 KB, so start the libary at 2 MB. -KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x00200000 +# Normal binaries start at 64 kiB. Jumps can use either a single +# instruction with offset of ?1 MiB, or two instructions with offset +# of ?2 GiB. Putting klibc.so close above the executable can cause +# breakage, so instead swap them around: klibc.so at 64 kiB and +# executable at 576 kiB. +KLIBCLDFLAGS = $(LD_IMAGE_BASE_OPT) 0x90000 +KLIBCSHAREDFLAGS = $(LD_IMAGE_BASE_OPT) 0x10000 KLIBCSHAREDFLAGS += --defsym '__global_pointer$$=0' # Kernel has never used stack trampolines -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.zytor.com/archives/klibc/attachments/20230716/dd8eed1a/attachment.sig>
Thorsten Glaser
2023-Jul-16 20:20 UTC
[klibc] [PATCH klibc 3/3] riscv64: Move shared library below executables
Ben Hutchings dixit:>Move the shared library to 64 kiB and executables to 576 kiB, to allow >for generation of single-instruction jumps.Does this DTRT for binaries that are large enough to need two-instruction jumps in their upper part?>(klibc.so is currently >much smaller than the 512 kiB this allows for.)Since the .so is not a stable ABI, could even size that to fit. (That being said, klibc-using binaries tend to be small enough that it doesn?t matter; even mksh only comes in at around 180k statically(!) linked, on amd64.) Otherwise, lgtm, but again with two n?n-UTF-8 chars. Thanks, //mirabilos -- 15:41?<Lo-lan-do:#fusionforge> Somebody write a testsuite for helloworld :-)