[Driver] -fstack-size-section: pass -stack-size-section to backend for LTO
authorFangrui Song <i@maskray.me>
Sat, 10 Dec 2022 10:15:29 +0000 (10:15 +0000)
committerFangrui Song <i@maskray.me>
Sat, 10 Dec 2022 10:15:29 +0000 (10:15 +0000)
The option does not change IR but affect object file generation. Without a
backend option the option is a no-op for in-process ThinLTO.

The problem is known and there are many options similar to -fstack-size-section.
That said, -fstack-size-section has relatively wider adoption, so it probably
makes sense to have custom code for it.

Close https://github.com/llvm/llvm-project/issues/59424

clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/stack-size-section.c

index 6f975ef..47f5ff2 100644 (file)
@@ -773,6 +773,11 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
       D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
   }
 
+  if (Args.hasFlag(options::OPT_fstack_size_section,
+                   options::OPT_fno_stack_size_section, false))
+    CmdArgs.push_back(
+        Args.MakeArgString(Twine(PluginOptPrefix) + "-stack-size-section"));
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
index b99b140..71b9f85 100644 (file)
 // RUN: %clang -target x86_64-unknown -fno-stack-size-section -fstack-size-section %s -### 2>&1 \
 // RUN:     | FileCheck %s --check-prefix=CHECK-PRESENT
 
+// RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section %s 2>&1 | FileCheck %s --check-prefix=LTO
+// RUN: %clang -### --target=x86_64-linux-gnu -flto -fstack-size-section -fno-stack-size-section %s 2>&1 | FileCheck %s --check-prefix=LTO-NO
+
+// LTO: "-plugin-opt=-stack-size-section"
+// LTO-NO-NOT: "-plugin-opt=-stack-size-section"
+
 int foo() { return 42; }