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 @@ -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 diff --git a/clang/test/Driver/debug-options-lld.c b/clang/test/Driver/debug-options-lld.c new file mode 100644 --- /dev/null +++ b/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"