2015-09-22 05:38:08 +08:00
|
|
|
//===- OutputSections.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_OUTPUT_SECTIONS_H
|
|
|
|
#define LLD_ELF_OUTPUT_SECTIONS_H
|
|
|
|
|
2016-03-14 04:28:29 +08:00
|
|
|
#include "Config.h"
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2016-03-14 04:28:29 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
2016-03-29 22:07:22 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2015-09-22 05:38:08 +08:00
|
|
|
#include "llvm/MC/StringTableBuilder.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
2016-04-08 06:49:21 +08:00
|
|
|
#include "llvm/Support/MD5.h"
|
2016-04-08 07:51:56 +08:00
|
|
|
#include "llvm/Support/SHA1.h"
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
namespace lld {
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
class SymbolBody;
|
2016-05-23 07:16:14 +08:00
|
|
|
struct SectionPiece;
|
2015-10-10 05:07:25 +08:00
|
|
|
template <class ELFT> class SymbolTable;
|
2015-09-22 05:38:08 +08:00
|
|
|
template <class ELFT> class SymbolTableSection;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> class StringTableSection;
|
2015-11-12 03:54:14 +08:00
|
|
|
template <class ELFT> class EHInputSection;
|
2015-09-22 05:38:08 +08:00
|
|
|
template <class ELFT> class InputSection;
|
2015-11-12 03:54:14 +08:00
|
|
|
template <class ELFT> class InputSectionBase;
|
2015-10-20 05:00:02 +08:00
|
|
|
template <class ELFT> class MergeInputSection;
|
2015-12-20 18:57:34 +08:00
|
|
|
template <class ELFT> class MipsReginfoInputSection;
|
2015-09-22 05:38:08 +08:00
|
|
|
template <class ELFT> class OutputSection;
|
|
|
|
template <class ELFT> class ObjectFile;
|
2016-04-28 04:22:31 +08:00
|
|
|
template <class ELFT> class SharedFile;
|
|
|
|
template <class ELFT> class SharedSymbol;
|
2015-09-22 05:38:08 +08:00
|
|
|
template <class ELFT> class DefinedRegular;
|
|
|
|
|
|
|
|
template <class ELFT>
|
2016-03-15 07:16:09 +08:00
|
|
|
static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) {
|
2015-10-20 04:24:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2016-03-15 07:16:09 +08:00
|
|
|
static inline typename ELFT::uint getAddend(const typename ELFT::Rela &Rel) {
|
2015-10-20 04:24:44 +08:00
|
|
|
return Rel.r_addend;
|
|
|
|
}
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2016-02-25 16:40:26 +08:00
|
|
|
bool isValidCIdentifier(StringRef S);
|
|
|
|
|
2015-09-22 08:16:19 +08:00
|
|
|
// This represents a section in an output file.
|
|
|
|
// Different sub classes represent different types of sections. Some contain
|
|
|
|
// input sections, others are created by the linker.
|
|
|
|
// The writer creates multiple OutputSections and assign them unique,
|
2015-09-22 05:38:08 +08:00
|
|
|
// non-overlapping file offsets and VAs.
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> class OutputSectionBase {
|
2015-09-22 05:38:08 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2016-02-18 22:20:08 +08:00
|
|
|
OutputSectionBase(StringRef Name, uint32_t Type, uintX_t Flags);
|
2015-09-22 05:38:08 +08:00
|
|
|
void setVA(uintX_t VA) { Header.sh_addr = VA; }
|
|
|
|
uintX_t getVA() const { return Header.sh_addr; }
|
|
|
|
void setFileOffset(uintX_t Off) { Header.sh_offset = Off; }
|
2016-01-29 09:24:25 +08:00
|
|
|
void setSHName(unsigned Val) { Header.sh_name = Val; }
|
2015-10-16 06:27:29 +08:00
|
|
|
void writeHeaderTo(Elf_Shdr *SHdr);
|
2015-09-22 05:38:08 +08:00
|
|
|
StringRef getName() { return Name; }
|
|
|
|
|
2015-12-26 13:51:07 +08:00
|
|
|
virtual void addSection(InputSectionBase<ELFT> *C) {}
|
|
|
|
|
2015-10-16 04:55:22 +08:00
|
|
|
unsigned SectionIndex;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
// Returns the size of the section in the output file.
|
2015-10-03 03:37:55 +08:00
|
|
|
uintX_t getSize() const { return Header.sh_size; }
|
2015-09-22 05:38:08 +08:00
|
|
|
void setSize(uintX_t Val) { Header.sh_size = Val; }
|
2016-04-11 21:44:05 +08:00
|
|
|
uintX_t getFlags() const { return Header.sh_flags; }
|
|
|
|
uintX_t getFileOff() const { return Header.sh_offset; }
|
|
|
|
uintX_t getAlign() const {
|
2015-09-22 05:38:08 +08:00
|
|
|
// The ELF spec states that a value of 0 means the section has no alignment
|
|
|
|
// constraits.
|
|
|
|
return std::max<uintX_t>(Header.sh_addralign, 1);
|
|
|
|
}
|
2016-04-11 21:44:05 +08:00
|
|
|
uint32_t getType() const { return Header.sh_type; }
|
2015-11-03 22:13:40 +08:00
|
|
|
void updateAlign(uintX_t Align) {
|
|
|
|
if (Align > Header.sh_addralign)
|
|
|
|
Header.sh_addralign = Align;
|
|
|
|
}
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2016-03-31 03:41:51 +08:00
|
|
|
// If true, this section will be page aligned on disk.
|
|
|
|
// Typically the first section of each PT_LOAD segment has this flag.
|
|
|
|
bool PageAlign = false;
|
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
virtual void finalize() {}
|
2016-04-07 22:22:09 +08:00
|
|
|
virtual void
|
|
|
|
forEachInputSection(std::function<void(InputSectionBase<ELFT> *)> F) {}
|
2016-02-11 06:43:13 +08:00
|
|
|
virtual void writeTo(uint8_t *Buf) {}
|
2015-12-26 15:01:26 +08:00
|
|
|
virtual ~OutputSectionBase() = default;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
StringRef Name;
|
2016-04-20 12:26:16 +08:00
|
|
|
Elf_Shdr Header;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> class GotSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef OutputSectionBase<ELFT> Base;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
public:
|
2015-10-08 03:18:16 +08:00
|
|
|
GotSection();
|
2015-11-06 15:43:03 +08:00
|
|
|
void finalize() override;
|
2015-10-07 07:56:53 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-03-11 20:06:30 +08:00
|
|
|
void addEntry(SymbolBody &Sym);
|
|
|
|
bool addDynTlsEntry(SymbolBody &Sym);
|
2016-02-05 08:10:02 +08:00
|
|
|
bool addTlsIndex();
|
2016-01-21 13:33:23 +08:00
|
|
|
bool empty() const { return MipsLocalEntries == 0 && Entries.empty(); }
|
2016-04-20 06:46:03 +08:00
|
|
|
uintX_t getMipsLocalEntryOffset(uintX_t EntryValue);
|
|
|
|
uintX_t getMipsLocalPageOffset(uintX_t Addr);
|
2015-12-02 03:20:26 +08:00
|
|
|
uintX_t getGlobalDynAddr(const SymbolBody &B) const;
|
2016-04-07 23:20:56 +08:00
|
|
|
uintX_t getGlobalDynOffset(const SymbolBody &B) const;
|
2015-12-02 17:58:20 +08:00
|
|
|
uintX_t getNumEntries() const { return Entries.size(); }
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2015-11-12 12:39:49 +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.
|
|
|
|
const SymbolBody *getMipsFirstGlobalEntry() const;
|
|
|
|
|
|
|
|
// Returns the number of entries in the local part of GOT including
|
|
|
|
// the number of reserved entries. This method is MIPS-specific.
|
|
|
|
unsigned getMipsLocalEntriesNum() const;
|
|
|
|
|
2016-02-05 08:10:02 +08:00
|
|
|
uintX_t getTlsIndexVA() { return Base::getVA() + TlsIndexOff; }
|
2016-04-07 23:20:56 +08:00
|
|
|
uint32_t getTlsIndexOff() { return TlsIndexOff; }
|
2015-12-02 02:24:07 +08:00
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
private:
|
|
|
|
std::vector<const SymbolBody *> Entries;
|
2016-02-05 08:10:02 +08:00
|
|
|
uint32_t TlsIndexOff = -1;
|
2016-01-21 13:33:23 +08:00
|
|
|
uint32_t MipsLocalEntries = 0;
|
2016-03-29 22:07:22 +08:00
|
|
|
// Output sections referenced by MIPS GOT relocations.
|
|
|
|
llvm::SmallPtrSet<const OutputSectionBase<ELFT> *, 10> MipsOutSections;
|
2016-01-21 13:33:23 +08:00
|
|
|
llvm::DenseMap<uintX_t, size_t> MipsLocalGotPos;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
2015-10-20 16:54:27 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class GotPltSection final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-10-20 16:54:27 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
GotPltSection();
|
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-03-11 20:06:30 +08:00
|
|
|
void addEntry(SymbolBody &Sym);
|
2015-10-20 16:54:27 +08:00
|
|
|
bool empty() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<const SymbolBody *> Entries;
|
|
|
|
};
|
|
|
|
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> class PltSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef OutputSectionBase<ELFT> Base;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
public:
|
2015-10-08 03:18:16 +08:00
|
|
|
PltSection();
|
2015-10-09 05:51:31 +08:00
|
|
|
void finalize() override;
|
2015-09-22 05:38:08 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-03-11 20:06:30 +08:00
|
|
|
void addEntry(SymbolBody &Sym);
|
2015-09-22 05:38:08 +08:00
|
|
|
bool empty() const { return Entries.empty(); }
|
|
|
|
|
|
|
|
private:
|
2015-11-26 06:15:01 +08:00
|
|
|
std::vector<std::pair<const SymbolBody *, unsigned>> Entries;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> struct DynamicReloc {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-02-05 05:33:05 +08:00
|
|
|
uint32_t Type;
|
|
|
|
|
2016-04-11 21:47:35 +08:00
|
|
|
SymbolBody *Sym;
|
2016-04-11 21:51:23 +08:00
|
|
|
const OutputSectionBase<ELFT> *OffsetSec;
|
2016-04-11 21:47:35 +08:00
|
|
|
uintX_t OffsetInSec;
|
|
|
|
bool UseSymVA;
|
|
|
|
uintX_t Addend;
|
2016-02-05 05:33:05 +08:00
|
|
|
|
2016-04-11 21:51:23 +08:00
|
|
|
DynamicReloc(uint32_t Type, const OutputSectionBase<ELFT> *OffsetSec,
|
2016-02-05 05:33:05 +08:00
|
|
|
uintX_t OffsetInSec, bool UseSymVA, SymbolBody *Sym,
|
|
|
|
uintX_t Addend)
|
2016-04-07 23:20:56 +08:00
|
|
|
: Type(Type), Sym(Sym), OffsetSec(OffsetSec), OffsetInSec(OffsetInSec),
|
|
|
|
UseSymVA(UseSymVA), Addend(Addend) {}
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-10-16 06:27:29 +08:00
|
|
|
class SymbolTableSection final : public OutputSectionBase<ELFT> {
|
2015-09-22 05:38:08 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::SymRange Elf_Sym_Range;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-10-10 05:07:25 +08:00
|
|
|
SymbolTableSection(SymbolTable<ELFT> &Table,
|
2015-10-16 06:27:29 +08:00
|
|
|
StringTableSection<ELFT> &StrTabSec);
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2015-10-08 00:58:54 +08:00
|
|
|
void finalize() override;
|
2015-09-22 05:38:08 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2015-10-21 05:47:58 +08:00
|
|
|
void addSymbol(SymbolBody *Body);
|
2015-10-16 06:27:29 +08:00
|
|
|
StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
|
2016-01-28 00:41:24 +08:00
|
|
|
unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; }
|
2015-09-22 05:38:08 +08:00
|
|
|
|
2016-02-17 13:06:40 +08:00
|
|
|
ArrayRef<std::pair<SymbolBody *, size_t>> getSymbols() const {
|
2016-01-29 09:24:25 +08:00
|
|
|
return Symbols;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned NumLocals = 0;
|
|
|
|
StringTableSection<ELFT> &StrTabSec;
|
2015-10-21 05:47:58 +08:00
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
private:
|
2015-09-30 08:32:10 +08:00
|
|
|
void writeLocalSymbols(uint8_t *&Buf);
|
2015-10-19 16:01:51 +08:00
|
|
|
void writeGlobalSymbols(uint8_t *Buf);
|
2015-09-30 08:32:10 +08:00
|
|
|
|
2016-02-17 12:56:44 +08:00
|
|
|
const OutputSectionBase<ELFT> *getOutputSection(SymbolBody *Sym);
|
2015-10-21 04:52:14 +08:00
|
|
|
|
2015-10-10 05:07:25 +08:00
|
|
|
SymbolTable<ELFT> &Table;
|
2016-02-17 13:06:40 +08:00
|
|
|
|
|
|
|
// A vector of symbols and their string table offsets.
|
|
|
|
std::vector<std::pair<SymbolBody *, size_t>> Symbols;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
2016-04-28 04:22:31 +08:00
|
|
|
// For more information about .gnu.version and .gnu.version_r see:
|
|
|
|
// https://www.akkadia.org/drepper/symbol-versioning
|
|
|
|
|
|
|
|
// 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 .gnu.version_r section.
|
|
|
|
template <class ELFT>
|
|
|
|
class VersionTableSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef typename ELFT::Versym Elf_Versym;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VersionTableSection();
|
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
template <class ELFT>
|
|
|
|
class VersionNeedSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef typename ELFT::Verneed Elf_Verneed;
|
|
|
|
typedef typename ELFT::Vernaux Elf_Vernaux;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// The next available version identifier. Identifiers start at 2 because 0 and
|
|
|
|
// 1 are reserved.
|
|
|
|
unsigned NextIndex = 2;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VersionNeedSection();
|
|
|
|
void addSymbol(SharedSymbol<ELFT> *SS);
|
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
size_t getNeedNum() const { return Needed.size(); }
|
|
|
|
};
|
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
template <class ELFT>
|
2015-10-16 06:27:29 +08:00
|
|
|
class RelocationSection final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
public:
|
2016-05-10 23:47:57 +08:00
|
|
|
RelocationSection(StringRef Name, bool Sort);
|
2016-02-05 23:03:10 +08:00
|
|
|
void addReloc(const DynamicReloc<ELFT> &Reloc);
|
2015-11-26 06:15:01 +08:00
|
|
|
unsigned getRelocOffset();
|
2015-09-22 05:38:08 +08:00
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
bool hasRelocs() const { return !Relocs.empty(); }
|
|
|
|
|
2015-12-21 18:12:06 +08:00
|
|
|
bool Static = false;
|
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
private:
|
2016-05-10 23:47:57 +08:00
|
|
|
bool Sort;
|
2015-09-22 05:38:08 +08:00
|
|
|
std::vector<DynamicReloc<ELFT>> Relocs;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-10-16 06:27:29 +08:00
|
|
|
class OutputSection final : public OutputSectionBase<ELFT> {
|
2015-09-22 05:38:08 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-02-18 22:20:08 +08:00
|
|
|
OutputSection(StringRef Name, uint32_t Type, uintX_t Flags);
|
2015-12-26 13:51:07 +08:00
|
|
|
void addSection(InputSectionBase<ELFT> *C) override;
|
2016-02-12 07:41:38 +08:00
|
|
|
void sortInitFini();
|
|
|
|
void sortCtorsDtors();
|
2015-09-22 05:38:08 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-02-25 16:23:37 +08:00
|
|
|
void finalize() override;
|
2016-04-07 22:22:09 +08:00
|
|
|
void
|
|
|
|
forEachInputSection(std::function<void(InputSectionBase<ELFT> *)> F) override;
|
2015-09-22 08:16:19 +08:00
|
|
|
std::vector<InputSection<ELFT> *> Sections;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
2015-10-20 05:00:02 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class MergeOutputSection final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
|
|
|
public:
|
2016-02-19 22:17:40 +08:00
|
|
|
MergeOutputSection(StringRef Name, uint32_t Type, uintX_t Flags,
|
|
|
|
uintX_t Alignment);
|
2015-12-26 13:51:07 +08:00
|
|
|
void addSection(InputSectionBase<ELFT> *S) override;
|
2015-10-20 05:00:02 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2015-10-25 06:51:01 +08:00
|
|
|
unsigned getOffset(StringRef Val);
|
|
|
|
void finalize() override;
|
2016-05-05 12:10:12 +08:00
|
|
|
bool shouldTailMerge() const;
|
2015-10-20 05:00:02 +08:00
|
|
|
|
|
|
|
private:
|
2016-02-19 22:17:40 +08:00
|
|
|
llvm::StringTableBuilder Builder;
|
2015-10-20 05:00:02 +08:00
|
|
|
};
|
|
|
|
|
2016-05-23 07:16:14 +08:00
|
|
|
struct CieRecord {
|
|
|
|
SectionPiece *Piece = nullptr;
|
|
|
|
std::vector<SectionPiece *> FdePieces;
|
2015-11-12 03:54:14 +08:00
|
|
|
};
|
|
|
|
|
2016-05-23 07:16:14 +08:00
|
|
|
// Output section for .eh_frame.
|
2015-11-12 03:54:14 +08:00
|
|
|
template <class ELFT>
|
2016-05-23 23:07:59 +08:00
|
|
|
class EhOutputSection final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
2016-05-23 23:12:41 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
EhOutputSection();
|
2015-11-12 03:54:14 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-04-07 22:22:09 +08:00
|
|
|
void finalize() override;
|
2016-05-24 00:24:16 +08:00
|
|
|
bool empty() const { return Sections.empty(); }
|
2016-04-07 22:22:09 +08:00
|
|
|
void
|
|
|
|
forEachInputSection(std::function<void(InputSectionBase<ELFT> *)> F) override;
|
2015-11-12 03:54:14 +08:00
|
|
|
|
2016-05-23 07:16:14 +08:00
|
|
|
void addSection(InputSectionBase<ELFT> *S) override;
|
|
|
|
|
2016-05-24 00:30:41 +08:00
|
|
|
size_t NumFdes = 0;
|
|
|
|
|
2016-05-23 07:16:14 +08:00
|
|
|
private:
|
2016-03-13 13:06:50 +08:00
|
|
|
template <class RelTy>
|
2016-04-05 22:47:28 +08:00
|
|
|
void addSectionAux(EHInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels);
|
2015-11-12 03:54:14 +08:00
|
|
|
|
2016-05-23 07:16:14 +08:00
|
|
|
template <class RelTy>
|
2016-05-23 07:52:56 +08:00
|
|
|
CieRecord *addCie(SectionPiece &Piece, EHInputSection<ELFT> *Sec,
|
2016-05-23 07:16:14 +08:00
|
|
|
ArrayRef<RelTy> Rels);
|
|
|
|
|
|
|
|
template <class RelTy>
|
|
|
|
bool isFdeLive(SectionPiece &Piece, EHInputSection<ELFT> *Sec,
|
|
|
|
ArrayRef<RelTy> Rels);
|
2015-11-12 03:54:14 +08:00
|
|
|
|
2016-05-23 11:00:33 +08:00
|
|
|
uintX_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
|
|
|
|
|
2015-11-12 03:54:14 +08:00
|
|
|
std::vector<EHInputSection<ELFT> *> Sections;
|
2016-05-23 07:16:14 +08:00
|
|
|
std::vector<CieRecord *> Cies;
|
|
|
|
|
|
|
|
// CIE records are uniquified by their contents and personality functions.
|
|
|
|
llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;
|
2015-11-12 03:54:14 +08:00
|
|
|
|
2016-04-07 22:22:09 +08:00
|
|
|
bool Finalized = false;
|
2015-11-12 03:54:14 +08:00
|
|
|
};
|
|
|
|
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class InterpSection final : public OutputSectionBase<ELFT> {
|
2015-09-22 05:38:08 +08:00
|
|
|
public:
|
|
|
|
InterpSection();
|
2015-11-04 10:11:57 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class StringTableSection final : public OutputSectionBase<ELFT> {
|
2015-09-22 05:38:08 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-10-21 01:21:35 +08:00
|
|
|
StringTableSection(StringRef Name, bool Dynamic);
|
2016-01-29 09:24:25 +08:00
|
|
|
unsigned addString(StringRef S, bool HashIt = true);
|
2015-09-22 05:38:08 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-01-29 09:24:25 +08:00
|
|
|
unsigned getSize() const { return Size; }
|
2016-01-07 10:35:32 +08:00
|
|
|
void finalize() override { this->Header.sh_size = getSize(); }
|
2015-09-22 05:38:08 +08:00
|
|
|
bool isDynamic() const { return Dynamic; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const bool Dynamic;
|
2016-01-29 09:24:25 +08:00
|
|
|
llvm::DenseMap<StringRef, unsigned> StringMap;
|
2016-01-07 10:35:32 +08:00
|
|
|
std::vector<StringRef> Strings;
|
2016-01-29 09:24:25 +08:00
|
|
|
unsigned Size = 1; // ELF string tables start with a NUL byte, so 1.
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
2015-10-16 06:27:29 +08:00
|
|
|
class HashTableSection final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Word Elf_Word;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
public:
|
2015-10-08 03:18:16 +08:00
|
|
|
HashTableSection();
|
2015-10-08 00:58:54 +08:00
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
|
|
|
|
2015-10-22 16:21:35 +08:00
|
|
|
// Outputs GNU Hash section. For detailed explanation see:
|
|
|
|
// https://blogs.oracle.com/ali/entry/gnu_hash_elf_sections
|
|
|
|
template <class ELFT>
|
|
|
|
class GnuHashTableSection final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Off Elf_Off;
|
|
|
|
typedef typename ELFT::Word Elf_Word;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-10-22 16:21:35 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
GnuHashTableSection();
|
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
|
2015-10-28 15:05:56 +08:00
|
|
|
// Adds symbols to the hash table.
|
|
|
|
// Sorts the input to satisfy GNU hash section requirements.
|
2016-02-17 13:06:40 +08:00
|
|
|
void addSymbols(std::vector<std::pair<SymbolBody *, size_t>> &Symbols);
|
2015-10-22 16:21:35 +08:00
|
|
|
|
|
|
|
private:
|
2015-10-28 15:05:56 +08:00
|
|
|
static unsigned calcNBuckets(unsigned NumHashed);
|
2015-10-22 16:21:35 +08:00
|
|
|
static unsigned calcMaskWords(unsigned NumHashed);
|
|
|
|
|
|
|
|
void writeHeader(uint8_t *&Buf);
|
|
|
|
void writeBloomFilter(uint8_t *&Buf);
|
|
|
|
void writeHashTable(uint8_t *Buf);
|
|
|
|
|
2016-02-17 13:40:03 +08:00
|
|
|
struct SymbolData {
|
2015-10-28 15:05:56 +08:00
|
|
|
SymbolBody *Body;
|
2016-02-17 13:06:40 +08:00
|
|
|
size_t STName;
|
2015-10-28 15:05:56 +08:00
|
|
|
uint32_t Hash;
|
|
|
|
};
|
|
|
|
|
2016-02-17 13:40:03 +08:00
|
|
|
std::vector<SymbolData> Symbols;
|
2015-10-28 15:05:56 +08:00
|
|
|
|
2015-10-22 16:21:35 +08:00
|
|
|
unsigned MaskWords;
|
|
|
|
unsigned NBuckets;
|
|
|
|
unsigned Shift2;
|
|
|
|
};
|
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
template <class ELFT>
|
2015-10-16 06:27:29 +08:00
|
|
|
class DynamicSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef OutputSectionBase<ELFT> Base;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Dyn Elf_Dyn;
|
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-01-26 05:32:04 +08:00
|
|
|
|
2016-02-02 11:11:27 +08:00
|
|
|
// The .dynamic section contains information for the dynamic linker.
|
|
|
|
// The section consists of fixed size entries, which consist of
|
|
|
|
// type and value fields. Value are one of plain integers, symbol
|
|
|
|
// addresses, or section addresses. This struct represents the entry.
|
2016-01-26 05:32:04 +08:00
|
|
|
struct Entry {
|
|
|
|
int32_t Tag;
|
|
|
|
union {
|
|
|
|
OutputSectionBase<ELFT> *OutSec;
|
|
|
|
uint64_t Val;
|
|
|
|
const SymbolBody *Sym;
|
|
|
|
};
|
|
|
|
enum KindT { SecAddr, SymAddr, PlainInt } Kind;
|
|
|
|
Entry(int32_t Tag, OutputSectionBase<ELFT> *OutSec)
|
|
|
|
: Tag(Tag), OutSec(OutSec), Kind(SecAddr) {}
|
|
|
|
Entry(int32_t Tag, uint64_t Val) : Tag(Tag), Val(Val), Kind(PlainInt) {}
|
|
|
|
Entry(int32_t Tag, const SymbolBody *Sym)
|
|
|
|
: Tag(Tag), Sym(Sym), Kind(SymAddr) {}
|
|
|
|
};
|
2016-02-02 11:11:27 +08:00
|
|
|
|
|
|
|
// finalize() fills this vector with the section contents. finalize()
|
|
|
|
// cannot directly create final section contents because when the
|
|
|
|
// function is called, symbol or section addresses are not fixed yet.
|
2016-01-26 05:32:04 +08:00
|
|
|
std::vector<Entry> Entries;
|
2015-09-22 05:38:08 +08:00
|
|
|
|
|
|
|
public:
|
2016-05-17 05:06:31 +08:00
|
|
|
explicit DynamicSection(SymbolTable<ELFT> &SymTab);
|
2015-09-22 05:38:08 +08:00
|
|
|
void finalize() override;
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
|
|
|
|
2015-10-16 06:27:29 +08:00
|
|
|
OutputSectionBase<ELFT> *PreInitArraySec = nullptr;
|
|
|
|
OutputSectionBase<ELFT> *InitArraySec = nullptr;
|
|
|
|
OutputSectionBase<ELFT> *FiniArraySec = nullptr;
|
2015-10-03 03:37:55 +08:00
|
|
|
|
2015-09-22 05:38:08 +08:00
|
|
|
private:
|
2015-10-10 05:07:25 +08:00
|
|
|
SymbolTable<ELFT> &SymTab;
|
2015-09-22 05:38:08 +08:00
|
|
|
};
|
2015-10-08 03:18:16 +08:00
|
|
|
|
2015-12-20 18:57:34 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class MipsReginfoOutputSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MipsReginfoOutputSection();
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-05-04 18:07:38 +08:00
|
|
|
void addSection(InputSectionBase<ELFT> *S) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t GprMask = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
class MipsOptionsOutputSection final : public OutputSectionBase<ELFT> {
|
|
|
|
typedef llvm::object::Elf_Mips_Options<ELFT> Elf_Mips_Options;
|
|
|
|
typedef llvm::object::Elf_Mips_RegInfo<ELFT> Elf_Mips_RegInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MipsOptionsOutputSection();
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2015-12-26 13:51:07 +08:00
|
|
|
void addSection(InputSectionBase<ELFT> *S) override;
|
2015-12-20 18:57:34 +08:00
|
|
|
|
|
|
|
private:
|
2016-01-07 06:42:43 +08:00
|
|
|
uint32_t GprMask = 0;
|
2015-12-20 18:57:34 +08:00
|
|
|
};
|
|
|
|
|
2016-01-15 21:34:52 +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")
|
|
|
|
template <class ELFT>
|
|
|
|
class EhFrameHeader final : public OutputSectionBase<ELFT> {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-01-15 21:34:52 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
EhFrameHeader();
|
2016-05-24 00:30:41 +08:00
|
|
|
void finalize() override;
|
2016-01-15 21:34:52 +08:00
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-05-23 11:00:33 +08:00
|
|
|
void addFde(uint32_t Pc, uint32_t FdeVA);
|
2016-01-15 21:34:52 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct FdeData {
|
2016-05-23 11:00:33 +08:00
|
|
|
uint32_t Pc;
|
|
|
|
uint32_t FdeVA;
|
2016-01-15 21:34:52 +08:00
|
|
|
};
|
|
|
|
|
2016-05-23 11:00:33 +08:00
|
|
|
std::vector<FdeData> Fdes;
|
2016-01-15 21:34:52 +08:00
|
|
|
};
|
|
|
|
|
2016-04-08 06:49:21 +08:00
|
|
|
template <class ELFT> class BuildIdSection : public OutputSectionBase<ELFT> {
|
ELF: Implement --build-id.
This patch implements --build-id. After the linker creates an output file
in the memory buffer, it computes the FNV1 hash of the resulting file
and set the hash to the .note section as a build-id.
GNU ld and gold have the same feature, but their default choice of the
hash function is different. Their default is SHA1.
We made a deliberate choice to not use a secure hash function for the
sake of performance. Computing a secure hash is slow -- for example,
MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that.
As a result, if you pass --build-id to gold, then the linker becomes about
10% slower than that without the option. We observed a similar degradation
in an experimental implementation of build-id for LLD. On the other hand,
we observed only 1-2% performance degradation with the FNV hash.
Since build-id is not for digital certificate or anything, we think that
a very small probability of collision is acceptable.
We considered using other signals such as using input file timestamps as
inputs to a secure hash function. But such signals would have an issue
with build reproducibility (if you build a binary from the same source
tree using the same toolchain, the build id should become the same.)
GNU linkers accepts --build-id=<style> option where style is one of
"MD5", "SHA1", or an arbitrary hex string. That option is out of scope
of this patch.
http://reviews.llvm.org/D18091
llvm-svn: 263292
2016-03-12 04:51:53 +08:00
|
|
|
public:
|
|
|
|
void writeTo(uint8_t *Buf) override;
|
2016-05-03 07:35:59 +08:00
|
|
|
virtual void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) = 0;
|
2016-04-08 06:49:21 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
BuildIdSection(size_t HashSize);
|
|
|
|
size_t HashSize;
|
|
|
|
uint8_t *HashBuf = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> class BuildIdFnv1 final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdFnv1() : BuildIdSection<ELFT>(8) {}
|
2016-05-03 07:35:59 +08:00
|
|
|
void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
|
2016-04-08 06:49:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdMd5() : BuildIdSection<ELFT>(16) {}
|
2016-05-03 07:35:59 +08:00
|
|
|
void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
|
ELF: Implement --build-id.
This patch implements --build-id. After the linker creates an output file
in the memory buffer, it computes the FNV1 hash of the resulting file
and set the hash to the .note section as a build-id.
GNU ld and gold have the same feature, but their default choice of the
hash function is different. Their default is SHA1.
We made a deliberate choice to not use a secure hash function for the
sake of performance. Computing a secure hash is slow -- for example,
MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that.
As a result, if you pass --build-id to gold, then the linker becomes about
10% slower than that without the option. We observed a similar degradation
in an experimental implementation of build-id for LLD. On the other hand,
we observed only 1-2% performance degradation with the FNV hash.
Since build-id is not for digital certificate or anything, we think that
a very small probability of collision is acceptable.
We considered using other signals such as using input file timestamps as
inputs to a secure hash function. But such signals would have an issue
with build reproducibility (if you build a binary from the same source
tree using the same toolchain, the build id should become the same.)
GNU linkers accepts --build-id=<style> option where style is one of
"MD5", "SHA1", or an arbitrary hex string. That option is out of scope
of this patch.
http://reviews.llvm.org/D18091
llvm-svn: 263292
2016-03-12 04:51:53 +08:00
|
|
|
};
|
|
|
|
|
2016-04-08 07:51:56 +08:00
|
|
|
template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdSha1() : BuildIdSection<ELFT>(20) {}
|
2016-05-03 07:35:59 +08:00
|
|
|
void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
|
2016-04-08 07:51:56 +08:00
|
|
|
};
|
|
|
|
|
2016-05-14 05:55:56 +08:00
|
|
|
template <class ELFT>
|
|
|
|
class BuildIdHexstring final : public BuildIdSection<ELFT> {
|
|
|
|
public:
|
|
|
|
BuildIdHexstring();
|
|
|
|
void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
|
|
|
|
};
|
|
|
|
|
2015-10-08 03:18:16 +08:00
|
|
|
// All output sections that are hadnled by the linker specially are
|
|
|
|
// globally accessible. Writer initializes them, so don't use them
|
|
|
|
// until Writer is initialized.
|
|
|
|
template <class ELFT> struct Out {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
|
|
|
typedef typename ELFT::Phdr Elf_Phdr;
|
ELF: Implement --build-id.
This patch implements --build-id. After the linker creates an output file
in the memory buffer, it computes the FNV1 hash of the resulting file
and set the hash to the .note section as a build-id.
GNU ld and gold have the same feature, but their default choice of the
hash function is different. Their default is SHA1.
We made a deliberate choice to not use a secure hash function for the
sake of performance. Computing a secure hash is slow -- for example,
MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that.
As a result, if you pass --build-id to gold, then the linker becomes about
10% slower than that without the option. We observed a similar degradation
in an experimental implementation of build-id for LLD. On the other hand,
we observed only 1-2% performance degradation with the FNV hash.
Since build-id is not for digital certificate or anything, we think that
a very small probability of collision is acceptable.
We considered using other signals such as using input file timestamps as
inputs to a secure hash function. But such signals would have an issue
with build reproducibility (if you build a binary from the same source
tree using the same toolchain, the build id should become the same.)
GNU linkers accepts --build-id=<style> option where style is one of
"MD5", "SHA1", or an arbitrary hex string. That option is out of scope
of this patch.
http://reviews.llvm.org/D18091
llvm-svn: 263292
2016-03-12 04:51:53 +08:00
|
|
|
static BuildIdSection<ELFT> *BuildId;
|
2015-10-08 03:18:16 +08:00
|
|
|
static DynamicSection<ELFT> *Dynamic;
|
2016-01-15 21:34:52 +08:00
|
|
|
static EhFrameHeader<ELFT> *EhFrameHdr;
|
2016-05-24 00:24:16 +08:00
|
|
|
static EhOutputSection<ELFT> *EhFrame;
|
2015-10-22 16:21:35 +08:00
|
|
|
static GnuHashTableSection<ELFT> *GnuHashTab;
|
2015-10-20 16:54:27 +08:00
|
|
|
static GotPltSection<ELFT> *GotPlt;
|
2015-10-08 03:18:16 +08:00
|
|
|
static GotSection<ELFT> *Got;
|
|
|
|
static HashTableSection<ELFT> *HashTab;
|
2015-10-16 06:27:29 +08:00
|
|
|
static InterpSection<ELFT> *Interp;
|
2015-10-08 03:18:16 +08:00
|
|
|
static OutputSection<ELFT> *Bss;
|
2015-11-12 12:39:49 +08:00
|
|
|
static OutputSection<ELFT> *MipsRldMap;
|
2015-10-16 06:27:29 +08:00
|
|
|
static OutputSectionBase<ELFT> *Opd;
|
[ELF2/PPC64] Resolve local-call relocations using the correct function-descriptor values
Under PPC64 ELF v1 ABI, the symbols associated with each function name don't
point directly to the code in the .text section (or similar), but rather to a
function descriptor structure in a special data section named .opd. The
elements in the .opd structure include a pointer to the actual code, and a the
relevant TOC base value. Both of these are themselves set by relocations.
When we have a local call, we need the relevant relocation to refer directly to
the target code, not to the function-descriptor in the .opd section. Only when
we have a .plt stub do we care about the address of the .opd function
descriptor itself.
So we make a few changes here:
1. Always write .opd first, so that its relocated data values are available
for later use when writing the text sections. Record a pointer to the .opd
structure, and its corresponding buffer.
2. When processing a relative branch relocation under ppc64, if the
destination points into the .opd section, read the code pointer out of the
function descriptor structure and use that instead.
This this, I can link, and run, a dynamically-compiled "hello world"
application on big-Endian PPC64/Linux (ELF v1 ABI) using lld.
llvm-svn: 250122
2015-10-13 07:16:53 +08:00
|
|
|
static uint8_t *OpdBuf;
|
2015-10-08 03:18:16 +08:00
|
|
|
static PltSection<ELFT> *Plt;
|
|
|
|
static RelocationSection<ELFT> *RelaDyn;
|
2015-10-20 16:54:27 +08:00
|
|
|
static RelocationSection<ELFT> *RelaPlt;
|
2015-10-16 06:27:29 +08:00
|
|
|
static StringTableSection<ELFT> *DynStrTab;
|
2015-10-21 01:21:35 +08:00
|
|
|
static StringTableSection<ELFT> *ShStrTab;
|
2015-10-16 06:27:29 +08:00
|
|
|
static StringTableSection<ELFT> *StrTab;
|
2015-10-08 03:18:16 +08:00
|
|
|
static SymbolTableSection<ELFT> *DynSymTab;
|
|
|
|
static SymbolTableSection<ELFT> *SymTab;
|
2016-04-28 04:22:31 +08:00
|
|
|
static VersionTableSection<ELFT> *VerSym;
|
|
|
|
static VersionNeedSection<ELFT> *VerNeed;
|
2015-11-07 06:14:44 +08:00
|
|
|
static Elf_Phdr *TlsPhdr;
|
2016-02-11 06:43:13 +08:00
|
|
|
static OutputSectionBase<ELFT> *ElfHeader;
|
|
|
|
static OutputSectionBase<ELFT> *ProgramHeaders;
|
2015-10-08 03:18:16 +08:00
|
|
|
};
|
2015-10-10 03:34:55 +08:00
|
|
|
|
ELF: Implement --build-id.
This patch implements --build-id. After the linker creates an output file
in the memory buffer, it computes the FNV1 hash of the resulting file
and set the hash to the .note section as a build-id.
GNU ld and gold have the same feature, but their default choice of the
hash function is different. Their default is SHA1.
We made a deliberate choice to not use a secure hash function for the
sake of performance. Computing a secure hash is slow -- for example,
MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that.
As a result, if you pass --build-id to gold, then the linker becomes about
10% slower than that without the option. We observed a similar degradation
in an experimental implementation of build-id for LLD. On the other hand,
we observed only 1-2% performance degradation with the FNV hash.
Since build-id is not for digital certificate or anything, we think that
a very small probability of collision is acceptable.
We considered using other signals such as using input file timestamps as
inputs to a secure hash function. But such signals would have an issue
with build reproducibility (if you build a binary from the same source
tree using the same toolchain, the build id should become the same.)
GNU linkers accepts --build-id=<style> option where style is one of
"MD5", "SHA1", or an arbitrary hex string. That option is out of scope
of this patch.
http://reviews.llvm.org/D18091
llvm-svn: 263292
2016-03-12 04:51:53 +08:00
|
|
|
template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
|
2015-10-10 03:34:55 +08:00
|
|
|
template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
|
2016-01-15 21:34:52 +08:00
|
|
|
template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr;
|
2016-05-24 00:24:16 +08:00
|
|
|
template <class ELFT> EhOutputSection<ELFT> *Out<ELFT>::EhFrame;
|
2015-10-22 16:21:35 +08:00
|
|
|
template <class ELFT> GnuHashTableSection<ELFT> *Out<ELFT>::GnuHashTab;
|
2015-10-20 16:54:27 +08:00
|
|
|
template <class ELFT> GotPltSection<ELFT> *Out<ELFT>::GotPlt;
|
2015-10-10 03:34:55 +08:00
|
|
|
template <class ELFT> GotSection<ELFT> *Out<ELFT>::Got;
|
|
|
|
template <class ELFT> HashTableSection<ELFT> *Out<ELFT>::HashTab;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> InterpSection<ELFT> *Out<ELFT>::Interp;
|
2015-11-04 06:01:20 +08:00
|
|
|
template <class ELFT> OutputSection<ELFT> *Out<ELFT>::Bss;
|
2015-11-12 12:39:49 +08:00
|
|
|
template <class ELFT> OutputSection<ELFT> *Out<ELFT>::MipsRldMap;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::Opd;
|
[ELF2/PPC64] Resolve local-call relocations using the correct function-descriptor values
Under PPC64 ELF v1 ABI, the symbols associated with each function name don't
point directly to the code in the .text section (or similar), but rather to a
function descriptor structure in a special data section named .opd. The
elements in the .opd structure include a pointer to the actual code, and a the
relevant TOC base value. Both of these are themselves set by relocations.
When we have a local call, we need the relevant relocation to refer directly to
the target code, not to the function-descriptor in the .opd section. Only when
we have a .plt stub do we care about the address of the .opd function
descriptor itself.
So we make a few changes here:
1. Always write .opd first, so that its relocated data values are available
for later use when writing the text sections. Record a pointer to the .opd
structure, and its corresponding buffer.
2. When processing a relative branch relocation under ppc64, if the
destination points into the .opd section, read the code pointer out of the
function descriptor structure and use that instead.
This this, I can link, and run, a dynamically-compiled "hello world"
application on big-Endian PPC64/Linux (ELF v1 ABI) using lld.
llvm-svn: 250122
2015-10-13 07:16:53 +08:00
|
|
|
template <class ELFT> uint8_t *Out<ELFT>::OpdBuf;
|
2015-10-10 03:34:55 +08:00
|
|
|
template <class ELFT> PltSection<ELFT> *Out<ELFT>::Plt;
|
|
|
|
template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaDyn;
|
2015-10-20 16:54:27 +08:00
|
|
|
template <class ELFT> RelocationSection<ELFT> *Out<ELFT>::RelaPlt;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::DynStrTab;
|
2015-10-21 01:21:35 +08:00
|
|
|
template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::ShStrTab;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
|
2015-10-10 03:34:55 +08:00
|
|
|
template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
|
|
|
|
template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
|
2016-04-28 04:22:31 +08:00
|
|
|
template <class ELFT> VersionTableSection<ELFT> *Out<ELFT>::VerSym;
|
|
|
|
template <class ELFT> VersionNeedSection<ELFT> *Out<ELFT>::VerNeed;
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::Phdr *Out<ELFT>::TlsPhdr;
|
2016-02-11 06:43:13 +08:00
|
|
|
template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ElfHeader;
|
|
|
|
template <class ELFT> OutputSectionBase<ELFT> *Out<ELFT>::ProgramHeaders;
|
2015-11-04 10:11:57 +08:00
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-11-04 10:11:57 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif // LLD_ELF_OUTPUT_SECTIONS_H
|