[clang] [Clang] Add clang driver option -fpartition-static-data-sections (PR #124991)

Snehasish Kumar via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 29 10:18:15 PST 2025


================
@@ -6182,6 +6182,42 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     }
   }
 
+  if (Arg *A =
+          Args.getLastArg(options::OPT_fpartition_static_data_sections,
+                          options::OPT_fno_partition_static_data_sections)) {
+    if (!A->getOption().matches(
+            options::OPT_fno_partition_static_data_sections)) {
+      // This codegen pass is only available on x86 and AArch64 ELF targets.
+      if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
+        A->render(Args, CmdArgs);
+        // Turn on -memprof-annotate-static-data-prefix.
----------------
snehasish wrote:

I think the details here are important for userx but hard to discover. We need to add documentation to https://clang.llvm.org/docs/ClangCommandLineReference.html for this flag too. I suggest we drop the comments here and document the usage in the command line reference. What do you think?

A few thoughts on the description contents:
* It seems to assume that `-fprofile-use` is a given. 
* The last sentence "... this LLVM flag is a no-op" is inconsistent with the second bullet since it will draw the counts from the PGO profile.
* The linker flag comment seems a bit out of place and addresses my question in the review but might be confusing to readers. Instead we can say something like "For maximum effectiveness, use LLD and pass the `-Wl,-z,-keep-data-section-prefix flag`".

https://github.com/llvm/llvm-project/pull/124991


More information about the cfe-commits mailing list