aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorPetr Hosek <phosek@google.com>2024-05-07 09:18:55 -0700
committerGitHub <noreply@github.com>2024-05-07 09:18:55 -0700
commit8bcb0737056163686e967821bea7f9e87c57cdfc (patch)
treed7dfa658e2947f31c0c32aeee7aeeea1ca47a0f7 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parente74a7a9fd79a74073277471243a44527c71eb4a9 (diff)
downloadllvm-8bcb0737056163686e967821bea7f9e87c57cdfc.zip
llvm-8bcb0737056163686e967821bea7f9e87c57cdfc.tar.gz
llvm-8bcb0737056163686e967821bea7f9e87c57cdfc.tar.bz2
[Clang] -fseparate-named-sections option (#91028)
When set, the compiler will use separate unique sections for global symbols in named special sections (e.g. symbols that are annotated with __attribute__((section(...)))). Doing so enables linker GC to collect unused symbols without having to use a different section per-symbol.
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 2a77a68..81f3864 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -733,15 +733,20 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
Ctx.isELFGenericMergeableSection(SectionName);
// If this is the first ocurrence of this section name, treat it as the
// generic section
- if (!SymbolMergeable && !SeenSectionNameBefore)
- return MCContext::GenericSectionID;
+ if (!SymbolMergeable && !SeenSectionNameBefore) {
+ if (TM.getSeparateNamedSections())
+ return NextUniqueID++;
+ else
+ return MCContext::GenericSectionID;
+ }
// Symbols must be placed into sections with compatible entry sizes. Generate
// unique sections for symbols that have not been assigned to compatible
// sections.
const auto PreviousID =
Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
- if (PreviousID)
+ if (PreviousID && (!TM.getSeparateNamedSections() ||
+ *PreviousID == MCContext::GenericSectionID))
return *PreviousID;
// If the user has specified the same section name as would be created