Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] arch: Set max/common-page-size for libgcc & libstdc++
@ 2024-01-03 10:23 Alexey Brodkin via buildroot
  2024-01-04 21:19 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey Brodkin via buildroot @ 2024-01-03 10:23 UTC (permalink / raw)
  To: buildroot
  Cc: Vladimir Isaev, Pavel Kozlov, Alexey Brodkin, Thomas Petazzoni,
	Yann E . MORIN

With [1], [2] & [3] we made sure Buildroot packages get built with
proper MMU page size assumed. This was done nicely through insertion of
required flags into the toolchain wrapper so that there's no need to
pass these flags to each and every package separately - toolchain
wrapper used for real building has all set internally and so proper
flags are impleicitly used.

But there's yet another corner case which is not handled that way -
these are binaries or rather libraries which are being used as a part of
GCC compilation: libgcc_s.so.1 and libstdc++.so.

And so to make sure both the libraries get built properly we need to set
TARGET_CFLAGS (cures libgcc_s.so) & TARGET_LDFLAGS (cures libstdc++.so).

In case of ARM by defaut 64 KiB page size seems to be used, as w/o that
patch I see the following for BR2_ARM64_PAGE_SIZE_4K=y:
--------------------------->8----------------------------
$ ./output/host/bin/aarch64-linux-readelf -l ./output/target/lib/libgcc_s.so.1

Elf file type is DYN (Shared object file)
Entry point 0x0
There are 6 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000013d1c 0x0000000000013d1c  R E    0x10000
  LOAD           0x000000000001fd98 0x000000000002fd98 0x000000000002fd98
                 0x0000000000000438 0x00000000000005c8  RW     0x10000
  DYNAMIC        0x000000000001fdb8 0x000000000002fdb8 0x000000000002fdb8
                 0x0000000000000200 0x0000000000000200  RW     0x8

$ ./output/host/bin/aarch64-linux-readelf -l ./output/target/usr/lib/libstdc++.so.6.0.32

Elf file type is DYN (Shared object file)
Entry point 0x0
There are 7 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000001d3462 0x00000000001d3462  R E    0x10000
  LOAD           0x00000000001d5760 0x00000000001e5760 0x00000000001e5760
                 0x000000000000e528 0x0000000000012de8  RW     0x10000
  DYNAMIC        0x00000000001deef0 0x00000000001eeef0 0x00000000001eeef0
                 0x0000000000000240 0x0000000000000240  RW     0x8
--------------------------->8----------------------------

Note alignment of 0x10000 in sections marked for loading.
And with the patch applied we get expected alignment of 0x1000 (4 KiB):
--------------------------->8----------------------------
$ ./output/host/bin/aarch64-linux-readelf -l ./output/target/lib/libgcc_s.so.1

Elf file type is DYN (Shared object file)
Entry point 0x0
There are 6 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000013d1c 0x0000000000013d1c  R E    0x1000
  LOAD           0x0000000000013d98 0x0000000000014d98 0x0000000000014d98
                 0x0000000000000438 0x00000000000005c8  RW     0x1000
  DYNAMIC        0x0000000000013db8 0x0000000000014db8 0x0000000000014db8
                 0x0000000000000200 0x0000000000000200  RW     0x8

$ ./output/host/bin/aarch64-linux-readelf -l ./output/target/usr/lib/libstdc++.so.6.0.32

Elf file type is DYN (Shared object file)
Entry point 0x0
There are 7 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000001d3462 0x00000000001d3462  R E    0x1000
  LOAD           0x00000000001d3760 0x00000000001d4760 0x00000000001d4760
                 0x000000000000e528 0x0000000000012de8  RW     0x1000
  DYNAMIC        0x00000000001dcef0 0x00000000001ddef0 0x00000000001ddef0
                 0x0000000000000240 0x0000000000000240  RW     0x8
--------------------------->8----------------------------

I would agree that it gets more and more ugly, but so far I cannot see
any more elegant solution. So if there're suggestions how to improve,
let's discuss.

[1] https://git.buildroot.net/buildroot/commit/?id=3cc2c6d19ab2e1bb4634f26f9318da9b07df5fff
[2] https://git.buildroot.net/buildroot/commit/?id=dcb74db89e74e512e36b32cea6f574a1a1ca84c4
[3] https://git.buildroot.net/buildroot/commit/?id=5e52c28397b79f8c4c99552217cbe95202166626

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Signed-off-by: Vladimir Isaev <VVIsaev@gmail.com>
Signed-off-by: Pavel Kozlov <kozlov@synopsys.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Arnout Vandecappelle <arnout@mind.be>
---
 arch/arch.mk       | 8 ++++++++
 package/gcc/gcc.mk | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/arch/arch.mk b/arch/arch.mk
index 2e737b92ac..23733eb199 100644
--- a/arch/arch.mk
+++ b/arch/arch.mk
@@ -21,12 +21,20 @@ GCC_TARGET_MODE := $(call qstrip,$(BR2_GCC_TARGET_MODE))
 # Explicitly set LD's "max-page-size" instead of relying on some defaults
 ifeq ($(BR2_ARC_PAGE_SIZE_4K)$(BR2_ARM64_PAGE_SIZE_4K),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
+TARGET_CFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
+TARGET_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
 else ifeq ($(BR2_ARC_PAGE_SIZE_8K),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=8192 -Wl,-z,common-page-size=8192
+TARGET_CFLAGS += -Wl,-z,max-page-size=8192 -Wl,-z,common-page-size=8192
+TARGET_LDFLAGS += -Wl,-z,max-page-size=8192 -Wl,-z,common-page-size=8192
 else ifeq ($(BR2_ARC_PAGE_SIZE_16K),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384
+TARGET_CFLAGS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384
+TARGET_LDFLAGS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384
 else ifeq ($(BR2_ARM64_PAGE_SIZE_64K),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536
+TARGET_CFLAGS += -Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536
+TARGET_LDFLAGS += -Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536
 endif
 
 # Include any architecture specific makefiles.
diff --git a/package/gcc/gcc.mk b/package/gcc/gcc.mk
index 93bc46643c..d9a2164c74 100644
--- a/package/gcc/gcc.mk
+++ b/package/gcc/gcc.mk
@@ -100,6 +100,7 @@ HOST_GCC_COMMON_MAKE_OPTS = \
 
 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
+GCC_COMMON_TARGET_LDFLAGS = $(TARGET_LDFLAGS)
 
 # used to fix ../../../../libsanitizer/libbacktrace/../../libbacktrace/elf.c:772:21: error: 'st.st_mode' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 ifeq ($(BR2_ENABLE_DEBUG),y)
@@ -115,6 +116,7 @@ endif
 # Propagate options used for target software building to GCC target libs
 HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
 HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
+HOST_GCC_COMMON_CONF_ENV += LDFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_LDFLAGS)"
 HOST_GCC_COMMON_CONF_ENV += AR_FOR_TARGET=gcc-ar NM_FOR_TARGET=gcc-nm RANLIB_FOR_TARGET=gcc-ranlib
 
 # libitm needs sparc V9+
-- 
2.31.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-04 22:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-03 10:23 [Buildroot] [PATCH] arch: Set max/common-page-size for libgcc & libstdc++ Alexey Brodkin via buildroot
2024-01-04 21:19 ` Thomas Petazzoni via buildroot
2024-01-04 21:34   ` Yann E. MORIN
2024-01-04 21:38     ` Thomas Petazzoni via buildroot
2024-01-04 22:22       ` Alexey Brodkin via buildroot
2024-01-04 22:42         ` Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox