Skip to content

Commit cebb0a6

Browse files
committed
[ELF][ARM] Improve error message for unknown relocation
Like rLLD354040. Before: `error: unrecognized relocation Unknown (254)` Now: `error: unknown relocation (254) against symbol foo`
1 parent 0fa45d6 commit cebb0a6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ uint32_t ARM::calcEFlags() const {
8484
RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
8585
const uint8_t *loc) const {
8686
switch (type) {
87+
case R_ARM_ABS32:
88+
case R_ARM_MOVW_ABS_NC:
89+
case R_ARM_MOVT_ABS:
90+
case R_ARM_THM_MOVW_ABS_NC:
91+
case R_ARM_THM_MOVT_ABS:
92+
return R_ABS;
8793
case R_ARM_THM_JUMP11:
8894
return R_PC;
8995
case R_ARM_CALL:
@@ -156,7 +162,9 @@ RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
156162
// not ARMv4 output, we can just ignore it.
157163
return R_NONE;
158164
default:
159-
return R_ABS;
165+
error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
166+
") against symbol " + toString(s));
167+
return R_NONE;
160168
}
161169
}
162170

@@ -702,8 +710,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
702710
break;
703711
}
704712
default:
705-
error(getErrorLocation(loc) + "unrecognized relocation " +
706-
toString(rel.type));
713+
llvm_unreachable("unknown relocation");
707714
}
708715
}
709716

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# REQUIRES: arm
2+
# RUN: yaml2obj %s -o %t.o
3+
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
4+
# CHECK: error: unknown relocation (254) against symbol foo
5+
# CHECK-NEXT: error: unknown relocation (255) against symbol foo
6+
7+
!ELF
8+
FileHeader:
9+
Class: ELFCLASS32
10+
Data: ELFDATA2LSB
11+
Type: ET_REL
12+
Machine: EM_ARM
13+
Sections:
14+
- Name: .text
15+
Type: SHT_PROGBITS
16+
Flags: [ SHF_ALLOC ]
17+
- Name: .rela.text
18+
Type: SHT_RELA
19+
Link: .symtab
20+
Info: .text
21+
Relocations:
22+
- Symbol: foo
23+
Type: 0xfe
24+
- Symbol: foo
25+
Type: 0xff
26+
Symbols:
27+
- Name: foo
28+
Section: .text
29+
Binding: STB_GLOBAL

0 commit comments

Comments
 (0)