[llvm] [MemProf][Docs] Add more information on static data partitioning (PR #220446)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 23:14:35 PDT 2026
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/220446
>From cc795eddd4d9a174349a97bc423c21fa5d9545bb Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Wed, 2 Sep 2026 01:16:35 +0000
Subject: [PATCH 1/2] [MemProf][Docs] Add more information on static data
partitioning
Clarify some sentences that I found hard to parse. Also explicitly
mention that a linker script is required to ensure the sections are
split and give an example linker script.
---
llvm/docs/MemProf.md | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/llvm/docs/MemProf.md b/llvm/docs/MemProf.md
index c5a4b8e6ff131..3839e03f98455 100644
--- a/llvm/docs/MemProf.md
+++ b/llvm/docs/MemProf.md
@@ -129,11 +129,30 @@ This feature uses a hybrid approach:
To enable this feature, pass the following flags to the compiler:
- `-fpartition-static-data-sections`: Instructs the compiler to generate `.hot` and `.unlikely` section prefixes for hot and cold static data respectively in the relocatable object files.
-- `-Wl,-z,keep-data-section-prefix`: Informs the LLD linker that `.data.rel.ro.hot` and `.data.rel.ro.unlikely` as relro sections. LLD requires all relro sections to be contiguous and this flag allows us to interleave the hotness-suffixed `.data.rel.ro` sections with other relro sections.
-- `-Wl,-script=<linker_script>`: Group hot and/or cold data sections, and order the data sections.
+- `-Wl,-z,keep-data-section-prefix`: This flag is currently only supported in LLD. It informs the linker that `.data.rel.ro.hot` and `.data.rel.ro.unlikely` are relro sections (rather than only recognizing `.data.rel.ro`). LLD requires all relro sections to be contiguous and this flag allows us to interleave the hotness-suffixed `.data.rel.ro` sections with other relro sections.
+- `-Wl,-script=<linker_script>`: Group hot and/or cold data sections, and order the data sections. Without explicitly accounting for hotness suffixed data sections in a linker script, LLD will simply combine them, negating the effect. A simple linker script like the following should work on must Linux setups:
+
+```ld
+SECTIONS {
+ .rodata.unlikely : { *(.rodata.unlikely.); *(.rodata.cst*.unlikely); }
+ .rodata : { .rodata }
+} INSERT AFTER .fini
+
+SECTIONS {
+ .data.rel.ro : { .data.rel.ro }
+ .data.rel.ro.unlikely : { *(.data.rel.ro.unlikely.); }
+} INSERT AFTER .fini_array
+
+SECTIONS {
+ .data : { .data }
+ .data.unlikely : { *(.data.unlikely.); }
+ .bss : { .bss }
+ .bss.unlikely : { *(.bss.unlikely.); }
+} INSERT AFTER .got.plt
+```
```bash
-clang++ -fmemory-profile-use=memprof.memprofdata -fpartition-static-data-sections -fuse-ld=lld -Wl,-z,keep-data-section-prefix -O2 source.cpp -o optimized_app
+clang++ -fmemory-profile-use=memprof.memprofdata -fpartition-static-data-sections -fuse-ld=lld -Wl,-z,keep-data-section-prefix -Wl,-script=<linker_script> -O2 source.cpp -o optimized_app
```
The optimized layout clusters hot static data, improving dTLB and cache efficiency.
>From fea4018e8e14f0bc992c2d8064a7affc4b2ad737 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 4 Sep 2026 06:14:20 +0000
Subject: [PATCH 2/2] feedback
---
llvm/docs/MemProf.md | 24 ++----------------------
1 file changed, 2 insertions(+), 22 deletions(-)
diff --git a/llvm/docs/MemProf.md b/llvm/docs/MemProf.md
index 3839e03f98455..80520452e8d0b 100644
--- a/llvm/docs/MemProf.md
+++ b/llvm/docs/MemProf.md
@@ -129,30 +129,10 @@ This feature uses a hybrid approach:
To enable this feature, pass the following flags to the compiler:
- `-fpartition-static-data-sections`: Instructs the compiler to generate `.hot` and `.unlikely` section prefixes for hot and cold static data respectively in the relocatable object files.
-- `-Wl,-z,keep-data-section-prefix`: This flag is currently only supported in LLD. It informs the linker that `.data.rel.ro.hot` and `.data.rel.ro.unlikely` are relro sections (rather than only recognizing `.data.rel.ro`). LLD requires all relro sections to be contiguous and this flag allows us to interleave the hotness-suffixed `.data.rel.ro` sections with other relro sections.
-- `-Wl,-script=<linker_script>`: Group hot and/or cold data sections, and order the data sections. Without explicitly accounting for hotness suffixed data sections in a linker script, LLD will simply combine them, negating the effect. A simple linker script like the following should work on must Linux setups:
-
-```ld
-SECTIONS {
- .rodata.unlikely : { *(.rodata.unlikely.); *(.rodata.cst*.unlikely); }
- .rodata : { .rodata }
-} INSERT AFTER .fini
-
-SECTIONS {
- .data.rel.ro : { .data.rel.ro }
- .data.rel.ro.unlikely : { *(.data.rel.ro.unlikely.); }
-} INSERT AFTER .fini_array
-
-SECTIONS {
- .data : { .data }
- .data.unlikely : { *(.data.unlikely.); }
- .bss : { .bss }
- .bss.unlikely : { *(.bss.unlikely.); }
-} INSERT AFTER .got.plt
-```
+- `-Wl,-z,keep-data-section-prefix`: This flag is currently only supported in LLD. It informs the linker that `.data.rel.ro.hot` and `.data.rel.ro.unlikely` are relro sections (rather than only recognizing `.data.rel.ro`). LLD requires all relro sections to be contiguous and this flag allows us to interleave the hotness-suffixed `.data.rel.ro` sections with other relro sections. Additionally, it makes LLD keep the data section suffixes (hot/unlikely) as otherwise they will get merged together into the standard data sections.
```bash
-clang++ -fmemory-profile-use=memprof.memprofdata -fpartition-static-data-sections -fuse-ld=lld -Wl,-z,keep-data-section-prefix -Wl,-script=<linker_script> -O2 source.cpp -o optimized_app
+clang++ -fmemory-profile-use=memprof.memprofdata -fpartition-static-data-sections -fuse-ld=lld -Wl,-z,keep-data-section-prefix -O2 source.cpp -o optimized_app
```
The optimized layout clusters hot static data, improving dTLB and cache efficiency.
More information about the llvm-commits
mailing list