[lld] r298272 - [ELF] - Detemplate MipsGotSection<ELFT>
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 20 14:47:28 PDT 2017
George, could you please take a look?
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/3573/steps/check-lld%20msan/logs/stdio
******************** TEST 'lld :: ELF/mips-64.s' FAILED ********************
Script:
--
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/llvm-mc
-filetype=obj -triple=mips64-unknown-linux
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/ELF/mips-64.s
-o /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/Output/mips-64.s.tmp.o
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/ld.lld
--full-shutdown -shared
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/Output/mips-64.s.tmp.o
-o /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/Output/mips-64.s.tmp.so
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/llvm-objdump
-t /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/Output/mips-64.s.tmp.so
| /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/FileCheck
-check-prefix=SYM
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/ELF/mips-64.s
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/llvm-readobj
-r -dynamic-table -mips-plt-got
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/tools/lld/test/ELF/Output/mips-64.s.tmp.so
| /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_msan/./bin/FileCheck
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/ELF/mips-64.s
--
Exit Code: 1
Command Output (stderr):
--
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/ELF/mips-64.s:50:15:
error: CHECK-NEXT: is not on the line after the previous match
# CHECK-NEXT: ]
^
<stdin>:48:2: note: 'next' match was here
]
^
<stdin>:42:17: note: previous match ended here
Local entries [
^
<stdin>:43:1: note: non-matching line after previous match is here
Entry {
^
--
On Mon, Mar 20, 2017 at 9:56 AM George Rimar via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: grimar
> Date: Mon Mar 20 11:44:28 2017
> New Revision: 298272
>
> URL: http://llvm.org/viewvc/llvm-project?rev=298272&view=rev
> Log:
> [ELF] - Detemplate MipsGotSection<ELFT>
>
> This continues detemplation process.
>
> Detemplating MipsGotSection<ELFT> is helpfull because can
> help to detemplate getRelocTargetVA. (one more change is required)
> It opens road to detemplation of GotSection<ELFT> and probably
> something else after that.
>
> Differential revision: https://reviews.llvm.org/D31090
>
> Modified:
> lld/trunk/ELF/SyntheticSections.cpp
> lld/trunk/ELF/SyntheticSections.h
> lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/SyntheticSections.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=298272&r1=298271&r2=298272&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SyntheticSections.cpp (original)
> +++ lld/trunk/ELF/SyntheticSections.cpp Mon Mar 20 11:44:28 2017
> @@ -665,14 +665,11 @@ template <class ELFT> void GotSection<EL
> this->template relocate<ELFT>(Buf, Buf + Size);
> }
>
> -template <class ELFT>
> -MipsGotSection<ELFT>::MipsGotSection()
> +MipsGotSection::MipsGotSection()
> : SyntheticSection(SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL,
> SHT_PROGBITS, 16,
> ".got") {}
>
> -template <class ELFT>
> -void MipsGotSection<ELFT>::addEntry(SymbolBody &Sym, int64_t Addend,
> - RelExpr Expr) {
> +void MipsGotSection::addEntry(SymbolBody &Sym, int64_t Addend, RelExpr
> Expr) {
> // For "true" local symbols which can be referenced from the same module
> // only compiler creates two instructions for address loading:
> //
> @@ -715,7 +712,7 @@ void MipsGotSection<ELFT>::addEntry(Symb
> TlsEntries.push_back(&Sym);
> return;
> }
> - auto AddEntry = [&](SymbolBody &S, uintX_t A, GotEntries &Items) {
> + auto AddEntry = [&](SymbolBody &S, uint64_t A, GotEntries &Items) {
> if (S.isInGot() && !A)
> return;
> size_t NewIndex = Items.size();
> @@ -740,8 +737,7 @@ void MipsGotSection<ELFT>::addEntry(Symb
> }
> }
>
> -template <class ELFT>
> -bool MipsGotSection<ELFT>::addDynTlsEntry(SymbolBody &Sym) {
> +bool MipsGotSection::addDynTlsEntry(SymbolBody &Sym) {
> if (Sym.GlobalDynIndex != -1U)
> return false;
> Sym.GlobalDynIndex = TlsEntries.size();
> @@ -753,10 +749,10 @@ bool MipsGotSection<ELFT>::addDynTlsEntr
>
> // Reserves TLS entries for a TLS module ID and a TLS block offset.
> // In total it takes two GOT slots.
> -template <class ELFT> bool MipsGotSection<ELFT>::addTlsIndex() {
> +bool MipsGotSection::addTlsIndex() {
> if (TlsIndexOff != uint32_t(-1))
> return false;
> - TlsIndexOff = TlsEntries.size() * sizeof(uintX_t);
> + TlsIndexOff = TlsEntries.size() * Config->Wordsize;
> TlsEntries.push_back(nullptr);
> TlsEntries.push_back(nullptr);
> return true;
> @@ -770,25 +766,21 @@ static uint64_t getMipsPageCount(uint64_
> return (Size + 0xfffe) / 0xffff + 1;
> }
>
> -template <class ELFT>
> -typename MipsGotSection<ELFT>::uintX_t
> -MipsGotSection<ELFT>::getPageEntryOffset(const SymbolBody &B,
> - int64_t Addend) const {
> +uint64_t MipsGotSection::getPageEntryOffset(const SymbolBody &B,
> + int64_t Addend) const {
> const OutputSection *OutSec =
> cast<DefinedRegular>(&B)->Section->getOutputSection();
> - uintX_t SecAddr = getMipsPageAddr(OutSec->Addr);
> - uintX_t SymAddr = getMipsPageAddr(B.getVA(Addend));
> - uintX_t Index = PageIndexMap.lookup(OutSec) + (SymAddr - SecAddr) /
> 0xffff;
> + uint64_t SecAddr = getMipsPageAddr(OutSec->Addr);
> + uint64_t SymAddr = getMipsPageAddr(B.getVA(Addend));
> + uint64_t Index = PageIndexMap.lookup(OutSec) + (SymAddr - SecAddr) /
> 0xffff;
> assert(Index < PageEntriesNum);
> - return (HeaderEntriesNum + Index) * sizeof(uintX_t);
> + return (HeaderEntriesNum + Index) * Config->Wordsize;
> }
>
> -template <class ELFT>
> -typename MipsGotSection<ELFT>::uintX_t
> -MipsGotSection<ELFT>::getBodyEntryOffset(const SymbolBody &B,
> - int64_t Addend) const {
> +uint64_t MipsGotSection::getBodyEntryOffset(const SymbolBody &B,
> + int64_t Addend) const {
> // Calculate offset of the GOT entries block: TLS, global, local.
> - uintX_t Index = HeaderEntriesNum + PageEntriesNum;
> + uint64_t Index = HeaderEntriesNum + PageEntriesNum;
> if (B.isTls())
> Index += LocalEntries.size() + LocalEntries32.size() +
> GlobalEntries.size();
> else if (B.IsInGlobalMipsGot)
> @@ -803,37 +795,31 @@ MipsGotSection<ELFT>::getBodyEntryOffset
> assert(It != EntryIndexMap.end());
> Index += It->second;
> }
> - return Index * sizeof(uintX_t);
> + return Index * Config->Wordsize;
> }
>
> -template <class ELFT>
> -typename MipsGotSection<ELFT>::uintX_t
> -MipsGotSection<ELFT>::getTlsOffset() const {
> - return (getLocalEntriesNum() + GlobalEntries.size()) * sizeof(uintX_t);
> +uint64_t MipsGotSection::getTlsOffset() const {
> + return (getLocalEntriesNum() + GlobalEntries.size()) * Config->Wordsize;
> }
>
> -template <class ELFT>
> -typename MipsGotSection<ELFT>::uintX_t
> -MipsGotSection<ELFT>::getGlobalDynOffset(const SymbolBody &B) const {
> - return B.GlobalDynIndex * sizeof(uintX_t);
> +uint64_t MipsGotSection::getGlobalDynOffset(const SymbolBody &B) const {
> + return B.GlobalDynIndex * Config->Wordsize;
> }
>
> -template <class ELFT>
> -const SymbolBody *MipsGotSection<ELFT>::getFirstGlobalEntry() const {
> +const SymbolBody *MipsGotSection::getFirstGlobalEntry() const {
> return GlobalEntries.empty() ? nullptr : GlobalEntries.front().first;
> }
>
> -template <class ELFT>
> -unsigned MipsGotSection<ELFT>::getLocalEntriesNum() const {
> +unsigned MipsGotSection::getLocalEntriesNum() const {
> return HeaderEntriesNum + PageEntriesNum + LocalEntries.size() +
> LocalEntries32.size();
> }
>
> -template <class ELFT> void MipsGotSection<ELFT>::finalizeContents() {
> +void MipsGotSection::finalizeContents() {
> updateAllocSize();
> }
>
> -template <class ELFT> void MipsGotSection<ELFT>::updateAllocSize() {
> +void MipsGotSection::updateAllocSize() {
> PageEntriesNum = 0;
> for (std::pair<const OutputSection *, size_t> &P : PageIndexMap) {
> // For each output section referenced by GOT page relocations
> calculate
> @@ -846,27 +832,29 @@ template <class ELFT> void MipsGotSectio
> PageEntriesNum += getMipsPageCount(P.first->Size);
> }
> Size = (getLocalEntriesNum() + GlobalEntries.size() +
> TlsEntries.size()) *
> - sizeof(uintX_t);
> + Config->Wordsize;
> }
>
> -template <class ELFT> bool MipsGotSection<ELFT>::empty() const {
> +bool MipsGotSection::empty() const {
> // We add the .got section to the result for dynamic MIPS target because
> // its address and properties are mentioned in the .dynamic section.
> return Config->Relocatable;
> }
>
> -template <class ELFT>
> -typename MipsGotSection<ELFT>::uintX_t MipsGotSection<ELFT>::getGp()
> const {
> +uint64_t MipsGotSection::getGp() const {
> return ElfSym::MipsGp->getVA(0);
> }
>
> -template <class ELFT>
> -static void writeUint(uint8_t *Buf, typename ELFT::uint Val) {
> - typedef typename ELFT::uint uintX_t;
> - write<uintX_t, ELFT::TargetEndianness, sizeof(uintX_t)>(Buf, Val);
> +static void writeUint(uint8_t *Buf, uint64_t Val) {
> + support::endianness E =
> + Config->IsLE ? support::endianness::little :
> support::endianness::big;
> + if (Config->Wordsize == 0)
> + write64(Buf, Val, E);
> + else
> + write32(Buf, Val, E);
> }
>
> -template <class ELFT> void MipsGotSection<ELFT>::writeTo(uint8_t *Buf) {
> +void MipsGotSection::writeTo(uint8_t *Buf) {
> // Set the MSB of the second GOT slot. This is not required by any
> // MIPS ABI documentation, though.
> //
> @@ -881,25 +869,24 @@ template <class ELFT> void MipsGotSectio
> // we've been doing this for years, it is probably a safe bet to
> // keep doing this for now. We really need to revisit this to see
> // if we had to do this.
> - auto *P = reinterpret_cast<typename ELFT::Off *>(Buf);
> - P[1] = uintX_t(1) << (ELFT::Is64Bits ? 63 : 31);
> - Buf += HeaderEntriesNum * sizeof(uintX_t);
> + writeUint(Buf + Config->Wordsize, (uint64_t)1 << (Config->Wordsize * 8
> - 1));
> + Buf += HeaderEntriesNum * Config->Wordsize;
> // Write 'page address' entries to the local part of the GOT.
> for (std::pair<const OutputSection *, size_t> &L : PageIndexMap) {
> size_t PageCount = getMipsPageCount(L.first->Size);
> - uintX_t FirstPageAddr = getMipsPageAddr(L.first->Addr);
> + uint64_t FirstPageAddr = getMipsPageAddr(L.first->Addr);
> for (size_t PI = 0; PI < PageCount; ++PI) {
> - uint8_t *Entry = Buf + (L.second + PI) * sizeof(uintX_t);
> - writeUint<ELFT>(Entry, FirstPageAddr + PI * 0x10000);
> + uint8_t *Entry = Buf + (L.second + PI) * Config->Wordsize;
> + writeUint(Entry, FirstPageAddr + PI * 0x10000);
> }
> }
> - Buf += PageEntriesNum * sizeof(uintX_t);
> + Buf += PageEntriesNum * Config->Wordsize;
> auto AddEntry = [&](const GotEntry &SA) {
> uint8_t *Entry = Buf;
> - Buf += sizeof(uintX_t);
> + Buf += Config->Wordsize;
> const SymbolBody *Body = SA.first;
> - uintX_t VA = Body->getVA(SA.second);
> - writeUint<ELFT>(Entry, VA);
> + uint64_t VA = Body->getVA(SA.second);
> + writeUint(Entry, VA);
> };
> std::for_each(std::begin(LocalEntries), std::end(LocalEntries),
> AddEntry);
> std::for_each(std::begin(LocalEntries32), std::end(LocalEntries32),
> AddEntry);
> @@ -910,20 +897,20 @@ template <class ELFT> void MipsGotSectio
> // for thread-local storage.
> // https://www.linux-mips.org/wiki/NPTL
> if (TlsIndexOff != -1U && !Config->Pic)
> - writeUint<ELFT>(Buf + TlsIndexOff, 1);
> + writeUint(Buf + TlsIndexOff, 1);
> for (const SymbolBody *B : TlsEntries) {
> if (!B || B->isPreemptible())
> continue;
> - uintX_t VA = B->getVA();
> + uint64_t VA = B->getVA();
> if (B->GotIndex != -1U) {
> - uint8_t *Entry = Buf + B->GotIndex * sizeof(uintX_t);
> - writeUint<ELFT>(Entry, VA - 0x7000);
> + uint8_t *Entry = Buf + B->GotIndex * Config->Wordsize;
> + writeUint(Entry, VA - 0x7000);
> }
> if (B->GlobalDynIndex != -1U) {
> - uint8_t *Entry = Buf + B->GlobalDynIndex * sizeof(uintX_t);
> - writeUint<ELFT>(Entry, 1);
> - Entry += sizeof(uintX_t);
> - writeUint<ELFT>(Entry, VA - 0x8000);
> + uint8_t *Entry = Buf + B->GlobalDynIndex * Config->Wordsize;
> + writeUint(Entry, 1);
> + Entry += Config->Wordsize;
> + writeUint(Entry, VA - 0x8000);
> }
> }
> }
> @@ -2254,6 +2241,7 @@ StringTableSection *InX::DynStrTab;
> InputSection *InX::Interp;
> GotPltSection *InX::GotPlt;
> IgotPltSection *InX::IgotPlt;
> +MipsGotSection *InX::MipsGot;
> MipsRldMapSection *InX::MipsRldMap;
> PltSection *InX::Plt;
> PltSection *InX::Iplt;
> @@ -2308,11 +2296,6 @@ template class elf::GotSection<ELF32BE>;
> template class elf::GotSection<ELF64LE>;
> template class elf::GotSection<ELF64BE>;
>
> -template class elf::MipsGotSection<ELF32LE>;
> -template class elf::MipsGotSection<ELF32BE>;
> -template class elf::MipsGotSection<ELF64LE>;
> -template class elf::MipsGotSection<ELF64BE>;
> -
> template class elf::DynamicSection<ELF32LE>;
> template class elf::DynamicSection<ELF32BE>;
> template class elf::DynamicSection<ELF64LE>;
>
> Modified: lld/trunk/ELF/SyntheticSections.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=298272&r1=298271&r2=298272&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SyntheticSections.h (original)
> +++ lld/trunk/ELF/SyntheticSections.h Mon Mar 20 11:44:28 2017
> @@ -169,9 +169,7 @@ private:
> size_t Size = 0;
> };
>
> -template <class ELFT> class MipsGotSection final : public
> SyntheticSection {
> - typedef typename ELFT::uint uintX_t;
> -
> +class MipsGotSection final : public SyntheticSection {
> public:
> MipsGotSection();
> void writeTo(uint8_t *Buf) override;
> @@ -182,9 +180,9 @@ public:
> void addEntry(SymbolBody &Sym, int64_t Addend, RelExpr Expr);
> bool addDynTlsEntry(SymbolBody &Sym);
> bool addTlsIndex();
> - uintX_t getPageEntryOffset(const SymbolBody &B, int64_t Addend) const;
> - uintX_t getBodyEntryOffset(const SymbolBody &B, int64_t Addend) const;
> - uintX_t getGlobalDynOffset(const SymbolBody &B) const;
> + uint64_t getPageEntryOffset(const SymbolBody &B, int64_t Addend) const;
> + uint64_t getBodyEntryOffset(const SymbolBody &B, int64_t Addend) const;
> + uint64_t getGlobalDynOffset(const SymbolBody &B) const;
>
> // Returns the symbol which corresponds to the first entry of the
> global part
> // of GOT on MIPS platform. It is required to fill up MIPS-specific
> dynamic
> @@ -198,11 +196,11 @@ public:
>
> // Returns offset of TLS part of the MIPS GOT table. This part goes
> // after 'local' and 'global' entries.
> - uintX_t getTlsOffset() const;
> + uint64_t getTlsOffset() const;
>
> uint32_t getTlsIndexOff() const { return TlsIndexOff; }
>
> - uintX_t getGp() const;
> + uint64_t getGp() const;
>
> private:
> // MIPS GOT consists of three parts: local, global and tls. Each part
> @@ -250,7 +248,7 @@ private:
> // to the first index of "Page" entries allocated for this section.
> llvm::SmallMapVector<const OutputSection *, size_t, 16> PageIndexMap;
>
> - typedef std::pair<const SymbolBody *, uintX_t> GotEntry;
> + typedef std::pair<const SymbolBody *, uint64_t> GotEntry;
> typedef std::vector<GotEntry> GotEntries;
> // Map from Symbol-Addend pair to the GOT index.
> llvm::DenseMap<GotEntry, size_t> EntryIndexMap;
> @@ -266,7 +264,7 @@ private:
> std::vector<const SymbolBody *> TlsEntries;
>
> uint32_t TlsIndexOff = -1;
> - uintX_t Size = 0;
> + uint64_t Size = 0;
> };
>
> class GotPltSection final : public SyntheticSection {
> @@ -766,6 +764,7 @@ struct InX {
> static InputSection *Interp;
> static GotPltSection *GotPlt;
> static IgotPltSection *IgotPlt;
> + static MipsGotSection *MipsGot;
> static MipsRldMapSection *MipsRldMap;
> static PltSection *Plt;
> static PltSection *Iplt;
> @@ -781,7 +780,6 @@ template <class ELFT> struct In : public
> static GdbIndexSection<ELFT> *GdbIndex;
> static GotSection<ELFT> *Got;
> static EhFrameSection<ELFT> *EhFrame;
> - static MipsGotSection<ELFT> *MipsGot;
> static HashTableSection<ELFT> *HashTab;
> static RelocationSection<ELFT> *RelaDyn;
> static RelocationSection<ELFT> *RelaPlt;
> @@ -799,7 +797,6 @@ template <class ELFT> GdbIndexSection<EL
> template <class ELFT> GnuHashTableSection<ELFT> *In<ELFT>::GnuHashTab;
> template <class ELFT> GotSection<ELFT> *In<ELFT>::Got;
> template <class ELFT> EhFrameSection<ELFT> *In<ELFT>::EhFrame;
> -template <class ELFT> MipsGotSection<ELFT> *In<ELFT>::MipsGot;
> template <class ELFT> HashTableSection<ELFT> *In<ELFT>::HashTab;
> template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaDyn;
> template <class ELFT> RelocationSection<ELFT> *In<ELFT>::RelaPlt;
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=298272&r1=298271&r2=298272&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Mon Mar 20 11:44:28 2017
> @@ -415,7 +415,7 @@ template <class ELFT> void Writer<ELFT>:
> // Add .got. MIPS' .got is so different from the other archs,
> // it has its own class.
> if (Config->EMachine == EM_MIPS) {
> - In<ELFT>::MipsGot = make<MipsGotSection<ELFT>>();
> + In<ELFT>::MipsGot = make<MipsGotSection>();
> Add(In<ELFT>::MipsGot);
> } else {
> In<ELFT>::Got = make<GotSection<ELFT>>();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170320/b55da58c/attachment.html>
More information about the llvm-commits
mailing list