diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/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. diff --git a/clang/test/Driver/debug-options-aranges.c b/clang/test/Driver/debug-options-aranges.c new file mode 100644 --- /dev/null +++ b/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 = 0x0000002c, format = DWARF32, version = 0x0002, cu_offset = 0x00000000, addr_size = 0x08, seg_size = 0x00 + +int main() +{ +}