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 <a.khuz...@semrush.com> Suggested-by: OCHyams <orlando.hy...@sony.com> 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[^"]*"}} {{.*}} "-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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits