2016-11-02 04:28:21 +08:00
|
|
|
//===- SyntheticSection.h ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-11-02 04:28:21 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-01-25 05:35:25 +08:00
|
|
|
//
|
|
|
|
// Synthetic sections represent chunks of linker-created data. If you
|
|
|
|
// need to create a chunk of data that to be included in some section
|
2017-02-27 10:32:29 +08:00
|
|
|
// in the result, you probably want to create that as a synthetic section.
|
2017-01-25 05:35:25 +08:00
|
|
|
//
|
|
|
|
// Synthetic sections are designed as input sections as opposed to
|
|
|
|
// output sections because we want to allow them to be manipulated
|
|
|
|
// using linker scripts just like other input sections from regular
|
|
|
|
// files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-11-02 04:28:21 +08:00
|
|
|
|
|
|
|
#ifndef LLD_ELF_SYNTHETIC_SECTION_H
|
|
|
|
#define LLD_ELF_SYNTHETIC_SECTION_H
|
|
|
|
|
2018-09-15 07:51:05 +08:00
|
|
|
#include "DWARF.h"
|
2017-02-24 06:06:28 +08:00
|
|
|
#include "EhFrame.h"
|
2016-11-02 04:28:21 +08:00
|
|
|
#include "InputSection.h"
|
2016-11-29 21:26:04 +08:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2016-12-15 20:07:53 +08:00
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
2018-07-11 07:48:27 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2017-11-24 10:15:51 +08:00
|
|
|
#include <functional>
|
2016-11-02 04:28:21 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2018-03-30 06:32:13 +08:00
|
|
|
class Defined;
|
2016-11-02 04:28:21 +08:00
|
|
|
|
2017-02-27 10:56:02 +08:00
|
|
|
class SyntheticSection : public InputSection {
|
2016-11-10 17:48:29 +08:00
|
|
|
public:
|
2017-03-09 03:35:29 +08:00
|
|
|
SyntheticSection(uint64_t Flags, uint32_t Type, uint32_t Alignment,
|
2016-11-10 17:48:29 +08:00
|
|
|
StringRef Name)
|
2017-12-21 10:11:51 +08:00
|
|
|
: InputSection(nullptr, Flags, Type, Alignment, {}, Name,
|
2017-02-24 00:49:07 +08:00
|
|
|
InputSectionBase::Synthetic) {
|
2016-11-11 21:03:58 +08:00
|
|
|
this->Live = true;
|
|
|
|
}
|
2016-11-10 17:48:29 +08:00
|
|
|
|
2016-11-22 09:31:32 +08:00
|
|
|
virtual ~SyntheticSection() = default;
|
2016-11-10 20:50:59 +08:00
|
|
|
virtual void writeTo(uint8_t *Buf) = 0;
|
2016-11-22 12:17:12 +08:00
|
|
|
virtual size_t getSize() const = 0;
|
2017-02-27 11:07:41 +08:00
|
|
|
virtual void finalizeContents() {}
|
2017-03-08 22:06:24 +08:00
|
|
|
// If the section has the SHF_ALLOC flag and the size may be changed if
|
|
|
|
// thunks are added, update the section size.
|
2017-10-28 01:49:40 +08:00
|
|
|
virtual bool updateAllocSize() { return false; }
|
2019-04-01 16:16:08 +08:00
|
|
|
virtual bool isNeeded() const { return true; }
|
2016-11-10 17:48:29 +08:00
|
|
|
|
2017-06-01 04:17:44 +08:00
|
|
|
static bool classof(const SectionBase *D) {
|
2017-02-23 10:32:18 +08:00
|
|
|
return D->kind() == InputSectionBase::Synthetic;
|
2016-11-10 17:48:29 +08:00
|
|
|
}
|
2016-11-02 04:28:21 +08:00
|
|
|
};
|
|
|
|
|
2017-02-24 06:06:28 +08:00
|
|
|
struct CieRecord {
|
2017-09-20 05:31:57 +08:00
|
|
|
EhSectionPiece *Cie = nullptr;
|
|
|
|
std::vector<EhSectionPiece *> Fdes;
|
2017-02-24 06:06:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Section for .eh_frame.
|
2017-10-27 11:13:39 +08:00
|
|
|
class EhFrameSection final : public SyntheticSection {
|
2017-02-24 06:06:28 +08:00
|
|
|
public:
|
|
|
|
EhFrameSection();
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return !Sections.empty(); }
|
2017-02-24 06:06:28 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
|
|
|
|
2017-10-27 11:13:39 +08:00
|
|
|
template <class ELFT> void addSection(InputSectionBase *S);
|
2017-02-24 06:06:28 +08:00
|
|
|
|
2017-10-27 11:13:24 +08:00
|
|
|
std::vector<EhInputSection *> Sections;
|
2017-02-24 06:06:28 +08:00
|
|
|
size_t NumFdes = 0;
|
|
|
|
|
2017-10-27 11:13:24 +08:00
|
|
|
struct FdeData {
|
2018-07-21 04:27:42 +08:00
|
|
|
uint32_t PcRel;
|
|
|
|
uint32_t FdeVARel;
|
2017-10-27 11:13:24 +08:00
|
|
|
};
|
|
|
|
|
2017-10-27 11:14:24 +08:00
|
|
|
std::vector<FdeData> getFdeData() const;
|
2018-03-15 05:18:18 +08:00
|
|
|
ArrayRef<CieRecord *> getCieRecords() const { return CieRecords; }
|
2017-03-11 04:00:42 +08:00
|
|
|
|
2017-02-24 06:06:28 +08:00
|
|
|
private:
|
2018-04-28 04:19:28 +08:00
|
|
|
// This is used only when parsing EhInputSection. We keep it here to avoid
|
|
|
|
// allocating one for each EhInputSection.
|
|
|
|
llvm::DenseMap<size_t, CieRecord *> OffsetToCie;
|
|
|
|
|
2017-02-24 06:06:28 +08:00
|
|
|
uint64_t Size = 0;
|
2017-10-27 11:13:39 +08:00
|
|
|
|
|
|
|
template <class ELFT, class RelTy>
|
2017-03-07 05:17:18 +08:00
|
|
|
void addSectionAux(EhInputSection *S, llvm::ArrayRef<RelTy> Rels);
|
2017-02-24 06:06:28 +08:00
|
|
|
|
2017-10-27 11:13:39 +08:00
|
|
|
template <class ELFT, class RelTy>
|
2017-09-20 16:03:18 +08:00
|
|
|
CieRecord *addCie(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
|
2017-02-24 06:06:28 +08:00
|
|
|
|
2017-10-27 11:13:39 +08:00
|
|
|
template <class ELFT, class RelTy>
|
2017-09-20 16:03:18 +08:00
|
|
|
bool isFdeLive(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
|
2017-02-24 06:06:28 +08:00
|
|
|
|
2017-10-27 11:13:24 +08:00
|
|
|
uint64_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc) const;
|
2017-02-24 06:06:28 +08:00
|
|
|
|
2017-09-20 05:31:57 +08:00
|
|
|
std::vector<CieRecord *> CieRecords;
|
2017-02-24 06:06:28 +08:00
|
|
|
|
|
|
|
// CIE records are uniquified by their contents and personality functions.
|
2017-11-04 05:21:47 +08:00
|
|
|
llvm::DenseMap<std::pair<ArrayRef<uint8_t>, Symbol *>, CieRecord *> CieMap;
|
2017-02-24 06:06:28 +08:00
|
|
|
};
|
|
|
|
|
2017-05-19 00:45:36 +08:00
|
|
|
class GotSection : public SyntheticSection {
|
2016-11-11 19:33:32 +08:00
|
|
|
public:
|
2017-05-19 00:45:36 +08:00
|
|
|
GotSection();
|
2016-11-11 19:33:32 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2017-05-19 00:45:36 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-11-25 16:05:41 +08:00
|
|
|
|
2017-11-04 05:21:47 +08:00
|
|
|
void addEntry(Symbol &Sym);
|
|
|
|
bool addDynTlsEntry(Symbol &Sym);
|
2016-11-17 05:01:02 +08:00
|
|
|
bool addTlsIndex();
|
2017-11-04 05:21:47 +08:00
|
|
|
uint64_t getGlobalDynAddr(const Symbol &B) const;
|
|
|
|
uint64_t getGlobalDynOffset(const Symbol &B) const;
|
2016-11-17 05:01:02 +08:00
|
|
|
|
2017-04-14 09:34:45 +08:00
|
|
|
uint64_t getTlsIndexVA() { return this->getVA() + TlsIndexOff; }
|
2016-11-17 05:01:02 +08:00
|
|
|
uint32_t getTlsIndexOff() const { return TlsIndexOff; }
|
|
|
|
|
|
|
|
// Flag to force GOT to be in output if we have relocations
|
|
|
|
// that relies on its address.
|
|
|
|
bool HasGotOffRel = false;
|
|
|
|
|
2017-05-12 07:26:03 +08:00
|
|
|
protected:
|
2016-11-29 11:45:36 +08:00
|
|
|
size_t NumEntries = 0;
|
2016-11-17 05:01:02 +08:00
|
|
|
uint32_t TlsIndexOff = -1;
|
2017-04-14 09:34:45 +08:00
|
|
|
uint64_t Size = 0;
|
2016-11-17 05:01:02 +08:00
|
|
|
};
|
|
|
|
|
2018-08-29 15:27:09 +08:00
|
|
|
// .note.GNU-stack section.
|
|
|
|
class GnuStackSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
GnuStackSection()
|
|
|
|
: SyntheticSection(0, llvm::ELF::SHT_PROGBITS, 1, ".note.GNU-stack") {}
|
|
|
|
void writeTo(uint8_t *Buf) override {}
|
|
|
|
size_t getSize() const override { return 0; }
|
|
|
|
};
|
|
|
|
|
2016-11-22 09:31:32 +08:00
|
|
|
// .note.gnu.build-id section.
|
2017-03-21 00:40:21 +08:00
|
|
|
class BuildIdSection : public SyntheticSection {
|
2016-11-22 09:31:32 +08:00
|
|
|
// First 16 bytes are a header.
|
|
|
|
static const unsigned HeaderSize = 16;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BuildIdSection();
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override { return HeaderSize + HashSize; }
|
|
|
|
void writeBuildId(llvm::ArrayRef<uint8_t> Buf);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void computeHash(llvm::ArrayRef<uint8_t> Buf,
|
|
|
|
std::function<void(uint8_t *, ArrayRef<uint8_t>)> Hash);
|
|
|
|
|
|
|
|
size_t HashSize;
|
|
|
|
uint8_t *HashBuf;
|
|
|
|
};
|
|
|
|
|
2017-03-17 21:31:07 +08:00
|
|
|
// BssSection is used to reserve space for copy relocations and common symbols.
|
2017-03-24 08:15:57 +08:00
|
|
|
// We create three instances of this class for .bss, .bss.rel.ro and "COMMON",
|
|
|
|
// that are used for writable symbols, read-only symbols and common symbols,
|
|
|
|
// respectively.
|
2017-03-17 18:14:53 +08:00
|
|
|
class BssSection final : public SyntheticSection {
|
2017-02-09 18:27:57 +08:00
|
|
|
public:
|
2017-10-04 08:21:17 +08:00
|
|
|
BssSection(StringRef Name, uint64_t Size, uint32_t Alignment);
|
2018-11-26 18:07:10 +08:00
|
|
|
void writeTo(uint8_t *) override {
|
|
|
|
llvm_unreachable("unexpected writeTo() call for SHT_NOBITS section");
|
|
|
|
}
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return Size != 0; }
|
2017-03-16 16:44:53 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
2017-03-17 18:14:53 +08:00
|
|
|
|
2017-11-06 12:33:58 +08:00
|
|
|
static bool classof(const SectionBase *S) { return S->Bss; }
|
2017-10-04 08:21:17 +08:00
|
|
|
uint64_t Size;
|
2017-02-09 18:27:57 +08:00
|
|
|
};
|
|
|
|
|
2017-03-21 00:44:28 +08:00
|
|
|
class MipsGotSection final : public SyntheticSection {
|
2016-11-17 05:01:02 +08:00
|
|
|
public:
|
|
|
|
MipsGotSection();
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override { return Size; }
|
2017-10-28 01:49:40 +08:00
|
|
|
bool updateAllocSize() override;
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2018-06-11 15:24:31 +08:00
|
|
|
|
|
|
|
// Join separate GOTs built for each input file to generate
|
|
|
|
// primary and optional multiple secondary GOTs.
|
2019-03-06 11:07:57 +08:00
|
|
|
void build();
|
2018-06-11 15:24:31 +08:00
|
|
|
|
|
|
|
void addEntry(InputFile &File, Symbol &Sym, int64_t Addend, RelExpr Expr);
|
|
|
|
void addDynTlsEntry(InputFile &File, Symbol &Sym);
|
|
|
|
void addTlsIndex(InputFile &File);
|
|
|
|
|
2018-06-11 16:37:19 +08:00
|
|
|
uint64_t getPageEntryOffset(const InputFile *F, const Symbol &S,
|
2018-06-11 15:24:31 +08:00
|
|
|
int64_t Addend) const;
|
2018-06-11 16:37:19 +08:00
|
|
|
uint64_t getSymEntryOffset(const InputFile *F, const Symbol &S,
|
2018-06-11 15:24:31 +08:00
|
|
|
int64_t Addend) const;
|
2018-06-11 16:37:19 +08:00
|
|
|
uint64_t getGlobalDynOffset(const InputFile *F, const Symbol &S) const;
|
|
|
|
uint64_t getTlsIndexOffset(const InputFile *F) const;
|
2016-11-11 19:33:32 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// table properties.
|
|
|
|
// Returns nullptr if the global part is empty.
|
2017-11-04 05:21:47 +08:00
|
|
|
const Symbol *getFirstGlobalEntry() const;
|
2016-11-11 19:33:32 +08:00
|
|
|
|
|
|
|
// Returns the number of entries in the local part of GOT including
|
2016-11-18 05:49:14 +08:00
|
|
|
// the number of reserved entries.
|
|
|
|
unsigned getLocalEntriesNum() const;
|
2016-11-11 19:33:32 +08:00
|
|
|
|
2018-06-11 15:24:31 +08:00
|
|
|
// Return _gp value for primary GOT (nullptr) or particular input file.
|
|
|
|
uint64_t getGp(const InputFile *F = nullptr) const;
|
2016-11-24 06:22:16 +08:00
|
|
|
|
2016-11-11 19:33:32 +08:00
|
|
|
private:
|
2016-11-18 05:49:14 +08:00
|
|
|
// MIPS GOT consists of three parts: local, global and tls. Each part
|
|
|
|
// contains different types of entries. Here is a layout of GOT:
|
|
|
|
// - Header entries |
|
|
|
|
// - Page entries | Local part
|
|
|
|
// - Local entries (16-bit access) |
|
|
|
|
// - Local entries (32-bit access) |
|
|
|
|
// - Normal global entries || Global part
|
|
|
|
// - Reloc-only global entries ||
|
|
|
|
// - TLS entries ||| TLS part
|
|
|
|
//
|
|
|
|
// Header:
|
|
|
|
// Two entries hold predefined value 0x0 and 0x80000000.
|
|
|
|
// Page entries:
|
|
|
|
// These entries created by R_MIPS_GOT_PAGE relocation and R_MIPS_GOT16
|
|
|
|
// relocation against local symbols. They are initialized by higher 16-bit
|
|
|
|
// of the corresponding symbol's value. So each 64kb of address space
|
|
|
|
// requires a single GOT entry.
|
|
|
|
// Local entries (16-bit access):
|
|
|
|
// These entries created by GOT relocations against global non-preemptible
|
|
|
|
// symbols so dynamic linker is not necessary to resolve the symbol's
|
|
|
|
// values. "16-bit access" means that corresponding relocations address
|
|
|
|
// GOT using 16-bit index. Each unique Symbol-Addend pair has its own
|
|
|
|
// GOT entry.
|
|
|
|
// Local entries (32-bit access):
|
|
|
|
// These entries are the same as above but created by relocations which
|
|
|
|
// address GOT using 32-bit index (R_MIPS_GOT_HI16/LO16 etc).
|
|
|
|
// Normal global entries:
|
|
|
|
// These entries created by GOT relocations against preemptible global
|
|
|
|
// symbols. They need to be initialized by dynamic linker and they ordered
|
|
|
|
// exactly as the corresponding entries in the dynamic symbols table.
|
|
|
|
// Reloc-only global entries:
|
|
|
|
// These entries created for symbols that are referenced by dynamic
|
|
|
|
// relocations R_MIPS_REL32. These entries are not accessed with gp-relative
|
|
|
|
// addressing, but MIPS ABI requires that these entries be present in GOT.
|
|
|
|
// TLS entries:
|
|
|
|
// Entries created by TLS relocations.
|
2018-06-11 15:24:31 +08:00
|
|
|
//
|
|
|
|
// If the sum of local, global and tls entries is less than 64K only single
|
|
|
|
// got is enough. Otherwise, multi-got is created. Series of primary and
|
|
|
|
// multiple secondary GOTs have the following layout:
|
|
|
|
// - Primary GOT
|
|
|
|
// Header
|
|
|
|
// Local entries
|
|
|
|
// Global entries
|
|
|
|
// Relocation only entries
|
|
|
|
// TLS entries
|
|
|
|
//
|
|
|
|
// - Secondary GOT
|
|
|
|
// Local entries
|
|
|
|
// Global entries
|
|
|
|
// TLS entries
|
|
|
|
// ...
|
|
|
|
//
|
|
|
|
// All GOT entries required by relocations from a single input file entirely
|
|
|
|
// belong to either primary or one of secondary GOTs. To reference GOT entries
|
|
|
|
// each GOT has its own _gp value points to the "middle" of the GOT.
|
|
|
|
// In the code this value loaded to the register which is used for GOT access.
|
|
|
|
//
|
|
|
|
// MIPS 32 function's prologue:
|
|
|
|
// lui v0,0x0
|
|
|
|
// 0: R_MIPS_HI16 _gp_disp
|
|
|
|
// addiu v0,v0,0
|
|
|
|
// 4: R_MIPS_LO16 _gp_disp
|
|
|
|
//
|
|
|
|
// MIPS 64:
|
|
|
|
// lui at,0x0
|
|
|
|
// 14: R_MIPS_GPREL16 main
|
|
|
|
//
|
|
|
|
// Dynamic linker does not know anything about secondary GOTs and cannot
|
|
|
|
// use a regular MIPS mechanism for GOT entries initialization. So we have
|
|
|
|
// to use an approach accepted by other architectures and create dynamic
|
|
|
|
// relocations R_MIPS_REL32 to initialize global entries (and local in case
|
|
|
|
// of PIC code) in secondary GOTs. But ironically MIPS dynamic linker
|
|
|
|
// requires GOT entries and correspondingly ordered dynamic symbol table
|
|
|
|
// entries to deal with dynamic relocations. To handle this problem
|
|
|
|
// relocation-only section in the primary GOT contains entries for all
|
|
|
|
// symbols referenced in global parts of secondary GOTs. Although the sum
|
|
|
|
// of local and normal global entries of the primary got should be less
|
|
|
|
// than 64K, the size of the primary got (including relocation-only entries
|
|
|
|
// can be greater than 64K, because parts of the primary got that overflow
|
|
|
|
// the 64K limit are used only by the dynamic linker at dynamic link-time
|
|
|
|
// and not by 16-bit gp-relative addressing at run-time.
|
|
|
|
//
|
|
|
|
// For complete multi-GOT description see the following link
|
|
|
|
// https://dmz-portal.mips.com/wiki/MIPS_Multi_GOT
|
2016-11-18 05:49:14 +08:00
|
|
|
|
2016-11-29 18:23:50 +08:00
|
|
|
// Number of "Header" entries.
|
|
|
|
static const unsigned HeaderEntriesNum = 2;
|
2016-11-18 05:49:14 +08:00
|
|
|
|
2017-03-21 00:44:28 +08:00
|
|
|
uint64_t Size = 0;
|
2018-06-11 15:24:31 +08:00
|
|
|
|
|
|
|
// Symbol and addend.
|
2019-04-01 08:11:24 +08:00
|
|
|
using GotEntry = std::pair<Symbol *, int64_t>;
|
2018-06-11 15:24:31 +08:00
|
|
|
|
|
|
|
struct FileGot {
|
|
|
|
InputFile *File = nullptr;
|
|
|
|
size_t StartIndex = 0;
|
|
|
|
|
|
|
|
struct PageBlock {
|
2019-01-21 15:44:52 +08:00
|
|
|
size_t FirstIndex;
|
|
|
|
size_t Count;
|
|
|
|
PageBlock() : FirstIndex(0), Count(0) {}
|
2018-06-11 15:24:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Map output sections referenced by MIPS GOT relocations
|
|
|
|
// to the description (index/count) "page" entries allocated
|
|
|
|
// for this section.
|
|
|
|
llvm::SmallMapVector<const OutputSection *, PageBlock, 16> PagesMap;
|
|
|
|
// Maps from Symbol+Addend pair or just Symbol to the GOT entry index.
|
|
|
|
llvm::MapVector<GotEntry, size_t> Local16;
|
|
|
|
llvm::MapVector<GotEntry, size_t> Local32;
|
|
|
|
llvm::MapVector<Symbol *, size_t> Global;
|
|
|
|
llvm::MapVector<Symbol *, size_t> Relocs;
|
|
|
|
llvm::MapVector<Symbol *, size_t> Tls;
|
|
|
|
// Set of symbols referenced by dynamic TLS relocations.
|
|
|
|
llvm::MapVector<Symbol *, size_t> DynTlsSymbols;
|
|
|
|
|
|
|
|
// Total number of all entries.
|
|
|
|
size_t getEntriesNum() const;
|
|
|
|
// Number of "page" entries.
|
|
|
|
size_t getPageEntriesNum() const;
|
|
|
|
// Number of entries require 16-bit index to access.
|
|
|
|
size_t getIndexedEntriesNum() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Container of GOT created for each input file.
|
|
|
|
// After building a final series of GOTs this container
|
|
|
|
// holds primary and secondary GOT's.
|
|
|
|
std::vector<FileGot> Gots;
|
|
|
|
|
|
|
|
// Return (and create if necessary) `FileGot`.
|
|
|
|
FileGot &getGot(InputFile &F);
|
|
|
|
|
|
|
|
// Try to merge two GOTs. In case of success the `Dst` contains
|
|
|
|
// result of merging and the function returns true. In case of
|
|
|
|
// ovwerflow the `Dst` is unchanged and the function returns false.
|
|
|
|
bool tryMergeGots(FileGot & Dst, FileGot & Src, bool IsPrimary);
|
2016-11-11 19:33:32 +08:00
|
|
|
};
|
|
|
|
|
2017-03-15 17:12:56 +08:00
|
|
|
class GotPltSection final : public SyntheticSection {
|
2016-11-10 17:48:29 +08:00
|
|
|
public:
|
|
|
|
GotPltSection();
|
2017-11-04 05:21:47 +08:00
|
|
|
void addEntry(Symbol &Sym);
|
2016-11-10 17:48:29 +08:00
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2016-11-10 17:48:29 +08:00
|
|
|
|
[ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.
Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)
This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.
extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32
In this patch, we
* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.
The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).
We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.
Reviewers: ruiu, sivachandra, espindola
Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59594
llvm-svn: 356968
2019-03-26 07:46:19 +08:00
|
|
|
// Flag to force GotPlt to be in output if we have relocations
|
|
|
|
// that relies on its address.
|
|
|
|
bool HasGotPltOffRel = false;
|
|
|
|
|
2016-11-10 17:48:29 +08:00
|
|
|
private:
|
2017-11-04 05:21:47 +08:00
|
|
|
std::vector<const Symbol *> Entries;
|
2016-11-10 17:48:29 +08:00
|
|
|
};
|
|
|
|
|
2017-02-09 18:56:15 +08:00
|
|
|
// The IgotPltSection is a Got associated with the PltSection for GNU Ifunc
|
2016-12-08 20:58:55 +08:00
|
|
|
// Symbols that will be relocated by Target->IRelativeRel.
|
|
|
|
// On most Targets the IgotPltSection will immediately follow the GotPltSection
|
|
|
|
// on ARM the IgotPltSection will immediately follow the GotSection.
|
2017-03-15 17:12:56 +08:00
|
|
|
class IgotPltSection final : public SyntheticSection {
|
2016-12-08 20:58:55 +08:00
|
|
|
public:
|
|
|
|
IgotPltSection();
|
2017-11-04 05:21:47 +08:00
|
|
|
void addEntry(Symbol &Sym);
|
2016-12-08 20:58:55 +08:00
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return !Entries.empty(); }
|
2016-12-08 20:58:55 +08:00
|
|
|
|
|
|
|
private:
|
2017-11-04 05:21:47 +08:00
|
|
|
std::vector<const Symbol *> Entries;
|
2016-12-08 20:58:55 +08:00
|
|
|
};
|
|
|
|
|
2017-03-15 17:32:36 +08:00
|
|
|
class StringTableSection final : public SyntheticSection {
|
2016-11-14 17:16:00 +08:00
|
|
|
public:
|
|
|
|
StringTableSection(StringRef Name, bool Dynamic);
|
|
|
|
unsigned addString(StringRef S, bool HashIt = true);
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override { return Size; }
|
|
|
|
bool isDynamic() const { return Dynamic; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const bool Dynamic;
|
|
|
|
|
2017-03-15 17:32:36 +08:00
|
|
|
uint64_t Size = 0;
|
2016-11-14 17:16:00 +08:00
|
|
|
|
|
|
|
llvm::DenseMap<StringRef, unsigned> StringMap;
|
|
|
|
std::vector<StringRef> Strings;
|
|
|
|
};
|
|
|
|
|
2017-03-17 20:07:44 +08:00
|
|
|
class DynamicReloc {
|
2016-11-16 18:02:27 +08:00
|
|
|
public:
|
2018-02-11 02:14:34 +08:00
|
|
|
DynamicReloc(RelType Type, const InputSectionBase *InputSec,
|
2017-11-04 05:21:47 +08:00
|
|
|
uint64_t OffsetInSec, bool UseSymVA, Symbol *Sym, int64_t Addend)
|
2016-11-16 18:02:27 +08:00
|
|
|
: Type(Type), Sym(Sym), InputSec(InputSec), OffsetInSec(OffsetInSec),
|
2018-06-11 15:24:31 +08:00
|
|
|
UseSymVA(UseSymVA), Addend(Addend), OutputSec(nullptr) {}
|
|
|
|
// This constructor records dynamic relocation settings used by MIPS
|
|
|
|
// multi-GOT implementation. It's to relocate addresses of 64kb pages
|
|
|
|
// lie inside the output section.
|
|
|
|
DynamicReloc(RelType Type, const InputSectionBase *InputSec,
|
|
|
|
uint64_t OffsetInSec, const OutputSection *OutputSec,
|
|
|
|
int64_t Addend)
|
|
|
|
: Type(Type), Sym(nullptr), InputSec(InputSec), OffsetInSec(OffsetInSec),
|
|
|
|
UseSymVA(false), Addend(Addend), OutputSec(OutputSec) {}
|
2016-11-16 18:02:27 +08:00
|
|
|
|
2017-03-16 19:42:16 +08:00
|
|
|
uint64_t getOffset() const;
|
2016-11-16 18:02:27 +08:00
|
|
|
uint32_t getSymIndex() const;
|
|
|
|
|
2018-02-19 19:00:15 +08:00
|
|
|
// Computes the addend of the dynamic relocation. Note that this is not the
|
|
|
|
// same as the Addend member variable as it also includes the symbol address
|
|
|
|
// if UseSymVA is true.
|
|
|
|
int64_t computeAddend() const;
|
|
|
|
|
2018-02-11 02:14:34 +08:00
|
|
|
RelType Type;
|
2016-11-16 18:02:27 +08:00
|
|
|
|
|
|
|
private:
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *Sym;
|
2017-02-23 10:28:28 +08:00
|
|
|
const InputSectionBase *InputSec = nullptr;
|
2017-03-16 19:42:16 +08:00
|
|
|
uint64_t OffsetInSec;
|
2018-02-19 19:00:15 +08:00
|
|
|
// If this member is true, the dynamic relocation will not be against the
|
|
|
|
// symbol but will instead be a relative relocation that simply adds the
|
|
|
|
// load address. This means we need to write the symbol virtual address
|
|
|
|
// plus the original addend as the final relocation addend.
|
2016-11-16 18:02:27 +08:00
|
|
|
bool UseSymVA;
|
2017-02-16 08:12:34 +08:00
|
|
|
int64_t Addend;
|
2018-06-11 15:24:31 +08:00
|
|
|
const OutputSection *OutputSec;
|
2016-11-16 18:02:27 +08:00
|
|
|
};
|
|
|
|
|
2017-02-27 10:56:02 +08:00
|
|
|
template <class ELFT> class DynamicSection final : public SyntheticSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Dyn = typename ELFT::Dyn;
|
|
|
|
using Elf_Rel = typename ELFT::Rel;
|
|
|
|
using Elf_Rela = typename ELFT::Rela;
|
|
|
|
using Elf_Relr = typename ELFT::Relr;
|
|
|
|
using Elf_Shdr = typename ELFT::Shdr;
|
|
|
|
using Elf_Sym = typename ELFT::Sym;
|
2016-11-15 20:26:55 +08:00
|
|
|
|
2017-02-27 11:07:41 +08:00
|
|
|
// finalizeContents() fills this vector with the section contents.
|
2017-11-24 10:15:51 +08:00
|
|
|
std::vector<std::pair<int32_t, std::function<uint64_t()>>> Entries;
|
2016-11-15 20:26:55 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
DynamicSection();
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2016-11-15 20:26:55 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override { return Size; }
|
|
|
|
|
|
|
|
private:
|
2017-11-24 10:15:51 +08:00
|
|
|
void add(int32_t Tag, std::function<uint64_t()> Fn);
|
|
|
|
void addInt(int32_t Tag, uint64_t Val);
|
|
|
|
void addInSec(int32_t Tag, InputSection *Sec);
|
2018-04-13 16:15:01 +08:00
|
|
|
void addInSecRelative(int32_t Tag, InputSection *Sec);
|
2017-11-24 10:15:51 +08:00
|
|
|
void addOutSec(int32_t Tag, OutputSection *Sec);
|
|
|
|
void addSize(int32_t Tag, OutputSection *Sec);
|
|
|
|
void addSym(int32_t Tag, Symbol *Sym);
|
|
|
|
|
2017-04-14 09:34:45 +08:00
|
|
|
uint64_t Size = 0;
|
2016-11-15 20:26:55 +08:00
|
|
|
};
|
|
|
|
|
2017-10-28 01:49:40 +08:00
|
|
|
class RelocationBaseSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
RelocationBaseSection(StringRef Name, uint32_t Type, int32_t DynamicTag,
|
|
|
|
int32_t SizeDynamicTag);
|
2018-02-14 00:06:11 +08:00
|
|
|
void addReloc(RelType DynType, InputSectionBase *IS, uint64_t OffsetInSec,
|
2018-02-14 00:03:52 +08:00
|
|
|
Symbol *Sym);
|
2018-02-16 18:01:17 +08:00
|
|
|
// Add a dynamic relocation that might need an addend. This takes care of
|
|
|
|
// writing the addend to the output section if needed.
|
2018-02-14 00:06:11 +08:00
|
|
|
void addReloc(RelType DynType, InputSectionBase *InputSec,
|
2018-02-17 00:53:04 +08:00
|
|
|
uint64_t OffsetInSec, Symbol *Sym, int64_t Addend, RelExpr Expr,
|
|
|
|
RelType Type);
|
2017-10-28 01:49:40 +08:00
|
|
|
void addReloc(const DynamicReloc &Reloc);
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return !Relocs.empty(); }
|
2017-10-28 01:49:40 +08:00
|
|
|
size_t getSize() const override { return Relocs.size() * this->Entsize; }
|
|
|
|
size_t getRelativeRelocCount() const { return NumRelativeRelocs; }
|
|
|
|
void finalizeContents() override;
|
|
|
|
int32_t DynamicTag, SizeDynamicTag;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<DynamicReloc> Relocs;
|
|
|
|
size_t NumRelativeRelocs = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
class RelocationSection final : public RelocationBaseSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Rel = typename ELFT::Rel;
|
|
|
|
using Elf_Rela = typename ELFT::Rela;
|
2016-11-16 18:02:27 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
RelocationSection(StringRef Name, bool Sort);
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool Sort;
|
2017-10-28 01:49:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
class AndroidPackedRelocationSection final : public RelocationBaseSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Rel = typename ELFT::Rel;
|
|
|
|
using Elf_Rela = typename ELFT::Rela;
|
2017-10-28 01:49:40 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
AndroidPackedRelocationSection(StringRef Name);
|
|
|
|
|
|
|
|
bool updateAllocSize() override;
|
|
|
|
size_t getSize() const override { return RelocData.size(); }
|
|
|
|
void writeTo(uint8_t *Buf) override {
|
|
|
|
memcpy(Buf, RelocData.data(), RelocData.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmallVector<char, 0> RelocData;
|
2016-11-16 18:02:27 +08:00
|
|
|
};
|
|
|
|
|
2018-07-10 04:08:55 +08:00
|
|
|
struct RelativeReloc {
|
|
|
|
uint64_t getOffset() const { return InputSec->getVA(OffsetInSec); }
|
|
|
|
|
|
|
|
const InputSectionBase *InputSec;
|
|
|
|
uint64_t OffsetInSec;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RelrBaseSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
RelrBaseSection();
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return !Relocs.empty(); }
|
2018-07-10 04:08:55 +08:00
|
|
|
std::vector<RelativeReloc> Relocs;
|
|
|
|
};
|
|
|
|
|
|
|
|
// RelrSection is used to encode offsets for relative relocations.
|
|
|
|
// Proposal for adding SHT_RELR sections to generic-abi is here:
|
|
|
|
// https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg
|
|
|
|
// For more details, see the comment in RelrSection::updateAllocSize().
|
|
|
|
template <class ELFT> class RelrSection final : public RelrBaseSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Relr = typename ELFT::Relr;
|
2018-07-10 04:08:55 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
RelrSection();
|
|
|
|
|
|
|
|
bool updateAllocSize() override;
|
|
|
|
size_t getSize() const override { return RelrRelocs.size() * this->Entsize; }
|
|
|
|
void writeTo(uint8_t *Buf) override {
|
|
|
|
memcpy(Buf, RelrRelocs.data(), getSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Elf_Relr> RelrRelocs;
|
|
|
|
};
|
|
|
|
|
2016-11-18 14:44:18 +08:00
|
|
|
struct SymbolTableEntry {
|
2017-11-04 06:33:49 +08:00
|
|
|
Symbol *Sym;
|
2016-11-18 14:44:18 +08:00
|
|
|
size_t StrTabOffset;
|
|
|
|
};
|
|
|
|
|
2017-05-16 16:53:30 +08:00
|
|
|
class SymbolTableBaseSection : public SyntheticSection {
|
2016-11-17 17:16:34 +08:00
|
|
|
public:
|
2017-05-16 16:53:30 +08:00
|
|
|
SymbolTableBaseSection(StringTableSection &StrTabSec);
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2017-05-16 16:53:30 +08:00
|
|
|
size_t getSize() const override { return getNumSymbols() * Entsize; }
|
2017-11-04 08:31:04 +08:00
|
|
|
void addSymbol(Symbol *Sym);
|
2017-01-23 22:07:23 +08:00
|
|
|
unsigned getNumSymbols() const { return Symbols.size() + 1; }
|
2017-11-04 08:31:04 +08:00
|
|
|
size_t getSymbolIndex(Symbol *Sym);
|
2016-11-17 17:16:34 +08:00
|
|
|
ArrayRef<SymbolTableEntry> getSymbols() const { return Symbols; }
|
|
|
|
|
2017-05-16 16:53:30 +08:00
|
|
|
protected:
|
2018-08-10 15:24:18 +08:00
|
|
|
void sortSymTabSymbols();
|
|
|
|
|
2016-11-17 17:16:34 +08:00
|
|
|
// A vector of symbols and their string table offsets.
|
|
|
|
std::vector<SymbolTableEntry> Symbols;
|
2017-01-23 22:07:23 +08:00
|
|
|
|
2017-03-15 17:32:36 +08:00
|
|
|
StringTableSection &StrTabSec;
|
2017-09-27 17:08:53 +08:00
|
|
|
|
|
|
|
llvm::once_flag OnceFlag;
|
2017-11-04 05:21:47 +08:00
|
|
|
llvm::DenseMap<Symbol *, size_t> SymbolIndexMap;
|
2017-09-27 17:08:53 +08:00
|
|
|
llvm::DenseMap<OutputSection *, size_t> SectionIndexMap;
|
2016-11-17 17:16:34 +08:00
|
|
|
};
|
|
|
|
|
2017-05-16 16:53:30 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class SymbolTableSection final : public SymbolTableBaseSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Sym = typename ELFT::Sym;
|
2017-05-16 16:53:30 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
SymbolTableSection(StringTableSection &StrTabSec);
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
};
|
|
|
|
|
2018-07-30 20:39:54 +08:00
|
|
|
class SymtabShndxSection final : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
SymtabShndxSection();
|
|
|
|
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2018-07-30 20:39:54 +08:00
|
|
|
void finalizeContents() override;
|
|
|
|
};
|
|
|
|
|
2016-11-18 14:44:18 +08:00
|
|
|
// Outputs GNU Hash section. For detailed explanation see:
|
|
|
|
// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
|
2017-02-27 10:56:02 +08:00
|
|
|
class GnuHashTableSection final : public SyntheticSection {
|
2016-11-18 14:44:18 +08:00
|
|
|
public:
|
|
|
|
GnuHashTableSection();
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2016-11-18 14:44:18 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2017-02-27 11:10:06 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
2016-11-18 14:44:18 +08:00
|
|
|
|
|
|
|
// Adds symbols to the hash table.
|
|
|
|
// Sorts the input to satisfy GNU hash section requirements.
|
|
|
|
void addSymbols(std::vector<SymbolTableEntry> &Symbols);
|
|
|
|
|
|
|
|
private:
|
2018-12-22 05:59:34 +08:00
|
|
|
// See the comment in writeBloomFilter.
|
|
|
|
enum { Shift2 = 26 };
|
2016-11-18 14:44:18 +08:00
|
|
|
|
2017-03-01 10:51:42 +08:00
|
|
|
void writeBloomFilter(uint8_t *Buf);
|
2016-11-18 14:44:18 +08:00
|
|
|
void writeHashTable(uint8_t *Buf);
|
|
|
|
|
2017-03-01 10:51:42 +08:00
|
|
|
struct Entry {
|
2017-11-04 08:31:04 +08:00
|
|
|
Symbol *Sym;
|
2017-03-01 10:51:42 +08:00
|
|
|
size_t StrTabOffset;
|
2016-11-18 14:44:18 +08:00
|
|
|
uint32_t Hash;
|
2017-12-02 08:37:13 +08:00
|
|
|
uint32_t BucketIdx;
|
2016-11-18 14:44:18 +08:00
|
|
|
};
|
|
|
|
|
2017-03-01 10:51:42 +08:00
|
|
|
std::vector<Entry> Symbols;
|
|
|
|
size_t MaskWords;
|
2017-03-01 18:12:49 +08:00
|
|
|
size_t NBuckets = 0;
|
2017-03-01 10:51:42 +08:00
|
|
|
size_t Size = 0;
|
2016-11-18 14:44:18 +08:00
|
|
|
};
|
|
|
|
|
2017-09-27 17:14:59 +08:00
|
|
|
class HashTableSection final : public SyntheticSection {
|
2016-11-18 17:06:47 +08:00
|
|
|
public:
|
|
|
|
HashTableSection();
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2016-11-18 17:06:47 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2017-02-27 11:10:06 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
2016-11-18 17:06:47 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
size_t Size = 0;
|
|
|
|
};
|
|
|
|
|
2018-01-12 17:35:57 +08:00
|
|
|
// The PltSection is used for both the Plt and Iplt. The former usually has a
|
2017-02-09 18:56:15 +08:00
|
|
|
// header as its first entry that is used at run-time to resolve lazy binding.
|
|
|
|
// The latter is used for GNU Ifunc symbols, that will be subject to a
|
|
|
|
// Target->IRelativeRel.
|
2017-03-17 19:01:57 +08:00
|
|
|
class PltSection : public SyntheticSection {
|
2016-11-18 22:35:03 +08:00
|
|
|
public:
|
2018-01-13 06:29:29 +08:00
|
|
|
PltSection(bool IsIplt);
|
2016-12-08 20:58:55 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return !Entries.empty(); }
|
2017-01-25 18:31:16 +08:00
|
|
|
void addSymbols();
|
2017-11-04 05:21:47 +08:00
|
|
|
template <class ELFT> void addEntry(Symbol &Sym);
|
2017-03-17 19:01:57 +08:00
|
|
|
|
2018-11-29 01:42:59 +08:00
|
|
|
size_t HeaderSize;
|
|
|
|
|
2016-12-08 20:58:55 +08:00
|
|
|
private:
|
2019-03-23 05:17:25 +08:00
|
|
|
std::vector<const Symbol *> Entries;
|
2018-01-12 17:35:57 +08:00
|
|
|
bool IsIplt;
|
2016-12-08 20:58:55 +08:00
|
|
|
};
|
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
class GdbIndexSection final : public SyntheticSection {
|
|
|
|
public:
|
2017-09-25 05:45:35 +08:00
|
|
|
struct AddressEntry {
|
|
|
|
InputSection *Section;
|
|
|
|
uint64_t LowAddress;
|
|
|
|
uint64_t HighAddress;
|
|
|
|
uint32_t CuIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CuEntry {
|
|
|
|
uint64_t CuOffset;
|
|
|
|
uint64_t CuLength;
|
|
|
|
};
|
|
|
|
|
2018-11-14 04:25:51 +08:00
|
|
|
struct NameAttrEntry {
|
2017-09-25 09:42:57 +08:00
|
|
|
llvm::CachedHashStringRef Name;
|
2018-11-14 04:25:51 +08:00
|
|
|
uint32_t CuIndexAndAttrs;
|
2017-09-25 05:45:35 +08:00
|
|
|
};
|
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
struct GdbChunk {
|
|
|
|
InputSection *Sec;
|
|
|
|
std::vector<AddressEntry> AddressAreas;
|
|
|
|
std::vector<CuEntry> CompilationUnits;
|
|
|
|
};
|
2017-09-25 05:45:35 +08:00
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
struct GdbSymbol {
|
|
|
|
llvm::CachedHashStringRef Name;
|
|
|
|
std::vector<uint32_t> CuVector;
|
|
|
|
uint32_t NameOff;
|
|
|
|
uint32_t CuVectorOff;
|
|
|
|
};
|
|
|
|
|
|
|
|
GdbIndexSection();
|
|
|
|
template <typename ELFT> static GdbIndexSection *create();
|
2016-11-21 17:24:43 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2018-07-11 07:48:27 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2016-11-21 17:24:43 +08:00
|
|
|
|
2017-08-16 01:01:39 +08:00
|
|
|
private:
|
2018-07-11 07:48:27 +08:00
|
|
|
struct GdbIndexHeader {
|
|
|
|
llvm::support::ulittle32_t Version;
|
|
|
|
llvm::support::ulittle32_t CuListOff;
|
|
|
|
llvm::support::ulittle32_t CuTypesOff;
|
|
|
|
llvm::support::ulittle32_t AddressAreaOff;
|
|
|
|
llvm::support::ulittle32_t SymtabOff;
|
|
|
|
llvm::support::ulittle32_t ConstantPoolOff;
|
2018-07-10 23:57:25 +08:00
|
|
|
};
|
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
void initOutputSize();
|
|
|
|
size_t computeSymtabSize() const;
|
2016-12-15 20:07:53 +08:00
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
// Each chunk contains information gathered from debug sections of a
|
|
|
|
// single object file.
|
|
|
|
std::vector<GdbChunk> Chunks;
|
2016-12-15 17:08:13 +08:00
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
// A symbol table for this .gdb_index section.
|
|
|
|
std::vector<GdbSymbol> Symbols;
|
2016-12-15 20:07:53 +08:00
|
|
|
|
2018-07-11 07:48:27 +08:00
|
|
|
size_t Size;
|
2016-11-21 17:24:43 +08:00
|
|
|
};
|
|
|
|
|
2016-11-21 23:52:10 +08:00
|
|
|
// --eh-frame-hdr option tells linker to construct a header for all the
|
|
|
|
// .eh_frame sections. This header is placed to a section named .eh_frame_hdr
|
|
|
|
// and also to a PT_GNU_EH_FRAME segment.
|
|
|
|
// At runtime the unwinder then can find all the PT_GNU_EH_FRAME segments by
|
|
|
|
// calling dl_iterate_phdr.
|
|
|
|
// This section contains a lookup table for quick binary search of FDEs.
|
|
|
|
// Detailed info about internals can be found in Ian Lance Taylor's blog:
|
|
|
|
// http://www.airs.com/blog/archives/460 (".eh_frame")
|
|
|
|
// http://www.airs.com/blog/archives/462 (".eh_frame_hdr")
|
2017-10-27 11:14:24 +08:00
|
|
|
class EhFrameHeader final : public SyntheticSection {
|
2016-11-21 23:52:10 +08:00
|
|
|
public:
|
|
|
|
EhFrameHeader();
|
2019-03-01 07:11:35 +08:00
|
|
|
void write();
|
2016-11-21 23:52:10 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2016-11-21 23:52:10 +08:00
|
|
|
};
|
|
|
|
|
2016-11-22 00:59:33 +08:00
|
|
|
// For more information about .gnu.version and .gnu.version_r see:
|
|
|
|
// https://www.akkadia.org/drepper/symbol-versioning
|
|
|
|
|
|
|
|
// The .gnu.version_d section which has a section type of SHT_GNU_verdef shall
|
|
|
|
// contain symbol version definitions. The number of entries in this section
|
|
|
|
// shall be contained in the DT_VERDEFNUM entry of the .dynamic section.
|
|
|
|
// The section shall contain an array of Elf_Verdef structures, optionally
|
|
|
|
// followed by an array of Elf_Verdaux structures.
|
2017-02-27 10:56:02 +08:00
|
|
|
class VersionDefinitionSection final : public SyntheticSection {
|
2016-11-22 00:59:33 +08:00
|
|
|
public:
|
|
|
|
VersionDefinitionSection();
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2016-11-22 00:59:33 +08:00
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
|
|
|
|
private:
|
2018-09-26 04:37:51 +08:00
|
|
|
enum { EntrySize = 28 };
|
2016-11-22 00:59:33 +08:00
|
|
|
void writeOne(uint8_t *Buf, uint32_t Index, StringRef Name, size_t NameOff);
|
|
|
|
|
|
|
|
unsigned FileDefNameOff;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The .gnu.version section specifies the required version of each symbol in the
|
|
|
|
// dynamic symbol table. It contains one Elf_Versym for each dynamic symbol
|
|
|
|
// table entry. An Elf_Versym is just a 16-bit integer that refers to a version
|
|
|
|
// identifier defined in the either .gnu.version_r or .gnu.version_d section.
|
|
|
|
// The values 0 and 1 are reserved. All other values are used for versions in
|
|
|
|
// the own object or in any of the dependencies.
|
2017-02-27 10:56:02 +08:00
|
|
|
class VersionTableSection final : public SyntheticSection {
|
2016-11-22 00:59:33 +08:00
|
|
|
public:
|
|
|
|
VersionTableSection();
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2016-11-22 00:59:33 +08:00
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2016-11-22 00:59:33 +08:00
|
|
|
};
|
|
|
|
|
2019-03-06 11:07:48 +08:00
|
|
|
class VersionNeedBaseSection : public SyntheticSection {
|
|
|
|
protected:
|
|
|
|
// The next available version identifier.
|
|
|
|
unsigned NextIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VersionNeedBaseSection();
|
|
|
|
virtual void addSymbol(Symbol *Sym) = 0;
|
|
|
|
virtual size_t getNeedNum() const = 0;
|
|
|
|
};
|
|
|
|
|
2016-11-22 00:59:33 +08:00
|
|
|
// The .gnu.version_r section defines the version identifiers used by
|
|
|
|
// .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
|
|
|
|
// Elf_Verneed specifies the version requirements for a single DSO, and contains
|
|
|
|
// a reference to a linked list of Elf_Vernaux data structures which define the
|
|
|
|
// mapping from version identifiers to version names.
|
2019-03-06 11:07:48 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class VersionNeedSection final : public VersionNeedBaseSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Verneed = typename ELFT::Verneed;
|
|
|
|
using Elf_Vernaux = typename ELFT::Vernaux;
|
2016-11-22 00:59:33 +08:00
|
|
|
|
|
|
|
// A vector of shared files that need Elf_Verneed data structures and the
|
|
|
|
// string table offsets of their sonames.
|
|
|
|
std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
|
|
|
|
|
|
|
|
public:
|
2019-03-06 11:07:48 +08:00
|
|
|
void addSymbol(Symbol *Sym) override;
|
2017-02-27 11:07:41 +08:00
|
|
|
void finalizeContents() override;
|
2016-11-22 00:59:33 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getSize() const override;
|
2019-03-06 11:07:48 +08:00
|
|
|
size_t getNeedNum() const override { return Needed.size(); }
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2016-11-22 00:59:33 +08:00
|
|
|
};
|
|
|
|
|
2017-02-03 21:06:18 +08:00
|
|
|
// MergeSyntheticSection is a class that allows us to put mergeable sections
|
|
|
|
// with different attributes in a single output sections. To do that
|
|
|
|
// we put them into MergeSyntheticSection synthetic input sections which are
|
|
|
|
// attached to regular output sections.
|
2017-09-26 08:54:24 +08:00
|
|
|
class MergeSyntheticSection : public SyntheticSection {
|
2017-02-03 21:06:18 +08:00
|
|
|
public:
|
2017-03-07 04:23:56 +08:00
|
|
|
void addSection(MergeInputSection *MS);
|
2018-03-28 11:20:18 +08:00
|
|
|
std::vector<MergeInputSection *> Sections;
|
2017-02-03 21:06:18 +08:00
|
|
|
|
2017-09-26 08:54:24 +08:00
|
|
|
protected:
|
|
|
|
MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags,
|
2017-09-30 19:46:26 +08:00
|
|
|
uint32_t Alignment)
|
|
|
|
: SyntheticSection(Flags, Type, Alignment, Name) {}
|
2017-09-26 08:54:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MergeTailSection final : public MergeSyntheticSection {
|
|
|
|
public:
|
|
|
|
MergeTailSection(StringRef Name, uint32_t Type, uint64_t Flags,
|
2017-09-30 19:46:26 +08:00
|
|
|
uint32_t Alignment);
|
2017-09-26 08:54:24 +08:00
|
|
|
|
2017-09-30 19:46:26 +08:00
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2017-09-26 08:54:24 +08:00
|
|
|
void finalizeContents() override;
|
2017-09-30 19:46:26 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::StringTableBuilder Builder;
|
2017-09-26 08:54:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MergeNoTailSection final : public MergeSyntheticSection {
|
|
|
|
public:
|
|
|
|
MergeNoTailSection(StringRef Name, uint32_t Type, uint64_t Flags,
|
|
|
|
uint32_t Alignment)
|
|
|
|
: MergeSyntheticSection(Name, Type, Flags, Alignment) {}
|
|
|
|
|
2017-09-30 19:46:26 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2017-09-26 08:54:24 +08:00
|
|
|
void finalizeContents() override;
|
2017-09-30 19:46:26 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// We use the most significant bits of a hash as a shard ID.
|
|
|
|
// The reason why we don't want to use the least significant bits is
|
|
|
|
// because DenseMap also uses lower bits to determine a bucket ID.
|
|
|
|
// If we use lower bits, it significantly increases the probability of
|
|
|
|
// hash collisons.
|
|
|
|
size_t getShardId(uint32_t Hash) {
|
|
|
|
return Hash >> (32 - llvm::countTrailingZeros(NumShards));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Section size
|
|
|
|
size_t Size;
|
|
|
|
|
|
|
|
// String table contents
|
|
|
|
constexpr static size_t NumShards = 32;
|
|
|
|
std::vector<llvm::StringTableBuilder> Shards;
|
|
|
|
size_t ShardOffsets[NumShards];
|
2017-02-03 21:06:18 +08:00
|
|
|
};
|
|
|
|
|
2016-11-22 11:57:06 +08:00
|
|
|
// .MIPS.abiflags section.
|
|
|
|
template <class ELFT>
|
2017-02-27 10:56:02 +08:00
|
|
|
class MipsAbiFlagsSection final : public SyntheticSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Mips_ABIFlags = llvm::object::Elf_Mips_ABIFlags<ELFT>;
|
2016-11-22 11:57:06 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2016-11-22 12:13:09 +08:00
|
|
|
// .MIPS.options section.
|
2017-02-27 10:56:02 +08:00
|
|
|
template <class ELFT> class MipsOptionsSection final : public SyntheticSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Mips_Options = llvm::object::Elf_Mips_Options<ELFT>;
|
|
|
|
using Elf_Mips_RegInfo = llvm::object::Elf_Mips_RegInfo<ELFT>;
|
2016-11-22 12:13:09 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static MipsOptionsSection *create();
|
|
|
|
|
|
|
|
MipsOptionsSection(Elf_Mips_RegInfo Reginfo);
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
|
|
|
|
size_t getSize() const override {
|
|
|
|
return sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Elf_Mips_RegInfo Reginfo;
|
|
|
|
};
|
|
|
|
|
2016-11-22 11:57:08 +08:00
|
|
|
// MIPS .reginfo section.
|
2017-02-27 10:56:02 +08:00
|
|
|
template <class ELFT> class MipsReginfoSection final : public SyntheticSection {
|
2019-04-01 08:11:24 +08:00
|
|
|
using Elf_Mips_RegInfo = llvm::object::Elf_Mips_RegInfo<ELFT>;
|
2016-11-22 11:57:08 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static MipsReginfoSection *create();
|
|
|
|
|
|
|
|
MipsReginfoSection(Elf_Mips_RegInfo Reginfo);
|
|
|
|
size_t getSize() const override { return sizeof(Elf_Mips_RegInfo); }
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Elf_Mips_RegInfo Reginfo;
|
|
|
|
};
|
|
|
|
|
2016-11-23 01:49:14 +08:00
|
|
|
// This is a MIPS specific section to hold a space within the data segment
|
|
|
|
// of executable file which is pointed to by the DT_MIPS_RLD_MAP entry.
|
|
|
|
// See "Dynamic section" in Chapter 5 in the following document:
|
|
|
|
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
|
2017-03-15 20:02:31 +08:00
|
|
|
class MipsRldMapSection : public SyntheticSection {
|
2016-11-23 01:49:14 +08:00
|
|
|
public:
|
2016-11-23 03:24:52 +08:00
|
|
|
MipsRldMapSection();
|
2017-03-18 07:29:01 +08:00
|
|
|
size_t getSize() const override { return Config->Wordsize; }
|
2017-05-25 06:04:32 +08:00
|
|
|
void writeTo(uint8_t *Buf) override {}
|
2016-11-23 01:49:14 +08:00
|
|
|
};
|
|
|
|
|
2019-03-28 19:10:20 +08:00
|
|
|
// Representation of the combined .ARM.Exidx input sections. We process these
|
|
|
|
// as a SyntheticSection like .eh_frame as we need to merge duplicate entries
|
|
|
|
// and add terminating sentinel entries.
|
|
|
|
//
|
|
|
|
// The .ARM.exidx input sections after SHF_LINK_ORDER processing is done form
|
|
|
|
// a table that the unwinder can derive (Addresses are encoded as offsets from
|
|
|
|
// table):
|
|
|
|
// | Address of function | Unwind instructions for function |
|
|
|
|
// where the unwind instructions are either a small number of unwind or the
|
|
|
|
// special EXIDX_CANTUNWIND entry representing no unwinding information.
|
|
|
|
// When an exception is thrown from an address A, the unwinder searches the
|
|
|
|
// table for the closest table entry with Address of function <= A. This means
|
|
|
|
// that for two consecutive table entries:
|
|
|
|
// | A1 | U1 |
|
|
|
|
// | A2 | U2 |
|
|
|
|
// The range of addresses described by U1 is [A1, A2)
|
|
|
|
//
|
|
|
|
// There are two cases where we need a linker generated table entry to fixup
|
|
|
|
// the address ranges in the table
|
|
|
|
// Case 1:
|
|
|
|
// - A sentinel entry added with an address higher than all
|
|
|
|
// executable sections. This was needed to work around libunwind bug pr31091.
|
|
|
|
// - After address assignment we need to find the highest addressed executable
|
|
|
|
// section and use the limit of that section so that the unwinder never
|
|
|
|
// matches it.
|
|
|
|
// Case 2:
|
|
|
|
// - InputSections without a .ARM.exidx section (usually from Assembly)
|
|
|
|
// need a table entry so that they terminate the range of the previously
|
|
|
|
// function. This is pr40277.
|
|
|
|
//
|
|
|
|
// Instead of storing pointers to the .ARM.exidx InputSections from
|
|
|
|
// InputObjects, we store pointers to the executable sections that need
|
|
|
|
// .ARM.exidx sections. We can then use the dependentSections of these to
|
|
|
|
// either find the .ARM.exidx section or know that we need to generate one.
|
|
|
|
class ARMExidxSyntheticSection : public SyntheticSection {
|
2016-11-24 19:43:55 +08:00
|
|
|
public:
|
2019-03-28 19:10:20 +08:00
|
|
|
ARMExidxSyntheticSection();
|
2019-04-02 02:01:18 +08:00
|
|
|
|
|
|
|
// Add an input section to the ARMExidxSyntheticSection. Returns whether the
|
|
|
|
// section needs to be removed from the main input section list.
|
|
|
|
bool addSection(InputSection *IS);
|
|
|
|
|
2019-03-28 19:10:20 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
2016-11-24 19:43:55 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override { return !Empty; }
|
2019-03-28 19:10:20 +08:00
|
|
|
// Sort and remove duplicate entries.
|
|
|
|
void finalizeContents() override;
|
|
|
|
InputSection *getLinkOrderDep() const;
|
2017-12-20 16:56:10 +08:00
|
|
|
|
2018-07-11 23:11:13 +08:00
|
|
|
static bool classof(const SectionBase *D);
|
|
|
|
|
2019-03-28 19:10:20 +08:00
|
|
|
// Links to the ARMExidxSections so we can transfer the relocations once the
|
|
|
|
// layout is known.
|
|
|
|
std::vector<InputSection *> ExidxSections;
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t Size;
|
|
|
|
|
|
|
|
// Empty if ExecutableSections contains no dependent .ARM.exidx sections.
|
|
|
|
bool Empty = true;
|
|
|
|
|
|
|
|
// Instead of storing pointers to the .ARM.exidx InputSections from
|
|
|
|
// InputObjects, we store pointers to the executable sections that need
|
|
|
|
// .ARM.exidx sections. We can then use the dependentSections of these to
|
|
|
|
// either find the .ARM.exidx section or know that we need to generate one.
|
|
|
|
std::vector<InputSection *> ExecutableSections;
|
|
|
|
|
|
|
|
// The executable InputSection with the highest address to use for the
|
|
|
|
// sentinel. We store separately from ExecutableSections as merging of
|
|
|
|
// duplicate entries may mean this InputSection is removed from
|
|
|
|
// ExecutableSections.
|
|
|
|
InputSection *Sentinel = nullptr;
|
2016-11-24 19:43:55 +08:00
|
|
|
};
|
|
|
|
|
2017-02-01 18:26:03 +08:00
|
|
|
// A container for one or more linker generated thunks. Instances of these
|
|
|
|
// thunks including ARM interworking and Mips LA25 PI to non-PI thunks.
|
2017-03-16 18:40:50 +08:00
|
|
|
class ThunkSection : public SyntheticSection {
|
2017-02-01 18:26:03 +08:00
|
|
|
public:
|
|
|
|
// ThunkSection in OS, with desired OutSecOff of Off
|
2017-02-24 23:07:30 +08:00
|
|
|
ThunkSection(OutputSection *OS, uint64_t Off);
|
2017-02-01 18:26:03 +08:00
|
|
|
|
|
|
|
// Add a newly created Thunk to this container:
|
|
|
|
// Thunk is given offset from start of this InputSection
|
|
|
|
// Thunk defines a symbol in this InputSection that can be used as target
|
|
|
|
// of a relocation
|
2017-03-16 18:40:50 +08:00
|
|
|
void addThunk(Thunk *T);
|
2017-02-01 18:26:03 +08:00
|
|
|
size_t getSize() const override { return Size; }
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2017-02-24 00:49:07 +08:00
|
|
|
InputSection *getTargetInputSection() const;
|
2018-03-30 06:32:13 +08:00
|
|
|
bool assignOffsets();
|
2017-02-01 18:26:03 +08:00
|
|
|
|
|
|
|
private:
|
2018-03-29 05:33:31 +08:00
|
|
|
std::vector<Thunk *> Thunks;
|
2017-02-01 18:26:03 +08:00
|
|
|
size_t Size = 0;
|
|
|
|
};
|
|
|
|
|
2018-11-15 01:56:43 +08:00
|
|
|
// This section is used to store the addresses of functions that are called
|
|
|
|
// in range-extending thunks on PowerPC64. When producing position dependant
|
|
|
|
// code the addresses are link-time constants and the table is written out to
|
|
|
|
// the binary. When producing position-dependant code the table is allocated and
|
|
|
|
// filled in by the dynamic linker.
|
|
|
|
class PPC64LongBranchTargetSection final : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
PPC64LongBranchTargetSection();
|
|
|
|
void addEntry(Symbol &Sym);
|
|
|
|
size_t getSize() const override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2019-04-01 16:16:08 +08:00
|
|
|
bool isNeeded() const override;
|
2018-11-15 01:56:43 +08:00
|
|
|
void finalizeContents() override { Finalized = true; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<const Symbol *> Entries;
|
|
|
|
bool Finalized = false;
|
|
|
|
};
|
|
|
|
|
2017-02-27 10:32:49 +08:00
|
|
|
InputSection *createInterpSection();
|
2017-12-21 09:21:59 +08:00
|
|
|
MergeInputSection *createCommentSection();
|
2018-04-28 02:17:36 +08:00
|
|
|
template <class ELFT> void splitSections();
|
2017-10-11 11:12:53 +08:00
|
|
|
void mergeSections();
|
2017-05-16 18:11:36 +08:00
|
|
|
|
2018-03-30 06:32:13 +08:00
|
|
|
Defined *addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value,
|
|
|
|
uint64_t Size, InputSectionBase &Section);
|
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.
|
2018-09-26 03:26:58 +08:00
|
|
|
struct InStruct {
|
|
|
|
InputSection *ARMAttributes;
|
2019-03-28 19:10:20 +08:00
|
|
|
ARMExidxSyntheticSection *ARMExidx;
|
2018-09-26 03:26:58 +08:00
|
|
|
BssSection *Bss;
|
|
|
|
BssSection *BssRelRo;
|
|
|
|
BuildIdSection *BuildId;
|
|
|
|
EhFrameHeader *EhFrameHdr;
|
|
|
|
EhFrameSection *EhFrame;
|
|
|
|
SyntheticSection *Dynamic;
|
|
|
|
StringTableSection *DynStrTab;
|
|
|
|
SymbolTableBaseSection *DynSymTab;
|
|
|
|
GnuHashTableSection *GnuHashTab;
|
|
|
|
HashTableSection *HashTab;
|
|
|
|
GotSection *Got;
|
|
|
|
GotPltSection *GotPlt;
|
|
|
|
IgotPltSection *IgotPlt;
|
2018-11-15 01:56:43 +08:00
|
|
|
PPC64LongBranchTargetSection *PPC64LongBranchTarget;
|
2018-09-26 03:26:58 +08:00
|
|
|
MipsGotSection *MipsGot;
|
|
|
|
MipsRldMapSection *MipsRldMap;
|
|
|
|
PltSection *Plt;
|
|
|
|
PltSection *Iplt;
|
|
|
|
RelocationBaseSection *RelaDyn;
|
|
|
|
RelrBaseSection *RelrDyn;
|
|
|
|
RelocationBaseSection *RelaPlt;
|
|
|
|
RelocationBaseSection *RelaIplt;
|
|
|
|
StringTableSection *ShStrTab;
|
|
|
|
StringTableSection *StrTab;
|
|
|
|
SymbolTableBaseSection *SymTab;
|
|
|
|
SymtabShndxSection *SymTabShndx;
|
2018-09-26 04:37:51 +08:00
|
|
|
VersionDefinitionSection *VerDef;
|
2019-03-06 11:07:48 +08:00
|
|
|
VersionNeedBaseSection *VerNeed;
|
|
|
|
VersionTableSection *VerSym;
|
2017-03-15 23:29:29 +08:00
|
|
|
};
|
|
|
|
|
2018-09-26 03:26:58 +08:00
|
|
|
extern InStruct In;
|
|
|
|
|
2016-11-02 04:28:21 +08:00
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|