[clang] [lld] [lld][LoongArch] Enable relaxation when --relax option is passed (PR #111488)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 02:09:01 PDT 2024
https://github.com/ywgrit updated https://github.com/llvm/llvm-project/pull/111488
>From 32aae75a78fbd10c8238494b9b01b85f576a47a8 Mon Sep 17 00:00:00 2001
From: Xin Wang <wangxin03 at loongson.cn>
Date: Tue, 8 Oct 2024 14:03:51 +0800
Subject: [PATCH 1/3] [lld][LoongArch] Enable relaxation when --relax option is
passed
---
.../lib/Driver/ToolChains/Arch/LoongArch.cpp | 7 +
lld/ELF/Writer.cpp | 5 +-
lld/test/ELF/loongarch-relax-align.s | 209 ++++++++++++++----
lld/test/ELF/loongarch-relax-emit-relocs.s | 5 +-
4 files changed, 182 insertions(+), 44 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 771adade93813f..74d3ab65ed6643 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -134,6 +134,13 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
(!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
Features.push_back("+lsx");
+ // -mrelax is default, unless -mno-relax is specified.
+ if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
+ Features.push_back("+relax");
+ } else {
+ Features.push_back("-relax");
+ }
+
std::string ArchName;
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
ArchName = A->getValue();
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index f4a22ea953ec49..cf0ff432f920ad 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1462,6 +1462,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
for (;;) {
bool changed = ctx.target->needsThunks
? tc.createThunks(pass, ctx.outputSections)
+ : ctx.arg.emachine == EM_LOONGARCH && !ctx.arg.relax
+ ? false
: ctx.target->relaxOnce(pass);
bool spilled = ctx.script->spillSections();
changed |= spilled;
@@ -1545,7 +1547,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
finalizeOrderDependentContent();
}
}
- if (!ctx.arg.relocatable)
+ if (!ctx.arg.relocatable &&
+ !(ctx.arg.emachine == EM_LOONGARCH && !ctx.arg.relax))
ctx.target->finalizeRelax(pass);
if (ctx.arg.relocatable)
diff --git a/lld/test/ELF/loongarch-relax-align.s b/lld/test/ELF/loongarch-relax-align.s
index ab61e15d5caca2..158f1f80ba8489 100644
--- a/lld/test/ELF/loongarch-relax-align.s
+++ b/lld/test/ELF/loongarch-relax-align.s
@@ -6,56 +6,180 @@
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o -o %t.64
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.32.o --no-relax -o %t.32n
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o --no-relax -o %t.64n
-# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck %s
-# RUN: llvm-objdump -td --no-show-raw-insn %t.64 | FileCheck %s
-# RUN: llvm-objdump -td --no-show-raw-insn %t.32n | FileCheck %s
-# RUN: llvm-objdump -td --no-show-raw-insn %t.64n | FileCheck %s
+# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck %s --check-prefix=RELAX32
+# RUN: llvm-objdump -td --no-show-raw-insn %t.64 | FileCheck %s --check-prefixes=RELAX64,SRELAX64
+# RUN: llvm-objdump -td --no-show-raw-insn %t.32n | FileCheck %s --check-prefix=NORELAX
+# RUN: llvm-objdump -td --no-show-raw-insn %t.64n | FileCheck %s --check-prefix=NORELAX
## Test the R_LARCH_ALIGN without symbol index.
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.o64.o --defsym=old=1
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o -o %t.o64
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o --no-relax -o %t.o64n
-# RUN: llvm-objdump -td --no-show-raw-insn %t.o64 | FileCheck %s
-# RUN: llvm-objdump -td --no-show-raw-insn %t.o64n | FileCheck %s
+# RUN: llvm-objdump -td --no-show-raw-insn %t.o64 | FileCheck %s --check-prefixes=RELAX64,ORELAX64
+# RUN: llvm-objdump -td --no-show-raw-insn %t.o64n | FileCheck %s --check-prefix=ONORELAX
## -r keeps section contents unchanged.
# RUN: ld.lld -r %t.64.o -o %t.64.r
# RUN: llvm-objdump -dr --no-show-raw-insn %t.64.r | FileCheck %s --check-prefix=CHECKR
-# CHECK-DAG: {{0*}}10000 l .text {{0*}}44 .Ltext_start
-# CHECK-DAG: {{0*}}10038 l .text {{0*}}0c .L1
-# CHECK-DAG: {{0*}}10040 l .text {{0*}}04 .L2
-# CHECK-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start
-
-# CHECK: <.Ltext_start>:
-# CHECK-NEXT: break 1
-# CHECK-NEXT: break 2
-# CHECK-NEXT: nop
-# CHECK-NEXT: nop
-# CHECK-NEXT: break 3
-# CHECK-NEXT: break 4
-# CHECK-NEXT: nop
-# CHECK-NEXT: nop
-# CHECK-NEXT: pcalau12i $a0, 0
-# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# CHECK-NEXT: pcalau12i $a0, 0
-# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 56
-# CHECK-NEXT: pcalau12i $a0, 0
-# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 64
-# CHECK-EMPTY:
-# CHECK-NEXT: <.L1>:
-# CHECK-NEXT: nop
-# CHECK-NEXT: nop
-# CHECK-EMPTY:
-# CHECK-NEXT: <.L2>:
-# CHECK-NEXT: break 5
-
-# CHECK: <.Ltext2_start>:
-# CHECK-NEXT: pcalau12i $a0, 0
-# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# CHECK-NEXT: nop
-# CHECK-NEXT: nop
-# CHECK-NEXT: break 6
+
+# RELAX32-DAG: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol
+# RELAX32-DAG: {{0*}}10000 l .text {{0*}}44 .Ltext_start
+# RELAX32-DAG: {{0*}}10038 l .text {{0*}}0c .L1
+# RELAX32-DAG: {{0*}}10040 l .text {{0*}}04 .L2
+# RELAX32-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start
+
+# RELAX32: <.Ltext_start>:
+# RELAX32-NEXT: break 1
+# RELAX32-NEXT: break 2
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: break 3
+# RELAX32-NEXT: break 4
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: pcalau12i $a0, 0
+# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# RELAX32-NEXT: pcalau12i $a0, 0
+# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 56
+# RELAX32-NEXT: pcalau12i $a0, 0
+# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 64
+# RELAX32-EMPTY:
+# RELAX32-NEXT: <.L1>:
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: nop
+# RELAX32-EMPTY:
+# RELAX32-NEXT: <.L2>:
+# RELAX32-NEXT: break 5
+
+# RELAX32: <.Ltext2_start>:
+# RELAX32-NEXT: pcalau12i $a0, 0
+# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: nop
+# RELAX32-NEXT: break 6
+
+# NORELAX-DAG: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol
+# NORELAX-DAG: {{0*}}10000 l .text {{0*}}5c .Ltext_start
+# NORELAX-DAG: {{0*}}1004c l .text {{0*}}10 .L1
+# NORELAX-DAG: {{0*}}10058 l .text {{0*}}04 .L2
+# NORELAX-DAG: {{0*}}20000 l .text2 {{0*}}18 .Ltext2_start
+
+# NORELAX: <.Ltext_start>:
+# NORELAX-NEXT: break 1
+# NORELAX-NEXT: break 2
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: break 3
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: break 4
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: pcalau12i $a0, 0
+# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# NORELAX-NEXT: pcalau12i $a0, 0
+# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 76
+# NORELAX-NEXT: pcalau12i $a0, 0
+# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 88
+# NORELAX-EMPTY:
+# NORELAX-NEXT: <.L1>:
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-EMPTY:
+# NORELAX-NEXT: <.L2>:
+# NORELAX-NEXT: break 5
+
+# NORELAX: <.Ltext2_start>:
+# NORELAX-NEXT: pcalau12i $a0, 0
+# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: nop
+# NORELAX-NEXT: break 6
+
+
+
+# ORELAX64-DAG: {{0*}}00001 l *ABS* {{0*}}00 old
+# SRELAX64-DAG: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol
+# RELAX64-DAG: {{0*}}10000 l .text {{0*}}44 .Ltext_start
+# RELAX64-DAG: {{0*}}10038 l .text {{0*}}0c .L1
+# RELAX64-DAG: {{0*}}10040 l .text {{0*}}04 .L2
+# RELAX64-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start
+
+# RELAX64: <.Ltext_start>:
+# RELAX64-NEXT: break 1
+# RELAX64-NEXT: break 2
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: break 3
+# RELAX64-NEXT: break 4
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: pcalau12i $a0, 0
+# RELAX64-NEXT: addi.d $a0, $a0, 0
+# RELAX64-NEXT: pcalau12i $a0, 0
+# RELAX64-NEXT: addi.d $a0, $a0, 56
+# RELAX64-NEXT: pcalau12i $a0, 0
+# RELAX64-NEXT: addi.d $a0, $a0, 64
+# RELAX64-EMPTY:
+# RELAX64-NEXT: <.L1>:
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: nop
+# RELAX64-EMPTY:
+# RELAX64-NEXT: <.L2>:
+# RELAX64-NEXT: break 5
+
+# RELAX64: <.Ltext2_start>:
+# RELAX64-NEXT: pcalau12i $a0, 0
+# RELAX64-NEXT: addi.d $a0, $a0, 0
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: nop
+# RELAX64-NEXT: break 6
+
+
+# ONORELAX-DAG: {{0*}}00001 l *ABS* {{0*}}00 old
+# ONORELAX-DAG: {{0*}}10000 l .text {{0*}}4c .Ltext_start
+# ONORELAX-DAG: {{0*}}1003c l .text {{0*}}10 .L1
+# ONORELAX-DAG: {{0*}}10048 l .text {{0*}}04 .L2
+# ONORELAX-DAG: {{0*}}20000 l .text2 {{0*}}18 .Ltext2_start
+
+# ONORELAX: <.Ltext_start>:
+# ONORELAX-NEXT: break 1
+# ONORELAX-NEXT: break 2
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: break 3
+# ONORELAX-NEXT: break 4
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: pcalau12i $a0, 0
+# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# ONORELAX-NEXT: pcalau12i $a0, 0
+# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 60
+# ONORELAX-NEXT: pcalau12i $a0, 0
+# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 72
+# ONORELAX-EMPTY:
+# ONORELAX-NEXT: <.L1>:
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-EMPTY:
+# ONORELAX-NEXT: <.L2>:
+# ONORELAX-NEXT: break 5
+
+# ONORELAX: <.Ltext2_start>:
+# ONORELAX-NEXT: pcalau12i $a0, 0
+# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: nop
+# ONORELAX-NEXT: break 6
# CHECKR: <.Ltext2_start>:
# CHECKR-NEXT: pcalau12i $a0, 0
@@ -70,6 +194,11 @@
# CHECKR-NEXT: nop
# CHECKR-NEXT: break 6
+
+
+
+
+
.macro .fake_p2align_4 max=0
.ifdef old
.if \max==0
diff --git a/lld/test/ELF/loongarch-relax-emit-relocs.s b/lld/test/ELF/loongarch-relax-emit-relocs.s
index ba414e8c93f0fb..1feec64d722cab 100644
--- a/lld/test/ELF/loongarch-relax-emit-relocs.s
+++ b/lld/test/ELF/loongarch-relax-emit-relocs.s
@@ -12,10 +12,8 @@
# RUN: ld.lld -r %t.64.o -o %t.64.r
# RUN: llvm-objdump -dr %t.64.r | FileCheck %s --check-prefix=CHECKR
-## --no-relax should keep original relocations.
-## TODO Due to R_LARCH_RELAX is not relaxed, it plays same as --relax now.
# RUN: ld.lld -Ttext=0x10000 --emit-relocs --no-relax %t.64.o -o %t.64.norelax
-# RUN: llvm-objdump -dr %t.64.norelax | FileCheck %s
+# RUN: llvm-objdump -dr %t.64.norelax | FileCheck %s --check-prefixes=CHECK,NORELAX
# CHECK: 00010000 <_start>:
# CHECK-NEXT: pcalau12i $a0, 0
@@ -27,6 +25,7 @@
# CHECK-NEXT: nop
# CHECK-NEXT: R_LARCH_ALIGN *ABS*+0xc
# CHECK-NEXT: nop
+# NORELAX-NEXT: nop
# CHECK-NEXT: ret
# CHECKR: <_start>:
>From 8c6805109f33cb4cd64f4aca6b76ba68a152e731 Mon Sep 17 00:00:00 2001
From: Xin Wang <wangxin03 at loongson.cn>
Date: Tue, 8 Oct 2024 20:25:34 +0800
Subject: [PATCH 2/3] [clang][LoongArch] Fix test after enable relaxation
option
---
clang/test/Driver/loongarch-features.c | 4 ++--
clang/test/Driver/loongarch-march.c | 20 ++++++++++----------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/clang/test/Driver/loongarch-features.c b/clang/test/Driver/loongarch-features.c
index 90634bbcf00358..f68c1da3b40025 100644
--- a/clang/test/Driver/loongarch-features.c
+++ b/clang/test/Driver/loongarch-features.c
@@ -1,8 +1,8 @@
// RUN: %clang --target=loongarch32 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA32
// RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64
-// LA32: "target-features"="+32bit"
-// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual"
+// LA32: "target-features"="+32bit,+relax"
+// LA64: "target-features"="+64bit,+d,+f,+lsx,+relax,+ual"
int foo(void) {
return 3;
diff --git a/clang/test/Driver/loongarch-march.c b/clang/test/Driver/loongarch-march.c
index 2d5b315d962a1e..21d253da042ffe 100644
--- a/clang/test/Driver/loongarch-march.c
+++ b/clang/test/Driver/loongarch-march.c
@@ -21,39 +21,39 @@
// CC1-LOONGARCH64: "-target-cpu" "loongarch64"
// CC1-LOONGARCH64-NOT: "-target-feature"
-// CC1-LOONGARCH64: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
+// CC1-LOONGARCH64: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+ual"
// CC1-LOONGARCH64-NOT: "-target-feature"
// CC1-LOONGARCH64: "-target-abi" "lp64d"
// CC1-LA464: "-target-cpu" "la464"
// CC1-LA464-NOT: "-target-feature"
-// CC1-LA464: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual"
+// CC1-LA464: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual"
// CC1-LA464-NOT: "-target-feature"
// CC1-LA464: "-target-abi" "lp64d"
// CC1-LA64V1P0: "-target-cpu" "loongarch64"
// CC1-LA64V1P0-NOT: "-target-feature"
-// CC1-LA64V1P0: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual"
+// CC1-LA64V1P0: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual"
// CC1-LA64V1P0-NOT: "-target-feature"
// CC1-LA64V1P0: "-target-abi" "lp64d"
// CC1-LA64V1P1: "-target-cpu" "loongarch64"
// CC1-LA64V1P1-NOT: "-target-feature"
-// CC1-LA64V1P1: "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe"
+// CC1-LA64V1P1: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+ual" "-target-feature" "+frecipe"
// CC1-LA64V1P1-NOT: "-target-feature"
// CC1-LA64V1P1: "-target-abi" "lp64d"
// CC1-LA664: "-target-cpu" "la664"
// CC1-LA664-NOT: "-target-feature"
-// CC1-LA664: "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" "-target-feature" "+frecipe"
+// CC1-LA664: "-target-feature" "+relax" "-target-feature" "+64bit" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+lsx" "-target-feature" "+lasx" "-target-feature" "+ual" "-target-feature" "+frecipe"
// CC1-LA664-NOT: "-target-feature"
// CC1-LA664: "-target-abi" "lp64d"
-// IR-LOONGARCH64: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+ual"
-// IR-LA464: attributes #[[#]] ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+ual"
-// IR-LA64V1P0: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+ual"
-// IR-LA64V1P1: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lsx,+ual"
-// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+frecipe,+lasx,+lsx,+ual"
+// IR-LOONGARCH64: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+f,+relax,+ual"
+// IR-LA464: attributes #[[#]] ={{.*}}"target-cpu"="la464" {{.*}}"target-features"="+64bit,+d,+f,+lasx,+lsx,+relax,+ual"
+// IR-LA64V1P0: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+lsx,+relax,+ual"
+// IR-LA64V1P1: attributes #[[#]] ={{.*}}"target-cpu"="loongarch64" {{.*}}"target-features"="+64bit,+d,+frecipe,+lsx,+relax,+ual"
+// IR-LA664: attributes #[[#]] ={{.*}}"target-cpu"="la664" {{.*}}"target-features"="+64bit,+d,+f,+frecipe,+lasx,+lsx,+relax,+ual"
int foo(void) {
return 3;
>From 5c4a042641c37e5a2b894b041ac8bf7693653a78 Mon Sep 17 00:00:00 2001
From: Xin Wang <wangxin03 at loongson.cn>
Date: Mon, 14 Oct 2024 17:06:02 +0800
Subject: [PATCH 3/3] [lld][LoongArch] Revert test files as ctx.arg.relax is
not needed except for the getRelExpr function
---
.../lib/Driver/ToolChains/Arch/LoongArch.cpp | 1 -
lld/ELF/Writer.cpp | 5 +-
lld/test/ELF/loongarch-relax-align.s | 209 ++++--------------
lld/test/ELF/loongarch-relax-emit-relocs.s | 5 +-
4 files changed, 44 insertions(+), 176 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 74d3ab65ed6643..d365997a2a5363 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -134,7 +134,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
(!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
Features.push_back("+lsx");
- // -mrelax is default, unless -mno-relax is specified.
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
Features.push_back("+relax");
} else {
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index cf0ff432f920ad..f4a22ea953ec49 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1462,8 +1462,6 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
for (;;) {
bool changed = ctx.target->needsThunks
? tc.createThunks(pass, ctx.outputSections)
- : ctx.arg.emachine == EM_LOONGARCH && !ctx.arg.relax
- ? false
: ctx.target->relaxOnce(pass);
bool spilled = ctx.script->spillSections();
changed |= spilled;
@@ -1547,8 +1545,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
finalizeOrderDependentContent();
}
}
- if (!ctx.arg.relocatable &&
- !(ctx.arg.emachine == EM_LOONGARCH && !ctx.arg.relax))
+ if (!ctx.arg.relocatable)
ctx.target->finalizeRelax(pass);
if (ctx.arg.relocatable)
diff --git a/lld/test/ELF/loongarch-relax-align.s b/lld/test/ELF/loongarch-relax-align.s
index 158f1f80ba8489..ab61e15d5caca2 100644
--- a/lld/test/ELF/loongarch-relax-align.s
+++ b/lld/test/ELF/loongarch-relax-align.s
@@ -6,180 +6,56 @@
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o -o %t.64
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.32.o --no-relax -o %t.32n
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o --no-relax -o %t.64n
-# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck %s --check-prefix=RELAX32
-# RUN: llvm-objdump -td --no-show-raw-insn %t.64 | FileCheck %s --check-prefixes=RELAX64,SRELAX64
-# RUN: llvm-objdump -td --no-show-raw-insn %t.32n | FileCheck %s --check-prefix=NORELAX
-# RUN: llvm-objdump -td --no-show-raw-insn %t.64n | FileCheck %s --check-prefix=NORELAX
+# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck %s
+# RUN: llvm-objdump -td --no-show-raw-insn %t.64 | FileCheck %s
+# RUN: llvm-objdump -td --no-show-raw-insn %t.32n | FileCheck %s
+# RUN: llvm-objdump -td --no-show-raw-insn %t.64n | FileCheck %s
## Test the R_LARCH_ALIGN without symbol index.
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.o64.o --defsym=old=1
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o -o %t.o64
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o --no-relax -o %t.o64n
-# RUN: llvm-objdump -td --no-show-raw-insn %t.o64 | FileCheck %s --check-prefixes=RELAX64,ORELAX64
-# RUN: llvm-objdump -td --no-show-raw-insn %t.o64n | FileCheck %s --check-prefix=ONORELAX
+# RUN: llvm-objdump -td --no-show-raw-insn %t.o64 | FileCheck %s
+# RUN: llvm-objdump -td --no-show-raw-insn %t.o64n | FileCheck %s
## -r keeps section contents unchanged.
# RUN: ld.lld -r %t.64.o -o %t.64.r
# RUN: llvm-objdump -dr --no-show-raw-insn %t.64.r | FileCheck %s --check-prefix=CHECKR
-
-# RELAX32-DAG: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol
-# RELAX32-DAG: {{0*}}10000 l .text {{0*}}44 .Ltext_start
-# RELAX32-DAG: {{0*}}10038 l .text {{0*}}0c .L1
-# RELAX32-DAG: {{0*}}10040 l .text {{0*}}04 .L2
-# RELAX32-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start
-
-# RELAX32: <.Ltext_start>:
-# RELAX32-NEXT: break 1
-# RELAX32-NEXT: break 2
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: break 3
-# RELAX32-NEXT: break 4
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: pcalau12i $a0, 0
-# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# RELAX32-NEXT: pcalau12i $a0, 0
-# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 56
-# RELAX32-NEXT: pcalau12i $a0, 0
-# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 64
-# RELAX32-EMPTY:
-# RELAX32-NEXT: <.L1>:
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: nop
-# RELAX32-EMPTY:
-# RELAX32-NEXT: <.L2>:
-# RELAX32-NEXT: break 5
-
-# RELAX32: <.Ltext2_start>:
-# RELAX32-NEXT: pcalau12i $a0, 0
-# RELAX32-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: nop
-# RELAX32-NEXT: break 6
-
-# NORELAX-DAG: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol
-# NORELAX-DAG: {{0*}}10000 l .text {{0*}}5c .Ltext_start
-# NORELAX-DAG: {{0*}}1004c l .text {{0*}}10 .L1
-# NORELAX-DAG: {{0*}}10058 l .text {{0*}}04 .L2
-# NORELAX-DAG: {{0*}}20000 l .text2 {{0*}}18 .Ltext2_start
-
-# NORELAX: <.Ltext_start>:
-# NORELAX-NEXT: break 1
-# NORELAX-NEXT: break 2
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: break 3
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: break 4
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: pcalau12i $a0, 0
-# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# NORELAX-NEXT: pcalau12i $a0, 0
-# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 76
-# NORELAX-NEXT: pcalau12i $a0, 0
-# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 88
-# NORELAX-EMPTY:
-# NORELAX-NEXT: <.L1>:
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-EMPTY:
-# NORELAX-NEXT: <.L2>:
-# NORELAX-NEXT: break 5
-
-# NORELAX: <.Ltext2_start>:
-# NORELAX-NEXT: pcalau12i $a0, 0
-# NORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: nop
-# NORELAX-NEXT: break 6
-
-
-
-# ORELAX64-DAG: {{0*}}00001 l *ABS* {{0*}}00 old
-# SRELAX64-DAG: {{0*}}10000 l .text {{0*}}00 .Lalign_symbol
-# RELAX64-DAG: {{0*}}10000 l .text {{0*}}44 .Ltext_start
-# RELAX64-DAG: {{0*}}10038 l .text {{0*}}0c .L1
-# RELAX64-DAG: {{0*}}10040 l .text {{0*}}04 .L2
-# RELAX64-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start
-
-# RELAX64: <.Ltext_start>:
-# RELAX64-NEXT: break 1
-# RELAX64-NEXT: break 2
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: break 3
-# RELAX64-NEXT: break 4
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: pcalau12i $a0, 0
-# RELAX64-NEXT: addi.d $a0, $a0, 0
-# RELAX64-NEXT: pcalau12i $a0, 0
-# RELAX64-NEXT: addi.d $a0, $a0, 56
-# RELAX64-NEXT: pcalau12i $a0, 0
-# RELAX64-NEXT: addi.d $a0, $a0, 64
-# RELAX64-EMPTY:
-# RELAX64-NEXT: <.L1>:
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: nop
-# RELAX64-EMPTY:
-# RELAX64-NEXT: <.L2>:
-# RELAX64-NEXT: break 5
-
-# RELAX64: <.Ltext2_start>:
-# RELAX64-NEXT: pcalau12i $a0, 0
-# RELAX64-NEXT: addi.d $a0, $a0, 0
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: nop
-# RELAX64-NEXT: break 6
-
-
-# ONORELAX-DAG: {{0*}}00001 l *ABS* {{0*}}00 old
-# ONORELAX-DAG: {{0*}}10000 l .text {{0*}}4c .Ltext_start
-# ONORELAX-DAG: {{0*}}1003c l .text {{0*}}10 .L1
-# ONORELAX-DAG: {{0*}}10048 l .text {{0*}}04 .L2
-# ONORELAX-DAG: {{0*}}20000 l .text2 {{0*}}18 .Ltext2_start
-
-# ONORELAX: <.Ltext_start>:
-# ONORELAX-NEXT: break 1
-# ONORELAX-NEXT: break 2
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: break 3
-# ONORELAX-NEXT: break 4
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: pcalau12i $a0, 0
-# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# ONORELAX-NEXT: pcalau12i $a0, 0
-# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 60
-# ONORELAX-NEXT: pcalau12i $a0, 0
-# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 72
-# ONORELAX-EMPTY:
-# ONORELAX-NEXT: <.L1>:
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-EMPTY:
-# ONORELAX-NEXT: <.L2>:
-# ONORELAX-NEXT: break 5
-
-# ONORELAX: <.Ltext2_start>:
-# ONORELAX-NEXT: pcalau12i $a0, 0
-# ONORELAX-NEXT: addi.{{[dw]}} $a0, $a0, 0
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: nop
-# ONORELAX-NEXT: break 6
+# CHECK-DAG: {{0*}}10000 l .text {{0*}}44 .Ltext_start
+# CHECK-DAG: {{0*}}10038 l .text {{0*}}0c .L1
+# CHECK-DAG: {{0*}}10040 l .text {{0*}}04 .L2
+# CHECK-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start
+
+# CHECK: <.Ltext_start>:
+# CHECK-NEXT: break 1
+# CHECK-NEXT: break 2
+# CHECK-NEXT: nop
+# CHECK-NEXT: nop
+# CHECK-NEXT: break 3
+# CHECK-NEXT: break 4
+# CHECK-NEXT: nop
+# CHECK-NEXT: nop
+# CHECK-NEXT: pcalau12i $a0, 0
+# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# CHECK-NEXT: pcalau12i $a0, 0
+# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 56
+# CHECK-NEXT: pcalau12i $a0, 0
+# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 64
+# CHECK-EMPTY:
+# CHECK-NEXT: <.L1>:
+# CHECK-NEXT: nop
+# CHECK-NEXT: nop
+# CHECK-EMPTY:
+# CHECK-NEXT: <.L2>:
+# CHECK-NEXT: break 5
+
+# CHECK: <.Ltext2_start>:
+# CHECK-NEXT: pcalau12i $a0, 0
+# CHECK-NEXT: addi.{{[dw]}} $a0, $a0, 0
+# CHECK-NEXT: nop
+# CHECK-NEXT: nop
+# CHECK-NEXT: break 6
# CHECKR: <.Ltext2_start>:
# CHECKR-NEXT: pcalau12i $a0, 0
@@ -194,11 +70,6 @@
# CHECKR-NEXT: nop
# CHECKR-NEXT: break 6
-
-
-
-
-
.macro .fake_p2align_4 max=0
.ifdef old
.if \max==0
diff --git a/lld/test/ELF/loongarch-relax-emit-relocs.s b/lld/test/ELF/loongarch-relax-emit-relocs.s
index 1feec64d722cab..ba414e8c93f0fb 100644
--- a/lld/test/ELF/loongarch-relax-emit-relocs.s
+++ b/lld/test/ELF/loongarch-relax-emit-relocs.s
@@ -12,8 +12,10 @@
# RUN: ld.lld -r %t.64.o -o %t.64.r
# RUN: llvm-objdump -dr %t.64.r | FileCheck %s --check-prefix=CHECKR
+## --no-relax should keep original relocations.
+## TODO Due to R_LARCH_RELAX is not relaxed, it plays same as --relax now.
# RUN: ld.lld -Ttext=0x10000 --emit-relocs --no-relax %t.64.o -o %t.64.norelax
-# RUN: llvm-objdump -dr %t.64.norelax | FileCheck %s --check-prefixes=CHECK,NORELAX
+# RUN: llvm-objdump -dr %t.64.norelax | FileCheck %s
# CHECK: 00010000 <_start>:
# CHECK-NEXT: pcalau12i $a0, 0
@@ -25,7 +27,6 @@
# CHECK-NEXT: nop
# CHECK-NEXT: R_LARCH_ALIGN *ABS*+0xc
# CHECK-NEXT: nop
-# NORELAX-NEXT: nop
# CHECK-NEXT: ret
# CHECKR: <_start>:
More information about the cfe-commits
mailing list