aboutsummaryrefslogtreecommitdiffstats
path: root/ELF/LinkerScript.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:32 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:32 +0000
commitf1e1c239e31b467e17f1648b1f524fc9ab5b431a (patch)
treea855e7a2a8808555da60e6aa9601d6867eb23bac /ELF/LinkerScript.h
parent7d6988fdd2aee0e033034e147f16fe05594a60e4 (diff)
downloadsrc-f1e1c239e31b467e17f1648b1f524fc9ab5b431a.tar.gz
src-f1e1c239e31b467e17f1648b1f524fc9ab5b431a.zip
Vendor import of stripped lld trunk r366426 (just before the release_90vendor/lld/lld-trunk-r366426
Notes
Notes: svn path=/vendor/lld/dist/; revision=351288 svn path=/vendor/lld/lld-trunk-r366426/; revision=351289; tag=vendor/lld/lld-trunk-r366426
Diffstat (limited to 'ELF/LinkerScript.h')
-rw-r--r--ELF/LinkerScript.h222
1 files changed, 110 insertions, 112 deletions
diff --git a/ELF/LinkerScript.h b/ELF/LinkerScript.h
index 51161981efc8..9e9c08ef10ba 100644
--- a/ELF/LinkerScript.h
+++ b/ELF/LinkerScript.h
@@ -1,9 +1,8 @@
//===- LinkerScript.h -------------------------------------------*- C++ -*-===//
//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
@@ -32,7 +31,6 @@ namespace elf {
class Defined;
class InputSection;
class InputSectionBase;
-class InputSectionBase;
class OutputSection;
class SectionBase;
class Symbol;
@@ -40,35 +38,35 @@ class ThunkSection;
// This represents an r-value in the linker script.
struct ExprValue {
- ExprValue(SectionBase *Sec, bool ForceAbsolute, uint64_t Val,
- const Twine &Loc)
- : Sec(Sec), ForceAbsolute(ForceAbsolute), Val(Val), Loc(Loc.str()) {}
+ ExprValue(SectionBase *sec, bool forceAbsolute, uint64_t val,
+ const Twine &loc)
+ : sec(sec), forceAbsolute(forceAbsolute), val(val), loc(loc.str()) {}
- ExprValue(uint64_t Val) : ExprValue(nullptr, false, Val, "") {}
+ ExprValue(uint64_t val) : ExprValue(nullptr, false, val, "") {}
- bool isAbsolute() const { return ForceAbsolute || Sec == nullptr; }
+ bool isAbsolute() const { return forceAbsolute || sec == nullptr; }
uint64_t getValue() const;
uint64_t getSecAddr() const;
uint64_t getSectionOffset() const;
// If a value is relative to a section, it has a non-null Sec.
- SectionBase *Sec;
+ SectionBase *sec;
// True if this expression is enclosed in ABSOLUTE().
// This flag affects the return value of getValue().
- bool ForceAbsolute;
+ bool forceAbsolute;
- uint64_t Val;
- uint64_t Alignment = 1;
+ uint64_t val;
+ uint64_t alignment = 1;
// Original source location. Used for error messages.
- std::string Loc;
+ std::string loc;
};
// This represents an expression in the linker script.
// ScriptParser::readExpr reads an expression and returns an Expr.
// Later, we evaluate the expression by calling the function.
-typedef std::function<ExprValue()> Expr;
+using Expr = std::function<ExprValue()>;
// This enum is used to implement linker script SECTIONS command.
// https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS
@@ -80,42 +78,42 @@ enum SectionsCommandKind {
};
struct BaseCommand {
- BaseCommand(int K) : Kind(K) {}
- int Kind;
+ BaseCommand(int k) : kind(k) {}
+ int kind;
};
// This represents ". = <expr>" or "<symbol> = <expr>".
struct SymbolAssignment : BaseCommand {
- SymbolAssignment(StringRef Name, Expr E, std::string Loc)
- : BaseCommand(AssignmentKind), Name(Name), Expression(E), Location(Loc) {}
+ SymbolAssignment(StringRef name, Expr e, std::string loc)
+ : BaseCommand(AssignmentKind), name(name), expression(e), location(loc) {}
- static bool classof(const BaseCommand *C) {
- return C->Kind == AssignmentKind;
+ static bool classof(const BaseCommand *c) {
+ return c->kind == AssignmentKind;
}
// The LHS of an expression. Name is either a symbol name or ".".
- StringRef Name;
- Defined *Sym = nullptr;
+ StringRef name;
+ Defined *sym = nullptr;
// The RHS of an expression.
- Expr Expression;
+ Expr expression;
// Command attributes for PROVIDE, HIDDEN and PROVIDE_HIDDEN.
- bool Provide = false;
- bool Hidden = false;
+ bool provide = false;
+ bool hidden = false;
// Holds file name and line number for error reporting.
- std::string Location;
+ std::string location;
// A string representation of this command. We use this for -Map.
- std::string CommandString;
+ std::string commandString;
// Address of this assignment command.
- unsigned Addr;
+ unsigned addr;
// Size of this assignment command. This is usually 0, but if
// you move '.' this may be greater than 0.
- unsigned Size;
+ unsigned size;
};
// Linker scripts allow additional constraints to be put on ouput sections.
@@ -128,83 +126,83 @@ enum class ConstraintKind { NoConstraint, ReadOnly, ReadWrite };
// target memory. Instances of the struct are created by parsing the
// MEMORY command.
struct MemoryRegion {
- MemoryRegion(StringRef Name, uint64_t Origin, uint64_t Length, uint32_t Flags,
- uint32_t NegFlags)
- : Name(Name), Origin(Origin), Length(Length), Flags(Flags),
- NegFlags(NegFlags) {}
-
- std::string Name;
- uint64_t Origin;
- uint64_t Length;
- uint32_t Flags;
- uint32_t NegFlags;
- uint64_t CurPos = 0;
+ MemoryRegion(StringRef name, uint64_t origin, uint64_t length, uint32_t flags,
+ uint32_t negFlags)
+ : name(name), origin(origin), length(length), flags(flags),
+ negFlags(negFlags) {}
+
+ std::string name;
+ uint64_t origin;
+ uint64_t length;
+ uint32_t flags;
+ uint32_t negFlags;
+ uint64_t curPos = 0;
};
// This struct represents one section match pattern in SECTIONS() command.
// It can optionally have negative match pattern for EXCLUDED_FILE command.
// Also it may be surrounded with SORT() command, so contains sorting rules.
struct SectionPattern {
- SectionPattern(StringMatcher &&Pat1, StringMatcher &&Pat2)
- : ExcludedFilePat(Pat1), SectionPat(Pat2),
- SortOuter(SortSectionPolicy::Default),
- SortInner(SortSectionPolicy::Default) {}
-
- StringMatcher ExcludedFilePat;
- StringMatcher SectionPat;
- SortSectionPolicy SortOuter;
- SortSectionPolicy SortInner;
+ SectionPattern(StringMatcher &&pat1, StringMatcher &&pat2)
+ : excludedFilePat(pat1), sectionPat(pat2),
+ sortOuter(SortSectionPolicy::Default),
+ sortInner(SortSectionPolicy::Default) {}
+
+ StringMatcher excludedFilePat;
+ StringMatcher sectionPat;
+ SortSectionPolicy sortOuter;
+ SortSectionPolicy sortInner;
};
struct InputSectionDescription : BaseCommand {
- InputSectionDescription(StringRef FilePattern)
- : BaseCommand(InputSectionKind), FilePat(FilePattern) {}
+ InputSectionDescription(StringRef filePattern)
+ : BaseCommand(InputSectionKind), filePat(filePattern) {}
- static bool classof(const BaseCommand *C) {
- return C->Kind == InputSectionKind;
+ static bool classof(const BaseCommand *c) {
+ return c->kind == InputSectionKind;
}
- StringMatcher FilePat;
+ StringMatcher filePat;
// Input sections that matches at least one of SectionPatterns
// will be associated with this InputSectionDescription.
- std::vector<SectionPattern> SectionPatterns;
+ std::vector<SectionPattern> sectionPatterns;
- std::vector<InputSection *> Sections;
+ std::vector<InputSection *> sections;
// Temporary record of synthetic ThunkSection instances and the pass that
// they were created in. This is used to insert newly created ThunkSections
// into Sections at the end of a createThunks() pass.
- std::vector<std::pair<ThunkSection *, uint32_t>> ThunkSections;
+ std::vector<std::pair<ThunkSection *, uint32_t>> thunkSections;
};
// Represents BYTE(), SHORT(), LONG(), or QUAD().
struct ByteCommand : BaseCommand {
- ByteCommand(Expr E, unsigned Size, std::string CommandString)
- : BaseCommand(ByteKind), CommandString(CommandString), Expression(E),
- Size(Size) {}
+ ByteCommand(Expr e, unsigned size, std::string commandString)
+ : BaseCommand(ByteKind), commandString(commandString), expression(e),
+ size(size) {}
- static bool classof(const BaseCommand *C) { return C->Kind == ByteKind; }
+ static bool classof(const BaseCommand *c) { return c->kind == ByteKind; }
// Keeps string representing the command. Used for -Map" is perhaps better.
- std::string CommandString;
+ std::string commandString;
- Expr Expression;
+ Expr expression;
// This is just an offset of this assignment command in the output section.
- unsigned Offset;
+ unsigned offset;
// Size of this data command.
- unsigned Size;
+ unsigned size;
};
struct PhdrsCommand {
- StringRef Name;
- unsigned Type = llvm::ELF::PT_NULL;
- bool HasFilehdr = false;
- bool HasPhdrs = false;
- llvm::Optional<unsigned> Flags;
- Expr LMAExpr = nullptr;
+ StringRef name;
+ unsigned type = llvm::ELF::PT_NULL;
+ bool hasFilehdr = false;
+ bool hasPhdrs = false;
+ llvm::Optional<unsigned> flags;
+ Expr lmaExpr = nullptr;
};
class LinkerScript final {
@@ -213,35 +211,35 @@ class LinkerScript final {
// not be used outside of the scope of a call to the above functions.
struct AddressState {
AddressState();
- uint64_t ThreadBssOffset = 0;
- OutputSection *OutSec = nullptr;
- MemoryRegion *MemRegion = nullptr;
- MemoryRegion *LMARegion = nullptr;
- uint64_t LMAOffset = 0;
+ uint64_t threadBssOffset = 0;
+ OutputSection *outSec = nullptr;
+ MemoryRegion *memRegion = nullptr;
+ MemoryRegion *lmaRegion = nullptr;
+ uint64_t lmaOffset = 0;
};
- llvm::DenseMap<StringRef, OutputSection *> NameToOutputSection;
+ llvm::DenseMap<StringRef, OutputSection *> nameToOutputSection;
- void addSymbol(SymbolAssignment *Cmd);
- void assignSymbol(SymbolAssignment *Cmd, bool InSec);
- void setDot(Expr E, const Twine &Loc, bool InSec);
- void expandOutputSection(uint64_t Size);
- void expandMemoryRegions(uint64_t Size);
+ void addSymbol(SymbolAssignment *cmd);
+ void assignSymbol(SymbolAssignment *cmd, bool inSec);
+ void setDot(Expr e, const Twine &loc, bool inSec);
+ void expandOutputSection(uint64_t size);
+ void expandMemoryRegions(uint64_t size);
std::vector<InputSection *>
computeInputSections(const InputSectionDescription *);
- std::vector<InputSection *> createInputSectionList(OutputSection &Cmd);
+ std::vector<InputSection *> createInputSectionList(OutputSection &cmd);
- std::vector<size_t> getPhdrIndices(OutputSection *Sec);
+ std::vector<size_t> getPhdrIndices(OutputSection *sec);
- MemoryRegion *findMemoryRegion(OutputSection *Sec);
+ MemoryRegion *findMemoryRegion(OutputSection *sec);
- void switchTo(OutputSection *Sec);
- uint64_t advance(uint64_t Size, unsigned Align);
- void output(InputSection *Sec);
+ void switchTo(OutputSection *sec);
+ uint64_t advance(uint64_t size, unsigned align);
+ void output(InputSection *sec);
- void assignOffsets(OutputSection *Sec);
+ void assignOffsets(OutputSection *sec);
// Ctx captures the local AddressState and makes it accessible
// deliberately. This is needed as there are some cases where we cannot just
@@ -249,21 +247,21 @@ class LinkerScript final {
// script parser.
// This should remain a plain pointer as its lifetime is smaller than
// LinkerScript.
- AddressState *Ctx = nullptr;
+ AddressState *ctx = nullptr;
- OutputSection *Aether;
+ OutputSection *aether;
- uint64_t Dot;
+ uint64_t dot;
public:
- OutputSection *createOutputSection(StringRef Name, StringRef Location);
- OutputSection *getOrCreateOutputSection(StringRef Name);
+ OutputSection *createOutputSection(StringRef name, StringRef location);
+ OutputSection *getOrCreateOutputSection(StringRef name);
- bool hasPhdrsCommands() { return !PhdrsCommands.empty(); }
- uint64_t getDot() { return Dot; }
- void discard(ArrayRef<InputSection *> V);
+ bool hasPhdrsCommands() { return !phdrsCommands.empty(); }
+ uint64_t getDot() { return dot; }
+ void discard(ArrayRef<InputSection *> v);
- ExprValue getSymbolValue(StringRef Name, const Twine &Loc);
+ ExprValue getSymbolValue(StringRef name, const Twine &loc);
void addOrphanSections();
void adjustSectionsBeforeSorting();
@@ -272,9 +270,9 @@ public:
std::vector<PhdrEntry *> createPhdrs();
bool needsInterpSection();
- bool shouldKeep(InputSectionBase *S);
+ bool shouldKeep(InputSectionBase *s);
void assignAddresses();
- void allocateHeaders(std::vector<PhdrEntry *> &Phdrs);
+ void allocateHeaders(std::vector<PhdrEntry *> &phdrs);
void processSectionCommands();
void declareSymbols();
@@ -282,31 +280,31 @@ public:
void processInsertCommands();
// SECTIONS command list.
- std::vector<BaseCommand *> SectionCommands;
+ std::vector<BaseCommand *> sectionCommands;
// PHDRS command list.
- std::vector<PhdrsCommand> PhdrsCommands;
+ std::vector<PhdrsCommand> phdrsCommands;
- bool HasSectionsCommand = false;
- bool ErrorOnMissingSection = false;
+ bool hasSectionsCommand = false;
+ bool errorOnMissingSection = false;
// List of section patterns specified with KEEP commands. They will
// be kept even if they are unused and --gc-sections is specified.
- std::vector<InputSectionDescription *> KeptSections;
+ std::vector<InputSectionDescription *> keptSections;
// A map from memory region name to a memory region descriptor.
- llvm::MapVector<llvm::StringRef, MemoryRegion *> MemoryRegions;
+ llvm::MapVector<llvm::StringRef, MemoryRegion *> memoryRegions;
// A list of symbols referenced by the script.
- std::vector<llvm::StringRef> ReferencedSymbols;
+ std::vector<llvm::StringRef> referencedSymbols;
// Used to implement INSERT [AFTER|BEFORE]. Contains commands that need
// to be inserted into SECTIONS commands list.
- llvm::DenseMap<StringRef, std::vector<BaseCommand *>> InsertAfterCommands;
- llvm::DenseMap<StringRef, std::vector<BaseCommand *>> InsertBeforeCommands;
+ llvm::DenseMap<StringRef, std::vector<BaseCommand *>> insertAfterCommands;
+ llvm::DenseMap<StringRef, std::vector<BaseCommand *>> insertBeforeCommands;
};
-extern LinkerScript *Script;
+extern LinkerScript *script;
} // end namespace elf
} // end namespace lld