[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-25 Thread Azat Khuzhin via Phabricator via cfe-commits
azat abandoned this revision.
azat added a comment.

Closing in favor of https://reviews.llvm.org/D133092


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Azat Khuzhin via Phabricator via cfe-commits
azat marked 2 inline comments as done.
azat added inline comments.



Comment at: clang/test/Driver/debug-options-aranges.c:7
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section

probinson wrote:
> I don't see any FileCheck commands that use prefix GARANGE.
Indeed, that was a leftover. Removed.



Comment at: clang/test/Driver/debug-options-aranges.c:15
+// RUN: %clang -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges 
%s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, 
version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+

dblaikie wrote:
> Generally Clang tests don't test the LLVM behavior - this test should 
> probably just check how -gdwarf-aranges is passed to the linker. Other 
> linker-level tests will test that, given that flag, the linker does the right 
> thing.
Okay, removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 460475.
azat added a comment.

Update the test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,7 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 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.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,7 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 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.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/Driver/debug-options-aranges.c:15
+// RUN: %clang -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges 
%s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, 
version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+

Generally Clang tests don't test the LLVM behavior - this test should probably 
just check how -gdwarf-aranges is passed to the linker. Other linker-level 
tests will test that, given that flag, the linker does the right thing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/test/Driver/debug-options-aranges.c:7
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section

I don't see any FileCheck commands that use prefix GARANGE.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 460321.
azat added a comment.

Fix clang-format and tiny test refactoring


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,19 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
+
+// Check that .debug_aranges will be emitted
+//
+// RUN: %clang -g -target x86_64-linux-fuse-ld=lld -gdwarf-aranges 
%s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-linux -flto  -fuse-ld=lld -gdwarf-aranges 
%s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges 
%s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, 
version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+
+int main()
+{
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 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.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,19 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
+
+// Check that .debug_aranges will be emitted
+//
+// RUN: %clang -g -target x86_64-linux-fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-linux -flto  -fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+
+int main()
+{
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 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.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Azat Khuzhin via Phabricator via cfe-commits
azat marked an inline comment as done.
azat added a comment.

> The message is outdated now.

Actually even before it does not check that `.debug_aranges` had been emitted.

> This just checks how -gdwarf-aranges ias passed to the compiler and linker.

I've improved the test (though maybe `Address Range Header` match requires 
regex?)




Comment at: clang/test/Driver/debug-options-aranges.c:3
+
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | 
FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 
| FileCheck -check-prefix=PLUGIN_GARANGE %s

MaskRay wrote:
> `--target=x86_64`
> error: 'x86_64': unable to pass LLVM bit-code files to linker


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 460304.
azat added a comment.

Test cleanup


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,20 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-unknown-linux -c -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
+
+// Check that .debug_aranges will be emitted
+//
+// RUN: %clang -g -target x86_64-unknown-linux-fuse-ld=lld 
-gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck 
-check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck 
-check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck 
-check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, 
version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+
+int main()
+{
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,13 @@
 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.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,20 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-unknown-linux -c -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto  -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
+
+// Check that .debug_aranges will be emitted
+//
+// RUN: %clang -g -target x86_64-unknown-linux-fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto  -fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+
+int main()
+{
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,13 @@
 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.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-15 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 460302.
azat added a comment.

Add a real check of .debug_aranges in the test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,20 @@
+// REQUIRES: lld
+// Check that lld will emit dwarf aranges.
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-unknown-linux -c -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+//
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
+
+// RUN: %clang -g -target x86_64-unknown-linux-fuse-ld=lld 
-gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck 
-check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck 
-check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck 
-check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, 
version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+
+int main()
+{
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,13 @@
 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.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,20 @@
+// REQUIRES: lld
+// Check that lld will emit dwarf aranges.
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g -target x86_64-unknown-linux -c -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto  -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+//
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
+
+// RUN: %clang -g -target x86_64-unknown-linux-fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto  -fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// RUN: %clang -g -target x86_64-unknown-linux -flto=thin -fuse-ld=lld -gdwarf-aranges %s -o - | llvm-dwarfdump --debug-aranges - | FileCheck -check-prefix=ARANGES %s
+// ARANGES: Address Range Header: length = 0x002c, format = DWARF32, version = 0x0002, cu_offset = 0x, addr_size = 0x08, seg_size = 0x00
+
+int main()
+{
+}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,13 @@
 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.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/debug-options-aranges.c:1
+// Check that lld will emit dwarf aranges.
+

The message is outdated now. This just checks how -gdwarf-aranges ias passed to 
the compiler and linker.



Comment at: clang/test/Driver/debug-options-aranges.c:3
+
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | 
FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 
| FileCheck -check-prefix=PLUGIN_GARANGE %s

`--target=x86_64`



Comment at: clang/test/Driver/debug-options-aranges.c:6
+// RUN: %clang -### -target x86_64-unknown-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+//
+// GARANGE: -generate-arange-section

delete empty `//`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-14 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 460212.
azat added a comment.

Use --plugin-opt=-generate-arange-section instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,8 @@
+// Check that lld will emit dwarf aranges.
+
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | 
FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 
| FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+//
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,13 @@
 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.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,8 @@
+// Check that lld will emit dwarf aranges.
+
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=PLUGIN_GARANGE %s
+//
+// GARANGE: -generate-arange-section
+// PLUGIN_GARANGE: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,13 @@
 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.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-14 Thread Azat Khuzhin via Phabricator via cfe-commits
azat added a comment.

> I think @MaskRay was saying this doesn't actually work & different flags are 
> needed to pass to lld

I thought that @MaskRay was talking about more generic approach that will not 
require if for the linker name, and indeed 
`--plugin-opt=-generate-arange-section` is better, and both `gold` and `bfd` 
support it!

> have you tested this end-to-end/with a real compilation, does that work? (are 
> there other cases that already use -mllvm to pass flags down to lld?)

Sure:

  $ cat test.c
  void __attribute__((optnone)) bar()
  {
  }
  void __attribute__((optnone)) foo()
  {
  bar();
  }
  int main()
  {
  foo();
  }
  $ clang -c -flto=thin -fuse-ld=lld -gdwarf-aranges -g -O3 test.c
  $ clang -flto=thin -fuse-ld=lld -gdwarf-aranges -g -O3 test.c -### # to get 
full command
  $ /usr/bin/ld.lld ... -mllvm -generate-arange-section
  $ eu-readelf -waranges a.out  | grep -F -c -e foo -e bar
  2


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-14 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

I think @maskray was saying this doesn't actually work & different flags are 
needed to pass to lld - have you tested this end-to-end/with a real 
compilation, does that work? (are there other cases that already use `-mllvm` 
to pass flags down to lld?)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133875/new/

https://reviews.llvm.org/D133875

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


[PATCH] D133875: [clang] fix generation of .debug_aranges with LTO (resubmit)

2022-09-14 Thread Azat Khuzhin via Phabricator via cfe-commits
azat created this revision.
Herald added a subscriber: inglorion.
Herald added a project: All.
azat requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

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 -mllvm -generate-arange-section.

But as mentioned by @dblaikie:

  the better solution would be to encode this in IR metadata
  (DICompileUnit) if it's reasonable to respect this option on a per-CU
  basis (which it probably is, though that'd be a bit of backend work) -
  or to set it as IR global metadata (like how the DWARF version is
  encoded - probably using the same IR linker merging strategy, of
  choosing the highest value (so if any module has aranges, then a linked
  module has aranges too - even for the CUs that had it turned off) if
  it's really not feasible to support on a per-CU basis) but probably
  OK-enough, given that aranges is hopefully on the way out & not worth
  all the work of the deeper fix

This is the resubmit, previous submission [1], got reverted, due to test
failures, that had been addressed in [2] and [3].

  [1]: https://reviews.llvm.org/D133092
  [3]: https://reviews.llvm.org/D133841
  [4]: https://reviews.llvm.org/D133847

Signed-off-by: Azat Khuzhin 
Suggested-by: OCHyams 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133875

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-lld.c


Index: clang/test/Driver/debug-options-lld.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-lld.c
@@ -0,0 +1,12 @@
+// REQUIRES: lld
+// Check that lld will emit dwarf aranges.
+
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | 
FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 
| FileCheck -check-prefix=LDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck -check-prefix=LDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -fuse-ld=lld -flto 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LLDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -fuse-ld=lld -flto=thin 
-gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LLDGARANGE %s
+//
+// GARANGE-DAG: -generate-arange-section
+// LDGARANGE-NOT: {{"[^"]*lld[^"]*"}} {{.*}} "-generate-arange-section"
+// LLDGARANGE: {{"[^"]*lld[^"]*"}} {{.*}} "-generate-arange-section"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -506,6 +506,19 @@
 Suffix,
 Plugin);
 CmdArgs.push_back(Args.MakeArgString(Plugin));
+  } else {
+// NOTE:
+// - it is not possible to use lld for PS4
+// - addLTOOptions() is not used for PS5
+// Hence no need to handle SCE (like in Clang.cpp::renderDebugOptions()).
+//
+// But 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("-mllvm"));
+  CmdArgs.push_back(Args.MakeArgString("-generate-arange-section"));
+}
   }
 
   // Try to pass driver level flags relevant to LTO code generation down to


Index: clang/test/Driver/debug-options-lld.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-lld.c
@@ -0,0 +1,12 @@
+// REQUIRES: lld
+// Check that lld will emit dwarf aranges.
+
+// RUN: %clang -### -target x86_64-unknown-linux -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -fuse-ld=lld -flto -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LLDGARANGE %s
+// RUN: %clang -### -target x86_64-unknown-linux -fuse-ld=lld -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=LLDGARANGE %s
+//
+// GARANGE-DAG: -generate-arange-section
+// LDGARANGE-NOT: {{"[^"]*lld[^"]*"}} {{.*}} "-generate-arange-section"
+// LLDGARANGE: {{"[^"]*lld[^"]*"}} {{.*}}