2016-02-12 05:17:59 +08:00
|
|
|
//===- LinkerScript.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_LINKER_SCRIPT_H
|
|
|
|
#define LLD_ELF_LINKER_SCRIPT_H
|
|
|
|
|
|
|
|
#include "lld/Core/LLVM.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/MapVector.h"
|
2016-02-12 05:38:55 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2016-02-12 05:17:59 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf2 {
|
|
|
|
|
|
|
|
class ScriptParser;
|
2016-02-13 05:47:28 +08:00
|
|
|
template <class ELFT> class InputSectionBase;
|
2016-02-12 05:17:59 +08:00
|
|
|
|
2016-02-13 05:47:28 +08:00
|
|
|
// This class represents each rule in SECTIONS command.
|
|
|
|
class SectionRule {
|
|
|
|
public:
|
2016-02-23 15:47:54 +08:00
|
|
|
SectionRule(StringRef D, StringRef S, bool Keep)
|
|
|
|
: Dest(D), Keep(Keep), SectionPattern(S) {}
|
2016-02-13 05:47:28 +08:00
|
|
|
|
|
|
|
// Returns true if S should be in Dest section.
|
|
|
|
template <class ELFT> bool match(InputSectionBase<ELFT> *S);
|
|
|
|
|
|
|
|
StringRef Dest;
|
|
|
|
|
2016-02-23 15:47:54 +08:00
|
|
|
// KEEP command saves unused sections even if --gc-sections is specified.
|
|
|
|
bool Keep = false;
|
|
|
|
|
2016-02-13 05:47:28 +08:00
|
|
|
private:
|
|
|
|
StringRef SectionPattern;
|
|
|
|
};
|
|
|
|
|
2016-02-26 22:48:31 +08:00
|
|
|
struct OutSection {
|
|
|
|
StringRef Name;
|
|
|
|
std::vector<uint8_t> Filler;
|
|
|
|
};
|
|
|
|
|
2016-02-13 05:47:28 +08:00
|
|
|
// This is a runner of the linker script.
|
2016-02-12 05:17:59 +08:00
|
|
|
class LinkerScript {
|
|
|
|
friend class ScriptParser;
|
|
|
|
|
|
|
|
public:
|
2016-02-12 05:38:55 +08:00
|
|
|
// Parses a linker script. Calling this function may update
|
|
|
|
// this object and Config.
|
|
|
|
void read(MemoryBufferRef MB);
|
|
|
|
|
2016-02-13 05:47:28 +08:00
|
|
|
template <class ELFT> StringRef getOutputSection(InputSectionBase<ELFT> *S);
|
2016-02-26 22:48:31 +08:00
|
|
|
ArrayRef<uint8_t> getFiller(StringRef Name);
|
2016-02-13 05:47:28 +08:00
|
|
|
template <class ELFT> bool isDiscarded(InputSectionBase<ELFT> *S);
|
2016-02-23 15:47:54 +08:00
|
|
|
template <class ELFT> bool shouldKeep(InputSectionBase<ELFT> *S);
|
2016-02-12 05:17:59 +08:00
|
|
|
int compareSections(StringRef A, StringRef B);
|
|
|
|
|
|
|
|
private:
|
2016-02-23 15:47:54 +08:00
|
|
|
template <class ELFT> SectionRule *find(InputSectionBase<ELFT> *S);
|
|
|
|
|
2016-02-13 05:47:28 +08:00
|
|
|
// SECTIONS commands.
|
|
|
|
std::vector<SectionRule> Sections;
|
2016-02-12 05:17:59 +08:00
|
|
|
|
2016-02-26 22:48:31 +08:00
|
|
|
// Output sections information.
|
|
|
|
// They are sorted by the order of the container.
|
|
|
|
std::vector<OutSection> OutSections;
|
2016-02-12 05:38:55 +08:00
|
|
|
|
|
|
|
llvm::BumpPtrAllocator Alloc;
|
2016-02-12 05:17:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern LinkerScript *Script;
|
|
|
|
|
|
|
|
} // namespace elf2
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|