Skip to content

[CLANG][DWARF] Do not emit -ggnu-pubnames for split dwarf version 5. #82840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

ayermolo
Copy link
Contributor

When -gsplit-dwarf is passed in clang emmmits -ggnu-pubnames which results in
.debug_gnu_pubnames/..debug_gnu_pubtypes being generated. For DWARF5 we have
functional .debug_names.

TBH not sure what the right behavior should be. Should we not generate anything
at all by default or generate .debug_names? Doing some archeological digging
initially -gnu-pubnames was always generated to be in line with what gcc does.. It was then
changed so that it was generated when split-dwarf was enabled:
6586452#diff-bac41c71569f27df21a843bcd74d2e604ed508afbdf141777761dfb545c5d228

For LLDB these gnu sections are not useful and just waste space. Maybe a better
check is to be based on tunning?

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Feb 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Alexander Yermolovich (ayermolo)

Changes

When -gsplit-dwarf is passed in clang emmmits -ggnu-pubnames which results in
.debug_gnu_pubnames/..debug_gnu_pubtypes being generated. For DWARF5 we have
functional .debug_names.

TBH not sure what the right behavior should be. Should we not generate anything
at all by default or generate .debug_names? Doing some archeological digging
initially -gnu-pubnames was always generated to be in line with what gcc does.. It was then
changed so that it was generated when split-dwarf was enabled:
6586452#diff-bac41c71569f27df21a843bcd74d2e604ed508afbdf141777761dfb545c5d228

For LLDB these gnu sections are not useful and just waste space. Maybe a better
check is to be based on tunning?


Full diff: https://github.com/llvm/llvm-project/pull/82840.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Clang.cpp (+4-3)
  • (modified) clang/test/Driver/split-debug.c (-1)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 6e1b7e8657d0dc..27a5aef17c8d71 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4479,9 +4479,10 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
                       options::OPT_gpubnames, options::OPT_gno_pubnames);
   if (DwarfFission != DwarfFissionKind::None ||
       (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
-    if (!PubnamesArg ||
-        (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
-         !PubnamesArg->getOption().matches(options::OPT_gno_pubnames)))
+    if (EffectiveDWARFVersion < 5 &&
+        (!PubnamesArg ||
+         (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
+          !PubnamesArg->getOption().matches(options::OPT_gno_pubnames))))
       CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
                                            options::OPT_gpubnames)
                             ? "-gpubnames"
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index 968f33b4cc035c..1d5f0fa42fdeea 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -11,7 +11,6 @@
 // NOINLINE-NOT: "-fsplit-dwarf-inlining"
 // SPLIT-NOT:  "-dumpdir"
 // SPLIT:      "-debug-info-kind=constructor"
-// SPLIT-SAME: "-ggnu-pubnames"
 // SPLIT-SAME: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
 
 // RUN: %clang -### -c -target wasm32 -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=SPLIT

@dwblaikie
Copy link
Collaborator

If you're debugging with lldb you should probably be using -glldb - if you're doing that, certainly gnu-pubnames should not be enabled by default or implicitly by gsplit-dwarf.

I'd say -gsplit-dwarf -glldb probably doesn't need any names/accelerator table by default (any more than the non-split dwarf should default enable names in -glldb - which, maybe it should be, since it is the default on apple platforms, I think?) - split dwarf for gcc needed to (& I think should still be the default, under -ggdb (the default on Linux etc)) enable gnuoubnames by default for correctness (gdb would assume it was present/accurate and fail lookups, rather than falling back to slow performance/exhaustive search)

@clayborg
Copy link
Collaborator

I am fine with -glldb doing the right thing for LLDB.

That being said, I don't believe that LLDB or GDB use .debug_pubnames or .debug_pubtypes as they are incomplete and can't be relied upon. So I would say we should never emit these tables unless these older GNU tables unless the user explicitly asks for them.

@clayborg
Copy link
Collaborator

I just noticed the naming difference. I am thinking of the standard older .debug_pubnames and .debug_pubtypes. Are the .debug_gnu_pubnames and .debug_gnu_pubtypes more complete and usable by debuggers? If so, then we should use the -dlldb to disable these GNU specific pubnames and pubtypes sections. And ensure that -ggdb enables these if GDB still uses them and if it doesn't support .debug_names very well.

@ayermolo
Copy link
Contributor Author

Changed to tunning.

When -gsplit-dwarf is passed in clang emmmits -ggnu-pubnames which results in
.debug_gnu_pubnames/..debug_gnu_pubtypes being generated. For DWARF5 we have
functional .debug_names.

TBH not sure what the right behavior should be. Should we not generate anything
at all by default or generate .debug_names? Doing some archeological digging
initially -gnu-pubnames was always generated to be in line with what gcc does.. It was then
changed so that it was generated when split-dwarf was enabled:
llvm@6586452#diff-bac41c71569f27df21a843bcd74d2e604ed508afbdf141777761dfb545c5d228

For LLDB these gnu sections are not useful and just waste space. Maybe a better
check is to be based on tunning?
@ayermolo ayermolo merged commit b3ae6c2 into llvm:main Feb 27, 2024
@ayermolo ayermolo deleted the disableGNUpubnames branch February 27, 2024 15:05
@nico
Copy link
Contributor

nico commented Feb 27, 2024

Looks this breaks tests on macOS: http://45.33.8.238/macm1/79435/step_7.txt

Please take a look and revert for now if it takes a while to fix.

@ayermolo
Copy link
Contributor Author

Looks this breaks tests on macOS: http://45.33.8.238/macm1/79435/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Looks this breaks tests on macOS: http://45.33.8.238/macm1/79435/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Looks like it's just one test that checks for -ggnu-pubnames. Let me take a look.

@nico
Copy link
Contributor

nico commented Feb 27, 2024

It's been a few hours. Time to revert and analyze offline?

@ayermolo
Copy link
Contributor Author

It's been a few hours. Time to revert and analyze offline?

I think I have a fix. Just takes forever to setup and build on my laptop to test it.
Basically I think mac defaults to LLDB tuning, and test that fails explicitly passes the flag in.

ayermolo added a commit to ayermolo/llvm-project that referenced this pull request Feb 27, 2024
This is a fix for llvm#82840. On mac
tunning is by default LLDB. If the flag was passed in to clang after that PR it
would not have been passed in by the driver.
@ayermolo
Copy link
Contributor Author

ayermolo commented Feb 27, 2024

fix: #83206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants