go: cmd/link: Apple's symbols tool unable to read DWARF data from c-archive go.o
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.
package main
import "C"
import "log"
func main() {
log.Printf("foo")
}
$ go version
go version devel +3b6f9a0b9b Fri Apr 12 17:45:10 2019 -0700 darwin/amd64
$ CGO_CFLAGS=-g go build -buildmode=c-archive -o test.a test.go
$ ar xv test.a
x - go.o
x - 000000.o
$ symbols go.o
go.o [x86_64, 0.012018 seconds]:
null-uuid go.o [OBJECT, Empty]
0x0000000000000000 (0x3332de) SEGMENT
$ symbols 000000.o
000000.o [x86_64, 0.000155 seconds]:
null-uuid 000000.o [OBJECT, FaultedFromDisk]
0x0000000000000000 ( 0x98) SEGMENT
0x0000000000000000 ( 0x24) __DWARF __apple_names
0x0000000000000024 ( 0x24) __DWARF __apple_objc
0x0000000000000048 ( 0x24) __DWARF __apple_namespac
0x000000000000006c ( 0x2c) __DWARF __apple_types
$ symbols -v
symbols version: @(#)PROGRAM:symbols PROJECT:SamplingTools-64460.8
CoreSymbolicationDT.framework version: 64460.7
I filed a bug report with Apple about this, and they verified an issue in symbols
:
Thanks for bringing this to our attention. Our Developer Tools team has analyzed your object files, in particular the one with DWARF, and identified potential improvements for how DWARF data is extracted from an object file by the symbols tool. Specifically, the tool is currently short-circuiting because it encountered a DW_TAG_inlined_subroutine abbreviation table that includes a pair of DW_AT_call_line, DW_FORM_udata. Using DW_FORM_udata is valid DWARF, so handling this better is something the team may consider for the future. We can’t guarantee if or when this may happen.
One change for you to try and make this better right now — could you try using DW_FORM_data1 or DW_FORM_data2 in place of DW_FORM_udata? If you do so, does your interaction with the
symbols
data improve to a workable level?
Based on the above, I tried this patch which makes symbols go.o
work as expected once applied:
diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go
index df80039063..b0349a15bc 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_udata},
},
},
@@ -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_udata},
},
},
I also tried replacing FORM_udata
with FORM_data1
and FORM_data2
, but that did not fix symbols
and also caused dwarfdump
to report errors in the generated go.o
.
@aclements Can you offer any advice here? (If you’re testing locally, note that you will need 3cb92fcba71f9c0d64b3b714fc92870065848345 for symbols go.o
to work at all.)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (17 by maintainers)
Commits related to this issue
- cmd/compile: emit DWARF call_line attrs with data4 form on iOS When targeting iOS, change the format (DWARF "form") of the call line attribute for inlined subroutine DIEs, to work around an apparent ... — committed to golang/go by thanm 5 years ago
- cmd/compile: emit DWARF call_line attrs with data4 form on iOS When targeting iOS, change the format (DWARF "form") of the call line attribute for inlined subroutine DIEs, to work around an apparent ... — committed to fancybits/go by thanm 5 years ago
- cmd/link/internal/ld: ensure mach-o debug symbols are visible to App Store Passing test that shows Apple's symbols utility can now read DWARF data in go.o, after the fix in CL174538 Updates #31022 #... — committed to golang/go by tmm1 5 years ago
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.
After some testing, I’ve found that this patch generates valid symbols that can be used in the app store for iOS:
I don’t know what the implications of these changes are and whether they would be ok to upstream.