-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/link: Apple's symbols tool unable to read DWARF data from c-archive go.o #31459
Comments
Related, but I don't think it is your bug: https://go-review.googlesource.com/c/go/+/170638 . Dwarfdump is afflicted by some of these same LLVM bugs, so its diagnoses are not 100% trustworthy except as an indicator that Apple's tools are likely to reject an input. You might want to get your hands on a copy of gnu binutils (Macports or Homebrew) and see what [g]objdump says. |
@tmm1 thanks for the analysis and for getting in touch with the Apple support folks. You posted a patch that changes the definition of the abbrev entry for the inlined routine DIE, but I don't see any changes to other related parts of dwarf.go. Could you please post the entire patch? (or if this the entire patch, please confirm)? Switching from FORM_udata to FORM_data4 is certainly doable, but it would increase the overall size of the DWARF (not good) and goes against the advice given in the DWARF standard (e.g. DWARF 4 spec section 7.5.4 " Producers are therefore strongly encouraged to use DW_FORM_sdata or DW_FORM_udata for signed and unsigned integers respectively, rather than DW_FORM_data). |
Sorry, hit the wrong button there (didn't mean to close the issue). |
I did not change anything else, but I am not very familiar with dwarf or this part of the code so I didn't know what else might need to change. |
The code you modified controls how the .debug_abbrev section is emitted, but for that change to take effect you also have to change other parts the compiler that emit DWARF DIE data against that template. When I pull in your patch and rebuild (make/bash), I see a bunch of errors in the linker's dwarf tests (e.g. "cd src/cmd/link/internal/ld ; go test -test.v"):
|
@thanm Thanks this makes a lot more sense now. So I'm generating broken DWARF, but since it is no longer broken in the way symbols dislikes (i.e containing a pair of DW_AT_call_line,DW_FORM_udata), the tool is able to read it. I understand the downsides of switching from udata, and it's unfortunate the Apple tool doesn't conform to the spec here. I've added that section to my bug report and hope this is something they can fix in the future. In the mean time it appears our only option would be a patch to switch to data4. Would something like this be merged despite the downsides? Would it need to be behind an optional flag? |
After some testing, I've found that this patch generates valid symbols that can be used in the app store for iOS: diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go
index df80039063..ad8344ebe3 100644
--- a/src/cmd/internal/dwarf/dwarf.go
+++ b/src/cmd/internal/dwarf/dwarf.go
@@ -434,7 +434,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
{DW_AT_low_pc, DW_FORM_addr},
{DW_AT_high_pc, DW_FORM_addr},
{DW_AT_call_file, DW_FORM_data4},
- {DW_AT_call_line, DW_FORM_udata},
+ {DW_AT_call_line, DW_FORM_sdata},
},
},
@@ -446,7 +446,7 @@ var abbrevs = [DW_NABRV]dwAbbrev{
{DW_AT_abstract_origin, DW_FORM_ref_addr},
{DW_AT_ranges, DW_FORM_sec_offset},
{DW_AT_call_file, DW_FORM_data4},
- {DW_AT_call_line, DW_FORM_udata},
+ {DW_AT_call_line, DW_FORM_sdata},
},
},
@@ -1212,7 +1212,7 @@ func PutInlinedFunc(ctxt Context, s *FnState, callersym Sym, callIdx int) error
// Emit call file, line attrs.
ctxt.AddFileRef(s.Info, ic.CallFile)
- putattr(ctxt, s.Info, abbrev, DW_FORM_udata, DW_CLS_CONSTANT, int64(ic.CallLine), nil)
+ putattr(ctxt, s.Info, abbrev, DW_FORM_sdata, DW_CLS_CONSTANT, int64(ic.CallLine), nil)
// Variables associated with this inlined routine instance.
vars := ic.InlVars I don't know what the implications of these changes are and whether they would be ok to upstream. |
FYI this was Apple's response about using udata vs data1:
|
@champo Awesome! Does the test I added in https://go-review.googlesource.com/c/go/+/170451 pass with your changes? |
@tmm1 I'm afraid not :( It seems that this patch only works using |
Change https://golang.org/cl/174538 mentions this issue: |
@tmm1 You mentioned previously that you filed a bug with Apple on this issue. Is there a bug number you could share, so that I can monitor it? If Apple fixes the bug I would like to find out, so that I can consider updating the Go compiler. |
Sure, it's rdar://49599876 |
This seems to fix the bug, at least for me.
begins
piu.go (same file as above):
Discarding the proposed fix, I get(end-to-end):
I probably ought to concoct a test for this. |
I have a test in https://go-review.googlesource.com/c/go/+/170451 |
When targeting iOS, change the format (DWARF "form") of the call line attribute for inlined subroutine DIEs, to work around an apparent bug in /usr/bin/symbols on Darwin. [Just for posterity: there is nothing wrong with using DW_FORM_udata for the call_line attribute form; this is perfectly legal DWARF (and is in fact recommended by the standard relative to data4, which is less descriptive and often takes more space). The form switch is there just to make the Apple tools happy.] Updates #31459. Change-Id: Iaf362788a8c6684eea4cde8956c0661b694cecc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/174538 Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
When targeting iOS, change the format (DWARF "form") of the call line attribute for inlined subroutine DIEs, to work around an apparent bug in /usr/bin/symbols on Darwin. [Just for posterity: there is nothing wrong with using DW_FORM_udata for the call_line attribute form; this is perfectly legal DWARF (and is in fact recommended by the standard relative to data4, which is less descriptive and often takes more space). The form switch is there just to make the Apple tools happy.] Updates golang#31459. Change-Id: Iaf362788a8c6684eea4cde8956c0661b694cecc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/174538 Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]> (cherry picked from commit b56d1ba)
Change https://golang.org/cl/170451 mentions this issue: |
…Store Passing test that shows Apple's symbols utility can now read DWARF data in go.o, after the fix in CL174538 Updates #31022 #22716 #31459 Change-Id: I56c3517ad6d0a9f39537182f63cef56bb198aa83 Reviewed-on: https://go-review.googlesource.com/c/go/+/170451 Reviewed-by: Than McIntosh <[email protected]>
I received an update from Apple today regarding another possible problem with our DWARF output. I think this is based on the original
|
Thanks for the update. I will take a look. |
For the specific case of the relocatable object I'm not sure if the errors being reported make sense, since the ranges in question are covered by relocations and the verifier itself doesn't seem to be reading or applying relocations. When I do a regular link of the program in question I do still see some issues, however, meaning that the verifier does seem to be catching potential problems. I filed a new issue to track: |
Can this bug be closed now, given the compiler change that was submitted? There is a tracking bug for the DWARF verifier issues that the Apple folks reported. |
Apple's
/usr/bin/symbols
is unable to parse DWARF data embedded by the golang compiler, making iOS app using gomobile hard to debug because their crash reports are missing symbols.I filed a bug report with Apple about this, and they verified an issue in
symbols
:Based on the above, I tried this patch which makes
symbols go.o
work as expected once applied:I also tried replacing
FORM_udata
withFORM_data1
andFORM_data2
, but that did not fixsymbols
and also causeddwarfdump
to report errors in the generatedgo.o
.@aclements Can you offer any advice here? (If you're testing locally, note that you will need 3cb92fc for
symbols go.o
to work at all.)cc #31022 #28997 @eliasnaur
The text was updated successfully, but these errors were encountered: