blob: a846797e5a8bc82419a2a5d5cf4c9bea544adf39 [file] [log] [blame]
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +00001//===- LinkerScript.cpp ---------------------------------------------------===//
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// This file contains the parser/evaluator of the linker script.
11// It does not construct an AST but consume linker script directives directly.
Rui Ueyama34f29242015-10-13 19:51:57 +000012// Results are written to Driver or Config object.
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000013//
14//===----------------------------------------------------------------------===//
15
Rui Ueyama717677a2016-02-11 21:17:59 +000016#include "LinkerScript.h"
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000017#include "Config.h"
18#include "Driver.h"
Rui Ueyama1ebc8ed2016-02-12 21:47:28 +000019#include "InputSection.h"
George Rimar652852c2016-04-16 10:10:32 +000020#include "OutputSections.h"
Adhemerval Zanellae77b5bf2016-04-06 20:59:11 +000021#include "ScriptParser.h"
Rui Ueyama93c9af42016-06-29 08:01:32 +000022#include "Strings.h"
Eugene Levianteda81a12016-07-12 06:39:48 +000023#include "Symbols.h"
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000024#include "SymbolTable.h"
Eugene Leviant467c4d52016-07-01 10:27:36 +000025#include "Target.h"
Eugene Leviantbbe38602016-07-19 09:25:43 +000026#include "Writer.h"
Rui Ueyama960504b2016-04-19 18:58:11 +000027#include "llvm/ADT/StringSwitch.h"
George Rimar652852c2016-04-16 10:10:32 +000028#include "llvm/Support/ELF.h"
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000029#include "llvm/Support/FileSystem.h"
30#include "llvm/Support/MemoryBuffer.h"
Rui Ueyamaf03f3cc2015-10-13 00:09:21 +000031#include "llvm/Support/Path.h"
Rui Ueyamaa47ee682015-10-11 01:53:04 +000032#include "llvm/Support/StringSaver.h"
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000033
34using namespace llvm;
George Rimar652852c2016-04-16 10:10:32 +000035using namespace llvm::ELF;
Rui Ueyama1ebc8ed2016-02-12 21:47:28 +000036using namespace llvm::object;
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000037using namespace lld;
Rafael Espindolae0df00b2016-02-28 00:25:54 +000038using namespace lld::elf;
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +000039
Rui Ueyama07320e42016-04-20 20:13:41 +000040ScriptConfiguration *elf::ScriptConfig;
Rui Ueyama717677a2016-02-11 21:17:59 +000041
Rui Ueyama9c1112d2016-04-23 00:04:03 +000042// This is an operator-precedence parser to parse and evaluate
43// a linker script expression. For each linker script arithmetic
44// expression (e.g. ". = . + 0x1000"), a new instance of ExprParser
45// is created and ran.
46namespace {
47class ExprParser : public ScriptParserBase {
48public:
49 ExprParser(std::vector<StringRef> &Tokens, uint64_t Dot)
50 : ScriptParserBase(Tokens), Dot(Dot) {}
51
52 uint64_t run();
53
54private:
55 uint64_t parsePrimary();
56 uint64_t parseTernary(uint64_t Cond);
57 uint64_t apply(StringRef Op, uint64_t L, uint64_t R);
58 uint64_t parseExpr1(uint64_t Lhs, int MinPrec);
59 uint64_t parseExpr();
60
61 uint64_t Dot;
62};
63}
64
Rui Ueyama960504b2016-04-19 18:58:11 +000065static int precedence(StringRef Op) {
66 return StringSwitch<int>(Op)
67 .Case("*", 4)
George Rimarab939062016-04-25 08:14:41 +000068 .Case("/", 4)
69 .Case("+", 3)
70 .Case("-", 3)
71 .Case("<", 2)
72 .Case(">", 2)
73 .Case(">=", 2)
74 .Case("<=", 2)
75 .Case("==", 2)
76 .Case("!=", 2)
Rui Ueyama960504b2016-04-19 18:58:11 +000077 .Case("&", 1)
78 .Default(-1);
79}
80
Rui Ueyama9c1112d2016-04-23 00:04:03 +000081static uint64_t evalExpr(std::vector<StringRef> &Tokens, uint64_t Dot) {
82 return ExprParser(Tokens, Dot).run();
Rui Ueyama960504b2016-04-19 18:58:11 +000083}
84
Rui Ueyama9c1112d2016-04-23 00:04:03 +000085uint64_t ExprParser::run() {
86 uint64_t V = parseExpr();
87 if (!atEOF() && !Error)
88 setError("stray token: " + peek());
89 return V;
Rui Ueyama60118112016-04-20 20:54:13 +000090}
91
Rui Ueyama960504b2016-04-19 18:58:11 +000092// This is a part of the operator-precedence parser to evaluate
93// arithmetic expressions in SECTIONS command. This function evaluates an
Rui Ueyamae29a9752016-04-22 21:02:27 +000094// integer literal, a parenthesized expression, the ALIGN function,
95// or the special variable ".".
Rui Ueyama9c1112d2016-04-23 00:04:03 +000096uint64_t ExprParser::parsePrimary() {
97 StringRef Tok = next();
Rui Ueyama960504b2016-04-19 18:58:11 +000098 if (Tok == ".")
99 return Dot;
100 if (Tok == "(") {
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000101 uint64_t V = parseExpr();
102 expect(")");
Rui Ueyama960504b2016-04-19 18:58:11 +0000103 return V;
104 }
George Rimardffc1412016-04-22 11:40:53 +0000105 if (Tok == "ALIGN") {
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000106 expect("(");
107 uint64_t V = parseExpr();
108 expect(")");
George Rimardffc1412016-04-22 11:40:53 +0000109 return alignTo(Dot, V);
110 }
Rui Ueyama5fa60982016-04-22 21:05:04 +0000111 uint64_t V = 0;
112 if (Tok.getAsInteger(0, V))
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000113 setError("malformed number: " + Tok);
Rui Ueyama5fa60982016-04-22 21:05:04 +0000114 return V;
Rui Ueyama960504b2016-04-19 18:58:11 +0000115}
116
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000117uint64_t ExprParser::parseTernary(uint64_t Cond) {
118 next();
119 uint64_t V = parseExpr();
120 expect(":");
121 uint64_t W = parseExpr();
George Rimarfba45c42016-04-22 11:28:54 +0000122 return Cond ? V : W;
123}
124
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000125uint64_t ExprParser::apply(StringRef Op, uint64_t L, uint64_t R) {
Rui Ueyama960504b2016-04-19 18:58:11 +0000126 if (Op == "*")
127 return L * R;
128 if (Op == "/") {
129 if (R == 0) {
130 error("division by zero");
George Rimar652852c2016-04-16 10:10:32 +0000131 return 0;
132 }
Rui Ueyama960504b2016-04-19 18:58:11 +0000133 return L / R;
George Rimar652852c2016-04-16 10:10:32 +0000134 }
George Rimarab939062016-04-25 08:14:41 +0000135 if (Op == "+")
136 return L + R;
137 if (Op == "-")
138 return L - R;
139 if (Op == "<")
140 return L < R;
141 if (Op == ">")
142 return L > R;
143 if (Op == ">=")
144 return L >= R;
145 if (Op == "<=")
146 return L <= R;
147 if (Op == "==")
148 return L == R;
149 if (Op == "!=")
150 return L != R;
Rui Ueyama960504b2016-04-19 18:58:11 +0000151 if (Op == "&")
152 return L & R;
Rui Ueyama7a81d672016-04-19 19:04:03 +0000153 llvm_unreachable("invalid operator");
Rui Ueyama960504b2016-04-19 18:58:11 +0000154}
155
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000156// This is a part of the operator-precedence parser.
157// This function assumes that the remaining token stream starts
158// with an operator.
159uint64_t ExprParser::parseExpr1(uint64_t Lhs, int MinPrec) {
160 while (!atEOF()) {
Rui Ueyama960504b2016-04-19 18:58:11 +0000161 // Read an operator and an expression.
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000162 StringRef Op1 = peek();
George Rimarfba45c42016-04-22 11:28:54 +0000163 if (Op1 == "?")
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000164 return parseTernary(Lhs);
Rui Ueyama960504b2016-04-19 18:58:11 +0000165 if (precedence(Op1) < MinPrec)
166 return Lhs;
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000167 next();
168 uint64_t Rhs = parsePrimary();
Rui Ueyama960504b2016-04-19 18:58:11 +0000169
170 // Evaluate the remaining part of the expression first if the
171 // next operator has greater precedence than the previous one.
172 // For example, if we have read "+" and "3", and if the next
173 // operator is "*", then we'll evaluate 3 * ... part first.
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000174 while (!atEOF()) {
175 StringRef Op2 = peek();
Rui Ueyama960504b2016-04-19 18:58:11 +0000176 if (precedence(Op2) <= precedence(Op1))
177 break;
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000178 Rhs = parseExpr1(Rhs, precedence(Op2));
Rui Ueyama960504b2016-04-19 18:58:11 +0000179 }
180
181 Lhs = apply(Op1, Lhs, Rhs);
182 }
183 return Lhs;
184}
185
Rui Ueyama9c1112d2016-04-23 00:04:03 +0000186// Reads and evaluates an arithmetic expression.
187uint64_t ExprParser::parseExpr() { return parseExpr1(parsePrimary(), 0); }
George Rimar652852c2016-04-16 10:10:32 +0000188
Rui Ueyama1ebc8ed2016-02-12 21:47:28 +0000189template <class ELFT>
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000190StringRef LinkerScript<ELFT>::getOutputSection(InputSectionBase<ELFT> *S) {
Rui Ueyama07320e42016-04-20 20:13:41 +0000191 for (SectionRule &R : Opt.Sections)
Rui Ueyama722830a2016-06-29 05:32:09 +0000192 if (globMatch(R.SectionPattern, S->getSectionName()))
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000193 return R.Dest;
194 return "";
Rui Ueyama717677a2016-02-11 21:17:59 +0000195}
196
Rui Ueyama1ebc8ed2016-02-12 21:47:28 +0000197template <class ELFT>
Rui Ueyama07320e42016-04-20 20:13:41 +0000198bool LinkerScript<ELFT>::isDiscarded(InputSectionBase<ELFT> *S) {
Eugene Leviante63d81b2016-07-20 14:43:20 +0000199 return !S || !S->Live || getOutputSection(S) == "/DISCARD/";
Rui Ueyama717677a2016-02-11 21:17:59 +0000200}
201
Rui Ueyama07320e42016-04-20 20:13:41 +0000202template <class ELFT>
203bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) {
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000204 for (StringRef Pat : Opt.KeptSections)
Rui Ueyama722830a2016-06-29 05:32:09 +0000205 if (globMatch(Pat, S->getSectionName()))
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000206 return true;
207 return false;
George Rimar481c2ce2016-02-23 07:47:54 +0000208}
209
George Rimar652852c2016-04-16 10:10:32 +0000210template <class ELFT>
Rui Ueyamaa7f78842016-07-20 17:19:03 +0000211std::vector<OutputSectionBase<ELFT> *>
Eugene Leviante63d81b2016-07-20 14:43:20 +0000212LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
Rui Ueyamaa7f78842016-07-20 17:19:03 +0000213 std::vector<OutputSectionBase<ELFT> *> Result;
214
Eugene Leviante63d81b2016-07-20 14:43:20 +0000215 // Add input section to output section. If there is no output section yet,
216 // then create it and add to output section list.
217 auto AddInputSec = [&](InputSectionBase<ELFT> *C, StringRef Name) {
218 OutputSectionBase<ELFT> *Sec;
219 bool IsNew;
220 std::tie(Sec, IsNew) = Factory.create(C, Name);
221 if (IsNew)
Rui Ueyamaa7f78842016-07-20 17:19:03 +0000222 Result.push_back(Sec);
Eugene Leviante63d81b2016-07-20 14:43:20 +0000223 Sec->addSection(C);
224 };
225
226 // Select input sections matching rule and add them to corresponding
227 // output section. Section rules are processed in order they're listed
228 // in script, so correct input section order is maintained by design.
229 for (SectionRule &R : Opt.Sections)
230 for (const std::unique_ptr<ObjectFile<ELFT>> &F :
231 Symtab<ELFT>::X->getObjectFiles())
232 for (InputSectionBase<ELFT> *S : F->getSections())
233 if (!isDiscarded(S) && !S->OutSec &&
234 globMatch(R.SectionPattern, S->getSectionName()))
235 // Add single input section to output section.
236 AddInputSec(S, R.Dest);
237
238 // Add all other input sections, which are not listed in script.
239 for (const std::unique_ptr<ObjectFile<ELFT>> &F :
240 Symtab<ELFT>::X->getObjectFiles())
241 for (InputSectionBase<ELFT> *S : F->getSections())
242 if (!isDiscarded(S)) {
243 if (!S->OutSec)
244 AddInputSec(S, getOutputSectionName(S));
245 } else
246 reportDiscarded(S, F);
247
248 return Result;
249}
250
251template <class ELFT>
Rui Ueyama07320e42016-04-20 20:13:41 +0000252void LinkerScript<ELFT>::assignAddresses(
George Rimardbbd8b12016-04-21 11:21:48 +0000253 ArrayRef<OutputSectionBase<ELFT> *> Sections) {
George Rimar652852c2016-04-16 10:10:32 +0000254 // Orphan sections are sections present in the input files which
Rui Ueyama7c18c282016-04-18 21:00:40 +0000255 // are not explicitly placed into the output file by the linker script.
256 // We place orphan sections at end of file.
257 // Other linkers places them using some heuristics as described in
George Rimar652852c2016-04-16 10:10:32 +0000258 // https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections.
Rui Ueyama7c18c282016-04-18 21:00:40 +0000259 for (OutputSectionBase<ELFT> *Sec : Sections) {
George Rimar652852c2016-04-16 10:10:32 +0000260 StringRef Name = Sec->getName();
Rui Ueyamac3e2a4b2016-04-21 20:30:00 +0000261 if (getSectionIndex(Name) == INT_MAX)
Eugene Leviantbbe38602016-07-19 09:25:43 +0000262 Opt.Commands.push_back({SectionKind, {}, Name, {}});
George Rimar652852c2016-04-16 10:10:32 +0000263 }
George Rimar652852c2016-04-16 10:10:32 +0000264
Rui Ueyama7c18c282016-04-18 21:00:40 +0000265 // Assign addresses as instructed by linker script SECTIONS sub-commands.
Rui Ueyama52c4e172016-07-01 10:42:25 +0000266 Dot = Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
Eugene Leviant467c4d52016-07-01 10:27:36 +0000267 uintX_t MinVA = std::numeric_limits<uintX_t>::max();
George Rimar652852c2016-04-16 10:10:32 +0000268 uintX_t ThreadBssOffset = 0;
George Rimar652852c2016-04-16 10:10:32 +0000269
Rui Ueyama07320e42016-04-20 20:13:41 +0000270 for (SectionsCommand &Cmd : Opt.Commands) {
Rui Ueyama05ef4cf2016-07-15 04:19:37 +0000271 if (Cmd.Kind == AssignmentKind) {
272 uint64_t Val = evalExpr(Cmd.Expr, Dot);
273
274 if (Cmd.Name == ".") {
275 Dot = Val;
276 } else {
277 auto *D = cast<DefinedRegular<ELFT>>(Symtab<ELFT>::X->find(Cmd.Name));
278 D->Value = Val;
279 }
George Rimar652852c2016-04-16 10:10:32 +0000280 continue;
281 }
282
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000283 // Find all the sections with required name. There can be more than
George Rimar6ad330a2016-07-19 07:39:07 +0000284 // one section with such name, if the alignment, flags or type
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000285 // attribute differs.
Rui Ueyama05ef4cf2016-07-15 04:19:37 +0000286 assert(Cmd.Kind == SectionKind);
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000287 for (OutputSectionBase<ELFT> *Sec : Sections) {
Eugene Levianteda81a12016-07-12 06:39:48 +0000288 if (Sec->getName() != Cmd.Name)
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000289 continue;
George Rimar652852c2016-04-16 10:10:32 +0000290
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000291 if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
292 uintX_t TVA = Dot + ThreadBssOffset;
Rui Ueyama424b4082016-06-17 01:18:46 +0000293 TVA = alignTo(TVA, Sec->getAlignment());
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000294 Sec->setVA(TVA);
295 ThreadBssOffset = TVA - Dot + Sec->getSize();
296 continue;
297 }
George Rimar652852c2016-04-16 10:10:32 +0000298
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000299 if (Sec->getFlags() & SHF_ALLOC) {
Rui Ueyama424b4082016-06-17 01:18:46 +0000300 Dot = alignTo(Dot, Sec->getAlignment());
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000301 Sec->setVA(Dot);
Rui Ueyama52c4e172016-07-01 10:42:25 +0000302 MinVA = std::min(MinVA, Dot);
Dima Stepanovfb8978f2016-05-19 18:15:54 +0000303 Dot += Sec->getSize();
304 continue;
305 }
George Rimar652852c2016-04-16 10:10:32 +0000306 }
307 }
Rui Ueyama52c4e172016-07-01 10:42:25 +0000308
Rafael Espindola64c32d62016-07-07 14:28:47 +0000309 // ELF and Program headers need to be right before the first section in
George Rimarb91e7112016-07-19 07:42:07 +0000310 // memory. Set their addresses accordingly.
Eugene Leviant467c4d52016-07-01 10:27:36 +0000311 MinVA = alignDown(MinVA - Out<ELFT>::ElfHeader->getSize() -
312 Out<ELFT>::ProgramHeaders->getSize(),
313 Target->PageSize);
314 Out<ELFT>::ElfHeader->setVA(MinVA);
315 Out<ELFT>::ProgramHeaders->setVA(Out<ELFT>::ElfHeader->getSize() + MinVA);
George Rimar652852c2016-04-16 10:10:32 +0000316}
317
Rui Ueyama07320e42016-04-20 20:13:41 +0000318template <class ELFT>
Rafael Espindola74df5c72016-07-19 12:33:46 +0000319std::vector<PhdrEntry<ELFT>>
Eugene Leviantbbe38602016-07-19 09:25:43 +0000320LinkerScript<ELFT>::createPhdrs(ArrayRef<OutputSectionBase<ELFT> *> Sections) {
321 int TlsNum = -1;
322 int NoteNum = -1;
323 int RelroNum = -1;
324 Phdr *Load = nullptr;
325 uintX_t Flags = PF_R;
326 std::vector<Phdr> Phdrs;
327
328 for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
329 Phdrs.emplace_back(Cmd.Type, PF_R);
330 Phdr &Added = Phdrs.back();
331
332 if (Cmd.HasFilehdr)
333 Added.AddSec(Out<ELFT>::ElfHeader);
334 if (Cmd.HasPhdrs)
335 Added.AddSec(Out<ELFT>::ProgramHeaders);
336
337 switch (Cmd.Type) {
338 case PT_INTERP:
339 if (needsInterpSection<ELFT>())
340 Added.AddSec(Out<ELFT>::Interp);
341 break;
342 case PT_DYNAMIC:
343 if (isOutputDynamic<ELFT>()) {
344 Added.H.p_flags = toPhdrFlags(Out<ELFT>::Dynamic->getFlags());
345 Added.AddSec(Out<ELFT>::Dynamic);
346 }
347 break;
348 case PT_TLS:
349 TlsNum = Phdrs.size() - 1;
350 break;
351 case PT_NOTE:
352 NoteNum = Phdrs.size() - 1;
353 break;
354 case PT_GNU_RELRO:
355 RelroNum = Phdrs.size() - 1;
356 break;
357 case PT_GNU_EH_FRAME:
358 if (!Out<ELFT>::EhFrame->empty() && Out<ELFT>::EhFrameHdr) {
359 Added.H.p_flags = toPhdrFlags(Out<ELFT>::EhFrameHdr->getFlags());
360 Added.AddSec(Out<ELFT>::EhFrameHdr);
361 }
362 break;
363 }
364 }
365
366 for (OutputSectionBase<ELFT> *Sec : Sections) {
367 if (!(Sec->getFlags() & SHF_ALLOC))
368 break;
369
370 if (TlsNum != -1 && (Sec->getFlags() & SHF_TLS))
371 Phdrs[TlsNum].AddSec(Sec);
372
373 if (!needsPtLoad<ELFT>(Sec))
374 continue;
375
376 const std::vector<size_t> &PhdrIds =
377 getPhdrIndicesForSection(Sec->getName());
378 if (!PhdrIds.empty()) {
379 // Assign headers specified by linker script
380 for (size_t Id : PhdrIds) {
381 Phdrs[Id].AddSec(Sec);
382 Phdrs[Id].H.p_flags |= toPhdrFlags(Sec->getFlags());
383 }
384 } else {
385 // If we have no load segment or flags've changed then we want new load
386 // segment.
387 uintX_t NewFlags = toPhdrFlags(Sec->getFlags());
388 if (Load == nullptr || Flags != NewFlags) {
389 Load = &*Phdrs.emplace(Phdrs.end(), PT_LOAD, NewFlags);
390 Flags = NewFlags;
391 }
392 Load->AddSec(Sec);
393 }
394
395 if (RelroNum != -1 && isRelroSection(Sec))
396 Phdrs[RelroNum].AddSec(Sec);
397 if (NoteNum != -1 && Sec->getType() == SHT_NOTE)
398 Phdrs[NoteNum].AddSec(Sec);
399 }
400 return Phdrs;
401}
402
403template <class ELFT>
Rui Ueyama07320e42016-04-20 20:13:41 +0000404ArrayRef<uint8_t> LinkerScript<ELFT>::getFiller(StringRef Name) {
405 auto I = Opt.Filler.find(Name);
406 if (I == Opt.Filler.end())
Rui Ueyama3e808972016-02-28 05:09:11 +0000407 return {};
408 return I->second;
George Rimare2ee72b2016-02-26 14:48:31 +0000409}
410
Rui Ueyamac3e2a4b2016-04-21 20:30:00 +0000411// Returns the index of the given section name in linker script
412// SECTIONS commands. Sections are laid out as the same order as they
413// were in the script. If a given name did not appear in the script,
414// it returns INT_MAX, so that it will be laid out at end of file.
George Rimar71b26e92016-04-21 10:22:02 +0000415template <class ELFT>
Rui Ueyamac3e2a4b2016-04-21 20:30:00 +0000416int LinkerScript<ELFT>::getSectionIndex(StringRef Name) {
George Rimar71b26e92016-04-21 10:22:02 +0000417 auto Begin = Opt.Commands.begin();
418 auto End = Opt.Commands.end();
419 auto I = std::find_if(Begin, End, [&](SectionsCommand &N) {
Eugene Levianteda81a12016-07-12 06:39:48 +0000420 return N.Kind == SectionKind && N.Name == Name;
George Rimar71b26e92016-04-21 10:22:02 +0000421 });
Rui Ueyamac3e2a4b2016-04-21 20:30:00 +0000422 return I == End ? INT_MAX : (I - Begin);
George Rimar71b26e92016-04-21 10:22:02 +0000423}
424
425// A compartor to sort output sections. Returns -1 or 1 if
426// A or B are mentioned in linker script. Otherwise, returns 0.
Rui Ueyama07320e42016-04-20 20:13:41 +0000427template <class ELFT>
428int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
Rui Ueyamac3e2a4b2016-04-21 20:30:00 +0000429 int I = getSectionIndex(A);
430 int J = getSectionIndex(B);
431 if (I == INT_MAX && J == INT_MAX)
Rui Ueyama717677a2016-02-11 21:17:59 +0000432 return 0;
433 return I < J ? -1 : 1;
434}
435
Eugene Leviantb0304112016-07-14 09:21:24 +0000436template <class ELFT>
437void LinkerScript<ELFT>::addScriptedSymbols() {
Eugene Levianteda81a12016-07-12 06:39:48 +0000438 for (SectionsCommand &Cmd : Opt.Commands)
Rui Ueyama05ef4cf2016-07-15 04:19:37 +0000439 if (Cmd.Kind == AssignmentKind)
Eugene Leviant0e36f422016-07-15 11:20:04 +0000440 if (Cmd.Name != "." && Symtab<ELFT>::X->find(Cmd.Name) == nullptr)
Rui Ueyama05ef4cf2016-07-15 04:19:37 +0000441 Symtab<ELFT>::X->addAbsolute(Cmd.Name, STV_DEFAULT);
Eugene Levianteda81a12016-07-12 06:39:48 +0000442}
443
Eugene Leviantbbe38602016-07-19 09:25:43 +0000444template <class ELFT> bool LinkerScript<ELFT>::hasPhdrsCommands() {
445 return !Opt.PhdrsCommands.empty();
446}
447
448// Returns indices of ELF headers containing specific section, identified
449// by Name. Each index is a zero based number of ELF header listed within
450// PHDRS {} script block.
451template <class ELFT>
452std::vector<size_t>
453LinkerScript<ELFT>::getPhdrIndicesForSection(StringRef Name) {
George Rimar31d842f2016-07-20 16:43:03 +0000454 for (SectionsCommand &Cmd : Opt.Commands) {
455 if (Cmd.Kind != SectionKind || Cmd.Name != Name)
456 continue;
457
458 std::vector<size_t> Indices;
459 for (StringRef PhdrName : Cmd.Phdrs) {
460 auto ItPhdr =
461 std::find_if(Opt.PhdrsCommands.rbegin(), Opt.PhdrsCommands.rend(),
462 [&](PhdrsCommand &Cmd) { return Cmd.Name == PhdrName; });
Eugene Leviantbbe38602016-07-19 09:25:43 +0000463 if (ItPhdr == Opt.PhdrsCommands.rend())
464 error("section header '" + PhdrName + "' is not listed in PHDRS");
465 else
466 Indices.push_back(std::distance(ItPhdr, Opt.PhdrsCommands.rend()) - 1);
467 }
George Rimar31d842f2016-07-20 16:43:03 +0000468 return Indices;
Eugene Leviantbbe38602016-07-19 09:25:43 +0000469 }
George Rimar31d842f2016-07-20 16:43:03 +0000470 return {};
Eugene Leviantbbe38602016-07-19 09:25:43 +0000471}
472
Rui Ueyama07320e42016-04-20 20:13:41 +0000473class elf::ScriptParser : public ScriptParserBase {
George Rimarc3794e52016-02-24 09:21:47 +0000474 typedef void (ScriptParser::*Handler)();
475
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000476public:
Rui Ueyama07320e42016-04-20 20:13:41 +0000477 ScriptParser(StringRef S, bool B) : ScriptParserBase(S), IsUnderSysroot(B) {}
George Rimarf23b2322016-02-19 10:45:45 +0000478
Rui Ueyama4a465392016-04-22 22:59:24 +0000479 void run();
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000480
481private:
Rui Ueyama52a15092015-10-11 03:28:42 +0000482 void addFile(StringRef Path);
483
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000484 void readAsNeeded();
Denis Protivensky90c50992015-10-08 06:48:38 +0000485 void readEntry();
George Rimar83f406c2015-10-19 17:35:12 +0000486 void readExtern();
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000487 void readGroup();
Rui Ueyama31aa1f82015-10-11 01:31:55 +0000488 void readInclude();
George Rimarc3794e52016-02-24 09:21:47 +0000489 void readNothing() {}
Rui Ueyamaee592822015-10-07 00:25:09 +0000490 void readOutput();
Davide Italiano9159ce92015-10-12 21:50:08 +0000491 void readOutputArch();
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000492 void readOutputFormat();
Eugene Leviantbbe38602016-07-19 09:25:43 +0000493 void readPhdrs();
Davide Italiano68a39a62015-10-08 17:51:41 +0000494 void readSearchDir();
Denis Protivensky8e3b38a2015-11-12 09:52:08 +0000495 void readSections();
496
George Rimar652852c2016-04-16 10:10:32 +0000497 void readLocationCounterValue();
Eugene Levianteda81a12016-07-12 06:39:48 +0000498 void readOutputSectionDescription(StringRef OutSec);
Eugene Leviantbbe38602016-07-19 09:25:43 +0000499 std::vector<StringRef> readOutputSectionPhdrs();
500 unsigned readPhdrType();
Eugene Levianteda81a12016-07-12 06:39:48 +0000501 void readSymbolAssignment(StringRef Name);
502 std::vector<StringRef> readSectionsCommandExpr();
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000503
George Rimarc3794e52016-02-24 09:21:47 +0000504 const static StringMap<Handler> Cmd;
Rui Ueyama07320e42016-04-20 20:13:41 +0000505 ScriptConfiguration &Opt = *ScriptConfig;
506 StringSaver Saver = {ScriptConfig->Alloc};
Simon Atanasyan16b0cc92015-11-26 05:53:00 +0000507 bool IsUnderSysroot;
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000508};
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000509
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000510const StringMap<elf::ScriptParser::Handler> elf::ScriptParser::Cmd = {
George Rimarc3794e52016-02-24 09:21:47 +0000511 {"ENTRY", &ScriptParser::readEntry},
512 {"EXTERN", &ScriptParser::readExtern},
513 {"GROUP", &ScriptParser::readGroup},
514 {"INCLUDE", &ScriptParser::readInclude},
515 {"INPUT", &ScriptParser::readGroup},
516 {"OUTPUT", &ScriptParser::readOutput},
517 {"OUTPUT_ARCH", &ScriptParser::readOutputArch},
518 {"OUTPUT_FORMAT", &ScriptParser::readOutputFormat},
Eugene Leviantbbe38602016-07-19 09:25:43 +0000519 {"PHDRS", &ScriptParser::readPhdrs},
George Rimarc3794e52016-02-24 09:21:47 +0000520 {"SEARCH_DIR", &ScriptParser::readSearchDir},
521 {"SECTIONS", &ScriptParser::readSections},
522 {";", &ScriptParser::readNothing}};
523
Rui Ueyama717677a2016-02-11 21:17:59 +0000524void ScriptParser::run() {
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000525 while (!atEOF()) {
526 StringRef Tok = next();
George Rimarc3794e52016-02-24 09:21:47 +0000527 if (Handler Fn = Cmd.lookup(Tok))
528 (this->*Fn)();
529 else
George Rimar57610422016-03-11 14:43:02 +0000530 setError("unknown directive: " + Tok);
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000531 }
532}
533
Rui Ueyama717677a2016-02-11 21:17:59 +0000534void ScriptParser::addFile(StringRef S) {
Simon Atanasyan16b0cc92015-11-26 05:53:00 +0000535 if (IsUnderSysroot && S.startswith("/")) {
536 SmallString<128> Path;
537 (Config->Sysroot + S).toStringRef(Path);
538 if (sys::fs::exists(Path)) {
539 Driver->addFile(Saver.save(Path.str()));
540 return;
541 }
542 }
543
Rui Ueyamaf03f3cc2015-10-13 00:09:21 +0000544 if (sys::path::is_absolute(S)) {
Rui Ueyama52a15092015-10-11 03:28:42 +0000545 Driver->addFile(S);
546 } else if (S.startswith("=")) {
547 if (Config->Sysroot.empty())
548 Driver->addFile(S.substr(1));
549 else
550 Driver->addFile(Saver.save(Config->Sysroot + "/" + S.substr(1)));
551 } else if (S.startswith("-l")) {
Rui Ueyama21eecb42016-02-02 21:13:09 +0000552 Driver->addLibrary(S.substr(2));
Simon Atanasyana1b8fc32015-11-26 20:23:46 +0000553 } else if (sys::fs::exists(S)) {
554 Driver->addFile(S);
Rui Ueyama52a15092015-10-11 03:28:42 +0000555 } else {
556 std::string Path = findFromSearchPaths(S);
557 if (Path.empty())
George Rimar777f9632016-03-12 08:31:34 +0000558 setError("unable to find " + S);
Rui Ueyama025d59b2016-02-02 20:27:59 +0000559 else
560 Driver->addFile(Saver.save(Path));
Rui Ueyama52a15092015-10-11 03:28:42 +0000561 }
562}
563
Rui Ueyama717677a2016-02-11 21:17:59 +0000564void ScriptParser::readAsNeeded() {
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000565 expect("(");
Rui Ueyama35da9b62015-10-11 20:59:12 +0000566 bool Orig = Config->AsNeeded;
567 Config->AsNeeded = true;
Rui Ueyama025d59b2016-02-02 20:27:59 +0000568 while (!Error) {
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000569 StringRef Tok = next();
570 if (Tok == ")")
Rui Ueyama35da9b62015-10-11 20:59:12 +0000571 break;
Rui Ueyama52a15092015-10-11 03:28:42 +0000572 addFile(Tok);
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000573 }
Rui Ueyama35da9b62015-10-11 20:59:12 +0000574 Config->AsNeeded = Orig;
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000575}
576
Rui Ueyama717677a2016-02-11 21:17:59 +0000577void ScriptParser::readEntry() {
Denis Protivensky90c50992015-10-08 06:48:38 +0000578 // -e <symbol> takes predecence over ENTRY(<symbol>).
579 expect("(");
580 StringRef Tok = next();
581 if (Config->Entry.empty())
582 Config->Entry = Tok;
583 expect(")");
584}
585
Rui Ueyama717677a2016-02-11 21:17:59 +0000586void ScriptParser::readExtern() {
George Rimar83f406c2015-10-19 17:35:12 +0000587 expect("(");
Rui Ueyama025d59b2016-02-02 20:27:59 +0000588 while (!Error) {
George Rimar83f406c2015-10-19 17:35:12 +0000589 StringRef Tok = next();
590 if (Tok == ")")
591 return;
592 Config->Undefined.push_back(Tok);
593 }
594}
595
Rui Ueyama717677a2016-02-11 21:17:59 +0000596void ScriptParser::readGroup() {
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000597 expect("(");
Rui Ueyama025d59b2016-02-02 20:27:59 +0000598 while (!Error) {
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000599 StringRef Tok = next();
600 if (Tok == ")")
601 return;
602 if (Tok == "AS_NEEDED") {
603 readAsNeeded();
604 continue;
605 }
Rui Ueyama52a15092015-10-11 03:28:42 +0000606 addFile(Tok);
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000607 }
608}
609
Rui Ueyama717677a2016-02-11 21:17:59 +0000610void ScriptParser::readInclude() {
Rui Ueyama31aa1f82015-10-11 01:31:55 +0000611 StringRef Tok = next();
612 auto MBOrErr = MemoryBuffer::getFile(Tok);
Rui Ueyama025d59b2016-02-02 20:27:59 +0000613 if (!MBOrErr) {
George Rimar57610422016-03-11 14:43:02 +0000614 setError("cannot open " + Tok);
Rui Ueyama025d59b2016-02-02 20:27:59 +0000615 return;
616 }
Rui Ueyama31aa1f82015-10-11 01:31:55 +0000617 std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
Rui Ueyamaa47ee682015-10-11 01:53:04 +0000618 StringRef S = Saver.save(MB->getMemBufferRef().getBuffer());
619 std::vector<StringRef> V = tokenize(S);
Rui Ueyama31aa1f82015-10-11 01:31:55 +0000620 Tokens.insert(Tokens.begin() + Pos, V.begin(), V.end());
Rui Ueyama31aa1f82015-10-11 01:31:55 +0000621}
622
Rui Ueyama717677a2016-02-11 21:17:59 +0000623void ScriptParser::readOutput() {
Rui Ueyamaee592822015-10-07 00:25:09 +0000624 // -o <file> takes predecence over OUTPUT(<file>).
625 expect("(");
626 StringRef Tok = next();
627 if (Config->OutputFile.empty())
628 Config->OutputFile = Tok;
629 expect(")");
630}
631
Rui Ueyama717677a2016-02-11 21:17:59 +0000632void ScriptParser::readOutputArch() {
Davide Italiano9159ce92015-10-12 21:50:08 +0000633 // Error checking only for now.
634 expect("(");
635 next();
636 expect(")");
637}
638
Rui Ueyama717677a2016-02-11 21:17:59 +0000639void ScriptParser::readOutputFormat() {
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000640 // Error checking only for now.
641 expect("(");
642 next();
Davide Italiano6836c612015-10-12 21:08:41 +0000643 StringRef Tok = next();
644 if (Tok == ")")
645 return;
Rui Ueyama025d59b2016-02-02 20:27:59 +0000646 if (Tok != ",") {
George Rimar57610422016-03-11 14:43:02 +0000647 setError("unexpected token: " + Tok);
Rui Ueyama025d59b2016-02-02 20:27:59 +0000648 return;
649 }
Davide Italiano6836c612015-10-12 21:08:41 +0000650 next();
651 expect(",");
652 next();
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000653 expect(")");
654}
655
Eugene Leviantbbe38602016-07-19 09:25:43 +0000656void ScriptParser::readPhdrs() {
657 expect("{");
658 while (!Error && !skip("}")) {
659 StringRef Tok = next();
660 Opt.PhdrsCommands.push_back({Tok, PT_NULL, false, false});
661 PhdrsCommand &PhdrCmd = Opt.PhdrsCommands.back();
662
663 PhdrCmd.Type = readPhdrType();
664 do {
665 Tok = next();
666 if (Tok == ";")
667 break;
668 if (Tok == "FILEHDR")
669 PhdrCmd.HasFilehdr = true;
670 else if (Tok == "PHDRS")
671 PhdrCmd.HasPhdrs = true;
672 else
673 setError("unexpected header attribute: " + Tok);
674 } while (!Error);
675 }
676}
677
Rui Ueyama717677a2016-02-11 21:17:59 +0000678void ScriptParser::readSearchDir() {
Davide Italiano68a39a62015-10-08 17:51:41 +0000679 expect("(");
Rafael Espindola06501922016-03-08 17:13:12 +0000680 Config->SearchPaths.push_back(next());
Davide Italiano68a39a62015-10-08 17:51:41 +0000681 expect(")");
682}
683
Rui Ueyama717677a2016-02-11 21:17:59 +0000684void ScriptParser::readSections() {
Rui Ueyama07320e42016-04-20 20:13:41 +0000685 Opt.DoLayout = true;
Denis Protivensky8e3b38a2015-11-12 09:52:08 +0000686 expect("{");
George Rimar652852c2016-04-16 10:10:32 +0000687 while (!Error && !skip("}")) {
688 StringRef Tok = peek();
Eugene Levianteda81a12016-07-12 06:39:48 +0000689 if (Tok == ".") {
George Rimar652852c2016-04-16 10:10:32 +0000690 readLocationCounterValue();
Eugene Levianteda81a12016-07-12 06:39:48 +0000691 continue;
692 }
693 next();
694 if (peek() == "=")
695 readSymbolAssignment(Tok);
George Rimar652852c2016-04-16 10:10:32 +0000696 else
Eugene Levianteda81a12016-07-12 06:39:48 +0000697 readOutputSectionDescription(Tok);
George Rimar652852c2016-04-16 10:10:32 +0000698 }
Denis Protivensky8e3b38a2015-11-12 09:52:08 +0000699}
700
George Rimar652852c2016-04-16 10:10:32 +0000701void ScriptParser::readLocationCounterValue() {
702 expect(".");
703 expect("=");
Eugene Levianteda81a12016-07-12 06:39:48 +0000704 std::vector<StringRef> Expr = readSectionsCommandExpr();
705 if (Expr.empty())
George Rimar652852c2016-04-16 10:10:32 +0000706 error("error in location counter expression");
Eugene Levianteda81a12016-07-12 06:39:48 +0000707 else
Eugene Leviantbbe38602016-07-19 09:25:43 +0000708 Opt.Commands.push_back({AssignmentKind, std::move(Expr), ".", {}});
George Rimar652852c2016-04-16 10:10:32 +0000709}
710
Eugene Levianteda81a12016-07-12 06:39:48 +0000711void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
Eugene Leviantbbe38602016-07-19 09:25:43 +0000712 Opt.Commands.push_back({SectionKind, {}, OutSec, {}});
713 SectionsCommand &Cmd = Opt.Commands.back();
Denis Protivensky8e3b38a2015-11-12 09:52:08 +0000714 expect(":");
715 expect("{");
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000716
Rui Ueyama025d59b2016-02-02 20:27:59 +0000717 while (!Error && !skip("}")) {
George Rimar481c2ce2016-02-23 07:47:54 +0000718 StringRef Tok = next();
719 if (Tok == "*") {
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000720 expect("(");
721 while (!Error && !skip(")"))
722 Opt.Sections.emplace_back(OutSec, next());
George Rimar481c2ce2016-02-23 07:47:54 +0000723 } else if (Tok == "KEEP") {
724 expect("(");
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000725 expect("*");
726 expect("(");
727 while (!Error && !skip(")")) {
728 StringRef Sec = next();
729 Opt.Sections.emplace_back(OutSec, Sec);
730 Opt.KeptSections.push_back(Sec);
731 }
George Rimar481c2ce2016-02-23 07:47:54 +0000732 expect(")");
733 } else {
George Rimar777f9632016-03-12 08:31:34 +0000734 setError("unknown command " + Tok);
George Rimar481c2ce2016-02-23 07:47:54 +0000735 }
Denis Protivensky8e3b38a2015-11-12 09:52:08 +0000736 }
Eugene Leviantbbe38602016-07-19 09:25:43 +0000737 Cmd.Phdrs = readOutputSectionPhdrs();
Rui Ueyama8ec77e62016-04-21 22:00:51 +0000738
George Rimare2ee72b2016-02-26 14:48:31 +0000739 StringRef Tok = peek();
740 if (Tok.startswith("=")) {
741 if (!Tok.startswith("=0x")) {
Rui Ueyama3ed2f062016-03-13 03:17:44 +0000742 setError("filler should be a hexadecimal value");
George Rimare2ee72b2016-02-26 14:48:31 +0000743 return;
744 }
Rui Ueyama3e808972016-02-28 05:09:11 +0000745 Tok = Tok.substr(3);
Rui Ueyama07320e42016-04-20 20:13:41 +0000746 Opt.Filler[OutSec] = parseHex(Tok);
George Rimare2ee72b2016-02-26 14:48:31 +0000747 next();
748 }
Denis Protivensky8e3b38a2015-11-12 09:52:08 +0000749}
750
Eugene Levianteda81a12016-07-12 06:39:48 +0000751void ScriptParser::readSymbolAssignment(StringRef Name) {
752 expect("=");
753 std::vector<StringRef> Expr = readSectionsCommandExpr();
754 if (Expr.empty())
755 error("error in symbol assignment expression");
756 else
Eugene Leviantbbe38602016-07-19 09:25:43 +0000757 Opt.Commands.push_back({AssignmentKind, std::move(Expr), Name, {}});
Eugene Levianteda81a12016-07-12 06:39:48 +0000758}
759
760std::vector<StringRef> ScriptParser::readSectionsCommandExpr() {
761 std::vector<StringRef> Expr;
762 while (!Error) {
763 StringRef Tok = next();
764 if (Tok == ";")
765 break;
766 Expr.push_back(Tok);
767 }
768 return Expr;
769}
770
Eugene Leviantbbe38602016-07-19 09:25:43 +0000771std::vector<StringRef> ScriptParser::readOutputSectionPhdrs() {
772 std::vector<StringRef> Phdrs;
773 while (!Error && peek().startswith(":")) {
774 StringRef Tok = next();
775 Tok = (Tok.size() == 1) ? next() : Tok.substr(1);
776 if (Tok.empty()) {
777 setError("section header name is empty");
778 break;
779 }
Rui Ueyama047404f2016-07-20 19:36:36 +0000780 Phdrs.push_back(Tok);
Eugene Leviantbbe38602016-07-19 09:25:43 +0000781 }
782 return Phdrs;
783}
784
785unsigned ScriptParser::readPhdrType() {
786 static const char *typeNames[] = {
787 "PT_NULL", "PT_LOAD", "PT_DYNAMIC", "PT_INTERP",
788 "PT_NOTE", "PT_SHLIB", "PT_PHDR", "PT_TLS",
789 "PT_GNU_EH_FRAME", "PT_GNU_STACK", "PT_GNU_RELRO"};
790 static unsigned typeCodes[] = {
791 PT_NULL, PT_LOAD, PT_DYNAMIC, PT_INTERP, PT_NOTE, PT_SHLIB,
792 PT_PHDR, PT_TLS, PT_GNU_EH_FRAME, PT_GNU_STACK, PT_GNU_RELRO};
793
794 unsigned PhdrType = PT_NULL;
795 StringRef Tok = next();
796 auto It = std::find(std::begin(typeNames), std::end(typeNames), Tok);
797 if (It != std::end(typeNames))
798 PhdrType = typeCodes[std::distance(std::begin(typeNames), It)];
799 else
800 setError("invalid program header type");
801
802 return PhdrType;
803}
804
Simon Atanasyan16b0cc92015-11-26 05:53:00 +0000805static bool isUnderSysroot(StringRef Path) {
806 if (Config->Sysroot == "")
807 return false;
808 for (; !Path.empty(); Path = sys::path::parent_path(Path))
809 if (sys::fs::equivalent(Config->Sysroot, Path))
810 return true;
811 return false;
812}
813
Rui Ueyama07320e42016-04-20 20:13:41 +0000814// Entry point.
815void elf::readLinkerScript(MemoryBufferRef MB) {
Simon Atanasyan16b0cc92015-11-26 05:53:00 +0000816 StringRef Path = MB.getBufferIdentifier();
Rui Ueyama07320e42016-04-20 20:13:41 +0000817 ScriptParser(MB.getBuffer(), isUnderSysroot(Path)).run();
Rui Ueyamaf7c5fbb2015-09-30 17:23:26 +0000818}
Rui Ueyama1ebc8ed2016-02-12 21:47:28 +0000819
Rui Ueyama07320e42016-04-20 20:13:41 +0000820template class elf::LinkerScript<ELF32LE>;
821template class elf::LinkerScript<ELF32BE>;
822template class elf::LinkerScript<ELF64LE>;
823template class elf::LinkerScript<ELF64BE>;