Skip to content

Commit ebc123e

Browse files
committed
[ELF] Create some synthetic sections only if !relocatable
`.rela.dyn` is currently created outside of the `config->hasDynSymTab` condition. In relocatable links, `.rela.dyn` will be discarded by `removeUnusedSyntheticSections`. It's better than suppress the creation so that .relr.auth.dyn support (#96496) does not need to adjust `removeUnusedSyntheticSections`.
1 parent 0991bd7 commit ebc123e

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lld/ELF/SyntheticSections.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -4720,9 +4720,14 @@ template <class ELFT> void elf::createSyntheticSections() {
47204720
add(*part.buildId);
47214721
}
47224722

4723+
// dynSymTab is always present to simplify sym->includeInDynsym() in
4724+
// finalizeSections.
47234725
part.dynStrTab = std::make_unique<StringTableSection>(".dynstr", true);
47244726
part.dynSymTab =
47254727
std::make_unique<SymbolTableSection<ELFT>>(*part.dynStrTab);
4728+
4729+
if (config->relocatable)
4730+
continue;
47264731
part.dynamic = std::make_unique<DynamicSection<ELFT>>();
47274732

47284733
if (hasMemtag()) {
@@ -4776,19 +4781,17 @@ template <class ELFT> void elf::createSyntheticSections() {
47764781
add(*part.relrDyn);
47774782
}
47784783

4779-
if (!config->relocatable) {
4780-
if (config->ehFrameHdr) {
4781-
part.ehFrameHdr = std::make_unique<EhFrameHeader>();
4782-
add(*part.ehFrameHdr);
4783-
}
4784-
part.ehFrame = std::make_unique<EhFrameSection>();
4785-
add(*part.ehFrame);
4784+
if (config->ehFrameHdr) {
4785+
part.ehFrameHdr = std::make_unique<EhFrameHeader>();
4786+
add(*part.ehFrameHdr);
4787+
}
4788+
part.ehFrame = std::make_unique<EhFrameSection>();
4789+
add(*part.ehFrame);
47864790

4787-
if (config->emachine == EM_ARM) {
4788-
// This section replaces all the individual .ARM.exidx InputSections.
4789-
part.armExidx = std::make_unique<ARMExidxSyntheticSection>();
4790-
add(*part.armExidx);
4791-
}
4791+
if (config->emachine == EM_ARM) {
4792+
// This section replaces all the individual .ARM.exidx InputSections.
4793+
part.armExidx = std::make_unique<ARMExidxSyntheticSection>();
4794+
add(*part.armExidx);
47924795
}
47934796

47944797
if (!config->packageMetadata.empty()) {

lld/ELF/Writer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
14581458
in.mipsGot->updateAllocSize();
14591459

14601460
for (Partition &part : partitions) {
1461-
changed |= part.relaDyn->updateAllocSize();
1461+
if (part.relaDyn)
1462+
changed |= part.relaDyn->updateAllocSize();
14621463
if (part.relrDyn)
14631464
changed |= part.relrDyn->updateAllocSize();
14641465
if (part.memtagGlobalDescriptors)

0 commit comments

Comments
 (0)