[lld] r232360 - [Mips] Implement R_MIPS_GOT_DISP/PAGE/OFST relocations handling
Simon Atanasyan
simon at atanasyan.com
Mon Mar 16 02:14:17 PDT 2015
Author: atanasyan
Date: Mon Mar 16 04:14:17 2015
New Revision: 232360
URL: http://llvm.org/viewvc/llvm-project?rev=232360&view=rev
Log:
[Mips] Implement R_MIPS_GOT_DISP/PAGE/OFST relocations handling
Added:
lld/trunk/test/elf/Mips/got-page-32.test
lld/trunk/test/elf/Mips/got-page-64.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
lld/trunk/test/elf/Mips/exe-fileheader-64.test
lld/trunk/test/elf/Mips/exe-fileheader-micro-64.test
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h?rev=232360&r1=232359&r2=232360&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h Mon Mar 16 04:14:17 2015
@@ -31,6 +31,8 @@ enum {
LLD_R_MIPS_STO_PLT = 1029,
/// \brief The same as R_MICROMIPS_26_S1 but for global symbols.
LLD_R_MICROMIPS_GLOBAL_26_S1 = 1030,
+ /// \brief Apply high 32+16 bits of symbol + addend.
+ LLD_R_MIPS_64_HI16 = 1031,
};
typedef llvm::object::ELFType<llvm::support::little, 2, false> Mips32ELType;
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=232360&r1=232359&r2=232360&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Mon Mar 16 04:14:17 2015
@@ -57,8 +57,11 @@ static MipsRelocationParams getRelocatio
case R_MIPS_32:
case R_MIPS_GPREL32:
case R_MIPS_PC32:
- case LLD_R_MIPS_32_HI16:
return {4, 0xffffffff, 0, false};
+ case LLD_R_MIPS_32_HI16:
+ return {4, 0xffff0000, 0, false};
+ case LLD_R_MIPS_64_HI16:
+ return {8, 0xffffffffffff0000ull, 0, false};
case R_MIPS_26:
case LLD_R_MIPS_GLOBAL_26:
return {4, 0x3ffffff, 2, false};
@@ -66,6 +69,9 @@ static MipsRelocationParams getRelocatio
case R_MIPS_LO16:
case R_MIPS_GPREL16:
case R_MIPS_GOT16:
+ case R_MIPS_GOT_DISP:
+ case R_MIPS_GOT_PAGE:
+ case R_MIPS_GOT_OFST:
case R_MIPS_TLS_DTPREL_HI16:
case R_MIPS_TLS_DTPREL_LO16:
case R_MIPS_TLS_TPREL_HI16:
@@ -185,11 +191,18 @@ static uint32_t relocLo16(uint64_t P, ui
/// \brief R_MIPS_GOT16, R_MIPS_CALL16, R_MICROMIPS_GOT16, R_MICROMIPS_CALL16
/// rel16 G (verify)
-static uint32_t relocGOT(uint64_t S, uint64_t GP) {
- int32_t G = (int32_t)(S - GP);
+static uint64_t relocGOT(uint64_t S, uint64_t GP) {
+ int64_t G = (int64_t)(S - GP);
return G;
}
+/// R_MIPS_GOT_OFST
+/// rel16 offset of (S+A) from the page pointer (verify)
+static uint32_t relocGOTOfst(uint64_t S, int64_t A) {
+ uint64_t page = (S + A + 0x8000) & ~0xffff;
+ return S + A - page;
+}
+
/// \brief R_MIPS_GPREL16
/// local: sign-extend(A) + S + GP0 - GP
/// external: sign-extend(A) + S - GP
@@ -241,9 +254,9 @@ static uint32_t relocPc23(uint64_t P, ui
return result >> 2;
}
-/// \brief LLD_R_MIPS_32_HI16
-static uint32_t reloc32hi16(uint64_t S, int64_t A) {
- return (S + A + 0x8000) & 0xffff0000;
+/// \brief LLD_R_MIPS_32_HI16, LLD_R_MIPS_64_HI16
+static uint64_t relocMaskLow16(uint64_t S, int64_t A) {
+ return S + A + 0x8000;
}
static std::error_code adjustJumpOpCode(uint64_t &ins, uint64_t tgt,
@@ -326,6 +339,8 @@ static ErrorOr<uint64_t> calculateReloca
return relocLo16(relAddr, tgtAddr, ref.addend(), isGP, true);
case R_MIPS_GOT16:
case R_MIPS_CALL16:
+ case R_MIPS_GOT_DISP:
+ case R_MIPS_GOT_PAGE:
case R_MICROMIPS_GOT16:
case R_MICROMIPS_CALL16:
case R_MIPS_TLS_GD:
@@ -335,6 +350,8 @@ static ErrorOr<uint64_t> calculateReloca
case R_MICROMIPS_TLS_LDM:
case R_MICROMIPS_TLS_GOTTPREL:
return relocGOT(tgtAddr, gpAddr);
+ case R_MIPS_GOT_OFST:
+ return relocGOTOfst(tgtAddr, ref.addend());
case R_MICROMIPS_PC7_S1:
return relocPc7(relAddr, tgtAddr, ref.addend());
case R_MICROMIPS_PC10_S1:
@@ -375,7 +392,8 @@ static ErrorOr<uint64_t> calculateReloca
case LLD_R_MIPS_GLOBAL_GOT:
// Do nothing.
case LLD_R_MIPS_32_HI16:
- return reloc32hi16(tgtAddr, ref.addend());
+ case LLD_R_MIPS_64_HI16:
+ return relocMaskLow16(tgtAddr, ref.addend());
case LLD_R_MIPS_GLOBAL_26:
return reloc26ext(tgtAddr, ref.addend(), 2);
case LLD_R_MICROMIPS_GLOBAL_26_S1:
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=232360&r1=232359&r2=232360&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Mon Mar 16 04:14:17 2015
@@ -19,11 +19,13 @@ using namespace llvm::ELF;
// Lazy resolver
static const uint8_t mipsGot0AtomContent[] = {
+ 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
// Module pointer
static const uint8_t mipsGotModulePointerAtomContent[] = {
+ 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80
};
@@ -101,25 +103,37 @@ public:
};
/// \brief MIPS GOT entry initialized by zero.
-class GOT0Atom : public MipsGOTAtom {
+template <typename ELFT> class GOT0Atom : public MipsGOTAtom {
public:
GOT0Atom(const File &f) : MipsGOTAtom(f) {}
- ArrayRef<uint8_t> rawContent() const override {
- return llvm::makeArrayRef(mipsGot0AtomContent);
- }
+ ArrayRef<uint8_t> rawContent() const override;
};
+template <> ArrayRef<uint8_t> GOT0Atom<Mips32ELType>::rawContent() const {
+ return llvm::makeArrayRef(mipsGot0AtomContent).slice(4);
+}
+template <> ArrayRef<uint8_t> GOT0Atom<Mips64ELType>::rawContent() const {
+ return llvm::makeArrayRef(mipsGot0AtomContent);
+}
+
/// \brief MIPS GOT entry initialized by zero.
-class GOTModulePointerAtom : public MipsGOTAtom {
+template <typename ELFT> class GOTModulePointerAtom : public MipsGOTAtom {
public:
GOTModulePointerAtom(const File &f) : MipsGOTAtom(f) {}
- ArrayRef<uint8_t> rawContent() const override {
- return llvm::makeArrayRef(mipsGotModulePointerAtomContent);
- }
+ ArrayRef<uint8_t> rawContent() const override;
};
+template <>
+ArrayRef<uint8_t> GOTModulePointerAtom<Mips32ELType>::rawContent() const {
+ return llvm::makeArrayRef(mipsGotModulePointerAtomContent).slice(4);
+}
+template <>
+ArrayRef<uint8_t> GOTModulePointerAtom<Mips64ELType>::rawContent() const {
+ return llvm::makeArrayRef(mipsGotModulePointerAtomContent);
+}
+
/// \brief MIPS GOT TLS GD entry.
class GOTTLSGdAtom : public MipsGOTAtom {
public:
@@ -146,7 +160,7 @@ public:
Alignment alignment() const override { return Alignment(2); }
ArrayRef<uint8_t> rawContent() const override {
- return llvm::makeArrayRef(mipsGot0AtomContent);
+ return llvm::makeArrayRef(mipsGot0AtomContent).slice(4);
}
};
@@ -268,6 +282,7 @@ private:
/// \brief Map Atoms and addend to local GOT entries.
typedef std::pair<const Atom *, int64_t> LocalGotMapKeyT;
llvm::DenseMap<LocalGotMapKeyT, GOTAtom *> _gotLocalMap;
+ llvm::DenseMap<LocalGotMapKeyT, GOTAtom *> _gotLocalPageMap;
/// \brief Map Atoms to global GOT entries.
llvm::DenseMap<const Atom *, GOTAtom *> _gotGlobalMap;
@@ -340,6 +355,7 @@ private:
void handleGOT(Reference &ref);
const GOTAtom *getLocalGOTEntry(const Reference &ref);
+ const GOTAtom *getLocalGOTPageEntry(const Reference &ref);
const GOTAtom *getGlobalGOTEntry(const Atom *a);
const GOTAtom *getTLSGOTEntry(const Atom *a);
const GOTAtom *getTLSGdGOTEntry(const Atom *a);
@@ -369,8 +385,9 @@ private:
template <typename ELFT>
RelocationPass<ELFT>::RelocationPass(MipsLinkingContext &ctx)
: _ctx(ctx), _file(ctx), _gotLDMEntry(nullptr) {
- _localGotVector.push_back(new (_file._alloc) GOT0Atom(_file));
- _localGotVector.push_back(new (_file._alloc) GOTModulePointerAtom(_file));
+ _localGotVector.push_back(new (_file._alloc) GOT0Atom<ELFT>(_file));
+ _localGotVector.push_back(new (_file._alloc)
+ GOTModulePointerAtom<ELFT>(_file));
}
template <typename ELFT>
@@ -483,8 +500,13 @@ void RelocationPass<ELFT>::handleReferen
case R_MIPS_CALL16:
case R_MICROMIPS_GOT16:
case R_MICROMIPS_CALL16:
+ case R_MIPS_GOT_DISP:
+ case R_MIPS_GOT_PAGE:
handleGOT(ref);
break;
+ case R_MIPS_GOT_OFST:
+ // Nothing to do. We create GOT page entry in the R_MIPS_GOT_PAGE handler.
+ break;
case R_MIPS_GPREL16:
if (isLocal(ref.target()))
ref.setAddend(ref.addend() + atom.file().getGP0());
@@ -722,10 +744,19 @@ void RelocationPass<ELFT>::handle26(cons
}
template <typename ELFT> void RelocationPass<ELFT>::handleGOT(Reference &ref) {
- if (isLocalCall(ref.target()))
+ if (!isLocalCall(ref.target())) {
+ ref.setTarget(getGlobalGOTEntry(ref.target()));
+ return;
+ }
+
+ if (ref.kindValue() == R_MIPS_GOT_PAGE)
+ ref.setTarget(getLocalGOTPageEntry(ref));
+ else if (ref.kindValue() == R_MIPS_GOT_DISP)
ref.setTarget(getLocalGOTEntry(ref));
+ else if (isLocal(ref.target()))
+ ref.setTarget(getLocalGOTPageEntry(ref));
else
- ref.setTarget(getGlobalGOTEntry(ref.target()));
+ ref.setTarget(getLocalGOTEntry(ref));
}
template <typename ELFT>
@@ -767,15 +798,35 @@ const GOTAtom *RelocationPass<ELFT>::get
if (got != _gotLocalMap.end())
return got->second;
- auto ga = new (_file._alloc) GOT0Atom(_file);
+ auto ga = new (_file._alloc) GOT0Atom<ELFT>(_file);
_gotLocalMap[key] = ga;
_localGotVector.push_back(ga);
- if (isLocal(a))
- ga->addReferenceELF_Mips(LLD_R_MIPS_32_HI16, 0, a, ref.addend());
- else
- ga->addReferenceELF_Mips(R_MIPS_32, 0, a, 0);
+ Reference::KindValue relKind = ELFT::Is64Bits ? R_MIPS_64 : R_MIPS_32;
+ ga->addReferenceELF_Mips(relKind, 0, a, 0);
+
+ return ga;
+}
+
+template <typename ELFT>
+const GOTAtom *
+RelocationPass<ELFT>::getLocalGOTPageEntry(const Reference &ref) {
+ const Atom *a = ref.target();
+ LocalGotMapKeyT key(a, ref.addend());
+
+ auto got = _gotLocalPageMap.find(key);
+ if (got != _gotLocalPageMap.end())
+ return got->second;
+
+ auto ga = new (_file._alloc) GOT0Atom<ELFT>(_file);
+ _gotLocalPageMap[key] = ga;
+
+ _localGotVector.push_back(ga);
+
+ Reference::KindValue relKind =
+ ELFT::Is64Bits ? LLD_R_MIPS_64_HI16 : LLD_R_MIPS_32_HI16;
+ ga->addReferenceELF_Mips(relKind, 0, a, ref.addend());
return ga;
}
@@ -786,7 +837,7 @@ const GOTAtom *RelocationPass<ELFT>::get
if (got != _gotGlobalMap.end())
return got->second;
- auto ga = new (_file._alloc) GOT0Atom(_file);
+ auto ga = new (_file._alloc) GOT0Atom<ELFT>(_file);
_gotGlobalMap[a] = ga;
_globalGotVector.push_back(ga);
@@ -804,7 +855,7 @@ const GOTAtom *RelocationPass<ELFT>::get
if (got != _gotTLSMap.end())
return got->second;
- auto ga = new (_file._alloc) GOT0Atom(_file);
+ auto ga = new (_file._alloc) GOT0Atom<ELFT>(_file);
_gotTLSMap[a] = ga;
_tlsGotVector.push_back(ga);
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp?rev=232360&r1=232359&r2=232360&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp Mon Mar 16 04:14:17 2015
@@ -23,6 +23,7 @@ const Registry::KindStrings MipsRelocati
#include "llvm/Support/ELFRelocs/Mips.def"
LLD_KIND_STRING_ENTRY(LLD_R_MIPS_GLOBAL_GOT),
LLD_KIND_STRING_ENTRY(LLD_R_MIPS_32_HI16),
+ LLD_KIND_STRING_ENTRY(LLD_R_MIPS_64_HI16),
LLD_KIND_STRING_ENTRY(LLD_R_MIPS_GLOBAL_26),
LLD_KIND_STRING_ENTRY(LLD_R_MIPS_HI16),
LLD_KIND_STRING_ENTRY(LLD_R_MIPS_LO16),
Modified: lld/trunk/test/elf/Mips/exe-fileheader-64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-fileheader-64.test?rev=232360&r1=232359&r2=232360&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/exe-fileheader-64.test (original)
+++ lld/trunk/test/elf/Mips/exe-fileheader-64.test Mon Mar 16 04:14:17 2015
@@ -24,7 +24,7 @@
# CHECK: Version: 1
# CHECK: Entry: 0x1200001A0
# CHECK: ProgramHeaderOffset: 0x40
-# CHECK: SectionHeaderOffset: 0x12F8
+# CHECK: SectionHeaderOffset: 0x1300
# CHECK: Flags [ (0x60000007)
# CHECK: EF_MIPS_ARCH_64 (0x60000000)
# CHECK: EF_MIPS_CPIC (0x4)
Modified: lld/trunk/test/elf/Mips/exe-fileheader-micro-64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-fileheader-micro-64.test?rev=232360&r1=232359&r2=232360&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/exe-fileheader-micro-64.test (original)
+++ lld/trunk/test/elf/Mips/exe-fileheader-micro-64.test Mon Mar 16 04:14:17 2015
@@ -24,7 +24,7 @@
# CHECK: Version: 1
# CHECK: Entry: 0x1200001A1
# CHECK: ProgramHeaderOffset: 0x40
-# CHECK: SectionHeaderOffset: 0x12F8
+# CHECK: SectionHeaderOffset: 0x1300
# CHECK: Flags [ (0x82000007)
# CHECK: EF_MIPS_ARCH_64R2 (0x80000000)
# CHECK: EF_MIPS_CPIC (0x4)
Added: lld/trunk/test/elf/Mips/got-page-32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/got-page-32.test?rev=232360&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/got-page-32.test (added)
+++ lld/trunk/test/elf/Mips/got-page-32.test Mon Mar 16 04:14:17 2015
@@ -0,0 +1,203 @@
+# Check handling of R_MIPS_GOT_DISP / PAGE / OFST relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: T0 (1)
+# GOT-NEXT: Value: 0x400154
+# GOT: Symbol {
+# GOT: Name: LT1 (4)
+# GOT-NEXT: Value: 0x40017C
+# GOT: Symbol {
+# GOT: Name: LT2 (8)
+# GOT-NEXT: Value: 0x400180
+# GOT: Symbol {
+# GOT: Name: T1@ (1)
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@ (4)
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x408FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401004
+# GOT-NEXT: Access: -32748
+# GOT-NEXT: Initial: 0x80000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x40017C
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 400154 24800000 18800000 24800000 28800000 $.......$...(...
+# ^ = -32732 (T1)
+# ^ = -32744 (LT1)
+# ^ -32732 (T1)
+# ^ -32728 (T2)
+# RAW-NEXT: 400164 1c800000 20800000 00000000 00000000 .... ...........
+# ^ -32740 (PAGE)
+# ^ -32736 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: 400174 7c010000 80010000 00000000 00000000 |...............
+# ^ LT1 OFST
+# ^ LT2 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_32, EF_MIPS_ABI_O32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_32, EF_MIPS_ABI_O32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x30
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ - Name: T1
+ - Name: T2
+...
Added: lld/trunk/test/elf/Mips/got-page-64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/got-page-64.test?rev=232360&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/got-page-64.test (added)
+++ lld/trunk/test/elf/Mips/got-page-64.test Mon Mar 16 04:14:17 2015
@@ -0,0 +1,203 @@
+# Check handling of R_MIPS_GOT_DISP / PAGE / OFST relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: T0 (1)
+# GOT-NEXT: Value: 0x1200001F0
+# GOT: Symbol {
+# GOT: Name: LT1 (4)
+# GOT-NEXT: Value: 0x120000218
+# GOT: Symbol {
+# GOT: Name: LT2 (8)
+# GOT-NEXT: Value: 0x12000021C
+# GOT: Symbol {
+# GOT: Name: T1@ (1)
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@ (4)
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x120008FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x8000000000000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x120000218
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001030
+# GOT-NEXT: Access: -32704
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 1200001f0 38800000 20800000 38800000 40800000 8... ...8... at ...
+# ^ = -32712 (T1)
+# ^ = -32736 (LT1)
+# ^ -32712 (T1)
+# ^ -32704 (T2)
+# RAW-NEXT: 120000200 28800000 30800000 00000000 00000000 (...0...........
+# ^ -32728 (PAGE)
+# ^ -32720 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: 120000210 18020000 1c020000 00000000 00000000 ................
+# ^ LT1 OFST
+# ^ LT2 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x30
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ - Name: T1
+ - Name: T2
+...
More information about the llvm-commits
mailing list