[lld] r354040 - Improve error message for unknown relocations.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 14 10:02:22 PST 2019
Author: ruiu
Date: Thu Feb 14 10:02:20 2019
New Revision: 354040
URL: http://llvm.org/viewvc/llvm-project?rev=354040&view=rev
Log:
Improve error message for unknown relocations.
Previously, we showed the following message for an unknown relocation:
foo.o: unrecognized reloc 256
This patch improves it so that the error message includes a symbol name:
foo.o: unknown relocation (256) against symbol bar
Modified:
lld/trunk/ELF/Arch/AMDGPU.cpp
lld/trunk/ELF/Arch/Mips.cpp
lld/trunk/ELF/Arch/SPARCV9.cpp
lld/trunk/ELF/Arch/X86.cpp
lld/trunk/ELF/Arch/X86_64.cpp
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/Relocations.h
lld/trunk/test/ELF/invalid/invalid-debug-relocations.test
lld/trunk/test/ELF/invalid/invalid-relocation-x64.test
Modified: lld/trunk/ELF/Arch/AMDGPU.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/AMDGPU.cpp?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/AMDGPU.cpp (original)
+++ lld/trunk/ELF/Arch/AMDGPU.cpp Thu Feb 14 10:02:20 2019
@@ -74,7 +74,7 @@ void AMDGPU::relocateOne(uint8_t *Loc, R
write32le(Loc, Val >> 32);
break;
default:
- error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
+ llvm_unreachable("unknown relocation");
}
}
@@ -94,7 +94,9 @@ RelExpr AMDGPU::getRelExpr(RelType Type,
case R_AMDGPU_GOTPCREL32_HI:
return R_GOT_PC;
default:
- return R_INVALID;
+ error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
+ ") against symbol " + toString(S));
+ return R_NONE;
}
}
Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Thu Feb 14 10:02:20 2019
@@ -175,7 +175,9 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType T
case R_MIPS_NONE:
return R_NONE;
default:
- return R_INVALID;
+ error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
+ ") against symbol " + toString(S));
+ return R_NONE;
}
}
@@ -631,7 +633,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo
writeShuffleValue<E>(Loc, Val, 23, 2);
break;
default:
- error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
+ llvm_unreachable("unknown relocation");
}
}
Modified: lld/trunk/ELF/Arch/SPARCV9.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/SPARCV9.cpp?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/SPARCV9.cpp (original)
+++ lld/trunk/ELF/Arch/SPARCV9.cpp Thu Feb 14 10:02:20 2019
@@ -68,7 +68,9 @@ RelExpr SPARCV9::getRelExpr(RelType Type
case R_SPARC_NONE:
return R_NONE;
default:
- return R_INVALID;
+ error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
+ ") against symbol " + toString(S));
+ return R_NONE;
}
}
@@ -118,7 +120,7 @@ void SPARCV9::relocateOne(uint8_t *Loc,
write64be(Loc, Val);
break;
default:
- error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
+ llvm_unreachable("unknown relocation");
}
}
Modified: lld/trunk/ELF/Arch/X86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86.cpp?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86.cpp (original)
+++ lld/trunk/ELF/Arch/X86.cpp Thu Feb 14 10:02:20 2019
@@ -149,7 +149,9 @@ RelExpr X86::getRelExpr(RelType Type, co
case R_386_NONE:
return R_NONE;
default:
- return R_INVALID;
+ error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
+ ") against symbol " + toString(S));
+ return R_NONE;
}
}
@@ -318,7 +320,7 @@ void X86::relocateOne(uint8_t *Loc, RelT
write32le(Loc, Val);
break;
default:
- error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
+ llvm_unreachable("unknown relocation");
}
}
Modified: lld/trunk/ELF/Arch/X86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/X86_64.cpp?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/X86_64.cpp (original)
+++ lld/trunk/ELF/Arch/X86_64.cpp Thu Feb 14 10:02:20 2019
@@ -125,7 +125,9 @@ RelExpr X86_64<ELFT>::getRelExpr(RelType
case R_X86_64_NONE:
return R_NONE;
default:
- return R_INVALID;
+ error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
+ ") against symbol " + toString(S));
+ return R_NONE;
}
}
@@ -371,7 +373,7 @@ void X86_64<ELFT>::relocateOne(uint8_t *
write64le(Loc, Val);
break;
default:
- error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
+ llvm_unreachable("unknown relocation");
}
}
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Feb 14 10:02:20 2019
@@ -600,8 +600,6 @@ static int64_t getTlsTpOffset() {
static uint64_t getRelocTargetVA(const InputFile *File, RelType Type, int64_t A,
uint64_t P, const Symbol &Sym, RelExpr Expr) {
switch (Expr) {
- case R_INVALID:
- return 0;
case R_ABS:
case R_RELAX_TLS_LD_TO_LE_ABS:
case R_RELAX_GOT_PC_NOPIC:
Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Thu Feb 14 10:02:20 2019
@@ -29,7 +29,6 @@ typedef uint32_t RelType;
// from files are converted to these types so that the main code
// doesn't have to know about architecture-specific details.
enum RelExpr {
- R_INVALID,
R_ABS,
R_ADDEND,
R_AARCH64_GOT_PAGE_PC,
Modified: lld/trunk/test/ELF/invalid/invalid-debug-relocations.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-debug-relocations.test?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-debug-relocations.test (original)
+++ lld/trunk/test/ELF/invalid/invalid-debug-relocations.test Thu Feb 14 10:02:20 2019
@@ -2,7 +2,7 @@
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld -gdb-index %t.o -o %t.exe 2>&1 | FileCheck %s
-# CHECK: error: {{.*}}invalid-debug-relocations.test.tmp.o:(.debug_info+0x0): has non-ABS relocation Unknown (255) against symbol '_start'
+# CHECK: error: {{.*}}invalid-debug-relocations.test.tmp.o:(.debug_info+0x0): unknown relocation (255) against symbol _start
!ELF
FileHeader:
Modified: lld/trunk/test/ELF/invalid/invalid-relocation-x64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-relocation-x64.test?rev=354040&r1=354039&r2=354040&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-relocation-x64.test (original)
+++ lld/trunk/test/ELF/invalid/invalid-relocation-x64.test Thu Feb 14 10:02:20 2019
@@ -3,8 +3,8 @@
# RUN: echo ".global foo; foo:" > %t2.s
# RUN: llvm-mc %t2.s -o %t2.o -filetype=obj -triple x86_64-pc-linux
# RUN: not ld.lld %t1.o %t2.o -o /dev/null 2>&1 | FileCheck %s
-# CHECK: error: unrecognized reloc 152
-# CHECK: error: unrecognized reloc 153
+# CHECK: error: unknown relocation (152) against symbol foo
+# CHECK: error: unknown relocation (153) against symbol foo
!ELF
FileHeader:
More information about the llvm-commits
mailing list