From 87a594835feacbbc8002a950622952d781ca1cba Mon Sep 17 00:00:00 2001 From: Shankar Easwaran Date: Mon, 20 May 2013 03:57:01 +0000 Subject: [PATCH] [lld][ELF][x86_64,hexagon] Changed dynamic atoms to live in anonymous namespace so that their names are hidden. This addresses comments raised by Sean/Rafael. llvm-svn: 182230 --- .../ELF/Hexagon/HexagonDynamicAtoms.h | 85 +++++++++---------- .../ELF/X86_64/X86_64DynamicAtoms.h | 66 +++++++------- 2 files changed, 74 insertions(+), 77 deletions(-) diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicAtoms.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicAtoms.h index 2a91d898525d..436d63d1741d 100644 --- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicAtoms.h +++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonDynamicAtoms.h @@ -13,75 +13,72 @@ #include "Atoms.h" #include "HexagonTargetInfo.h" +/// \brief Specify various atom contents that are used by Hexagon dynamic +/// linking +namespace { +// .got atom +const uint8_t hexagonGotAtomContent[4] = { 0 }; +// .got.plt atom (entry 0) +const uint8_t hexagonGotPlt0AtomContent[16] = { 0 }; +// .got.plt atom (all other entries) +const uint8_t hexagonGotPltAtomContent[4] = { 0 }; +// .plt (entry 0) +const uint8_t hexagonPlt0AtomContent[28] = { + 0x00, 0x40, 0x00, 0x00, // { immext (#0) + 0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # address of GOT0 + 0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn from GOTa + 0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2 + 0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) }# dynamic link at GOT1 + 0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn + 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker +}; + +// .plt (other entries) +const uint8_t hexagonPltAtomContent[16] = { + 0x00, 0x40, 0x00, 0x00, // { immext (#0) + 0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) } # address of GOTn + 0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14) # contents of GOTn + 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 # call it +}; +} + namespace lld { namespace elf { class HexagonGOTAtom : public GOTAtom { - static const uint8_t _defaultContent[4]; - public: HexagonGOTAtom(const File &f) : GOTAtom(f, ".got") {} virtual ArrayRef rawContent() const { - return ArrayRef(_defaultContent, 4); + return ArrayRef(hexagonGotAtomContent, 4); } virtual Alignment alignment() const { return Alignment(2); } }; class HexagonGOTPLTAtom : public GOTAtom { - static const uint8_t _defaultContent[4]; - public: HexagonGOTPLTAtom(const File &f) : GOTAtom(f, ".got.plt") {} virtual ArrayRef rawContent() const { - return ArrayRef(_defaultContent, 4); + return ArrayRef(hexagonGotPltAtomContent, 4); } virtual Alignment alignment() const { return Alignment(2); } }; class HexagonGOTPLT0Atom : public GOTAtom { - static const uint8_t _defaultContent[16]; - public: HexagonGOTPLT0Atom(const File &f) : GOTAtom(f, ".got.plt") {} virtual ArrayRef rawContent() const { - return ArrayRef(_defaultContent, 16); + return ArrayRef(hexagonGotPlt0AtomContent, 16); } virtual Alignment alignment() const { return Alignment(3); } }; -const uint8_t HexagonGOTAtom::_defaultContent[4] = { 0 }; -const uint8_t HexagonGOTPLTAtom::_defaultContent[4] = { 0 }; -const uint8_t HexagonGOTPLT0Atom::_defaultContent[16] = { 0 }; - -class HexagonPLTAtom : public PLTAtom { - static const uint8_t _defaultContent[16]; - -public: - HexagonPLTAtom(const File &f, StringRef secName) - : PLTAtom(f, secName) { - } - - virtual ArrayRef rawContent() const { - return ArrayRef(_defaultContent, 16); - } -}; - -const uint8_t HexagonPLTAtom::_defaultContent[16] = { - 0x00, 0x40, 0x00, 0x00, // { immext (#0) - 0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) } # address of GOTn - 0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14) # contents of GOTn - 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 # call it -}; - class HexagonPLT0Atom : public PLT0Atom { - static const uint8_t _plt0Content[28]; - public: HexagonPLT0Atom(const File &f) : PLT0Atom(f) { #ifndef NDEBUG @@ -90,18 +87,18 @@ public: } virtual ArrayRef rawContent() const { - return ArrayRef(_plt0Content, 28); + return ArrayRef(hexagonPlt0AtomContent, 28); } }; -const uint8_t HexagonPLT0Atom::_plt0Content[28] = { - 0x00, 0x40, 0x00, 0x00, // { immext (#0) - 0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # address of GOT0 - 0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn from GOTa - 0x4f, 0x40, 0x9c, 0x91, // r15 = memw (r28 + #8) # object ID at GOT2 - 0x3c, 0xc0, 0x9c, 0x91, // r28 = memw (r28 + #4) }# dynamic link at GOT1 - 0x0e, 0x42, 0x0e, 0x8c, // { r14 = asr (r14, #2) # index of PLTn - 0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker +class HexagonPLTAtom : public PLTAtom { + +public: + HexagonPLTAtom(const File &f, StringRef secName) : PLTAtom(f, secName) {} + + virtual ArrayRef rawContent() const { + return ArrayRef(hexagonPltAtomContent, 16); + } }; } // elf diff --git a/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicAtoms.h b/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicAtoms.h index c7a1bcdd701a..f8dadfad8f69 100644 --- a/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicAtoms.h +++ b/lld/lib/ReaderWriter/ELF/X86_64/X86_64DynamicAtoms.h @@ -13,58 +13,58 @@ #include "Atoms.h" #include "X86_64TargetInfo.h" -namespace lld { -namespace elf { +/// \brief Specify various atom contents that are used by X86_64 dynamic +/// linking +namespace { +// .got values +const uint8_t x86_64GotAtomContent[8] = { 0 }; -class X86_64GOTAtom : public GOTAtom { - static const uint8_t _defaultContent[8]; - -public: - X86_64GOTAtom(const File &f, StringRef secName) : GOTAtom(f, secName) {} - - virtual ArrayRef rawContent() const { - return ArrayRef(_defaultContent, 8); - } +// .plt value (entry 0) +const uint8_t x86_64Plt0AtomContent[16] = { + 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip) + 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip) + 0x90, 0x90, 0x90, 0x90 // nopnopnop }; -const uint8_t X86_64GOTAtom::_defaultContent[8] = { 0 }; - -class X86_64PLTAtom : public PLTAtom { - static const uint8_t _defaultContent[16]; - -public: - X86_64PLTAtom(const File &f, StringRef secName) : PLTAtom(f, secName) {} - - virtual ArrayRef rawContent() const { - return ArrayRef(_defaultContent, 16); - } -}; - -const uint8_t X86_64PLTAtom::_defaultContent[16] = { +// .plt values (other entries) +const uint8_t x86_64PltAtomContent[16] = { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmpq *gotatom(%rip) 0x68, 0x00, 0x00, 0x00, 0x00, // pushq reloc-index 0xe9, 0x00, 0x00, 0x00, 0x00 // jmpq plt[-1] }; +} + +namespace lld { +namespace elf { + +class X86_64GOTAtom : public GOTAtom { +public: + X86_64GOTAtom(const File &f, StringRef secName) : GOTAtom(f, secName) {} + + virtual ArrayRef rawContent() const { + return ArrayRef(x86_64GotAtomContent, 8); + } +}; class X86_64PLT0Atom : public PLT0Atom { - static const uint8_t _plt0Content[16]; - public: X86_64PLT0Atom(const File &f) : PLT0Atom(f) { #ifndef NDEBUG _name = ".PLT0"; #endif } - virtual ArrayRef rawContent() const { - return ArrayRef(_plt0Content, 16); + return ArrayRef(x86_64Plt0AtomContent, 16); } }; -const uint8_t X86_64PLT0Atom::_plt0Content[16] = { - 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, // pushq GOT+8(%rip) - 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp *GOT+16(%rip) - 0x90, 0x90, 0x90, 0x90 // nopnopnop +class X86_64PLTAtom : public PLTAtom { +public: + X86_64PLTAtom(const File &f, StringRef secName) : PLTAtom(f, secName) {} + + virtual ArrayRef rawContent() const { + return ArrayRef(x86_64PltAtomContent, 16); + } }; } // elf