2016-11-02 04:28:21 +08:00
|
|
|
//===- SyntheticSection.h ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_SYNTHETIC_SECTION_H
|
|
|
|
#define LLD_ELF_SYNTHETIC_SECTION_H
|
|
|
|
|
|
|
|
#include "InputSection.h"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
|
|
|
|
2016-11-10 05:37:06 +08:00
|
|
|
// .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 = {};
|
|
|
|
};
|
|
|
|
|
2016-11-10 05:36:56 +08:00
|
|
|
// .MIPS.options section.
|
|
|
|
template <class ELFT>
|
|
|
|
class MipsOptionsSection final : public InputSection<ELFT> {
|
|
|
|
typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
|
|
|
|
typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MipsOptionsSection();
|
|
|
|
void finalize();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<uint8_t> Buf;
|
|
|
|
|
|
|
|
Elf_Mips_Options *getOptions() {
|
|
|
|
return reinterpret_cast<Elf_Mips_Options *>(Buf.data());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// MIPS .reginfo section.
|
|
|
|
template <class ELFT>
|
|
|
|
class MipsReginfoSection final : public InputSection<ELFT> {
|
|
|
|
typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MipsReginfoSection();
|
|
|
|
void finalize();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Elf_Mips_RegInfo Reginfo = {};
|
|
|
|
};
|
|
|
|
|
2016-11-10 17:48:29 +08:00
|
|
|
template <class ELFT> class SyntheticSection : public InputSection<ELFT> {
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SyntheticSection(uintX_t Flags, uint32_t Type, uintX_t Addralign,
|
|
|
|
StringRef Name)
|
|
|
|
: InputSection<ELFT>(Flags, Type, Addralign, ArrayRef<uint8_t>(), Name,
|
|
|
|
InputSectionData::Synthetic) {}
|
|
|
|
|
|
|
|
virtual void writeTo(uint8_t *Buf) {}
|
|
|
|
virtual size_t getSize() const { return this->Data.size(); }
|
|
|
|
|
|
|
|
static bool classof(const InputSectionData *D) {
|
|
|
|
return D->kind() == InputSectionData::Synthetic;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~SyntheticSection() = default;
|
|
|
|
};
|
|
|
|
|
2016-11-06 07:05:47 +08:00
|
|
|
// .note.gnu.build-id section.
|
2016-11-02 04:28:21 +08:00
|
|
|
template <class ELFT> class BuildIdSection : public InputSection<ELFT> {
|
|
|
|
public:
|
|
|
|
virtual void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) = 0;
|
|
|
|
virtual ~BuildIdSection() = default;
|
|
|
|
|
|
|
|
uint8_t *getOutputLoc(uint8_t *Start) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BuildIdSection(size_t HashSize);
|
2016-11-08 22:47:16 +08:00
|
|
|
std::vector<uint8_t> Buf;
|
2016-11-06 15:42:55 +08:00
|
|
|
|
|
|
|
void
|
2016-11-06 16:39:46 +08:00
|
|
|
computeHash(llvm::MutableArrayRef<uint8_t> Buf,
|
2016-11-06 15:42:55 +08:00
|
|
|
std::function<void(ArrayRef<uint8_t> Arr, uint8_t *Hash)> Hash);
|
|
|
|
|
|
|
|
size_t HashSize;
|
2016-11-02 04:28:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
class BuildIdFastHash final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdFastHash() : BuildIdSection<ELFT>(8) {}
|
|
|
|
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdMd5() : BuildIdSection<ELFT>(16) {}
|
|
|
|
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdSha1() : BuildIdSection<ELFT>(20) {}
|
|
|
|
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> class BuildIdUuid final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdUuid() : BuildIdSection<ELFT>(16) {}
|
|
|
|
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
class BuildIdHexstring final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdHexstring();
|
|
|
|
void writeBuildId(llvm::MutableArrayRef<uint8_t>) override;
|
|
|
|
};
|
|
|
|
|
2016-11-10 17:48:29 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class GotPltSection final : public SyntheticSection<ELFT> {
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GotPltSection();
|
|
|
|
void addEntry(SymbolBody &Sym);
|
|
|
|
bool empty() const;
|
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
uintX_t getVA() { return this->OutSec->Addr + this->OutSecOff; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<const SymbolBody *> Entries;
|
|
|
|
};
|
|
|
|
|
2016-11-08 22:42:34 +08:00
|
|
|
template <class ELFT> InputSection<ELFT> *createCommonSection();
|
2016-11-08 22:56:27 +08:00
|
|
|
template <class ELFT> InputSection<ELFT> *createInterpSection();
|
2016-11-08 22:42:34 +08:00
|
|
|
|
2016-11-02 04:28:21 +08:00
|
|
|
// Linker generated sections which can be used as inputs.
|
|
|
|
template <class ELFT> struct In {
|
|
|
|
static BuildIdSection<ELFT> *BuildId;
|
2016-11-08 22:42:34 +08:00
|
|
|
static InputSection<ELFT> *Common;
|
2016-11-10 17:48:29 +08:00
|
|
|
static GotPltSection<ELFT> *GotPlt;
|
2016-11-08 22:56:27 +08:00
|
|
|
static InputSection<ELFT> *Interp;
|
2016-11-10 05:37:06 +08:00
|
|
|
static MipsAbiFlagsSection<ELFT> *MipsAbiFlags;
|
2016-11-10 05:36:56 +08:00
|
|
|
static MipsOptionsSection<ELFT> *MipsOptions;
|
|
|
|
static MipsReginfoSection<ELFT> *MipsReginfo;
|
2016-11-02 04:28:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> BuildIdSection<ELFT> *In<ELFT>::BuildId;
|
2016-11-08 22:42:34 +08:00
|
|
|
template <class ELFT> InputSection<ELFT> *In<ELFT>::Common;
|
2016-11-10 17:48:29 +08:00
|
|
|
template <class ELFT> GotPltSection<ELFT> *In<ELFT>::GotPlt;
|
2016-11-08 22:56:27 +08:00
|
|
|
template <class ELFT> InputSection<ELFT> *In<ELFT>::Interp;
|
2016-11-10 05:37:06 +08:00
|
|
|
template <class ELFT> MipsAbiFlagsSection<ELFT> *In<ELFT>::MipsAbiFlags;
|
2016-11-10 05:36:56 +08:00
|
|
|
template <class ELFT> MipsOptionsSection<ELFT> *In<ELFT>::MipsOptions;
|
|
|
|
template <class ELFT> MipsReginfoSection<ELFT> *In<ELFT>::MipsReginfo;
|
2016-11-02 04:28:21 +08:00
|
|
|
|
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|