[lld] ebc123e - [ELF] Create some synthetic sections only if !relocatable
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 17:48:29 PDT 2024
Author: Fangrui Song
Date: 2024-06-28T17:48:24-07:00
New Revision: ebc123e0793a1cbcb69b4af1548e339e018ffff2
URL: https://github.com/llvm/llvm-project/commit/ebc123e0793a1cbcb69b4af1548e339e018ffff2
DIFF: https://github.com/llvm/llvm-project/commit/ebc123e0793a1cbcb69b4af1548e339e018ffff2.diff
LOG: [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`.
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index cc423d152e912..496680180d68e 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 640cb2a445f7d..42f4bf764fadb 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)
More information about the llvm-commits
mailing list