[lld] r260083 - [ELF][MIPS] Support R_MIPS_COPY relocation
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 8 02:05:13 PST 2016
Author: atanasyan
Date: Mon Feb 8 04:05:13 2016
New Revision: 260083
URL: http://llvm.org/viewvc/llvm-project?rev=260083&view=rev
Log:
[ELF][MIPS] Support R_MIPS_COPY relocation
Generate R_MIPS_COPY relocation for 'static' relocations against object
symbols defined in a shared libraries.
Added:
lld/trunk/test/ELF/mips-plt-copy.s
Modified:
lld/trunk/ELF/Target.cpp
lld/trunk/test/ELF/Inputs/mips-dynamic.s
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=260083&r1=260082&r2=260083&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Mon Feb 8 04:05:13 2016
@@ -196,6 +196,7 @@ public:
MipsTargetInfo();
unsigned getDynRel(unsigned Type) const override;
void writeGotHeader(uint8_t *Buf) const override;
+ bool needsCopyRel(uint32_t Type, const SymbolBody &S) const override;
bool needsGot(uint32_t Type, const SymbolBody &S) const override;
bool needsPlt(uint32_t Type, const SymbolBody &S) const override;
void relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type, uint64_t P,
@@ -1386,6 +1387,7 @@ void AMDGPUTargetInfo::relocateOne(uint8
}
template <class ELFT> MipsTargetInfo<ELFT>::MipsTargetInfo() {
+ CopyRel = R_MIPS_COPY;
PageSize = 65536;
GotHeaderEntriesNum = 2;
RelativeRel = R_MIPS_REL32;
@@ -1426,6 +1428,17 @@ void MipsTargetInfo<ELFT>::writeGotHeade
}
template <class ELFT>
+bool MipsTargetInfo<ELFT>::needsCopyRel(uint32_t Type,
+ const SymbolBody &S) const {
+ if (Config->Shared)
+ return false;
+ if (Type == R_MIPS_HI16 || Type == R_MIPS_LO16 || isRelRelative(Type))
+ if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(&S))
+ return SS->Sym.getType() == STT_OBJECT;
+ return false;
+}
+
+template <class ELFT>
bool MipsTargetInfo<ELFT>::needsGot(uint32_t Type, const SymbolBody &S) const {
return Type == R_MIPS_GOT16 || Type == R_MIPS_CALL16;
}
Modified: lld/trunk/test/ELF/Inputs/mips-dynamic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/mips-dynamic.s?rev=260083&r1=260082&r2=260083&view=diff
==============================================================================
--- lld/trunk/test/ELF/Inputs/mips-dynamic.s (original)
+++ lld/trunk/test/ELF/Inputs/mips-dynamic.s Mon Feb 8 04:05:13 2016
@@ -1,4 +1,21 @@
+ .option pic2
.text
.globl _foo
_foo:
nop
+
+ .globl foo
+ .type foo, @function
+foo:
+ nop
+
+ .data
+ .globl data0
+ .type data0, @object
+data0:
+ .word 0
+
+ .globl data1
+ .type data1, @object
+data1:
+ .word 0
Added: lld/trunk/test/ELF/mips-plt-copy.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-plt-copy.s?rev=260083&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-plt-copy.s (added)
+++ lld/trunk/test/ELF/mips-plt-copy.s Mon Feb 8 04:05:13 2016
@@ -0,0 +1,42 @@
+# Check creating of R_MIPS_COPY dynamic relocation.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# 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: ld.lld %t.o %t.so -o %t.exe
+# RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (7) .rel.dyn {
+# CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY data0 0x0
+# CHECK-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY data1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: Primary GOT {
+# CHECK: Local entries [
+# CHECK-NEXT: ]
+# CHECK-NEXT: Global entries [
+# CHECK-NEXT: ]
+# CHECK-NEXT: Number of TLS and multi-GOT entries: 0
+# CHECK-NEXT: }
+
+ .text
+ .globl __start
+__start:
+ lui $t0,%hi(data0) # R_MIPS_HI16 requires COPY rel for DSO defined data.
+ addi $t0,$t0,%lo(data0)
+ lui $t0,%hi(gd) # Does not require COPY rel for locally defined data.
+ addi $t0,$t0,%lo(gd)
+ lui $t0,%hi(ld) # Does not require COPY rel for local data.
+ addi $t0,$t0,%lo(ld)
+
+ .data
+ .globl gd
+gd:
+ .word 0
+ld:
+ .word data1+8-. # R_MIPS_PC32 requires COPY rel for DSO defined data.
More information about the llvm-commits
mailing list