[flang-commits] [clang] [flang] [flang] Support -ffunction-sections and -fdata-sections. (PR #199731)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Wed May 27 07:01:38 PDT 2026


================
@@ -262,6 +262,18 @@ void Flang::addCodegenOptions(const ArgList &Args,
        options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
        options::OPT_ftime_report, options::OPT_ftime_report_EQ,
        options::OPT_funroll_loops, options::OPT_fno_unroll_loops});
+
+  const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
+  bool UseSeparateSections = isUseSeparateSections(Triple);
+  if (Args.hasFlag(options::OPT_ffunction_sections,
+                   options::OPT_fno_function_sections, UseSeparateSections))
+    CmdArgs.push_back("-ffunction-sections");
+
+  bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
+  if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
+                   UseSeparateSections || HasDefaultDataSections))
+    CmdArgs.push_back("-fdata-sections");
+
----------------
tarunprabhu wrote:

Is think the handling of these is exactly the same as in clang? If so, we should consider sharing the code. There is a lot of precedent for moving these to `clang/lib/Driver/ToolChains/CommonArgs.cpp`. See, for instance, `shouldRecordCommandLine` in that file.

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


More information about the flang-commits mailing list