Author: Azat Khuzhin
Date: 2022-10-04T20:03:36Z
New Revision: 16512898956857b13e566165ba9a195be81d325f

URL: 
https://github.com/llvm/llvm-project/commit/16512898956857b13e566165ba9a195be81d325f
DIFF: 
https://github.com/llvm/llvm-project/commit/16512898956857b13e566165ba9a195be81d325f.diff

LOG: [clang] fix generation of .debug_aranges with LTO

Right now in case of LTO the section is not emited:

    $ cat test.c
    void __attribute__((optnone)) bar()
    {
    }
    void __attribute__((optnone)) foo()
    {
            bar();
    }
    int main()
    {
            foo();
    }

    $ clang -flto=thin -gdwarf-aranges -g -O3 test.c
    $ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
    0

    $ clang -gdwarf-aranges -g -O3 test.c
    $ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
    2

Fix this by passing explicitly --plugin-opt=-generate-arange-section.

Suggested-by: OCHyams <orlando.hy...@sony.com>

Reviewed By: dblaikie, MaskRay

Differential Revision: https://reviews.llvm.org/D133092

Added: 
    clang/test/Driver/debug-options-aranges.c

Modified: 
    clang/lib/Driver/ToolChains/CommonArgs.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4bc16710e194..d81faa365228 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -509,6 +509,14 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
     CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+    CmdArgs.push_back(
+        Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 

diff  --git a/clang/test/Driver/debug-options-aranges.c 
b/clang/test/Driver/debug-options-aranges.c
new file mode 100644
index 000000000000..4dc098b7d185
--- /dev/null
+++ b/clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,6 @@
+// REQUIRES: lld
+
+/// Check that the linker plugin will get -generate-arange-section.
+// RUN: %clang -### -g --target=x86_64-linux -flto      -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to