From 3b5dbc5470eccf7f962e390da758711c40f9eff0 Mon Sep 17 00:00:00 2001 From: quic-areg Date: Wed, 8 Jul 2026 13:51:51 -0700 Subject: [PATCH] [test][Hexagon] Move MoveCommonsToBSS to standalone and add non-G0 case Move Hexagon/linux/MoveCommonsToBSS to Hexagon/standalone/. Nothing about the test is triple-dependent. Also add a non-G0 branch to improve coverage: run the link both with and without -G0 and check the resulting symbol table under G0:/NOG0: prefixes. Also address the FIXME comment in the test. Signed-off-by: quic-areg --- .../MoveCommonsToBSS/movecommon-to-bss.test | 10 ------- .../MoveCommonsToBSS/Inputs/1.c | 0 .../MoveCommonsToBSS/Inputs/2.c | 0 .../MoveCommonsToBSS/movecommon-to-bss.test | 28 +++++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) delete mode 100644 test/Hexagon/linux/MoveCommonsToBSS/movecommon-to-bss.test rename test/Hexagon/{linux => standalone}/MoveCommonsToBSS/Inputs/1.c (100%) rename test/Hexagon/{linux => standalone}/MoveCommonsToBSS/Inputs/2.c (100%) create mode 100644 test/Hexagon/standalone/MoveCommonsToBSS/movecommon-to-bss.test diff --git a/test/Hexagon/linux/MoveCommonsToBSS/movecommon-to-bss.test b/test/Hexagon/linux/MoveCommonsToBSS/movecommon-to-bss.test deleted file mode 100644 index 40879d621..000000000 --- a/test/Hexagon/linux/MoveCommonsToBSS/movecommon-to-bss.test +++ /dev/null @@ -1,10 +0,0 @@ -#FIXME: How does this test checks that commons are moved to bss? -# Test that commons are moved to bss, and commons appear at the end. -RUN: %clang %clangg0opts -fcommon -c %p/Inputs/1.c -o %t1.o -RUN: %clang %clangg0opts -fcommon -c %p/Inputs/2.c -o %t2.o -RUN: %link %linkg0opts %t1.o %t2.o -o %t.out 2>&1 -RUN: %readelf -s %t.out | %filecheck %s - -#CHECK: {{[0-9]+}}: {{[x0-9a-z]+}} 4 OBJECT GLOBAL DEFAULT 1 bss -#CHECK: {{[0-9]+}}: {{[x0-9a-z]+}} 4000 OBJECT GLOBAL DEFAULT 1 common1 - diff --git a/test/Hexagon/linux/MoveCommonsToBSS/Inputs/1.c b/test/Hexagon/standalone/MoveCommonsToBSS/Inputs/1.c similarity index 100% rename from test/Hexagon/linux/MoveCommonsToBSS/Inputs/1.c rename to test/Hexagon/standalone/MoveCommonsToBSS/Inputs/1.c diff --git a/test/Hexagon/linux/MoveCommonsToBSS/Inputs/2.c b/test/Hexagon/standalone/MoveCommonsToBSS/Inputs/2.c similarity index 100% rename from test/Hexagon/linux/MoveCommonsToBSS/Inputs/2.c rename to test/Hexagon/standalone/MoveCommonsToBSS/Inputs/2.c diff --git a/test/Hexagon/standalone/MoveCommonsToBSS/movecommon-to-bss.test b/test/Hexagon/standalone/MoveCommonsToBSS/movecommon-to-bss.test new file mode 100644 index 000000000..d1f4c5ec8 --- /dev/null +++ b/test/Hexagon/standalone/MoveCommonsToBSS/movecommon-to-bss.test @@ -0,0 +1,28 @@ +## Test how common symbols and regular BSS symbols land in the output on +## Hexagon with and without -G0. Under -G0, commons +## are merged into .bss alongside regular BSS symbols. Without -G0, the +## compiler places a 4-byte bss = 0 into .sbss.4 which +## the linker folds into .sdata. common1 still ends up in .bss. + +## Single .bss holding both common1 and bss. +RUN: %clang %clangg0opts -fcommon -c %p/Inputs/1.c -o %t1.g0.o +RUN: %clang %clangg0opts -fcommon -c %p/Inputs/2.c -o %t2.g0.o +RUN: %link %linkg0opts %t1.g0.o %t2.g0.o -o %t.g0.out +RUN: %readelf -S %t.g0.out | %filecheck --check-prefix=G0-SEC %s +RUN: %readelf -s %t.g0.out | %filecheck --check-prefix=G0-SYM %s + +G0-SEC: [ 1] .bss +G0-SYM-DAG: {{[0-9]+}}: {{[x0-9a-z]+}} 4000 OBJECT GLOBAL DEFAULT 1 common1 +G0-SYM-DAG: {{[0-9]+}}: {{[x0-9a-z]+}} 4 OBJECT GLOBAL DEFAULT 1 bss + +## Non-G0 branch: `bss` in .sdata and common1 in .bss. +RUN: %clang %clangopts -fcommon -c %p/Inputs/1.c -o %t1.o +RUN: %clang %clangopts -fcommon -c %p/Inputs/2.c -o %t2.o +RUN: %link %linkopts %t1.o %t2.o -o %t.out +RUN: %readelf -S %t.out | %filecheck --check-prefix=NOG0-SEC %s +RUN: %readelf -s %t.out | %filecheck --check-prefix=NOG0-SYM %s + +NOG0-SEC: [ 1] .sdata +NOG0-SEC: [ 2] .bss +NOG0-SYM-DAG: {{[0-9]+}}: {{[x0-9a-z]+}} 4000 OBJECT GLOBAL DEFAULT 2 common1 +NOG0-SYM-DAG: {{[0-9]+}}: {{[x0-9a-z]+}} 4 OBJECT GLOBAL DEFAULT 1 bss