[lld] r261879 - [ELF][MIPS] Add STO_MIPS_PLT flag to the symbols require pointer equality
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 25 08:19:16 PST 2016
Author: atanasyan
Date: Thu Feb 25 10:19:15 2016
New Revision: 261879
URL: http://llvm.org/viewvc/llvm-project?rev=261879&view=rev
Log:
[ELF][MIPS] Add STO_MIPS_PLT flag to the symbols require pointer equality
On MIPS we need to mark symbol which has a PLT entry and requires
pointer equality by STO_MIPS_PLT flag. That is necessary to help
dynamic linker distinguish such symbols and MIPS lazy-binding stubs.
https://sourceware.org/ml/binutils/2008-07/txt00000.txt
Differential Revision: http://reviews.llvm.org/D17593
Added:
lld/trunk/test/ELF/mips-sto-plt.s
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=261879&r1=261878&r2=261879&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Feb 25 10:19:15 2016
@@ -1509,6 +1509,14 @@ void SymbolTableSection<ELFT>::writeGlob
ESym->st_shndx = OutSec->SectionIndex;
else if (isa<DefinedRegular<ELFT>>(Body))
ESym->st_shndx = SHN_ABS;
+
+ // On MIPS we need to mark symbol which has a PLT entry and requires pointer
+ // equality by STO_MIPS_PLT flag. That is necessary to help dynamic linker
+ // distinguish such symbols and MIPS lazy-binding stubs.
+ // https://sourceware.org/ml/binutils/2008-07/txt00000.txt
+ if (Config->EMachine == EM_MIPS && Body->isInPlt() &&
+ Body->NeedsCopyOrPltAddr)
+ ESym->st_other |= ELF::STO_MIPS_PLT;
++ESym;
}
}
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=261879&r1=261878&r2=261879&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Feb 25 10:19:15 2016
@@ -228,6 +228,7 @@ public:
uint8_t *PairedLoc = nullptr) const override;
bool isHintRel(uint32_t Type) const override;
bool isRelRelative(uint32_t Type) const override;
+ bool refersToGotEntry(uint32_t Type) const override;
};
} // anonymous namespace
@@ -1705,8 +1706,12 @@ bool MipsTargetInfo<ELFT>::needsCopyRelI
template <class ELFT>
bool MipsTargetInfo<ELFT>::needsGot(uint32_t Type, SymbolBody &S) const {
- return needsPlt<ELFT>(Type, S) || Type == R_MIPS_GOT16 ||
- Type == R_MIPS_CALL16;
+ return needsPlt<ELFT>(Type, S) || refersToGotEntry(Type);
+}
+
+template <class ELFT>
+bool MipsTargetInfo<ELFT>::refersToGotEntry(uint32_t Type) const {
+ return Type == R_MIPS_GOT16 || Type == R_MIPS_CALL16;
}
template <class ELFT>
@@ -1716,8 +1721,6 @@ bool MipsTargetInfo<ELFT>::needsPltImpl(
return false;
if (Type == R_MIPS_26 && canBePreempted(&S, false))
return true;
- if (!isRelRelative(Type) && S.isShared())
- return true;
return false;
}
Added: lld/trunk/test/ELF/mips-sto-plt.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-sto-plt.s?rev=261879&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-sto-plt.s (added)
+++ lld/trunk/test/ELF/mips-sto-plt.s Thu Feb 25 10:19:15 2016
@@ -0,0 +1,65 @@
+# Check assigning STO_MIPS_PLT flag to symbol needs a pointer equality.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: %S/Inputs/mips-dynamic.s -o %t.so.o
+# RUN: ld.lld %t.so.o -shared -o %t.so
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o %t.so -o %t.exe
+# RUN: llvm-readobj -dt -mips-plt-got %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK: Symbol {
+# CHECK: Name: foo0@
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: Function
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: }
+# CHECK: Symbol {
+# CHECK: Name: foo1@
+# CHECK-NEXT: Value: 0x20050
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: Function
+# CHECK-NEXT: Other: 8
+# ^-- STO_MIPS_PLT
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: }
+
+# CHECK: Primary GOT {
+# CHECK: Local entries [
+# CHECK-NEXT: ]
+# CHECK-NEXT: Global entries [
+# CHECK-NEXT: ]
+# CHECK: PLT GOT {
+# CHECK: Entries [
+# CHECK-NEXT: Entry {
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Initial:
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Type: Function
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: Name: foo0
+# CHECK-NEXT: }
+# CHECK-NEXT: Entry {
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Initial:
+# CHECK-NEXT: Value: 0x20050
+# CHECK-NEXT: Type: Function
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: Name: foo1
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+ .text
+ .globl __start
+__start:
+ jal foo0 # R_MIPS_26 against 'foo0' from DSO
+ lui $t0,%hi(foo1) # R_MIPS_HI16/LO16 against 'foo1' from DSO
+ addi $t0,$t0,%lo(foo1)
+
+loc:
+ nop
More information about the llvm-commits
mailing list