@@ -47,8 +47,7 @@ using namespace lld::elf;
4747namespace {
4848class ScriptParser final : ScriptLexer {
4949public:
50- ScriptParser (MemoryBufferRef mb) : ScriptLexer(mb) {
51- }
50+ ScriptParser (Ctx &ctx, MemoryBufferRef mb) : ScriptLexer(ctx, mb) {}
5251
5352 void readLinkerScript ();
5453 void readVersionScript ();
@@ -197,7 +196,7 @@ void ScriptParser::readDynamicList() {
197196 }
198197
199198 for (SymbolVersion v : globals)
200- config-> dynamicList .push_back (v);
199+ ctx. arg . dynamicList .push_back (v);
201200}
202201
203202void ScriptParser::readVersionScript () {
@@ -313,11 +312,11 @@ void ScriptParser::readNoCrossRefs(bool to) {
313312void ScriptParser::addFile (StringRef s) {
314313 if (curBuf.isUnderSysroot && s.starts_with (" /" )) {
315314 SmallString<128 > pathData;
316- StringRef path = (config-> sysroot + s).toStringRef (pathData);
315+ StringRef path = (ctx. arg . sysroot + s).toStringRef (pathData);
317316 if (sys::fs::exists (path))
318317 ctx.driver .addFile (saver ().save (path), /* withLOption=*/ false );
319318 else
320- setError (" cannot find " + s + " inside " + config-> sysroot );
319+ setError (" cannot find " + s + " inside " + ctx. arg . sysroot );
321320 return ;
322321 }
323322
@@ -326,10 +325,10 @@ void ScriptParser::addFile(StringRef s) {
326325 ctx.driver .addFile (s, /* withLOption=*/ false );
327326 } else if (s.starts_with (" =" )) {
328327 // Case 2: relative to the sysroot.
329- if (config-> sysroot .empty ())
328+ if (ctx. arg . sysroot .empty ())
330329 ctx.driver .addFile (s.substr (1 ), /* withLOption=*/ false );
331330 else
332- ctx.driver .addFile (saver ().save (config-> sysroot + " /" + s.substr (1 )),
331+ ctx.driver .addFile (saver ().save (ctx. arg . sysroot + " /" + s.substr (1 )),
333332 /* withLOption=*/ false );
334333 } else if (s.starts_with (" -l" )) {
335334 // Case 3: search in the list of library paths.
@@ -361,26 +360,26 @@ void ScriptParser::addFile(StringRef s) {
361360
362361void ScriptParser::readAsNeeded () {
363362 expect (" (" );
364- bool orig = config-> asNeeded ;
365- config-> asNeeded = true ;
363+ bool orig = ctx. arg . asNeeded ;
364+ ctx. arg . asNeeded = true ;
366365 while (auto tok = till (" )" ))
367366 addFile (unquote (tok));
368- config-> asNeeded = orig;
367+ ctx. arg . asNeeded = orig;
369368}
370369
371370void ScriptParser::readEntry () {
372371 // -e <symbol> takes predecence over ENTRY(<symbol>).
373372 expect (" (" );
374373 StringRef name = readName ();
375- if (config-> entry .empty ())
376- config-> entry = name;
374+ if (ctx. arg . entry .empty ())
375+ ctx. arg . entry = name;
377376 expect (" )" );
378377}
379378
380379void ScriptParser::readExtern () {
381380 expect (" (" );
382381 while (auto tok = till (" )" ))
383- config-> undefined .push_back (unquote (tok));
382+ ctx. arg . undefined .push_back (unquote (tok));
384383}
385384
386385void ScriptParser::readGroup () {
@@ -402,7 +401,7 @@ void ScriptParser::readInclude() {
402401 if (std::optional<std::string> path = searchScript (name)) {
403402 if (std::optional<MemoryBufferRef> mb = readFile (*path)) {
404403 buffers.push_back (curBuf);
405- curBuf = Buffer (*mb);
404+ curBuf = Buffer (ctx, *mb);
406405 mbs.push_back (*mb);
407406 }
408407 return ;
@@ -424,8 +423,8 @@ void ScriptParser::readOutput() {
424423 // -o <file> takes predecence over OUTPUT(<file>).
425424 expect (" (" );
426425 StringRef name = readName ();
427- if (config-> outputFile .empty ())
428- config-> outputFile = name;
426+ if (ctx. arg . outputFile .empty ())
427+ ctx. arg . outputFile = name;
429428 expect (" )" );
430429}
431430
@@ -479,34 +478,34 @@ void ScriptParser::readOutputFormat() {
479478 if (!consume (" )" )) {
480479 expect (" ," );
481480 StringRef tmp = readName ();
482- if (config-> optEB )
481+ if (ctx. arg . optEB )
483482 s = tmp;
484483 expect (" ," );
485484 tmp = readName ();
486- if (config-> optEL )
485+ if (ctx. arg . optEL )
487486 s = tmp;
488487 consume (" )" );
489488 }
490489 // If more than one OUTPUT_FORMAT is specified, only the first is checked.
491- if (!config-> bfdname .empty ())
490+ if (!ctx. arg . bfdname .empty ())
492491 return ;
493- config-> bfdname = s;
492+ ctx. arg . bfdname = s;
494493
495494 if (s == " binary" ) {
496- config-> oFormatBinary = true ;
495+ ctx. arg . oFormatBinary = true ;
497496 return ;
498497 }
499498
500499 if (s.consume_back (" -freebsd" ))
501- config-> osabi = ELFOSABI_FREEBSD;
500+ ctx. arg . osabi = ELFOSABI_FREEBSD;
502501
503- std::tie (config-> ekind , config-> emachine ) = parseBfdName (s);
504- if (config-> emachine == EM_NONE)
505- setError (" unknown output format name: " + config-> bfdname );
502+ std::tie (ctx. arg . ekind , ctx. arg . emachine ) = parseBfdName (s);
503+ if (ctx. arg . emachine == EM_NONE)
504+ setError (" unknown output format name: " + ctx. arg . bfdname );
506505 if (s == " elf32-ntradlittlemips" || s == " elf32-ntradbigmips" )
507- config-> mipsN32Abi = true ;
508- if (config-> emachine == EM_MSP430)
509- config-> osabi = ELFOSABI_STANDALONE;
506+ ctx. arg . mipsN32Abi = true ;
507+ if (ctx. arg . emachine == EM_MSP430)
508+ ctx. arg . osabi = ELFOSABI_STANDALONE;
510509}
511510
512511void ScriptParser::readPhdrs () {
@@ -550,8 +549,8 @@ void ScriptParser::readRegionAlias() {
550549void ScriptParser::readSearchDir () {
551550 expect (" (" );
552551 StringRef name = readName ();
553- if (!config-> nostdlib )
554- config-> searchPaths .push_back (name);
552+ if (!ctx. arg . nostdlib )
553+ ctx. arg . searchPaths .push_back (name);
555554 expect (" )" );
556555}
557556
@@ -562,15 +561,15 @@ void ScriptParser::readSearchDir() {
562561SmallVector<SectionCommand *, 0 > ScriptParser::readOverlay () {
563562 Expr addrExpr;
564563 if (consume (" :" )) {
565- addrExpr = [] { return ctx.script ->getDot (); };
564+ addrExpr = [& ] { return ctx.script ->getDot (); };
566565 } else {
567566 addrExpr = readExpr ();
568567 expect (" :" );
569568 }
570569 // When AT is omitted, LMA should equal VMA. script->getDot() when evaluating
571570 // lmaExpr will ensure this, even if the start address is specified.
572571 Expr lmaExpr =
573- consume (" AT" ) ? readParenExpr () : [] { return ctx.script ->getDot (); };
572+ consume (" AT" ) ? readParenExpr () : [& ] { return ctx.script ->getDot (); };
574573 expect (" {" );
575574
576575 SmallVector<SectionCommand *, 0 > v;
@@ -704,9 +703,9 @@ void ScriptParser::readTarget() {
704703 expect (" )" );
705704
706705 if (tok.starts_with (" elf" ))
707- config-> formatBinary = false ;
706+ ctx. arg . formatBinary = false ;
708707 else if (tok == " binary" )
709- config-> formatBinary = true ;
708+ ctx. arg . formatBinary = true ;
710709 else
711710 setError (" unknown target: " + tok);
712711}
@@ -1327,7 +1326,7 @@ Expr ScriptParser::getPageSize() {
13271326 std::string location = getCurrentLocation ();
13281327 return [=]() -> uint64_t {
13291328 if (ctx.target )
1330- return config-> commonPageSize ;
1329+ return ctx. arg . commonPageSize ;
13311330 error (location + " : unable to calculate page size" );
13321331 return 4096 ; // Return a dummy value.
13331332 };
@@ -1338,7 +1337,7 @@ Expr ScriptParser::readConstant() {
13381337 if (s == " COMMONPAGESIZE" )
13391338 return getPageSize ();
13401339 if (s == " MAXPAGESIZE" )
1341- return [] { return config-> maxPageSize ; };
1340+ return [& ] { return ctx. arg . maxPageSize ; };
13421341 setError (" unknown constant: " + s);
13431342 return [] { return 0 ; };
13441343}
@@ -1556,7 +1555,7 @@ Expr ScriptParser::readPrimary() {
15561555 expect (" (" );
15571556 expect (" ." );
15581557 expect (" )" );
1559- return [] { return ctx.script ->getDot (); };
1558+ return [& ] { return ctx.script ->getDot (); };
15601559 }
15611560 if (tok == " DATA_SEGMENT_RELRO_END" ) {
15621561 // GNU linkers implements more complicated logic to handle
@@ -1568,8 +1567,8 @@ Expr ScriptParser::readPrimary() {
15681567 readExpr ();
15691568 expect (" )" );
15701569 ctx.script ->seenRelroEnd = true ;
1571- return [= ] {
1572- return alignToPowerOf2 (ctx.script ->getDot (), config-> maxPageSize );
1570+ return [& ] {
1571+ return alignToPowerOf2 (ctx.script ->getDot (), ctx. arg . maxPageSize );
15731572 };
15741573 }
15751574 if (tok == " DEFINED" ) {
@@ -1728,9 +1727,9 @@ void ScriptParser::readAnonymousDeclaration() {
17281727 SmallVector<SymbolVersion, 0 > globals;
17291728 std::tie (locals, globals) = readSymbols ();
17301729 for (const SymbolVersion &pat : locals)
1731- config-> versionDefinitions [VER_NDX_LOCAL].localPatterns .push_back (pat);
1730+ ctx. arg . versionDefinitions [VER_NDX_LOCAL].localPatterns .push_back (pat);
17321731 for (const SymbolVersion &pat : globals)
1733- config-> versionDefinitions [VER_NDX_GLOBAL].nonLocalPatterns .push_back (pat);
1732+ ctx. arg . versionDefinitions [VER_NDX_GLOBAL].nonLocalPatterns .push_back (pat);
17341733
17351734 expect (" ;" );
17361735}
@@ -1748,8 +1747,8 @@ void ScriptParser::readVersionDeclaration(StringRef verStr) {
17481747 ver.name = verStr;
17491748 ver.nonLocalPatterns = std::move (globals);
17501749 ver.localPatterns = std::move (locals);
1751- ver.id = config-> versionDefinitions .size ();
1752- config-> versionDefinitions .push_back (ver);
1750+ ver.id = ctx. arg . versionDefinitions .size ();
1751+ ctx. arg . versionDefinitions .push_back (ver);
17531752
17541753 // Each version may have a parent version. For example, "Ver2"
17551754 // defined as "Ver2 { global: foo; local: *; } Ver1;" has "Ver1"
@@ -1891,21 +1890,23 @@ void ScriptParser::readMemoryAttributes(uint32_t &flags, uint32_t &invFlags,
18911890 }
18921891}
18931892
1894- void elf::readLinkerScript (MemoryBufferRef mb) {
1893+ void elf::readLinkerScript (Ctx &ctx, MemoryBufferRef mb) {
18951894 llvm::TimeTraceScope timeScope (" Read linker script" ,
18961895 mb.getBufferIdentifier ());
1897- ScriptParser (mb).readLinkerScript ();
1896+ ScriptParser (ctx, mb).readLinkerScript ();
18981897}
18991898
1900- void elf::readVersionScript (MemoryBufferRef mb) {
1899+ void elf::readVersionScript (Ctx &ctx, MemoryBufferRef mb) {
19011900 llvm::TimeTraceScope timeScope (" Read version script" ,
19021901 mb.getBufferIdentifier ());
1903- ScriptParser (mb).readVersionScript ();
1902+ ScriptParser (ctx, mb).readVersionScript ();
19041903}
19051904
1906- void elf::readDynamicList (MemoryBufferRef mb) {
1905+ void elf::readDynamicList (Ctx &ctx, MemoryBufferRef mb) {
19071906 llvm::TimeTraceScope timeScope (" Read dynamic list" , mb.getBufferIdentifier ());
1908- ScriptParser (mb).readDynamicList ();
1907+ ScriptParser (ctx, mb).readDynamicList ();
19091908}
19101909
1911- void elf::readDefsym (MemoryBufferRef mb) { ScriptParser (mb).readDefsym (); }
1910+ void elf::readDefsym (Ctx &ctx, MemoryBufferRef mb) {
1911+ ScriptParser (ctx, mb).readDefsym ();
1912+ }
0 commit comments