[lld] r287613 - Convert MipsAbiFlagsSection to SyntheticSection.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 19:57:06 PST 2016
Author: ruiu
Date: Mon Nov 21 21:57:06 2016
New Revision: 287613
URL: http://llvm.org/viewvc/llvm-project?rev=287613&view=rev
Log:
Convert MipsAbiFlagsSection to SyntheticSection.
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=287613&r1=287612&r2=287613&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Nov 21 21:57:06 2016
@@ -129,20 +129,37 @@ static void iterateSectionContents(
// .MIPS.abiflags section.
template <class ELFT>
-MipsAbiFlagsSection<ELFT>::MipsAbiFlagsSection()
- : InputSection<ELFT>(SHF_ALLOC, SHT_MIPS_ABIFLAGS, 8, ArrayRef<uint8_t>(),
- ".MIPS.abiflags") {
- auto Func = [this](ObjectFile<ELFT> *F, ArrayRef<uint8_t> D) {
- if (D.size() != sizeof(Elf_Mips_ABIFlags)) {
- error(getFilename(F) + ": invalid size of .MIPS.abiflags section");
- return;
+MipsAbiFlagsSection<ELFT>::MipsAbiFlagsSection(Elf_Mips_ABIFlags Flags)
+ : SyntheticSection<ELFT>(SHF_ALLOC, SHT_MIPS_ABIFLAGS, 8, ".MIPS.abiflags"),
+ Flags(Flags) {}
+
+template <class ELFT> void MipsAbiFlagsSection<ELFT>::writeTo(uint8_t *Buf) {
+ memcpy(Buf, &Flags, sizeof(Flags));
+}
+
+template <class ELFT>
+MipsAbiFlagsSection<ELFT> *MipsAbiFlagsSection<ELFT>::create() {
+ Elf_Mips_ABIFlags Flags = {};
+ bool Create = false;
+
+ for (InputSectionBase<ELFT> *Sec : Symtab<ELFT>::X->Sections) {
+ if (!Sec->Live || Sec->Type != SHT_MIPS_ABIFLAGS)
+ continue;
+ Sec->Live = false;
+ Create = true;
+
+ std::string Filename = getFilename(Sec->getFile());
+ if (Sec->Data.size() != sizeof(Elf_Mips_ABIFlags)) {
+ error(Filename + ": invalid size of .MIPS.abiflags section");
+ return nullptr;
}
- auto *S = reinterpret_cast<const Elf_Mips_ABIFlags *>(D.data());
+ auto *S = reinterpret_cast<const Elf_Mips_ABIFlags *>(Sec->Data.data());
if (S->version != 0) {
- error(getFilename(F) + ": unexpected .MIPS.abiflags version " +
+ error(Filename + ": unexpected .MIPS.abiflags version " +
Twine(S->version));
- return;
+ return nullptr;
}
+
// LLD checks ISA compatibility in getMipsEFlags(). Here we just
// select the highest number of ISA/Rev/Ext.
Flags.isa_level = std::max(Flags.isa_level, S->isa_level);
@@ -154,13 +171,12 @@ MipsAbiFlagsSection<ELFT>::MipsAbiFlagsS
Flags.ases |= S->ases;
Flags.flags1 |= S->flags1;
Flags.flags2 |= S->flags2;
- Flags.fp_abi =
- elf::getMipsFpAbiFlag(Flags.fp_abi, S->fp_abi, getFilename(F));
+ Flags.fp_abi = elf::getMipsFpAbiFlag(Flags.fp_abi, S->fp_abi, Filename);
};
- iterateSectionContents<ELFT>(SHT_MIPS_ABIFLAGS, Func);
- this->Data = ArrayRef<uint8_t>((const uint8_t *)&Flags, sizeof(Flags));
- this->Live = true;
+ if (Create)
+ return make<MipsAbiFlagsSection<ELFT>>(Flags);
+ return nullptr;
}
// .MIPS.options section.
Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=287613&r1=287612&r2=287613&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Mon Nov 21 21:57:06 2016
@@ -17,18 +17,6 @@
namespace lld {
namespace elf {
-// .MIPS.abiflags section.
-template <class ELFT>
-class MipsAbiFlagsSection final : public InputSection<ELFT> {
- typedef llvm::object::Elf_Mips_ABIFlags<ELFT> Elf_Mips_ABIFlags;
-
-public:
- MipsAbiFlagsSection();
-
-private:
- Elf_Mips_ABIFlags Flags = {};
-};
-
// .MIPS.options section.
template <class ELFT>
class MipsOptionsSection final : public InputSection<ELFT> {
@@ -589,6 +577,22 @@ public:
size_t getNeedNum() const { return Needed.size(); }
};
+// .MIPS.abiflags section.
+template <class ELFT>
+class MipsAbiFlagsSection final : public SyntheticSection<ELFT> {
+ typedef llvm::object::Elf_Mips_ABIFlags<ELFT> Elf_Mips_ABIFlags;
+
+public:
+ static MipsAbiFlagsSection *create();
+
+ MipsAbiFlagsSection(Elf_Mips_ABIFlags Flags);
+ size_t getSize() const override { return sizeof(Elf_Mips_ABIFlags); }
+ void writeTo(uint8_t *Buf) override;
+
+private:
+ Elf_Mips_ABIFlags Flags;
+};
+
template <class ELFT> InputSection<ELFT> *createCommonSection();
template <class ELFT> InputSection<ELFT> *createInterpSection();
template <class ELFT> MergeInputSection<ELFT> *createCommentSection();
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=287613&r1=287612&r2=287613&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Nov 21 21:57:06 2016
@@ -307,10 +307,9 @@ template <class ELFT> void Writer<ELFT>:
if (Config->EMachine == EM_MIPS) {
// .MIPS.abiflags
- auto *AbiFlags = make<MipsAbiFlagsSection<ELFT>>();
- if (AbiFlags->Live) {
- In<ELFT>::MipsAbiFlags = AbiFlags;
- Symtab<ELFT>::X->Sections.push_back(AbiFlags);
+ if (auto *Sec = MipsAbiFlagsSection<ELFT>::create()) {
+ In<ELFT>::MipsAbiFlags = Sec;
+ Symtab<ELFT>::X->Sections.push_back(Sec);
}
// .MIPS.options
auto *OptSec = make<MipsOptionsSection<ELFT>>();
More information about the llvm-commits
mailing list