arch: Set max/common-page-size for libgcc & libstdc++
PATCH v2 1/1 arch: Set max/common-page-size for libgcc & libstdc++
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----------------------------
What's nice, we're getting rid of a special handling of "-matomic" as it's already a part of ARCH_TOOLCHAIN_WRAPPER_OPTS.
[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
---
Changes in v2:
* Instead of setting TARGET_{C|LD}FLAGS use ARCH_TOOLCHAIN_WRAPPER_OPTS for configuring GCC.
package/gcc/gcc.mk | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
package/gcc/gcc.mk +9 -8
@@ -98,23 +98,24 @@ HOST_GCC_COMMON_CONF_ENV = \ HOST_GCC_COMMON_MAKE_OPTS = \ gcc_cv_prog_makeinfo_modern=no -GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS) -GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS) +# Target binaries and libraries which are being built as a part of GCC +# don't use Buildroot toolchain wrapper because, instead its very own "xgcc" +# binary is used. And so we need to explicitly propagate ALL the flags +# directly to "xgcc" and that is done via configure-time environment +# variables, see below setup of HOST_GCC_COMMON_CONF_ENV. +GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS) $(ARCH_TOOLCHAIN_WRAPPER_OPTS) +GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS) $(ARCH_TOOLCHAIN_WRAPPER_OPTS) +GCC_COMMON_TARGET_LDFLAGS = $(TARGET_LDFLAGS) $(ARCH_TOOLCHAIN_WRAPPER_OPTS) # 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) GCC_COMMON_TARGET_CFLAGS += -Wno-error endif -# Make sure libgcc & libstdc++ always get built with -matomic on ARC700 -ifeq ($(GCC_TARGET_CPU):$(BR2_ARC_ATOMIC_EXT),arc700:y) -GCC_COMMON_TARGET_CFLAGS += -matomic -GCC_COMMON_TARGET_CXXFLAGS += -matomic -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+
Signature · 6 lines
2.31.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Petazzoni via buildroot
AppliedQuoted 11 lines · On Fri, 5 Jan 2024 11:17:10 -0800 Alexey Brodkin via buildroot…
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.
Quoted 7 lines
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
Applied to master with a few minor improvements in the commit title and commit log. Thanks a lot!
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 13 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Alexey" == Alexey Brodkin via buildroot <[email protected]> writes:
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.
Quoted 5 lines
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----------------------------
Quoted 26 lines
$ ./output/host/bin/aarch64-linux-readelf -l ./output/target/lib/libgcc_s.so.1Elf file type is DYN (Shared object file) Entry point
0x0
There are 6 program headers, starting at offset 64Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD0x00000000000000000x00000000000000000x00000000000000000x0000000000013d1c 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.32Elf file type is DYN (Shared object file) Entry point
0x0
There are 7 program headers, starting at offset 64Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD0x00000000000000000x00000000000000000x0000000000000000
Quoted 5 lines
0x00000000001d3462 0x00000000001d3462 R E 0x10000
LOAD 0x00000000001d5760 0x00000000001e5760 0x00000000001e5760
0x000000000000e528 0x0000000000012de8 RW 0x10000
DYNAMIC 0x00000000001deef0 0x00000000001eeef0 0x00000000001eeef0
0x0000000000000240 0x0000000000000240 RW 0x8---------------------------> 8----------------------------
Quoted 2 lines
Note alignment of
0x10000in sections marked for loading. And with the patch applied we get expected alignment of0x1000(4 KiB):
---------------------------> 8----------------------------
Quoted 26 lines
$ ./output/host/bin/aarch64-linux-readelf -l ./output/target/lib/libgcc_s.so.1Elf file type is DYN (Shared object file) Entry point
0x0
There are 6 program headers, starting at offset 64Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD0x00000000000000000x00000000000000000x00000000000000000x0000000000013d1c 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.32Elf file type is DYN (Shared object file) Entry point
0x0
There are 7 program headers, starting at offset 64Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD0x00000000000000000x00000000000000000x0000000000000000
Quoted 5 lines
0x00000000001d3462 0x00000000001d3462 R E 0x1000
LOAD 0x00000000001d3760 0x00000000001d4760 0x00000000001d4760
0x000000000000e528 0x0000000000012de8 RW 0x1000
DYNAMIC 0x00000000001dcef0 0x00000000001ddef0 0x00000000001ddef0
0x0000000000000240 0x0000000000000240 RW 0x8---------------------------> 8----------------------------
Quoted 13 lines
What's nice, we're getting rid of a special handling of "-matomic" as it's already a part of
ARCH_TOOLCHAIN_WRAPPER_OPTS.[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=5e52c28397b79f8c4c99552217cbe95202166626Signed-off-by Alexey Brodkin <[email protected]>Signed-off-by Vladimir Isaev <[email protected]>Signed-off-by Pavel Kozlov <[email protected]>Cc Thomas Petazzoni <[email protected]>Cc Yann E. MORIN <[email protected]>Cc Arnout Vandecappelle <[email protected]>
Quoted 6 lines
---
Changes in v2:
* Instead of setting TARGET_{C|LD}FLAGS use
ARCH_TOOLCHAIN_WRAPPER_OPTSfor configuring GCC.
Committed to 2023.02.x and 2023.11.x, thanks.
Signature · 5 lines
Bye, Peter Korsgaard _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot