[lld] [lld][COFF] Don't truncate .llvm. and llvm_ section names (PR #229112)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 08:08:25 PDT 2026
https://github.com/matthew-j-code created https://github.com/llvm/llvm-project/pull/229112
Sections prefixed with ".llvm" or "llvm_" hold LLVM-specific metadata that standard Windows and Microsoft tools don't consume. Keep their full names in the string table so LLVM tools can find them.
>From 58f313998bd7ecc5ebc526c9e2bb49839d19e718 Mon Sep 17 00:00:00 2001
From: "Jones, Matthew (DI SW SIM FRWK PLAT SIMFW HPC)"
<jones.matthew at siemens.com>
Date: Thu, 24 Sep 2026 06:26:21 -0700
Subject: [PATCH] [lld][COFF] Don't truncate .llvm. and llvm_ section names
Sections prefixed with ".llvm" or "llvm_" hold LLVM-specific metadata
that standard Windows and Microsoft tools don't consume. Keep their
full names in the string table so LLVM tools can find them.
---
lld/COFF/Writer.cpp | 9 ++++++++-
lld/docs/ReleaseNotes.md | 6 ++++++
lld/test/COFF/ctors_dtors_priority.s | 10 ++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 3cab426df55cf3a..e0cd9093596f462 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1583,11 +1583,18 @@ void Writer::createSymbolAndStringTable() {
// solution where discardable sections have long names preserved and
// non-discardable sections have their names truncated, to ensure that any
// section which is mapped at runtime also has its name mapped at runtime.
+ // As an exception, sections prefixed with ".llvm." or "llvm_" preserve their
+ // full name in the string table. These sections are LLVM specific and are not
+ // consumed by standard Windows and Microsoft tooling, so they don't need to
+ // abide by the 8-character limit. Preserving their full names allows LLVM
+ // tools and runtime libraries to reliably identify and inspect them.
SmallVector<OutputSection *> longNameSections;
for (OutputSection *sec : ctx.outputSections) {
if (sec->name.size() <= COFF::NameSize)
continue;
- if ((sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
+ if (!((sec->name).starts_with(".llvm.") ||
+ (sec->name).starts_with("llvm_")) &&
+ (sec->header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
continue;
if (ctx.config.warnLongSectionNames) {
Warn(ctx)
diff --git a/lld/docs/ReleaseNotes.md b/lld/docs/ReleaseNotes.md
index 827d09bec5776a1..017924ba2f3586b 100644
--- a/lld/docs/ReleaseNotes.md
+++ b/lld/docs/ReleaseNotes.md
@@ -33,6 +33,12 @@ from the [LLVM releases web site](https://llvm.org/releases/).
### COFF Improvements
+* Non-standard section names prefixed with `.llvm.` or `llvm_` are no longer
+ truncated to the 8-character COFF limit. Because these sections represent
+ LLVM-specific metadata and are not consumed by standard Windows and Microsoft
+ tooling, preserving their full names in the string table allows LLVM
+ functionality to access them more easily.
+
### MinGW Improvements
### MachO Improvements
diff --git a/lld/test/COFF/ctors_dtors_priority.s b/lld/test/COFF/ctors_dtors_priority.s
index 0df3cd4a510c8fd..8ffd0aa8933fb7a 100644
--- a/lld/test/COFF/ctors_dtors_priority.s
+++ b/lld/test/COFF/ctors_dtors_priority.s
@@ -4,6 +4,7 @@
# RUN: llvm-objdump -s %t.exe | FileCheck %s
## In MSVC mode the second-dot stripping must NOT apply.
+## For LLD on Windows non-standard section names ".llvm." and "llvm_" should NOT be truncated.
# RUN: lld-link -force:unresolved -entry:main %t.obj -out:%t.msvc.exe
# RUN: llvm-readobj --section-headers %t.msvc.exe | FileCheck %s --check-prefix=MSVC
@@ -54,3 +55,12 @@ main:
# MSVC: Name: .ctors.0
# MSVC: Name: .dtors.0
# MSVC: Name: .dtors.0
+
+.section .llvm.offload.bad, "w"
+.quad 0
+
+.section llvm_offload_bad, "w"
+.quad 0
+
+# MSVC: Name: .llvm.offload.bad
+# MSVC: Name: llvm_offload_bad
\ No newline at end of file
More information about the llvm-commits
mailing list