From 2ad52e19e9a50fa29d372ea10cdea0c99dae2ddf Mon Sep 17 00:00:00 2001 From: Parth Arora Date: Thu, 28 Aug 2025 12:18:11 +0530 Subject: [PATCH 1/2] Fix Relaxation/UnalignedCrash/UnalignedCrash.test This commit fixes the test RISCV/standalone/Relaxation/UnalignedCrash/UnalignedCrash.test. The test checks that the link command fails with the insufficient bytes for alignment relaxation error. However, for this test, the link should pass without any errors. It was currently erroring out because of the incorrect fragment address. This commit fixes the test so that the link should fail with the insufficient bytes for alignment relaxation error without relying on the incorrect fragment address. Resolves #363 Signed-off-by: Parth Arora --- .../Inputs/1.s | 10 +++++----- .../Inputs/1.t | 2 +- .../InsufficientAlignmentRelaxation.test | 11 +++++++++++ .../UnalignedCrash-QTOOL-105850.test | 9 --------- 4 files changed, 17 insertions(+), 15 deletions(-) rename test/RISCV/standalone/Relaxation/{UnalignedCrash-QTOOL-105850 => InsufficientAlignmentRelaxation}/Inputs/1.s (78%) rename test/RISCV/standalone/Relaxation/{UnalignedCrash-QTOOL-105850 => InsufficientAlignmentRelaxation}/Inputs/1.t (61%) create mode 100644 test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test delete mode 100644 test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/UnalignedCrash-QTOOL-105850.test diff --git a/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/Inputs/1.s b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/Inputs/1.s similarity index 78% rename from test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/Inputs/1.s rename to test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/Inputs/1.s index 9e5c60ffa..b4717da84 100644 --- a/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/Inputs/1.s +++ b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/Inputs/1.s @@ -1,10 +1,9 @@ .text .globl foo .type foo, @function - call norelax - call norelax - call norelax - call norelax + .option rvc + j 1f + .option norvc .balign 32 foo: nop // Add a relaxation relocation as RISC-V ABI demands that R_ALIGN @@ -16,4 +15,5 @@ foo: nop ret .size foo, .-foo -.equ norelax, 0x40000000 +1: + nop diff --git a/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/Inputs/1.t b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/Inputs/1.t similarity index 61% rename from test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/Inputs/1.t rename to test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/Inputs/1.t index fc879f60d..fa6583ca7 100644 --- a/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/Inputs/1.t +++ b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/Inputs/1.t @@ -1,5 +1,5 @@ SECTIONS { - text (0xFE1) : { + text (0x0) : { *(.text) } } diff --git a/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test new file mode 100644 index 000000000..4aaa418c9 --- /dev/null +++ b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test @@ -0,0 +1,11 @@ +#----------InsufficientAlignmentRelaxation.test----------------- Executable------------------# +# BEGIN_COMMENT +# This test checks that the linker correctly emits insufficient bytes for alignment +# relaxation error. +# END_COMMENT +# START_TEST +RUN: %clang %clangopts -c %p/Inputs/1.s -o %t.1.o +RUN: %not %link %linkopts -o %t.1.out %t.1.o -T %p/Inputs/1.t 2>&1 | %filecheck %s +# END_TEST + +CHECK: Error: Insufficient number of spare bytes for alignment relaxation: present 28, needed 30 in section .text+0x20 file {{.*}}1.o diff --git a/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/UnalignedCrash-QTOOL-105850.test b/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/UnalignedCrash-QTOOL-105850.test deleted file mode 100644 index a913e0d0a..000000000 --- a/test/RISCV/standalone/Relaxation/UnalignedCrash-QTOOL-105850/UnalignedCrash-QTOOL-105850.test +++ /dev/null @@ -1,9 +0,0 @@ -#----------UnalignedCrash-QTOOL-105850.test----------------- Executable------------------# -# BEGIN_COMMENT -# Test that the linker does not crash. -# END_COMMENT -# START_TEST -#RUN: %clang %clangopts -c %p/Inputs/1.s -o %t.o -#RUN: not %link %linkopts %t.o -T %p/Inputs/1.t -o %t.out 2>&1 | %filecheck %s -# CHECK: Error: Insufficient number of spare bytes for alignment relaxation: present 30, needed 31 in section .text+{{.+}} file {{.*}}.o -# END_TEST From 3bf80d3178535918e2f0d7acc5b3df3bd481ec6f Mon Sep 17 00:00:00 2001 From: Parth Arora Date: Thu, 28 Aug 2025 20:09:28 +0530 Subject: [PATCH 2/2] Debug --- .../InsufficientAlignmentRelaxation.test | 1 + 1 file changed, 1 insertion(+) diff --git a/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test index 4aaa418c9..507d29f14 100644 --- a/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test +++ b/test/RISCV/standalone/Relaxation/InsufficientAlignmentRelaxation/InsufficientAlignmentRelaxation.test @@ -5,6 +5,7 @@ # END_COMMENT # START_TEST RUN: %clang %clangopts -c %p/Inputs/1.s -o %t.1.o +RUN: %objdump -dr %t.1.o RUN: %not %link %linkopts -o %t.1.out %t.1.o -T %p/Inputs/1.t 2>&1 | %filecheck %s # END_TEST