@@ -50,7 +50,7 @@ static bool isSectionPrefix(StringRef prefix, StringRef name) {
50
50
return name.consume_front (prefix) && (name.empty () || name[0 ] == ' .' );
51
51
}
52
52
53
- static StringRef getOutputSectionName (const InputSectionBase *s) {
53
+ StringRef LinkerScript:: getOutputSectionName (const InputSectionBase *s) const {
54
54
// This is for --emit-relocs and -r. If .text.foo is emitted as .text.bar, we
55
55
// want to emit .rela.text.foo as .rela.text.bar for consistency (this is not
56
56
// technically required, but not doing it is odd). This code guarantees that.
@@ -77,7 +77,7 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
77
77
if (s->name == " COMMON" )
78
78
return " .bss" ;
79
79
80
- if (script-> hasSectionsCommand )
80
+ if (hasSectionsCommand)
81
81
return s->name ;
82
82
83
83
// When no SECTIONS is specified, emulate GNU ld's internal linker scripts
@@ -596,7 +596,7 @@ LinkerScript::computeInputSections(const InputSectionDescription *cmd,
596
596
sortByPositionThenCommandLine (sizeAfterPrevSort, ret.size ());
597
597
} else {
598
598
SectionClassDesc *scd =
599
- script-> sectionClasses .lookup (CachedHashStringRef (cmd->classRef ));
599
+ sectionClasses.lookup (CachedHashStringRef (cmd->classRef ));
600
600
if (!scd) {
601
601
errorOrWarn (" undefined section class '" + cmd->classRef + " '" );
602
602
return ret;
@@ -1160,7 +1160,7 @@ bool LinkerScript::assignOffsets(OutputSection *sec) {
1160
1160
}
1161
1161
1162
1162
state->outSec = sec;
1163
- if (!(sec->addrExpr && script-> hasSectionsCommand )) {
1163
+ if (!(sec->addrExpr && hasSectionsCommand)) {
1164
1164
// ALIGN is respected. sec->alignment is the max of ALIGN and the maximum of
1165
1165
// input section alignments.
1166
1166
const uint64_t pos = dot;
@@ -1419,15 +1419,6 @@ void LinkerScript::adjustSectionsAfterSorting() {
1419
1419
maybePropagatePhdrs (osd->osec , defPhdrs);
1420
1420
}
1421
1421
1422
- static uint64_t computeBase (uint64_t min, bool allocateHeaders) {
1423
- // If there is no SECTIONS or if the linkerscript is explicit about program
1424
- // headers, do our best to allocate them.
1425
- if (!script->hasSectionsCommand || allocateHeaders)
1426
- return 0 ;
1427
- // Otherwise only allocate program headers if that would not add a page.
1428
- return alignDown (min, config->maxPageSize );
1429
- }
1430
-
1431
1422
// When the SECTIONS command is used, try to find an address for the file and
1432
1423
// program headers output sections, which can be added to the first PT_LOAD
1433
1424
// segment when program headers are created.
@@ -1453,8 +1444,13 @@ void LinkerScript::allocateHeaders(SmallVector<PhdrEntry *, 0> &phdrs) {
1453
1444
});
1454
1445
bool paged = !config->omagic && !config->nmagic ;
1455
1446
uint64_t headerSize = getHeaderSize ();
1456
- if ((paged || hasExplicitHeaders) &&
1457
- headerSize <= min - computeBase (min, hasExplicitHeaders)) {
1447
+
1448
+ uint64_t base = 0 ;
1449
+ // If SECTIONS is present and the linkerscript is not explicit about program
1450
+ // headers, only allocate program headers if that would not add a page.
1451
+ if (hasSectionsCommand && !hasExplicitHeaders)
1452
+ base = alignDown (min, config->maxPageSize );
1453
+ if ((paged || hasExplicitHeaders) && headerSize <= min - base) {
1458
1454
min = alignDown (min - headerSize, config->maxPageSize );
1459
1455
ctx.out .elfHeader ->addr = min;
1460
1456
ctx.out .programHeaders ->addr = min + ctx.out .elfHeader ->size ;
@@ -1487,7 +1483,7 @@ LinkerScript::AddressState::AddressState() {
1487
1483
// that has changed its section or value (or nullptr if no symbol has changed).
1488
1484
std::pair<const OutputSection *, const Defined *>
1489
1485
LinkerScript::assignAddresses () {
1490
- if (script-> hasSectionsCommand ) {
1486
+ if (hasSectionsCommand) {
1491
1487
// With a linker script, assignment of addresses to headers is covered by
1492
1488
// allocateHeaders().
1493
1489
dot = config->imageBase .value_or (0 );
@@ -1805,10 +1801,9 @@ void LinkerScript::addScriptReferencedSymbolsToSymTable() {
1805
1801
for (StringRef name : *symRefsVec.pop_back_val ()) {
1806
1802
reference (name);
1807
1803
// Prevent the symbol from being discarded by --gc-sections.
1808
- script->referencedSymbols .push_back (name);
1809
- auto it = script->provideMap .find (name);
1810
- if (it != script->provideMap .end () &&
1811
- LinkerScript::shouldAddProvideSym (name) &&
1804
+ referencedSymbols.push_back (name);
1805
+ auto it = provideMap.find (name);
1806
+ if (it != provideMap.end () && shouldAddProvideSym (name) &&
1812
1807
added.insert (name).second ) {
1813
1808
symRefsVec.push_back (&it->second );
1814
1809
}
0 commit comments