[lld] [lld][LoongArch] Print error when encountering R_LARCH_ALIGN (PR #67424)
Lu Weining via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 26 05:58:08 PDT 2023
https://github.com/SixWeining created https://github.com/llvm/llvm-project/pull/67424
GAS (from binutils 2.41) defaults to emit `R_LARCH_ALIGN` for the `.align` directive for later linker relaxation in `ld`. But `lld` hasn't unimplemented relaxation on LoongArch currently. So we print a more valuable error than the default when encountering `R_LARCH_ALIGN`.
Similar to https://reviews.llvm.org/D71820.
>From f27a9aa54b5c669ea53bf65decac79a76002dd5b Mon Sep 17 00:00:00 2001
From: Weining Lu <luweining at loongson.cn>
Date: Tue, 26 Sep 2023 20:28:30 +0800
Subject: [PATCH] [lld][LoongArch] Print error when encountering R_LARCH_ALIGN
GAS (from binutils 2.41) defaults to emit R_LARCH_ALIGN for the
`.align` directive for later linker relaxation in `ld`. But `lld`
hasn't unimplemented relaxation on LoongArch currently. So we print
a more valuable error than the default when encountering `R_LARCH_ALIGN`.
Similar to https://reviews.llvm.org/D71820.
---
lld/ELF/Arch/LoongArch.cpp | 7 +++++++
lld/test/ELF/loongarch-reloc-align.s | 15 +++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 lld/test/ELF/loongarch-reloc-align.s
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index 04ddb4682917b4b..8f7cd7db9233e88 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -521,6 +521,13 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
case R_LARCH_RELAX:
// LoongArch linker relaxation is not implemented yet.
return R_NONE;
+ case R_LARCH_ALIGN:
+ // Not just a hint; always padded to the worst-case number of NOPs, so may
+ // not currently be aligned, and without linker relaxation support we can't
+ // delete NOPs to realign.
+ errorOrWarn(getErrorLocation(loc) + "relocation R_LARCH_ALIGN requires "
+ "unimplemented linker relaxation; recompile with -mno-relax");
+ return R_NONE;
// Other known relocs that are explicitly unimplemented:
//
diff --git a/lld/test/ELF/loongarch-reloc-align.s b/lld/test/ELF/loongarch-reloc-align.s
new file mode 100644
index 000000000000000..8e4eeca3d8e0a25
--- /dev/null
+++ b/lld/test/ELF/loongarch-reloc-align.s
@@ -0,0 +1,15 @@
+# REQUIRES: loongarch
+
+# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.o
+# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+
+# CHECK: relocation R_LARCH_ALIGN requires unimplemented linker relaxation
+
+.global _start
+_start:
+ addi.d $t0, $t0, 1
+1:
+ nop
+ .reloc 1b, R_LARCH_ALIGN, 12
+ nop
+ nop
More information about the llvm-commits
mailing list