| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 1 | //===- LinkerScript.h -------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLD_ELF_LINKER_SCRIPT_H |
| 11 | #define LLD_ELF_LINKER_SCRIPT_H |
| 12 | |
| George Rimar | be394db | 2016-09-16 20:21:55 +0000 | [diff] [blame] | 13 | #include "Config.h" |
| George Rimar | c91930a | 2016-09-02 21:17:20 +0000 | [diff] [blame] | 14 | #include "Strings.h" |
| Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 15 | #include "Writer.h" |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 16 | #include "lld/Core/LLVM.h" |
| 17 | #include "llvm/ADT/DenseMap.h" |
| Rafael Espindola | d319079 | 2016-09-16 15:10:23 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseSet.h" |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/MapVector.h" |
| Rui Ueyama | f9de0d6 | 2016-02-11 21:38:55 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Allocator.h" |
| 21 | #include "llvm/Support/MemoryBuffer.h" |
| George Rimar | c91930a | 2016-09-02 21:17:20 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Regex.h" |
| Rui Ueyama | 708019c | 2016-07-24 18:19:40 +0000 | [diff] [blame] | 23 | #include <functional> |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 24 | |
| 25 | namespace lld { |
| Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 26 | namespace elf { |
| Rafael Espindola | e7553e4 | 2016-08-31 13:28:33 +0000 | [diff] [blame] | 27 | class DefinedCommon; |
| George Rimar | dbb76db | 2016-08-18 13:00:49 +0000 | [diff] [blame] | 28 | class ScriptParser; |
| Rui Ueyama | 8d083e6 | 2016-07-29 05:48:39 +0000 | [diff] [blame] | 29 | class SymbolBody; |
| Eugene Leviant | e63d81b | 2016-07-20 14:43:20 +0000 | [diff] [blame] | 30 | template <class ELFT> class InputSectionBase; |
| Rafael Espindola | d319079 | 2016-09-16 15:10:23 +0000 | [diff] [blame] | 31 | template <class ELFT> class InputSection; |
| Eugene Leviant | e63d81b | 2016-07-20 14:43:20 +0000 | [diff] [blame] | 32 | template <class ELFT> class OutputSectionBase; |
| 33 | template <class ELFT> class OutputSectionFactory; |
| Eugene Leviant | 97403d1 | 2016-09-01 09:55:57 +0000 | [diff] [blame] | 34 | class InputSectionData; |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 35 | |
| Rui Ueyama | b04af13 | 2016-10-13 23:08:33 +0000 | [diff] [blame] | 36 | // This represents an expression in the linker script. |
| 37 | // ScriptParser::readExpr reads an expression and returns an Expr. |
| 38 | // Later, we evaluate the expression by calling the function |
| 39 | // with the value of special context variable ".". |
| Rafael Espindola | f661393 | 2016-10-31 17:43:38 +0000 | [diff] [blame^] | 40 | struct Expr { |
| 41 | std::function<uint64_t(uint64_t)> Val; |
| 42 | bool IsAbsolute; |
| 43 | uint64_t operator()(uint64_t Dot) const { return Val(Dot); } |
| 44 | operator bool() const { return (bool)Val; } |
| 45 | |
| 46 | template <typename T> |
| 47 | Expr(T Val, bool IsAbsolute) : Val(Val), IsAbsolute(IsAbsolute) {} |
| 48 | template <typename T> Expr(T V) : Expr(V, false) {} |
| 49 | Expr() : Expr(nullptr) {} |
| 50 | }; |
| Rui Ueyama | 708019c | 2016-07-24 18:19:40 +0000 | [diff] [blame] | 51 | |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 52 | // Parses a linker script. Calling this function updates |
| 53 | // Config and ScriptConfig. |
| 54 | void readLinkerScript(MemoryBufferRef MB); |
| 55 | |
| Rui Ueyama | b04af13 | 2016-10-13 23:08:33 +0000 | [diff] [blame] | 56 | // Parses a version script. |
| George Rimar | 20b6598 | 2016-08-31 09:08:26 +0000 | [diff] [blame] | 57 | void readVersionScript(MemoryBufferRef MB); |
| 58 | |
| George Rimar | eea3114 | 2016-07-21 14:26:59 +0000 | [diff] [blame] | 59 | // This enum is used to implement linker script SECTIONS command. |
| 60 | // https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS |
| 61 | enum SectionsCommandKind { |
| George Rimar | e38cbab | 2016-09-26 19:22:50 +0000 | [diff] [blame] | 62 | AssignmentKind, // . = expr or <sym> = expr |
| George Rimar | eea3114 | 2016-07-21 14:26:59 +0000 | [diff] [blame] | 63 | OutputSectionKind, |
| George Rimar | eefa758 | 2016-08-04 09:29:31 +0000 | [diff] [blame] | 64 | InputSectionKind, |
| George Rimar | e38cbab | 2016-09-26 19:22:50 +0000 | [diff] [blame] | 65 | AssertKind, // ASSERT(expr) |
| 66 | BytesDataKind // BYTE(expr), SHORT(expr), LONG(expr) or QUAD(expr) |
| Rui Ueyama | 1ebc8ed | 2016-02-12 21:47:28 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 69 | struct BaseCommand { |
| 70 | BaseCommand(int K) : Kind(K) {} |
| 71 | virtual ~BaseCommand() {} |
| 72 | int Kind; |
| 73 | }; |
| 74 | |
| Rui Ueyama | b04af13 | 2016-10-13 23:08:33 +0000 | [diff] [blame] | 75 | // This represents ". = <expr>" or "<symbol> = <expr>". |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 76 | struct SymbolAssignment : BaseCommand { |
| Rafael Espindola | f661393 | 2016-10-31 17:43:38 +0000 | [diff] [blame^] | 77 | SymbolAssignment(StringRef Name, Expr E) |
| 78 | : BaseCommand(AssignmentKind), Name(Name), Expression(E) {} |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 79 | static bool classof(const BaseCommand *C); |
| Rui Ueyama | 2020424 | 2016-07-29 05:52:33 +0000 | [diff] [blame] | 80 | |
| 81 | // The LHS of an expression. Name is either a symbol name or ".". |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 82 | StringRef Name; |
| Rui Ueyama | 2020424 | 2016-07-29 05:52:33 +0000 | [diff] [blame] | 83 | SymbolBody *Sym = nullptr; |
| 84 | |
| 85 | // The RHS of an expression. |
| Rui Ueyama | 708019c | 2016-07-24 18:19:40 +0000 | [diff] [blame] | 86 | Expr Expression; |
| Rui Ueyama | 2020424 | 2016-07-29 05:52:33 +0000 | [diff] [blame] | 87 | |
| 88 | // Command attributes for PROVIDE, HIDDEN and PROVIDE_HIDDEN. |
| Eugene Leviant | a31c91b | 2016-07-22 07:38:40 +0000 | [diff] [blame] | 89 | bool Provide = false; |
| Eugene Leviant | a31c91b | 2016-07-22 07:38:40 +0000 | [diff] [blame] | 90 | bool Hidden = false; |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| Davide Italiano | 246f681 | 2016-07-22 03:36:24 +0000 | [diff] [blame] | 93 | // Linker scripts allow additional constraints to be put on ouput sections. |
| Rui Ueyama | b04af13 | 2016-10-13 23:08:33 +0000 | [diff] [blame] | 94 | // If an output section is marked as ONLY_IF_RO, the section is created |
| 95 | // only if its input sections are read-only. Likewise, an output section |
| 96 | // with ONLY_IF_RW is created if all input sections are RW. |
| Rui Ueyama | efc4066 | 2016-07-25 22:00:10 +0000 | [diff] [blame] | 97 | enum class ConstraintKind { NoConstraint, ReadOnly, ReadWrite }; |
| Davide Italiano | 246f681 | 2016-07-22 03:36:24 +0000 | [diff] [blame] | 98 | |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 99 | struct OutputSectionCommand : BaseCommand { |
| 100 | OutputSectionCommand(StringRef Name) |
| 101 | : BaseCommand(OutputSectionKind), Name(Name) {} |
| 102 | static bool classof(const BaseCommand *C); |
| Eugene Leviant | eda81a1 | 2016-07-12 06:39:48 +0000 | [diff] [blame] | 103 | StringRef Name; |
| George Rimar | 58e5c4d | 2016-07-25 08:29:46 +0000 | [diff] [blame] | 104 | Expr AddrExpr; |
| George Rimar | 630c617 | 2016-07-26 18:06:29 +0000 | [diff] [blame] | 105 | Expr AlignExpr; |
| Eugene Leviant | b71d6f7 | 2016-10-06 09:39:28 +0000 | [diff] [blame] | 106 | Expr LMAExpr; |
| George Rimar | db24d9c | 2016-08-19 15:18:23 +0000 | [diff] [blame] | 107 | Expr SubalignExpr; |
| George Rimar | eea3114 | 2016-07-21 14:26:59 +0000 | [diff] [blame] | 108 | std::vector<std::unique_ptr<BaseCommand>> Commands; |
| Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 109 | std::vector<StringRef> Phdrs; |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 110 | std::vector<uint8_t> Filler; |
| Rui Ueyama | efc4066 | 2016-07-25 22:00:10 +0000 | [diff] [blame] | 111 | ConstraintKind Constraint = ConstraintKind::NoConstraint; |
| Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| George Rimar | 8034d49 | 2016-09-17 07:31:49 +0000 | [diff] [blame] | 114 | // This struct represents one section match pattern in SECTIONS() command. |
| Rui Ueyama | 4dc07be | 2016-09-17 02:23:40 +0000 | [diff] [blame] | 115 | // It can optionally have negative match pattern for EXCLUDED_FILE command. |
| George Rimar | 07171f2 | 2016-09-21 15:56:44 +0000 | [diff] [blame] | 116 | // Also it may be surrounded with SORT() command, so contains sorting rules. |
| Rui Ueyama | 4dc07be | 2016-09-17 02:23:40 +0000 | [diff] [blame] | 117 | struct SectionPattern { |
| Rui Ueyama | d1d7cfc | 2016-09-20 00:02:06 +0000 | [diff] [blame] | 118 | SectionPattern(llvm::Regex &&Re1, llvm::Regex &&Re2) |
| 119 | : ExcludedFileRe(std::forward<llvm::Regex>(Re1)), |
| 120 | SectionRe(std::forward<llvm::Regex>(Re2)) {} |
| 121 | |
| 122 | SectionPattern(SectionPattern &&Other) { |
| 123 | std::swap(ExcludedFileRe, Other.ExcludedFileRe); |
| 124 | std::swap(SectionRe, Other.SectionRe); |
| George Rimar | 07171f2 | 2016-09-21 15:56:44 +0000 | [diff] [blame] | 125 | std::swap(SortOuter, Other.SortOuter); |
| 126 | std::swap(SortInner, Other.SortInner); |
| Rui Ueyama | d1d7cfc | 2016-09-20 00:02:06 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| Rui Ueyama | 4dc07be | 2016-09-17 02:23:40 +0000 | [diff] [blame] | 129 | llvm::Regex ExcludedFileRe; |
| 130 | llvm::Regex SectionRe; |
| George Rimar | 07171f2 | 2016-09-21 15:56:44 +0000 | [diff] [blame] | 131 | SortSectionPolicy SortOuter; |
| 132 | SortSectionPolicy SortInner; |
| Rui Ueyama | 4dc07be | 2016-09-17 02:23:40 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
| George Rimar | eea3114 | 2016-07-21 14:26:59 +0000 | [diff] [blame] | 135 | struct InputSectionDescription : BaseCommand { |
| George Rimar | c91930a | 2016-09-02 21:17:20 +0000 | [diff] [blame] | 136 | InputSectionDescription(StringRef FilePattern) |
| 137 | : BaseCommand(InputSectionKind), |
| 138 | FileRe(compileGlobPatterns({FilePattern})) {} |
| George Rimar | eea3114 | 2016-07-21 14:26:59 +0000 | [diff] [blame] | 139 | static bool classof(const BaseCommand *C); |
| George Rimar | c91930a | 2016-09-02 21:17:20 +0000 | [diff] [blame] | 140 | llvm::Regex FileRe; |
| Rui Ueyama | 4dc07be | 2016-09-17 02:23:40 +0000 | [diff] [blame] | 141 | |
| George Rimar | 8034d49 | 2016-09-17 07:31:49 +0000 | [diff] [blame] | 142 | // Input sections that matches at least one of SectionPatterns |
| Rui Ueyama | 70efa2f | 2016-09-17 02:34:50 +0000 | [diff] [blame] | 143 | // will be associated with this InputSectionDescription. |
| Rui Ueyama | d1d7cfc | 2016-09-20 00:02:06 +0000 | [diff] [blame] | 144 | std::vector<SectionPattern> SectionPatterns; |
| Rui Ueyama | 4dc07be | 2016-09-17 02:23:40 +0000 | [diff] [blame] | 145 | |
| Rafael Espindola | d319079 | 2016-09-16 15:10:23 +0000 | [diff] [blame] | 146 | std::vector<InputSectionData *> Sections; |
| George Rimar | eea3114 | 2016-07-21 14:26:59 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| Rui Ueyama | b04af13 | 2016-10-13 23:08:33 +0000 | [diff] [blame] | 149 | // Represents an ASSERT(). |
| George Rimar | eefa758 | 2016-08-04 09:29:31 +0000 | [diff] [blame] | 150 | struct AssertCommand : BaseCommand { |
| 151 | AssertCommand(Expr E) : BaseCommand(AssertKind), Expression(E) {} |
| 152 | static bool classof(const BaseCommand *C); |
| 153 | Expr Expression; |
| 154 | }; |
| 155 | |
| Rui Ueyama | b04af13 | 2016-10-13 23:08:33 +0000 | [diff] [blame] | 156 | // Represents BYTE(), SHORT(), LONG(), or QUAD(). |
| George Rimar | e38cbab | 2016-09-26 19:22:50 +0000 | [diff] [blame] | 157 | struct BytesDataCommand : BaseCommand { |
| 158 | BytesDataCommand(uint64_t Data, unsigned Size) |
| 159 | : BaseCommand(BytesDataKind), Data(Data), Size(Size) {} |
| 160 | static bool classof(const BaseCommand *C); |
| 161 | uint64_t Data; |
| 162 | unsigned Offset; |
| 163 | unsigned Size; |
| 164 | }; |
| 165 | |
| Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 166 | struct PhdrsCommand { |
| 167 | StringRef Name; |
| 168 | unsigned Type; |
| 169 | bool HasFilehdr; |
| 170 | bool HasPhdrs; |
| Eugene Leviant | 865bf86 | 2016-07-21 10:43:25 +0000 | [diff] [blame] | 171 | unsigned Flags; |
| Eugene Leviant | 56b21c8 | 2016-09-09 09:46:16 +0000 | [diff] [blame] | 172 | Expr LMAExpr; |
| George Rimar | 652852c | 2016-04-16 10:10:32 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 175 | class LinkerScriptBase { |
| Rafael Espindola | 4d1e4d7 | 2016-09-08 14:11:08 +0000 | [diff] [blame] | 176 | protected: |
| 177 | ~LinkerScriptBase() = default; |
| 178 | |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 179 | public: |
| 180 | virtual uint64_t getOutputSectionAddress(StringRef Name) = 0; |
| 181 | virtual uint64_t getOutputSectionSize(StringRef Name) = 0; |
| Eugene Leviant | 36fac7f | 2016-09-08 09:08:30 +0000 | [diff] [blame] | 182 | virtual uint64_t getOutputSectionAlign(StringRef Name) = 0; |
| Eugene Leviant | b71d6f7 | 2016-10-06 09:39:28 +0000 | [diff] [blame] | 183 | virtual uint64_t getOutputSectionLMA(StringRef Name) = 0; |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 184 | virtual uint64_t getHeaderSize() = 0; |
| 185 | virtual uint64_t getSymbolValue(StringRef S) = 0; |
| George Rimar | f34f45f | 2016-09-23 13:17:23 +0000 | [diff] [blame] | 186 | virtual bool isDefined(StringRef S) = 0; |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 189 | // ScriptConfiguration holds linker script parse results. |
| 190 | struct ScriptConfiguration { |
| George Rimar | 652852c | 2016-04-16 10:10:32 +0000 | [diff] [blame] | 191 | // Used to assign addresses to sections. |
| George Rimar | 076fe15 | 2016-07-21 06:43:01 +0000 | [diff] [blame] | 192 | std::vector<std::unique_ptr<BaseCommand>> Commands; |
| George Rimar | 652852c | 2016-04-16 10:10:32 +0000 | [diff] [blame] | 193 | |
| Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 194 | // Used to assign sections to headers. |
| George Rimar | 70ce0a9 | 2016-07-20 15:09:10 +0000 | [diff] [blame] | 195 | std::vector<PhdrsCommand> PhdrsCommands; |
| 196 | |
| Eugene Leviant | e05336ff | 2016-09-14 08:32:36 +0000 | [diff] [blame] | 197 | bool HasSections = false; |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 198 | |
| Rui Ueyama | 8ec77e6 | 2016-04-21 22:00:51 +0000 | [diff] [blame] | 199 | // List of section patterns specified with KEEP commands. They will |
| 200 | // be kept even if they are unused and --gc-sections is specified. |
| Eugene Leviant | cf43f17 | 2016-10-05 09:36:59 +0000 | [diff] [blame] | 201 | std::vector<InputSectionDescription *> KeptSections; |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 204 | extern ScriptConfiguration *ScriptConfig; |
| 205 | |
| 206 | // This is a runner of the linker script. |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 207 | template <class ELFT> class LinkerScript final : public LinkerScriptBase { |
| Rui Ueyama | 0b3868e | 2016-04-22 20:41:07 +0000 | [diff] [blame] | 208 | typedef typename ELFT::uint uintX_t; |
| 209 | |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 210 | public: |
| Rui Ueyama | f34d0e0 | 2016-08-12 01:24:53 +0000 | [diff] [blame] | 211 | LinkerScript(); |
| 212 | ~LinkerScript(); |
| Eugene Leviant | 20d0319 | 2016-09-16 15:30:47 +0000 | [diff] [blame] | 213 | void processCommands(OutputSectionFactory<ELFT> &Factory); |
| Rafael Espindola | a4b41dc | 2016-08-04 12:13:05 +0000 | [diff] [blame] | 214 | void createSections(OutputSectionFactory<ELFT> &Factory); |
| Rafael Espindola | 9546fff | 2016-09-22 14:40:50 +0000 | [diff] [blame] | 215 | void adjustSectionsBeforeSorting(); |
| Rui Ueyama | a7f7884 | 2016-07-20 17:19:03 +0000 | [diff] [blame] | 216 | |
| Rafael Espindola | a4b41dc | 2016-08-04 12:13:05 +0000 | [diff] [blame] | 217 | std::vector<PhdrEntry<ELFT>> createPhdrs(); |
| Eugene Leviant | f9bc3bd | 2016-08-16 06:40:58 +0000 | [diff] [blame] | 218 | bool ignoreInterpSection(); |
| Rui Ueyama | adca245 | 2016-07-23 14:18:48 +0000 | [diff] [blame] | 219 | |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 220 | ArrayRef<uint8_t> getFiller(StringRef Name); |
| George Rimar | e38cbab | 2016-09-26 19:22:50 +0000 | [diff] [blame] | 221 | void writeDataBytes(StringRef Name, uint8_t *Buf); |
| Eugene Leviant | b71d6f7 | 2016-10-06 09:39:28 +0000 | [diff] [blame] | 222 | bool hasLMA(StringRef Name); |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 223 | bool shouldKeep(InputSectionBase<ELFT> *S); |
| Rafael Espindola | d319079 | 2016-09-16 15:10:23 +0000 | [diff] [blame] | 224 | void assignOffsets(OutputSectionCommand *Cmd); |
| Rafael Espindola | 6d91fce | 2016-09-29 18:50:34 +0000 | [diff] [blame] | 225 | void assignAddresses(std::vector<PhdrEntry<ELFT>> &Phdrs); |
| Eugene Leviant | bbe3860 | 2016-07-19 09:25:43 +0000 | [diff] [blame] | 226 | bool hasPhdrsCommands(); |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 227 | uint64_t getOutputSectionAddress(StringRef Name) override; |
| 228 | uint64_t getOutputSectionSize(StringRef Name) override; |
| Eugene Leviant | 36fac7f | 2016-09-08 09:08:30 +0000 | [diff] [blame] | 229 | uint64_t getOutputSectionAlign(StringRef Name) override; |
| Eugene Leviant | b71d6f7 | 2016-10-06 09:39:28 +0000 | [diff] [blame] | 230 | uint64_t getOutputSectionLMA(StringRef Name) override; |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 231 | uint64_t getHeaderSize() override; |
| 232 | uint64_t getSymbolValue(StringRef S) override; |
| George Rimar | f34f45f | 2016-09-23 13:17:23 +0000 | [diff] [blame] | 233 | bool isDefined(StringRef S) override; |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 234 | |
| Rafael Espindola | a4b41dc | 2016-08-04 12:13:05 +0000 | [diff] [blame] | 235 | std::vector<OutputSectionBase<ELFT> *> *OutputSections; |
| 236 | |
| Rafael Espindola | b6b8f6c | 2016-09-20 22:43:15 +0000 | [diff] [blame] | 237 | int getSectionIndex(StringRef Name); |
| 238 | |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 239 | private: |
| Rafael Espindola | e71a3f8a | 2016-09-16 20:34:02 +0000 | [diff] [blame] | 240 | void computeInputSections(InputSectionDescription *); |
| Rui Ueyama | 6b27481 | 2016-07-25 22:51:07 +0000 | [diff] [blame] | 241 | |
| Eugene Leviant | 20d0319 | 2016-09-16 15:30:47 +0000 | [diff] [blame] | 242 | void addSection(OutputSectionFactory<ELFT> &Factory, |
| 243 | InputSectionBase<ELFT> *Sec, StringRef Name); |
| Rafael Espindola | 7bd3787 | 2016-09-12 16:05:16 +0000 | [diff] [blame] | 244 | void discard(ArrayRef<InputSectionBase<ELFT> *> V); |
| Rui Ueyama | 48c3f1c | 2016-08-12 00:27:23 +0000 | [diff] [blame] | 245 | |
| Rui Ueyama | 0b9ce6a | 2016-08-12 03:16:56 +0000 | [diff] [blame] | 246 | std::vector<InputSectionBase<ELFT> *> |
| 247 | createInputSectionList(OutputSectionCommand &Cmd); |
| 248 | |
| Rui Ueyama | c998a8c | 2016-04-22 00:03:13 +0000 | [diff] [blame] | 249 | // "ScriptConfig" is a bit too long, so define a short name for it. |
| 250 | ScriptConfiguration &Opt = *ScriptConfig; |
| 251 | |
| Rui Ueyama | edebbdf | 2016-07-24 23:47:31 +0000 | [diff] [blame] | 252 | std::vector<size_t> getPhdrIndices(StringRef SectionName); |
| Rui Ueyama | 29c5a2a | 2016-07-26 00:27:36 +0000 | [diff] [blame] | 253 | size_t getPhdrIndex(StringRef PhdrName); |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 254 | |
| Rui Ueyama | 0b3868e | 2016-04-22 20:41:07 +0000 | [diff] [blame] | 255 | uintX_t Dot; |
| Eugene Leviant | b71d6f7 | 2016-10-06 09:39:28 +0000 | [diff] [blame] | 256 | uintX_t LMAOffset = 0; |
| Rafael Espindola | d319079 | 2016-09-16 15:10:23 +0000 | [diff] [blame] | 257 | OutputSectionBase<ELFT> *CurOutSec = nullptr; |
| 258 | uintX_t ThreadBssOffset = 0; |
| 259 | void switchTo(OutputSectionBase<ELFT> *Sec); |
| 260 | void flush(); |
| 261 | void output(InputSection<ELFT> *Sec); |
| 262 | void process(BaseCommand &Base); |
| 263 | llvm::DenseSet<OutputSectionBase<ELFT> *> AlreadyOutputOS; |
| 264 | llvm::DenseSet<InputSectionData *> AlreadyOutputIS; |
| Rui Ueyama | 07320e4 | 2016-04-20 20:13:41 +0000 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | // Variable template is a C++14 feature, so we can't template |
| 268 | // a global variable. Use a struct to workaround. |
| 269 | template <class ELFT> struct Script { static LinkerScript<ELFT> *X; }; |
| 270 | template <class ELFT> LinkerScript<ELFT> *Script<ELFT>::X; |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 271 | |
| George Rimar | 884e786 | 2016-09-08 08:19:13 +0000 | [diff] [blame] | 272 | extern LinkerScriptBase *ScriptBase; |
| 273 | |
| Rafael Espindola | e0df00b | 2016-02-28 00:25:54 +0000 | [diff] [blame] | 274 | } // namespace elf |
| Rui Ueyama | 717677a | 2016-02-11 21:17:59 +0000 | [diff] [blame] | 275 | } // namespace lld |
| 276 | |
| 277 | #endif |