[lld] r240765 - [Mips] Reject R_MIPS_CALL16 against local symbols
Simon Atanasyan
simon at atanasyan.com
Fri Jun 26 00:25:21 PDT 2015
Author: atanasyan
Date: Fri Jun 26 02:25:20 2015
New Revision: 240765
URL: http://llvm.org/viewvc/llvm-project?rev=240765&view=rev
Log:
[Mips] Reject R_MIPS_CALL16 against local symbols
Added:
lld/trunk/test/elf/Mips/validate-rel-03.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=240765&r1=240764&r2=240765&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Fri Jun 26 02:25:20 2015
@@ -547,15 +547,23 @@ static bool isBranchReloc(Reference::Kin
}
static bool isGotReloc(Reference::KindValue kind) {
- return kind == R_MIPS_GOT16 || kind == R_MIPS_GOT_HI16 ||
- kind == R_MIPS_GOT_LO16 || kind == R_MICROMIPS_GOT16 ||
- kind == R_MICROMIPS_GOT_HI16 || kind == R_MICROMIPS_GOT_LO16;
+ return kind == R_MIPS_GOT16 || kind == R_MICROMIPS_GOT16;
+}
+
+static bool isAllGotReloc(Reference::KindValue kind) {
+ return isGotReloc(kind) || kind == R_MIPS_GOT_HI16 ||
+ kind == R_MIPS_GOT_LO16 || kind == R_MICROMIPS_GOT_HI16 ||
+ kind == R_MICROMIPS_GOT_LO16;
}
static bool isCallReloc(Reference::KindValue kind) {
- return kind == R_MIPS_CALL16 || kind == R_MIPS_CALL_HI16 ||
- kind == R_MIPS_CALL_LO16 || kind == R_MICROMIPS_CALL16 ||
- kind == R_MICROMIPS_CALL_HI16 || kind == R_MICROMIPS_CALL_LO16;
+ return kind == R_MIPS_CALL16 || kind == R_MICROMIPS_CALL16;
+}
+
+static bool isAllCallReloc(Reference::KindValue kind) {
+ return isCallReloc(kind) || kind == R_MIPS_CALL_HI16 ||
+ kind == R_MIPS_CALL_LO16 || kind == R_MICROMIPS_CALL_HI16 ||
+ kind == R_MICROMIPS_CALL_LO16;
}
static bool isGotDispReloc(Reference::KindValue kind) {
@@ -610,8 +618,8 @@ void RelocationPass<ELFT>::handleReferen
handlePlain(atom, ref);
else if (isBranchReloc(kind))
handleBranch(atom, ref);
- else if (isGotReloc(kind) || isCallReloc(kind) || isGotDispReloc(kind) ||
- isGotPageReloc(kind) || kind == R_MIPS_EH)
+ else if (isAllGotReloc(kind) || isAllCallReloc(kind) ||
+ isGotDispReloc(kind) || isGotPageReloc(kind) || kind == R_MIPS_EH)
handleGOT(ref);
else if (isTlsDtpReloc(kind))
ref.setAddend(ref.addend() - atom.file().getDTPOffset());
@@ -672,7 +680,8 @@ RelocationPass<ELFT>::collectReferenceIn
else
_hasStaticRelocations.insert(ref.target());
- if (!isBranchReloc(refKind) && !isCallReloc(refKind) && refKind != R_MIPS_EH)
+ if (!isBranchReloc(refKind) && !isAllCallReloc(refKind) &&
+ refKind != R_MIPS_EH)
_requiresPtrEquality.insert(ref.target());
return std::error_code();
@@ -703,6 +712,15 @@ make_external_gprel32_reloc_error(const
ref.target()->name() + " in file " + atom.file().path());
}
+static std::error_code
+make_local_call16_reloc_error(const ELFLinkingContext &ctx,
+ const DefinedAtom &atom, const Reference &ref) {
+ return make_dynamic_error_code("R_MIPS_CALL16 (11) relocation cannot be used "
+ "against local symbol " +
+ ref.target()->name() + " in file " +
+ atom.file().path());
+}
+
template <typename ELFT>
std::error_code
RelocationPass<ELFT>::validateRelocation(const DefinedAtom &atom,
@@ -713,6 +731,9 @@ RelocationPass<ELFT>::validateRelocation
if (ref.kindValue() == R_MIPS_GPREL32 && !isLocal(ref.target()))
return make_external_gprel32_reloc_error(this->_ctx, atom, ref);
+ if (isCallReloc(ref.kindValue()) && isLocal(ref.target()))
+ return make_local_call16_reloc_error(this->_ctx, atom, ref);
+
if (this->_ctx.getOutputELFType() != ET_DYN)
return std::error_code();
@@ -765,7 +786,7 @@ static bool isMipsReadonly(const MipsELF
template <typename ELFT>
bool RelocationPass<ELFT>::mightBeDynamic(const MipsELFDefinedAtom<ELFT> &atom,
Reference::KindValue refKind) const {
- if (isGotReloc(refKind) || isCallReloc(refKind))
+ if (isAllGotReloc(refKind) || isAllCallReloc(refKind))
return true;
if (refKind != R_MIPS_32 && refKind != R_MIPS_64)
@@ -902,10 +923,8 @@ template <typename ELFT> void Relocation
ref.setTarget(getGlobalGOTEntry(ref.target()));
else if (isGotPageReloc(ref.kindValue()))
ref.setTarget(getLocalGOTPageEntry(ref));
- else if (isLocal(ref.target()) && (ref.kindValue() == R_MIPS_GOT16 ||
- ref.kindValue() == R_MIPS_CALL16 ||
- ref.kindValue() == R_MICROMIPS_GOT16 ||
- ref.kindValue() == R_MICROMIPS_CALL16))
+ else if (isLocal(ref.target()) &&
+ (isCallReloc(ref.kindValue()) || isGotReloc(ref.kindValue())))
ref.setTarget(getLocalGOTPageEntry(ref));
else
ref.setTarget(getLocalGOTEntry(ref));
Added: lld/trunk/test/elf/Mips/validate-rel-03.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/validate-rel-03.test?rev=240765&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/validate-rel-03.test (added)
+++ lld/trunk/test/elf/Mips/validate-rel-03.test Fri Jun 26 02:25:20 2015
@@ -0,0 +1,56 @@
+# Check that the linker does not accept R_MIPS_CALL16 relocation
+# against local symbol.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.o
+# RUN: not lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: R_MIPS_CALL16 (11) relocation cannot be used against local symbol L0 in file {{.*}}validate-rel-03.test.tmp.o
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 16
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 8
+ Symbol: T0
+ Type: R_MIPS_CALL16
+ - Offset: 4
+ Symbol: L0
+ Type: R_MIPS_CALL16
+
+Symbols:
+ Local:
+ - Name: L0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 4
+ Size: 4
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 8
+ Size: 8
+...
More information about the llvm-commits
mailing list