diff options
author | Fangrui Song <i@maskray.me> | 2024-06-28 17:48:24 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2024-06-28 17:48:24 -0700 |
commit | ebc123e0793a1cbcb69b4af1548e339e018ffff2 (patch) | |
tree | 6772ab322d49b21b4a11c323f64f8634f650dfcc /lld | |
parent | 0991bd7887a313d4d6bb66ca44d11939ad71b660 (diff) | |
download | llvm-ebc123e0793a1cbcb69b4af1548e339e018ffff2.zip llvm-ebc123e0793a1cbcb69b4af1548e339e018ffff2.tar.gz llvm-ebc123e0793a1cbcb69b4af1548e339e018ffff2.tar.bz2 |
[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`.
Diffstat (limited to 'lld')
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 27 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 3 |
2 files changed, 17 insertions, 13 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index cc423d15..4966801 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4720,9 +4720,14 @@ template <class ELFT> void elf::createSyntheticSections() { add(*part.buildId); } + // dynSymTab is always present to simplify sym->includeInDynsym() in + // finalizeSections. part.dynStrTab = std::make_unique<StringTableSection>(".dynstr", true); part.dynSymTab = std::make_unique<SymbolTableSection<ELFT>>(*part.dynStrTab); + + if (config->relocatable) + continue; part.dynamic = std::make_unique<DynamicSection<ELFT>>(); if (hasMemtag()) { @@ -4776,19 +4781,17 @@ template <class ELFT> void elf::createSyntheticSections() { add(*part.relrDyn); } - if (!config->relocatable) { - if (config->ehFrameHdr) { - part.ehFrameHdr = std::make_unique<EhFrameHeader>(); - add(*part.ehFrameHdr); - } - part.ehFrame = std::make_unique<EhFrameSection>(); - add(*part.ehFrame); + if (config->ehFrameHdr) { + part.ehFrameHdr = std::make_unique<EhFrameHeader>(); + add(*part.ehFrameHdr); + } + part.ehFrame = std::make_unique<EhFrameSection>(); + add(*part.ehFrame); - if (config->emachine == EM_ARM) { - // This section replaces all the individual .ARM.exidx InputSections. - part.armExidx = std::make_unique<ARMExidxSyntheticSection>(); - add(*part.armExidx); - } + if (config->emachine == EM_ARM) { + // This section replaces all the individual .ARM.exidx InputSections. + part.armExidx = std::make_unique<ARMExidxSyntheticSection>(); + add(*part.armExidx); } if (!config->packageMetadata.empty()) { diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 640cb2a..42f4bf7 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1458,7 +1458,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() { in.mipsGot->updateAllocSize(); for (Partition &part : partitions) { - changed |= part.relaDyn->updateAllocSize(); + if (part.relaDyn) + changed |= part.relaDyn->updateAllocSize(); if (part.relrDyn) changed |= part.relrDyn->updateAllocSize(); if (part.memtagGlobalDescriptors) |