[lld] r368983 - [ELF][AArch64] Improve error message for unknown relocations
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 03:02:55 PDT 2019
Author: maskray
Date: Thu Aug 15 03:02:54 2019
New Revision: 368983
URL: http://llvm.org/viewvc/llvm-project?rev=368983&view=rev
Log:
[ELF][AArch64] Improve error message for unknown relocations
Like rLLD354040.
Previously, for unrecognized relocation types, in -no-pie/-pie mode, we got something like:
foo.o: unrecognized relocation ...
In -shared mode:
error: can't create dynamic relocation ... against symbol: yyy in readonly segment
Delete the default case from AArch64::getRelExpr and add the error there.
Reviewed By: grimar
Differential Revision: https://reviews.llvm.org/D66277
Added:
lld/trunk/test/ELF/invalid/invalid-relocation-aarch64.test
Modified:
lld/trunk/ELF/Arch/AArch64.cpp
Modified: lld/trunk/ELF/Arch/AArch64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AArch64.cpp?rev=368983&r1=368982&r2=368983&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AArch64.cpp (original)
+++ lld/trunk/ELF/Arch/AArch64.cpp Thu Aug 15 03:02:54 2019
@@ -76,6 +76,26 @@ AArch64::AArch64() {
RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const {
switch (type) {
+ case R_AARCH64_ABS16:
+ case R_AARCH64_ABS32:
+ case R_AARCH64_ABS64:
+ case R_AARCH64_ADD_ABS_LO12_NC:
+ case R_AARCH64_LDST128_ABS_LO12_NC:
+ case R_AARCH64_LDST16_ABS_LO12_NC:
+ case R_AARCH64_LDST32_ABS_LO12_NC:
+ case R_AARCH64_LDST64_ABS_LO12_NC:
+ case R_AARCH64_LDST8_ABS_LO12_NC:
+ case R_AARCH64_MOVW_SABS_G0:
+ case R_AARCH64_MOVW_SABS_G1:
+ case R_AARCH64_MOVW_SABS_G2:
+ case R_AARCH64_MOVW_UABS_G0:
+ case R_AARCH64_MOVW_UABS_G0_NC:
+ case R_AARCH64_MOVW_UABS_G1:
+ case R_AARCH64_MOVW_UABS_G1_NC:
+ case R_AARCH64_MOVW_UABS_G2:
+ case R_AARCH64_MOVW_UABS_G2_NC:
+ case R_AARCH64_MOVW_UABS_G3:
+ return R_ABS;
case R_AARCH64_TLSDESC_ADR_PAGE21:
return R_AARCH64_TLSDESC_PAGE;
case R_AARCH64_TLSDESC_LD64_LO12:
@@ -126,7 +146,9 @@ RelExpr AArch64::getRelExpr(RelType type
case R_AARCH64_NONE:
return R_NONE;
default:
- return R_ABS;
+ error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
+ ") against symbol " + toString(s));
+ return R_NONE;
}
}
@@ -421,7 +443,7 @@ void AArch64::relocateOne(uint8_t *loc,
or32AArch64Imm(loc, val);
break;
default:
- error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));
+ llvm_unreachable("unknown relocation");
}
}
Added: lld/trunk/test/ELF/invalid/invalid-relocation-aarch64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-relocation-aarch64.test?rev=368983&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-relocation-aarch64.test (added)
+++ lld/trunk/test/ELF/invalid/invalid-relocation-aarch64.test Thu Aug 15 03:02:54 2019
@@ -0,0 +1,31 @@
+# REQUIRES: aarch64
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+# CHECK: error: unknown relocation (1024) against symbol foo
+# CHECK: error: unknown relocation (1025) against symbol foo
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_AARCH64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000000
+ Symbol: foo
+ Type: 0x400
+ - Offset: 0x0000000000000000
+ Symbol: foo
+ Type: 0x401
+Symbols:
+ - Name: foo
+ Section: .text
+ Binding: STB_GLOBAL
More information about the llvm-commits
mailing list