From dcf5b72e20e331ee90450029033bb993dbf69cbd Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 21 Dec 2016 08:21:34 +0000 Subject: [PATCH] [ELF] - Do not call fatal() in Target.cpp, call error() instead. We probably would want to avoid fatal() if we can in context of librarification, but for me reason of that patch is to help D27900 go. D27900 changes errors reporting to something like error: text1 note: text2 note: text3 where hint used to provide additional information about location. In that case I can't just call fatal() because user will not see notes after that what adds additional complication to handle. So It is good to switch fatal() to error() where it is possible. Also it adds testcase with broken relocation number. Previously we did not have any, It checks that error() instead of fatal() works fine. Differential revision: https://reviews.llvm.org/D27973 llvm-svn: 290239 --- lld/ELF/Target.cpp | 14 +++++----- .../ELF/invalid/Inputs/invalid-relocation-x64.elf | Bin 0 -> 559 bytes lld/test/ELF/invalid/invalid-relocation-x64.s | 31 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 lld/test/ELF/invalid/Inputs/invalid-relocation-x64.elf create mode 100644 lld/test/ELF/invalid/invalid-relocation-x64.s diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index d50bd4e..c0fcd95 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -870,7 +870,7 @@ void X86_64TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, write64le(Loc, Val); break; default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } @@ -1039,7 +1039,7 @@ void PPCTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, or32be(Loc, Val & 0x3FFFFFC); break; default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } @@ -1217,7 +1217,7 @@ void PPC64TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, break; } default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } @@ -1468,7 +1468,7 @@ void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, or32AArch64Imm(Loc, Val); break; default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } @@ -1578,7 +1578,7 @@ void AMDGPUTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, write32le(Loc, Val >> 32); break; default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } @@ -1888,7 +1888,7 @@ void ARMTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, (Val & 0x00ff)); // imm8 break; default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } @@ -2336,7 +2336,7 @@ void MipsTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, applyMipsPcReloc(Loc, Type, Val); break; default: - fatal(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); + error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type)); } } diff --git a/lld/test/ELF/invalid/Inputs/invalid-relocation-x64.elf b/lld/test/ELF/invalid/Inputs/invalid-relocation-x64.elf new file mode 100644 index 0000000000000000000000000000000000000000..25df2944614ead659ad0b20c32c98097ea72b90b GIT binary patch literal 559 zcmb<-^>JfjWaMOk0!9Wq21XbMiFUwXJ20>@up)_)$7BO)1KG!fru_gmN1&+zaY4#h zu!zI-8$jilp=x1DC7=vBAdPM}Na_RBewaFt9UvhNkR%Ym#KnMYklE;f18OL`H_-V! zK#kb+b3*m2p&5*>A0|Bm#z3QIqVaKa^@>t+67@<_D@qvjiZhB!ib@ibfGikYnG50r E0Oe8?3IG5A literal 0 HcmV?d00001 diff --git a/lld/test/ELF/invalid/invalid-relocation-x64.s b/lld/test/ELF/invalid/invalid-relocation-x64.s new file mode 100644 index 0000000..a8c38fc --- /dev/null +++ b/lld/test/ELF/invalid/invalid-relocation-x64.s @@ -0,0 +1,31 @@ +## invalid-relocation-x64.elf contains relocations with invalid relocation number. +## Next yaml code was used to create initial binary. After that it +## was modified with hex-editor to replace known relocations with fake ones, +## that have 0x98 and 0x98 numbers. +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_FREEBSD + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + - Name: .rela.text + Type: SHT_RELA + Link: .symtab + Info: .text + Relocations: + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE + - Offset: 0x0000000000000000 + Symbol: '' + Type: R_X86_64_NONE + + +# RUN: not ld.lld %p/Inputs/invalid-relocation-x64.elf -o %t2 2>&1 | FileCheck %s +# CHECK: unrecognized reloc 152 +# CHECK: unrecognized reloc 153 -- 2.7.4