Skip to content
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

gcc13 defaults to the latest version of dwarf #9261

Closed
nexus6-haiku opened this issue Aug 22, 2023 · 20 comments
Closed

gcc13 defaults to the latest version of dwarf #9261

nexus6-haiku opened this issue Aug 22, 2023 · 20 comments

Comments

@nexus6-haiku
Copy link

Unlike gcc11, gcc13 seems to default to dwarf 5 that is incompatible with Debugger.
-gdwarf-3 must be passed manually and works for me.
From the recipe I can see the patch forces gcc to dwarf 2, do we know if version 3 has any issue?

@davidkaroly
Copy link
Contributor

davidkaroly commented Aug 25, 2023

default dwarf version seems to be 4 which is specified here:

void
haiku_override_options (void)
{
  if (!global_options_set.x_dwarf_strict)
    dwarf_strict = 1;
  if (!global_options_set.x_dwarf_version)
    dwarf_version = 4;

  /* PIE does not work on Haiku, but PIC does the right thing for position
   * independant executables. So if asked for PIE, do PIC instead.
   */
  if (flag_pie && !flag_pic)
    flag_pic = flag_pie;
  flag_pie = 0;
}

see:
https://github.com/haikuports/haikuports/blob/master/sys-devel/gcc/patches/gcc-13.2.0_2023_08_10.patchset#L5280
(the same code used to be there also in 8.3 and 11.2)

@davidkaroly
Copy link
Contributor

davidkaroly commented Aug 27, 2023

should we try something like this?

diff --git a/gcc/config/haiku.c b/gcc/config/haiku.c
index af14c02..bdd6f08 100644
--- a/gcc/config/haiku.c
+++ b/gcc/config/haiku.c
@@ -28,7 +28,7 @@ haiku_override_options (void)
   if (!global_options_set.x_dwarf_strict)
     dwarf_strict = 1;
   if (!global_options_set.x_dwarf_version)
-    dwarf_version = 4;
+    dwarf_version = 3;

   /* PIE does not work on Haiku, but PIC does the right thing for position
    * independant executables. So if asked for PIE, do PIC instead.

before

~> gcc -g -c test.c
~> readelf -w test.o | grep -A2 Unit
  Compilation Unit @ offset 0:
   Length:        0xc4 (32-bit)
   Version:       4

after

~> gcc -g -c test.c
~> readelf -w test.o | grep -A2 Unit
  Compilation Unit @ offset 0:
   Length:        0xc6 (32-bit)
   Version:       3
~>

@nielx @waddlesplash

@nielx
Copy link
Contributor

nielx commented Aug 27, 2023

I think @waddlesplash identified that it is actually not the case that we previously set dwarf version 2, but we have been at dwarf version 4 for a while now. Only it seems that GCC is now using Dwarf version 4 output for lineinfo, and our Debugger does not support that.

I suggest the actual solution is not to downgrade the default dwarf output, but to patch Debugger to support the lineinfo.

@nielx
Copy link
Contributor

nielx commented Aug 27, 2023

@davidkaroly
Copy link
Contributor

I suggest the actual solution is not to downgrade the default dwarf output, but to patch Debugger to support the lineinfo.

yes you're right, that would be a better way forward

@pulkomandy
Copy link
Member

@waddlesplash
Copy link
Member

I don't know about that; last I was seeing, without explicitly specifying -gdwarf-4, GCC was still generating version 5 lineinfo.

@davidkaroly
Copy link
Contributor

davidkaroly commented Sep 5, 2023

I don't know about that; last I was seeing, without explicitly specifying -gdwarf-4, GCC was still generating version 5 lineinfo.

yep that seems to be the case: gcc -g generates DWARFv4 debug info with v5 lineinfo, which cannot be parsed by Haiku Debugger.
gcc -gdwarf-4 generates DWARFv4 debug info with v4 lineinfo which can be processed by Debugger.

@nielx
Copy link
Contributor

nielx commented Sep 6, 2023

This smells like a GCC bug, but spending about an hour looking through the code and to be honest, nothing really stands out. There seems to be a global variable, dwarf_version which is set to the dwarf version that is either set explicitly, or implicitly. Then the meat seems to be in output_line_info(), specifically line 13092, where output_dwarf_version() seems to output 5, even though I assume that other uses of this function would output 4 (like the output_compilation_unit_header().

Am I looking at the right code? And if so, does that mean that somewhere during outputting dwarf info the global variable is changed, unless the option was set by command line?

@korli
Copy link
Contributor

korli commented Sep 6, 2023

While at here, the code for other OSes was updated to use if (!OPTION_SET_P (dwarf_version)) and if (!OPTION_SET_P (dwarf_strict))
see gcc-mirror/gcc@00f3429

An alternative like vxworks would be to set DWARF_VERSION_DEFAULT in gcc/gcc/config/haiku.h

@waddlesplash
Copy link
Member

DWARF_VERSION_DEFAULT sounds like the best solution.

@davidkaroly
Copy link
Contributor

Meanwhile Debugger now should be able to parse v5 line number info, see: hrev57309

@nielx
Copy link
Contributor

nielx commented Oct 4, 2023

Arguably the better solution anyway ;-)

@korli
Copy link
Contributor

korli commented Oct 5, 2023

Meanwhile Debugger now should be able to parse v5 line number info, see: hrev57309

Albeit only in nightlies... or do you intend to bring this into the beta4 branch?

@davidkaroly
Copy link
Contributor

Meanwhile Debugger now should be able to parse v5 line number info, see: hrev57309

Albeit only in nightlies... or do you intend to bring this into the beta4 branch?

not sure.

is there a description of the backporting process/policy for the beta maintenance branches? i.e. what kind of backports can be accepted, who makes the decision etc.

@pulkomandy
Copy link
Member

The process is to push some changes to the refs/for/r1beta4 branch on Gerrit and it gets reviewed and merged as usual (someone has to vote +2 and merge, anyone who has commit permissions can do it).

There isn't really a policy except for "don't break things". So, no ABI changes, mainly bugfixes, and usually changes that have been deployed on the nightlies for a few days/weeks to make sure there is no regressions.

And, "Debugger does not show any sourcecode" can be considered a bug, so, we can put it in the bugfix category?

@korli
Copy link
Contributor

korli commented Oct 5, 2023

I see 7 commits in src/kits/debugger since r1beta4, they look well concentrated on src/kits/debugger/dwarf. Debugger code isn't affected it seems.

Gerrit lets the user cherry-pick changes for review in the UI.

@davidkaroly
Copy link
Contributor

davidkaroly commented Oct 16, 2023

The patches for parsing lineinfo v4 have been cherry-picked to r1beta branch.
Two more patches are open in gerrit, for lineinfo v5. (update: these are also merged)

@korli
Copy link
Contributor

korli commented Dec 19, 2023

Can we close this?

@nexus6-haiku
Copy link
Author

Fine from my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants