forked from OSchip/llvm-project
Convert MipsAbiFlagsSection to SyntheticSection.
llvm-svn: 287613
This commit is contained in:
parent
da22267055
commit
12f2da870e
|
@ -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>::MipsAbiFlagsSection()
|
|||
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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -307,10 +307,9 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() {
|
|||
|
||||
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>>();
|
||||
|
|
Loading…
Reference in New Issue