@@ -47,8 +47,7 @@ using namespace lld::elf;
47
47
namespace {
48
48
class ScriptParser final : ScriptLexer {
49
49
public:
50
- ScriptParser (MemoryBufferRef mb) : ScriptLexer(mb) {
51
- }
50
+ ScriptParser (Ctx &ctx, MemoryBufferRef mb) : ScriptLexer(ctx, mb) {}
52
51
53
52
void readLinkerScript ();
54
53
void readVersionScript ();
@@ -197,7 +196,7 @@ void ScriptParser::readDynamicList() {
197
196
}
198
197
199
198
for (SymbolVersion v : globals)
200
- config-> dynamicList .push_back (v);
199
+ ctx. arg . dynamicList .push_back (v);
201
200
}
202
201
203
202
void ScriptParser::readVersionScript () {
@@ -313,11 +312,11 @@ void ScriptParser::readNoCrossRefs(bool to) {
313
312
void ScriptParser::addFile (StringRef s) {
314
313
if (curBuf.isUnderSysroot && s.starts_with (" /" )) {
315
314
SmallString<128 > pathData;
316
- StringRef path = (config-> sysroot + s).toStringRef (pathData);
315
+ StringRef path = (ctx. arg . sysroot + s).toStringRef (pathData);
317
316
if (sys::fs::exists (path))
318
317
ctx.driver .addFile (saver ().save (path), /* withLOption=*/ false );
319
318
else
320
- setError (" cannot find " + s + " inside " + config-> sysroot );
319
+ setError (" cannot find " + s + " inside " + ctx. arg . sysroot );
321
320
return ;
322
321
}
323
322
@@ -326,10 +325,10 @@ void ScriptParser::addFile(StringRef s) {
326
325
ctx.driver .addFile (s, /* withLOption=*/ false );
327
326
} else if (s.starts_with (" =" )) {
328
327
// Case 2: relative to the sysroot.
329
- if (config-> sysroot .empty ())
328
+ if (ctx. arg . sysroot .empty ())
330
329
ctx.driver .addFile (s.substr (1 ), /* withLOption=*/ false );
331
330
else
332
- ctx.driver .addFile (saver ().save (config-> sysroot + " /" + s.substr (1 )),
331
+ ctx.driver .addFile (saver ().save (ctx. arg . sysroot + " /" + s.substr (1 )),
333
332
/* withLOption=*/ false );
334
333
} else if (s.starts_with (" -l" )) {
335
334
// Case 3: search in the list of library paths.
@@ -361,26 +360,26 @@ void ScriptParser::addFile(StringRef s) {
361
360
362
361
void ScriptParser::readAsNeeded () {
363
362
expect (" (" );
364
- bool orig = config-> asNeeded ;
365
- config-> asNeeded = true ;
363
+ bool orig = ctx. arg . asNeeded ;
364
+ ctx. arg . asNeeded = true ;
366
365
while (auto tok = till (" )" ))
367
366
addFile (unquote (tok));
368
- config-> asNeeded = orig;
367
+ ctx. arg . asNeeded = orig;
369
368
}
370
369
371
370
void ScriptParser::readEntry () {
372
371
// -e <symbol> takes predecence over ENTRY(<symbol>).
373
372
expect (" (" );
374
373
StringRef name = readName ();
375
- if (config-> entry .empty ())
376
- config-> entry = name;
374
+ if (ctx. arg . entry .empty ())
375
+ ctx. arg . entry = name;
377
376
expect (" )" );
378
377
}
379
378
380
379
void ScriptParser::readExtern () {
381
380
expect (" (" );
382
381
while (auto tok = till (" )" ))
383
- config-> undefined .push_back (unquote (tok));
382
+ ctx. arg . undefined .push_back (unquote (tok));
384
383
}
385
384
386
385
void ScriptParser::readGroup () {
@@ -402,7 +401,7 @@ void ScriptParser::readInclude() {
402
401
if (std::optional<std::string> path = searchScript (name)) {
403
402
if (std::optional<MemoryBufferRef> mb = readFile (*path)) {
404
403
buffers.push_back (curBuf);
405
- curBuf = Buffer (*mb);
404
+ curBuf = Buffer (ctx, *mb);
406
405
mbs.push_back (*mb);
407
406
}
408
407
return ;
@@ -424,8 +423,8 @@ void ScriptParser::readOutput() {
424
423
// -o <file> takes predecence over OUTPUT(<file>).
425
424
expect (" (" );
426
425
StringRef name = readName ();
427
- if (config-> outputFile .empty ())
428
- config-> outputFile = name;
426
+ if (ctx. arg . outputFile .empty ())
427
+ ctx. arg . outputFile = name;
429
428
expect (" )" );
430
429
}
431
430
@@ -479,34 +478,34 @@ void ScriptParser::readOutputFormat() {
479
478
if (!consume (" )" )) {
480
479
expect (" ," );
481
480
StringRef tmp = readName ();
482
- if (config-> optEB )
481
+ if (ctx. arg . optEB )
483
482
s = tmp;
484
483
expect (" ," );
485
484
tmp = readName ();
486
- if (config-> optEL )
485
+ if (ctx. arg . optEL )
487
486
s = tmp;
488
487
consume (" )" );
489
488
}
490
489
// If more than one OUTPUT_FORMAT is specified, only the first is checked.
491
- if (!config-> bfdname .empty ())
490
+ if (!ctx. arg . bfdname .empty ())
492
491
return ;
493
- config-> bfdname = s;
492
+ ctx. arg . bfdname = s;
494
493
495
494
if (s == " binary" ) {
496
- config-> oFormatBinary = true ;
495
+ ctx. arg . oFormatBinary = true ;
497
496
return ;
498
497
}
499
498
500
499
if (s.consume_back (" -freebsd" ))
501
- config-> osabi = ELFOSABI_FREEBSD;
500
+ ctx. arg . osabi = ELFOSABI_FREEBSD;
502
501
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 );
506
505
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;
510
509
}
511
510
512
511
void ScriptParser::readPhdrs () {
@@ -550,8 +549,8 @@ void ScriptParser::readRegionAlias() {
550
549
void ScriptParser::readSearchDir () {
551
550
expect (" (" );
552
551
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);
555
554
expect (" )" );
556
555
}
557
556
@@ -562,15 +561,15 @@ void ScriptParser::readSearchDir() {
562
561
SmallVector<SectionCommand *, 0 > ScriptParser::readOverlay () {
563
562
Expr addrExpr;
564
563
if (consume (" :" )) {
565
- addrExpr = [] { return ctx.script ->getDot (); };
564
+ addrExpr = [& ] { return ctx.script ->getDot (); };
566
565
} else {
567
566
addrExpr = readExpr ();
568
567
expect (" :" );
569
568
}
570
569
// When AT is omitted, LMA should equal VMA. script->getDot() when evaluating
571
570
// lmaExpr will ensure this, even if the start address is specified.
572
571
Expr lmaExpr =
573
- consume (" AT" ) ? readParenExpr () : [] { return ctx.script ->getDot (); };
572
+ consume (" AT" ) ? readParenExpr () : [& ] { return ctx.script ->getDot (); };
574
573
expect (" {" );
575
574
576
575
SmallVector<SectionCommand *, 0 > v;
@@ -704,9 +703,9 @@ void ScriptParser::readTarget() {
704
703
expect (" )" );
705
704
706
705
if (tok.starts_with (" elf" ))
707
- config-> formatBinary = false ;
706
+ ctx. arg . formatBinary = false ;
708
707
else if (tok == " binary" )
709
- config-> formatBinary = true ;
708
+ ctx. arg . formatBinary = true ;
710
709
else
711
710
setError (" unknown target: " + tok);
712
711
}
@@ -1327,7 +1326,7 @@ Expr ScriptParser::getPageSize() {
1327
1326
std::string location = getCurrentLocation ();
1328
1327
return [=]() -> uint64_t {
1329
1328
if (ctx.target )
1330
- return config-> commonPageSize ;
1329
+ return ctx. arg . commonPageSize ;
1331
1330
error (location + " : unable to calculate page size" );
1332
1331
return 4096 ; // Return a dummy value.
1333
1332
};
@@ -1338,7 +1337,7 @@ Expr ScriptParser::readConstant() {
1338
1337
if (s == " COMMONPAGESIZE" )
1339
1338
return getPageSize ();
1340
1339
if (s == " MAXPAGESIZE" )
1341
- return [] { return config-> maxPageSize ; };
1340
+ return [& ] { return ctx. arg . maxPageSize ; };
1342
1341
setError (" unknown constant: " + s);
1343
1342
return [] { return 0 ; };
1344
1343
}
@@ -1556,7 +1555,7 @@ Expr ScriptParser::readPrimary() {
1556
1555
expect (" (" );
1557
1556
expect (" ." );
1558
1557
expect (" )" );
1559
- return [] { return ctx.script ->getDot (); };
1558
+ return [& ] { return ctx.script ->getDot (); };
1560
1559
}
1561
1560
if (tok == " DATA_SEGMENT_RELRO_END" ) {
1562
1561
// GNU linkers implements more complicated logic to handle
@@ -1568,8 +1567,8 @@ Expr ScriptParser::readPrimary() {
1568
1567
readExpr ();
1569
1568
expect (" )" );
1570
1569
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 );
1573
1572
};
1574
1573
}
1575
1574
if (tok == " DEFINED" ) {
@@ -1728,9 +1727,9 @@ void ScriptParser::readAnonymousDeclaration() {
1728
1727
SmallVector<SymbolVersion, 0 > globals;
1729
1728
std::tie (locals, globals) = readSymbols ();
1730
1729
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);
1732
1731
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);
1734
1733
1735
1734
expect (" ;" );
1736
1735
}
@@ -1748,8 +1747,8 @@ void ScriptParser::readVersionDeclaration(StringRef verStr) {
1748
1747
ver.name = verStr;
1749
1748
ver.nonLocalPatterns = std::move (globals);
1750
1749
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);
1753
1752
1754
1753
// Each version may have a parent version. For example, "Ver2"
1755
1754
// defined as "Ver2 { global: foo; local: *; } Ver1;" has "Ver1"
@@ -1891,21 +1890,23 @@ void ScriptParser::readMemoryAttributes(uint32_t &flags, uint32_t &invFlags,
1891
1890
}
1892
1891
}
1893
1892
1894
- void elf::readLinkerScript (MemoryBufferRef mb) {
1893
+ void elf::readLinkerScript (Ctx &ctx, MemoryBufferRef mb) {
1895
1894
llvm::TimeTraceScope timeScope (" Read linker script" ,
1896
1895
mb.getBufferIdentifier ());
1897
- ScriptParser (mb).readLinkerScript ();
1896
+ ScriptParser (ctx, mb).readLinkerScript ();
1898
1897
}
1899
1898
1900
- void elf::readVersionScript (MemoryBufferRef mb) {
1899
+ void elf::readVersionScript (Ctx &ctx, MemoryBufferRef mb) {
1901
1900
llvm::TimeTraceScope timeScope (" Read version script" ,
1902
1901
mb.getBufferIdentifier ());
1903
- ScriptParser (mb).readVersionScript ();
1902
+ ScriptParser (ctx, mb).readVersionScript ();
1904
1903
}
1905
1904
1906
- void elf::readDynamicList (MemoryBufferRef mb) {
1905
+ void elf::readDynamicList (Ctx &ctx, MemoryBufferRef mb) {
1907
1906
llvm::TimeTraceScope timeScope (" Read dynamic list" , mb.getBufferIdentifier ());
1908
- ScriptParser (mb).readDynamicList ();
1907
+ ScriptParser (ctx, mb).readDynamicList ();
1909
1908
}
1910
1909
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