2016-02-12 05:17:59 +08:00
|
|
|
//===- LinkerScript.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-02-12 05:17:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_LINKER_SCRIPT_H
|
|
|
|
#define LLD_ELF_LINKER_SCRIPT_H
|
|
|
|
|
2016-09-17 04:21:55 +08:00
|
|
|
#include "Config.h"
|
2016-07-19 17:25:43 +08:00
|
|
|
#include "Writer.h"
|
2017-10-03 05:00:41 +08:00
|
|
|
#include "lld/Common/LLVM.h"
|
2018-03-01 01:38:19 +08:00
|
|
|
#include "lld/Common/Strings.h"
|
2016-11-05 09:00:56 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2017-01-24 10:34:00 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2016-09-16 23:10:23 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2017-11-03 19:57:01 +08:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2016-11-05 09:00:56 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-02-12 05:38:55 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2016-11-05 09:00:56 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2016-11-06 06:37:59 +08:00
|
|
|
#include <functional>
|
2016-11-05 09:00:56 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2016-02-12 05:17:59 +08:00
|
|
|
|
|
|
|
namespace lld {
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2016-11-05 09:00:56 +08:00
|
|
|
|
2017-11-06 12:35:31 +08:00
|
|
|
class Defined;
|
2017-02-24 00:49:07 +08:00
|
|
|
class InputSection;
|
2017-02-23 10:32:18 +08:00
|
|
|
class InputSectionBase;
|
2018-10-24 06:37:14 +08:00
|
|
|
class OutputSection;
|
2017-03-10 08:47:33 +08:00
|
|
|
class SectionBase;
|
2018-10-24 06:37:14 +08:00
|
|
|
class Symbol;
|
|
|
|
class ThunkSection;
|
2016-02-12 05:17:59 +08:00
|
|
|
|
2017-10-11 08:01:49 +08:00
|
|
|
// This represents an r-value in the linker script.
|
2017-03-17 21:05:04 +08:00
|
|
|
struct ExprValue {
|
2017-05-30 11:18:28 +08:00
|
|
|
ExprValue(SectionBase *sec, bool forceAbsolute, uint64_t val,
|
2017-06-07 16:54:43 +08:00
|
|
|
const Twine &loc)
|
2017-10-11 08:01:49 +08:00
|
|
|
: sec(sec), forceAbsolute(forceAbsolute), val(val), loc(loc.str()) {}
|
|
|
|
|
|
|
|
ExprValue(uint64_t val) : ExprValue(nullptr, false, val, "") {}
|
|
|
|
|
2017-03-17 21:05:04 +08:00
|
|
|
bool isAbsolute() const { return forceAbsolute || sec == nullptr; }
|
|
|
|
uint64_t getValue() const;
|
2017-03-17 22:55:36 +08:00
|
|
|
uint64_t getSecAddr() const;
|
2017-09-12 08:06:00 +08:00
|
|
|
uint64_t getSectionOffset() const;
|
2017-10-11 08:01:49 +08:00
|
|
|
|
|
|
|
// If a value is relative to a section, it has a non-null Sec.
|
|
|
|
SectionBase *sec;
|
|
|
|
|
|
|
|
// True if this expression is enclosed in ABSOLUTE().
|
|
|
|
// This flag affects the return value of getValue().
|
|
|
|
bool forceAbsolute;
|
|
|
|
|
|
|
|
uint64_t val;
|
|
|
|
uint64_t alignment = 1;
|
|
|
|
|
|
|
|
// Original source location. Used for error messages.
|
|
|
|
std::string loc;
|
2017-03-17 21:05:04 +08:00
|
|
|
};
|
|
|
|
|
2016-10-14 07:08:33 +08:00
|
|
|
// This represents an expression in the linker script.
|
|
|
|
// ScriptParser::readExpr reads an expression and returns an Expr.
|
2017-03-17 21:05:04 +08:00
|
|
|
// Later, we evaluate the expression by calling the function.
|
2019-04-01 08:11:24 +08:00
|
|
|
using Expr = std::function<ExprValue()>;
|
Make readExpr return an Expr object instead of a vector of tokens.
Previously, we handled an expression as a vector of tokens. In other
words, an expression was a vector of uncooked raw StringRefs.
When we need a value of an expression, we used ExprParser to run
the expression.
The separation was needed essentially because parse time is too
early to evaluate an expression. In order to evaluate an expression,
we need to finalize section sizes. Because linker script parsing
is done at very early stage of the linking process, we can't
evaluate expressions while parsing.
The above mechanism worked fairly well, but there were a few
drawbacks.
One thing is that we sometimes have to parse the same expression
more than once in order to find the end of the expression.
In some contexts, linker script expressions have no clear end marker.
So, we needed to recognize balanced expressions and ternary operators.
The other is poor error reporting. Since expressions are parsed
basically twice, and some information that is available at the first
stage is lost in the second stage, it was hard to print out
apprpriate error messages.
This patch fixes the issues with a new approach.
Now the expression parsing is integrated into ScriptParser.
ExprParser class is removed. Expressions are represented as lambdas
instead of vectors of tokens. Lambdas captures information they
need to run themselves when they are created.
In this way, ends of expressions are naturally detected, and
errors are handled in the usual way. This patch also reduces
the amount of code.
Differential Revision: https://reviews.llvm.org/D22728
llvm-svn: 276574
2016-07-25 02:19:40 +08:00
|
|
|
|
2016-07-21 22:26:59 +08:00
|
|
|
// This enum is used to implement linker script SECTIONS command.
|
|
|
|
// https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS
|
|
|
|
enum SectionsCommandKind {
|
2016-09-27 03:22:50 +08:00
|
|
|
AssignmentKind, // . = expr or <sym> = expr
|
2016-07-21 22:26:59 +08:00
|
|
|
OutputSectionKind,
|
2016-08-04 17:29:31 +08:00
|
|
|
InputSectionKind,
|
2017-10-11 12:22:09 +08:00
|
|
|
ByteKind // BYTE(expr), SHORT(expr), LONG(expr) or QUAD(expr)
|
2016-02-13 05:47:28 +08:00
|
|
|
};
|
|
|
|
|
2016-07-21 14:43:01 +08:00
|
|
|
struct BaseCommand {
|
|
|
|
BaseCommand(int k) : kind(k) {}
|
|
|
|
int kind;
|
|
|
|
};
|
2016-04-16 18:10:32 +08:00
|
|
|
|
2016-10-14 07:08:33 +08:00
|
|
|
// This represents ". = <expr>" or "<symbol> = <expr>".
|
2016-07-21 14:43:01 +08:00
|
|
|
struct SymbolAssignment : BaseCommand {
|
2018-04-05 19:25:58 +08:00
|
|
|
SymbolAssignment(StringRef name, Expr e, std::string loc)
|
|
|
|
: BaseCommand(AssignmentKind), name(name), expression(e), location(loc) {}
|
2016-11-05 09:00:56 +08:00
|
|
|
|
2017-10-11 10:20:00 +08:00
|
|
|
static bool classof(const BaseCommand *c) {
|
|
|
|
return c->kind == AssignmentKind;
|
|
|
|
}
|
2016-07-29 13:52:33 +08:00
|
|
|
|
|
|
|
// The LHS of an expression. Name is either a symbol name or ".".
|
2016-07-21 14:43:01 +08:00
|
|
|
StringRef name;
|
2017-11-06 12:35:31 +08:00
|
|
|
Defined *sym = nullptr;
|
2016-07-29 13:52:33 +08:00
|
|
|
|
|
|
|
// The RHS of an expression.
|
Make readExpr return an Expr object instead of a vector of tokens.
Previously, we handled an expression as a vector of tokens. In other
words, an expression was a vector of uncooked raw StringRefs.
When we need a value of an expression, we used ExprParser to run
the expression.
The separation was needed essentially because parse time is too
early to evaluate an expression. In order to evaluate an expression,
we need to finalize section sizes. Because linker script parsing
is done at very early stage of the linking process, we can't
evaluate expressions while parsing.
The above mechanism worked fairly well, but there were a few
drawbacks.
One thing is that we sometimes have to parse the same expression
more than once in order to find the end of the expression.
In some contexts, linker script expressions have no clear end marker.
So, we needed to recognize balanced expressions and ternary operators.
The other is poor error reporting. Since expressions are parsed
basically twice, and some information that is available at the first
stage is lost in the second stage, it was hard to print out
apprpriate error messages.
This patch fixes the issues with a new approach.
Now the expression parsing is integrated into ScriptParser.
ExprParser class is removed. Expressions are represented as lambdas
instead of vectors of tokens. Lambdas captures information they
need to run themselves when they are created.
In this way, ends of expressions are naturally detected, and
errors are handled in the usual way. This patch also reduces
the amount of code.
Differential Revision: https://reviews.llvm.org/D22728
llvm-svn: 276574
2016-07-25 02:19:40 +08:00
|
|
|
Expr expression;
|
2016-07-29 13:52:33 +08:00
|
|
|
|
|
|
|
// Command attributes for PROVIDE, HIDDEN and PROVIDE_HIDDEN.
|
2016-07-22 15:38:40 +08:00
|
|
|
bool provide = false;
|
|
|
|
bool hidden = false;
|
2017-02-21 22:50:38 +08:00
|
|
|
|
2017-02-22 17:13:04 +08:00
|
|
|
// Holds file name and line number for error reporting.
|
2017-02-21 22:50:38 +08:00
|
|
|
std::string location;
|
2018-03-15 17:16:40 +08:00
|
|
|
|
|
|
|
// A string representation of this command. We use this for -Map.
|
|
|
|
std::string commandString;
|
|
|
|
|
2018-04-04 17:39:05 +08:00
|
|
|
// Address of this assignment command.
|
|
|
|
unsigned addr;
|
2018-03-15 17:16:40 +08:00
|
|
|
|
2018-04-04 17:39:05 +08:00
|
|
|
// Size of this assignment command. This is usually 0, but if
|
|
|
|
// you move '.' this may be greater than 0.
|
2018-03-15 17:16:40 +08:00
|
|
|
unsigned size;
|
2016-07-21 14:43:01 +08:00
|
|
|
};
|
|
|
|
|
2019-10-29 09:41:38 +08:00
|
|
|
// Linker scripts allow additional constraints to be put on output sections.
|
2016-10-14 07:08:33 +08:00
|
|
|
// If an output section is marked as ONLY_IF_RO, the section is created
|
|
|
|
// only if its input sections are read-only. Likewise, an output section
|
|
|
|
// with ONLY_IF_RW is created if all input sections are RW.
|
2016-07-26 06:00:10 +08:00
|
|
|
enum class ConstraintKind { NoConstraint, ReadOnly, ReadWrite };
|
2016-07-22 11:36:24 +08:00
|
|
|
|
2017-04-07 05:31:24 +08:00
|
|
|
// This struct is used to represent the location and size of regions of
|
|
|
|
// target memory. Instances of the struct are created by parsing the
|
|
|
|
// MEMORY command.
|
|
|
|
struct MemoryRegion {
|
2020-03-07 03:49:58 +08:00
|
|
|
MemoryRegion(StringRef name, Expr origin, Expr length, uint32_t flags,
|
2018-01-25 10:18:00 +08:00
|
|
|
uint32_t negFlags)
|
2020-01-29 03:23:46 +08:00
|
|
|
: name(std::string(name)), origin(origin), length(length), flags(flags),
|
2018-01-25 10:18:00 +08:00
|
|
|
negFlags(negFlags) {}
|
[Coding style change] Rename variables so that they start with a lowercase letter
This patch is mechanically generated by clang-llvm-rename tool that I wrote
using Clang Refactoring Engine just for creating this patch. You can see the
source code of the tool at https://reviews.llvm.org/D64123. There's no manual
post-processing; you can generate the same patch by re-running the tool against
lld's code base.
Here is the main discussion thread to change the LLVM coding style:
https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html
In the discussion thread, I proposed we use lld as a testbed for variable
naming scheme change, and this patch does that.
I chose to rename variables so that they are in camelCase, just because that
is a minimal change to make variables to start with a lowercase letter.
Note to downstream patch maintainers: if you are maintaining a downstream lld
repo, just rebasing ahead of this commit would cause massive merge conflicts
because this patch essentially changes every line in the lld subdirectory. But
there's a remedy.
clang-llvm-rename tool is a batch tool, so you can rename variables in your
downstream repo with the tool. Given that, here is how to rebase your repo to
a commit after the mass renaming:
1. rebase to the commit just before the mass variable renaming,
2. apply the tool to your downstream repo to mass-rename variables locally, and
3. rebase again to the head.
Most changes made by the tool should be identical for a downstream repo and
for the head, so at the step 3, almost all changes should be merged and
disappear. I'd expect that there would be some lines that you need to merge by
hand, but that shouldn't be too many.
Differential Revision: https://reviews.llvm.org/D64121
llvm-svn: 365595
2019-07-10 13:00:37 +08:00
|
|
|
|
2017-04-07 05:31:24 +08:00
|
|
|
std::string name;
|
2020-03-07 03:49:58 +08:00
|
|
|
Expr origin;
|
|
|
|
Expr length;
|
2017-04-07 05:31:24 +08:00
|
|
|
uint32_t flags;
|
|
|
|
uint32_t negFlags;
|
2018-01-25 10:18:00 +08:00
|
|
|
uint64_t curPos = 0;
|
2017-04-07 05:31:24 +08:00
|
|
|
};
|
|
|
|
|
2016-09-17 15:31:49 +08:00
|
|
|
// This struct represents one section match pattern in SECTIONS() command.
|
2016-09-17 10:23:40 +08:00
|
|
|
// It can optionally have negative match pattern for EXCLUDED_FILE command.
|
2016-09-21 23:56:44 +08:00
|
|
|
// Also it may be surrounded with SORT() command, so contains sorting rules.
|
2016-09-17 10:23:40 +08:00
|
|
|
struct SectionPattern {
|
2016-11-04 01:57:38 +08:00
|
|
|
SectionPattern(StringMatcher &&pat1, StringMatcher &&pat2)
|
2018-12-06 16:34:52 +08:00
|
|
|
: excludedFilePat(pat1), sectionPat(pat2),
|
|
|
|
sortOuter(SortSectionPolicy::Default),
|
|
|
|
sortInner(SortSectionPolicy::Default) {}
|
[Coding style change] Rename variables so that they start with a lowercase letter
This patch is mechanically generated by clang-llvm-rename tool that I wrote
using Clang Refactoring Engine just for creating this patch. You can see the
source code of the tool at https://reviews.llvm.org/D64123. There's no manual
post-processing; you can generate the same patch by re-running the tool against
lld's code base.
Here is the main discussion thread to change the LLVM coding style:
https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html
In the discussion thread, I proposed we use lld as a testbed for variable
naming scheme change, and this patch does that.
I chose to rename variables so that they are in camelCase, just because that
is a minimal change to make variables to start with a lowercase letter.
Note to downstream patch maintainers: if you are maintaining a downstream lld
repo, just rebasing ahead of this commit would cause massive merge conflicts
because this patch essentially changes every line in the lld subdirectory. But
there's a remedy.
clang-llvm-rename tool is a batch tool, so you can rename variables in your
downstream repo with the tool. Given that, here is how to rebase your repo to
a commit after the mass renaming:
1. rebase to the commit just before the mass variable renaming,
2. apply the tool to your downstream repo to mass-rename variables locally, and
3. rebase again to the head.
Most changes made by the tool should be identical for a downstream repo and
for the head, so at the step 3, almost all changes should be merged and
disappear. I'd expect that there would be some lines that you need to merge by
hand, but that shouldn't be too many.
Differential Revision: https://reviews.llvm.org/D64121
llvm-svn: 365595
2019-07-10 13:00:37 +08:00
|
|
|
|
2016-11-04 01:57:38 +08:00
|
|
|
StringMatcher excludedFilePat;
|
|
|
|
StringMatcher sectionPat;
|
2016-09-21 23:56:44 +08:00
|
|
|
SortSectionPolicy sortOuter;
|
|
|
|
SortSectionPolicy sortInner;
|
2016-09-17 10:23:40 +08:00
|
|
|
};
|
|
|
|
|
2016-07-21 22:26:59 +08:00
|
|
|
struct InputSectionDescription : BaseCommand {
|
2020-01-15 17:38:00 +08:00
|
|
|
InputSectionDescription(StringRef filePattern, uint64_t withFlags = 0,
|
|
|
|
uint64_t withoutFlags = 0)
|
|
|
|
: BaseCommand(InputSectionKind), filePat(filePattern),
|
|
|
|
withFlags(withFlags), withoutFlags(withoutFlags) {}
|
2016-11-05 09:00:56 +08:00
|
|
|
|
2017-10-11 10:20:00 +08:00
|
|
|
static bool classof(const BaseCommand *c) {
|
|
|
|
return c->kind == InputSectionKind;
|
|
|
|
}
|
2016-11-05 09:00:56 +08:00
|
|
|
|
[lld/ELF] PR44498: Support input filename in double quote
Summary:
Linker scripts allow filenames to be put in double quotes to prevent
characters in filenames that are part of the linker script syntax from
having their special meaning. Case in point the * wildcard character.
Availability of double quoting filenames also allows to fix a failure in
ELF/linkerscript/filename-spec.s when the path contain a @ which the
lexer consider as a special characters and thus break up a filename
containing it. This may happens under Jenkins which createspath such as
pipeline@2.
To avoid the need for escaping GlobPattern metacharacters in filename
in double quotes, GlobPattern::create is augmented with a new parameter
to request literal matching instead of relying on the presence of a
wildcard character in the pattern.
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: peter.smith, grimar, ruiu, emaste, arichardson, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72517
2020-01-11 00:56:07 +08:00
|
|
|
SingleStringMatcher filePat;
|
2016-09-17 10:23:40 +08:00
|
|
|
|
2016-09-17 15:31:49 +08:00
|
|
|
// Input sections that matches at least one of SectionPatterns
|
2016-09-17 10:34:50 +08:00
|
|
|
// will be associated with this InputSectionDescription.
|
2016-09-20 08:02:06 +08:00
|
|
|
std::vector<SectionPattern> sectionPatterns;
|
2016-09-17 10:23:40 +08:00
|
|
|
|
2019-09-24 19:48:31 +08:00
|
|
|
// Includes InputSections and MergeInputSections. Used temporarily during
|
|
|
|
// assignment of input sections to output sections.
|
|
|
|
std::vector<InputSectionBase *> sectionBases;
|
|
|
|
|
|
|
|
// Used after the finalizeInputSections() pass. MergeInputSections have been
|
|
|
|
// merged into MergeSyntheticSections.
|
2017-05-24 06:47:31 +08:00
|
|
|
std::vector<InputSection *> sections;
|
2017-10-27 16:56:20 +08:00
|
|
|
|
2017-10-27 17:07:10 +08:00
|
|
|
// 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;
|
2020-01-15 17:38:00 +08:00
|
|
|
|
|
|
|
// SectionPatterns can be filtered with the INPUT_SECTION_FLAGS command.
|
|
|
|
uint64_t withFlags;
|
|
|
|
uint64_t withoutFlags;
|
2016-07-21 22:26:59 +08:00
|
|
|
};
|
|
|
|
|
2016-10-14 07:08:33 +08:00
|
|
|
// Represents BYTE(), SHORT(), LONG(), or QUAD().
|
2017-10-11 12:22:09 +08:00
|
|
|
struct ByteCommand : BaseCommand {
|
2018-03-15 17:16:40 +08:00
|
|
|
ByteCommand(Expr e, unsigned size, std::string commandString)
|
2018-03-15 17:40:25 +08:00
|
|
|
: BaseCommand(ByteKind), commandString(commandString), expression(e),
|
2018-03-15 17:24:51 +08:00
|
|
|
size(size) {}
|
2016-11-05 09:00:56 +08:00
|
|
|
|
2017-10-11 12:22:09 +08:00
|
|
|
static bool classof(const BaseCommand *c) { return c->kind == ByteKind; }
|
2016-11-05 09:00:56 +08:00
|
|
|
|
2018-03-15 17:16:40 +08:00
|
|
|
// Keeps string representing the command. Used for -Map" is perhaps better.
|
|
|
|
std::string commandString;
|
|
|
|
|
2016-12-09 07:21:30 +08:00
|
|
|
Expr expression;
|
2018-04-04 17:39:05 +08:00
|
|
|
|
|
|
|
// This is just an offset of this assignment command in the output section.
|
2016-09-27 03:22:50 +08:00
|
|
|
unsigned offset;
|
2018-04-04 17:39:05 +08:00
|
|
|
|
|
|
|
// Size of this data command.
|
2016-09-27 03:22:50 +08:00
|
|
|
unsigned size;
|
|
|
|
};
|
|
|
|
|
2020-02-11 07:58:29 +08:00
|
|
|
struct InsertCommand {
|
|
|
|
OutputSection *os;
|
|
|
|
bool isAfter;
|
|
|
|
StringRef where;
|
|
|
|
};
|
|
|
|
|
2016-07-19 17:25:43 +08:00
|
|
|
struct PhdrsCommand {
|
|
|
|
StringRef name;
|
2017-10-08 11:45:49 +08:00
|
|
|
unsigned type = llvm::ELF::PT_NULL;
|
|
|
|
bool hasFilehdr = false;
|
|
|
|
bool hasPhdrs = false;
|
|
|
|
llvm::Optional<unsigned> flags;
|
|
|
|
Expr lmaExpr = nullptr;
|
2016-04-16 18:10:32 +08:00
|
|
|
};
|
|
|
|
|
2017-05-10 22:45:15 +08:00
|
|
|
class LinkerScript final {
|
2017-10-11 10:28:28 +08:00
|
|
|
// Temporary state used in processSectionCommands() and assignAddresses()
|
2017-07-07 17:11:27 +08:00
|
|
|
// that must be reinitialized for each call to the above functions, and must
|
|
|
|
// not be used outside of the scope of a call to the above functions.
|
|
|
|
struct AddressState {
|
2017-10-11 09:19:33 +08:00
|
|
|
AddressState();
|
2017-07-07 17:11:27 +08:00
|
|
|
uint64_t threadBssOffset = 0;
|
|
|
|
OutputSection *outSec = nullptr;
|
|
|
|
MemoryRegion *memRegion = nullptr;
|
2018-01-26 01:42:03 +08:00
|
|
|
MemoryRegion *lmaRegion = nullptr;
|
2018-01-26 00:43:49 +08:00
|
|
|
uint64_t lmaOffset = 0;
|
2017-07-07 17:11:27 +08:00
|
|
|
};
|
2017-10-11 09:19:33 +08:00
|
|
|
|
2017-07-28 03:22:43 +08:00
|
|
|
llvm::DenseMap<StringRef, OutputSection *> nameToOutputSection;
|
2017-06-01 09:16:50 +08:00
|
|
|
|
2017-10-11 10:28:39 +08:00
|
|
|
void addSymbol(SymbolAssignment *cmd);
|
2017-04-05 11:20:22 +08:00
|
|
|
void assignSymbol(SymbolAssignment *cmd, bool inSec);
|
|
|
|
void setDot(Expr e, const Twine &loc, bool inSec);
|
2018-03-05 18:54:03 +08:00
|
|
|
void expandOutputSection(uint64_t size);
|
2018-03-26 16:58:16 +08:00
|
|
|
void expandMemoryRegions(uint64_t size);
|
2017-03-14 20:03:34 +08:00
|
|
|
|
2019-09-24 19:48:31 +08:00
|
|
|
std::vector<InputSectionBase *>
|
2018-01-31 00:20:08 +08:00
|
|
|
computeInputSections(const InputSectionDescription *);
|
2017-04-05 10:05:48 +08:00
|
|
|
|
2019-09-24 19:48:31 +08:00
|
|
|
std::vector<InputSectionBase *> createInputSectionList(OutputSection &cmd);
|
2017-03-14 20:03:34 +08:00
|
|
|
|
2017-07-28 03:22:43 +08:00
|
|
|
std::vector<size_t> getPhdrIndices(OutputSection *sec);
|
2017-03-14 20:03:34 +08:00
|
|
|
|
2017-07-28 03:22:43 +08:00
|
|
|
MemoryRegion *findMemoryRegion(OutputSection *sec);
|
2017-03-14 20:03:34 +08:00
|
|
|
|
|
|
|
void switchTo(OutputSection *sec);
|
2017-05-04 11:00:27 +08:00
|
|
|
uint64_t advance(uint64_t size, unsigned align);
|
2017-03-14 20:03:34 +08:00
|
|
|
void output(InputSection *sec);
|
|
|
|
|
2017-10-18 20:09:41 +08:00
|
|
|
void assignOffsets(OutputSection *sec);
|
|
|
|
|
2017-10-24 05:12:19 +08:00
|
|
|
// Ctx captures the local AddressState and makes it accessible
|
|
|
|
// deliberately. This is needed as there are some cases where we cannot just
|
|
|
|
// thread the current state through to a lambda function created by the
|
|
|
|
// script parser.
|
|
|
|
// This should remain a plain pointer as its lifetime is smaller than
|
|
|
|
// LinkerScript.
|
|
|
|
AddressState *ctx = nullptr;
|
|
|
|
|
2017-03-14 17:03:53 +08:00
|
|
|
OutputSection *aether;
|
|
|
|
|
2017-03-17 05:50:30 +08:00
|
|
|
uint64_t dot;
|
2017-03-14 20:03:34 +08:00
|
|
|
|
2017-03-14 17:03:53 +08:00
|
|
|
public:
|
2017-07-28 03:22:43 +08:00
|
|
|
OutputSection *createOutputSection(StringRef name, StringRef location);
|
|
|
|
OutputSection *getOrCreateOutputSection(StringRef name);
|
2017-06-01 09:16:50 +08:00
|
|
|
|
2017-10-11 09:19:33 +08:00
|
|
|
bool hasPhdrsCommands() { return !phdrsCommands.empty(); }
|
2017-03-17 05:50:30 +08:00
|
|
|
uint64_t getDot() { return dot; }
|
2019-09-24 19:48:31 +08:00
|
|
|
void discard(InputSectionBase *s);
|
2017-03-14 17:03:53 +08:00
|
|
|
|
2017-10-11 12:34:34 +08:00
|
|
|
ExprValue getSymbolValue(StringRef name, const Twine &loc);
|
2017-03-14 18:15:53 +08:00
|
|
|
|
2017-11-05 07:54:25 +08:00
|
|
|
void addOrphanSections();
|
2020-02-26 07:02:04 +08:00
|
|
|
void diagnoseOrphanHandling() const;
|
2016-09-22 22:40:50 +08:00
|
|
|
void adjustSectionsBeforeSorting();
|
2016-11-14 23:39:38 +08:00
|
|
|
void adjustSectionsAfterSorting();
|
2016-07-21 01:19:03 +08:00
|
|
|
|
2017-07-27 15:46:50 +08:00
|
|
|
std::vector<PhdrEntry *> createPhdrs();
|
2017-10-08 11:52:15 +08:00
|
|
|
bool needsInterpSection();
|
2016-07-23 22:18:48 +08:00
|
|
|
|
2017-02-23 10:28:28 +08:00
|
|
|
bool shouldKeep(InputSectionBase *s);
|
2019-08-26 18:23:31 +08:00
|
|
|
const Defined *assignAddresses();
|
2018-01-31 01:24:28 +08:00
|
|
|
void allocateHeaders(std::vector<PhdrEntry *> &phdrs);
|
|
|
|
void processSectionCommands();
|
2019-09-06 23:57:24 +08:00
|
|
|
void processSymbolAssignments();
|
2018-01-31 01:24:28 +08:00
|
|
|
void declareSymbols();
|
|
|
|
|
2018-03-08 22:54:38 +08:00
|
|
|
// Used to handle INSERT AFTER statements.
|
|
|
|
void processInsertCommands();
|
|
|
|
|
2018-01-31 01:24:28 +08:00
|
|
|
// SECTIONS command list.
|
|
|
|
std::vector<BaseCommand *> sectionCommands;
|
2017-10-11 09:19:33 +08:00
|
|
|
|
|
|
|
// PHDRS command list.
|
|
|
|
std::vector<PhdrsCommand> phdrsCommands;
|
|
|
|
|
2017-10-11 09:34:51 +08:00
|
|
|
bool hasSectionsCommand = false;
|
2017-10-11 10:28:39 +08:00
|
|
|
bool errorOnMissingSection = false;
|
2017-10-11 09:19:33 +08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// A map from memory region name to a memory region descriptor.
|
2017-11-03 16:21:51 +08:00
|
|
|
llvm::MapVector<llvm::StringRef, MemoryRegion *> memoryRegions;
|
2017-10-11 09:19:33 +08:00
|
|
|
|
|
|
|
// A list of symbols referenced by the script.
|
|
|
|
std::vector<llvm::StringRef> referencedSymbols;
|
2018-03-08 22:54:38 +08:00
|
|
|
|
2020-02-11 07:58:29 +08:00
|
|
|
// Used to implement INSERT [AFTER|BEFORE]. Contains output sections that need
|
|
|
|
// to be reordered.
|
|
|
|
std::vector<InsertCommand> insertCommands;
|
2020-02-18 05:56:01 +08:00
|
|
|
|
2020-02-26 07:02:04 +08:00
|
|
|
// Sections that will be warned/errored by --orphan-handling.
|
|
|
|
std::vector<const InputSectionBase *> orphanSections;
|
2016-04-21 04:13:41 +08:00
|
|
|
};
|
|
|
|
|
2017-03-22 07:02:51 +08:00
|
|
|
extern LinkerScript *script;
|
2016-09-08 16:19:13 +08:00
|
|
|
|
2016-11-05 09:00:56 +08:00
|
|
|
} // end namespace elf
|
|
|
|
} // end namespace lld
|
2016-02-12 05:17:59 +08:00
|
|
|
|
2016-11-05 09:00:56 +08:00
|
|
|
#endif // LLD_ELF_LINKER_SCRIPT_H
|