Bug 68072 - malformed DWARF TagVariable entry
Summary: malformed DWARF TagVariable entry
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: go (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-23 17:25 UTC by Dominik Vogt
Modified: 2015-11-20 22:52 UTC (History)
1 user (show)

See Also:
Host: s390x
Target: s390x
Build: s390x
Known to work:
Known to fail:
Last reconfirmed: 2015-11-11 00:00:00


Attachments
Experimental fix (547 bytes, application/mbox)
2015-10-26 16:06 UTC, Dominik Vogt
Details
Test case (65 bytes, text/plain)
2015-11-18 09:42 UTC, Dominik Vogt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dominik Vogt 2015-10-23 17:25:22 UTC
Compiling the package crypto/secp256k1 from the go-ethereum package yields the error message "malformed DWARF TagVariable entry" from cgo.  Maybe it does not yet know about the latest changes to debug information in Gcc?

I know this report is very terse; if a code example is necessary to debug or fix this issue, just give me a shout and I'll see what I can do next week.

(Gcc sources checked out at 25th of Septermber, 2015.)
Comment 1 Dominik Vogt 2015-10-26 15:40:46 UTC
It seems that the DWARF library is unable to handle DW_AT_specification:

-- snip --
 <1><7b4>: Abbrev Number: 27 (DW_TAG_variable)
    <7b5>   DW_AT_specification: <0x8b>
    <7b9>   DW_AT_decl_file   : 13
    <7ba>   DW_AT_decl_line   : 77
    <7bb>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 4 80    (DW_OP_addr: 480)


 <1><8b>: Abbrev Number: 10 (DW_TAG_variable)
    <8c>   DW_AT_name        : (indirect string, offset: 0x3c4): secp256k1_nonce_function_rfc6979
    <90>   DW_AT_decl_file   : 14
    <91>   DW_AT_decl_line   : 104
    <92>   DW_AT_type        : <0x98>
    <96>   DW_AT_external    : 1
    <97>   DW_AT_declaration : 1
-- snip --

DW_AT_name and DW_AT_type are provided by the DW_TAG_variable that the DW_AT_specification attribute is pointing to.  Is that a known problem; ist there already a fix?  Otherwise I can try to make a patch.
Comment 2 Ian Lance Taylor 2015-10-26 15:55:59 UTC
This is not a known bug.  I wonder what is special about this package that it causes it to happen?  I don't see anything new in GCC related to DW_AT_specification.

I think the place to fix in the Go sources would be cmd/cgo/gcc.go.
Comment 3 Dominik Vogt 2015-10-26 16:06:32 UTC
Created attachment 36588 [details]
Experimental fix

The attached patch fixes the problem for us by skipping DW_TAG_variable DWARF info that only contains a DW_AT_specification (no DW_AT_type and DW_AT_name), assuming that they are just duplicate declarations/definitions.
Comment 4 Dominik Vogt 2015-10-26 16:11:35 UTC
@comment 2

I can't see anything special that the file does:

-- secp256.go --
package secp256k1

/*
#cgo CFLAGS: -I./secp256k1
...
#include "./secp256k1/src/secp256k1.c"
*/
import "C"
-- END --

Then in

-- secp256k1.c --
const secp256k1_nonce_function_t secp256k1_nonce_function_rfc6979 = nonce_function_rfc6979;
-- END --

Just this one occurence of the symbol "secp256k1_nonce_function_rfc6979".
Comment 5 Dominik Vogt 2015-11-11 06:45:54 UTC
Any opinions on the patch in comment 3?
Comment 6 Ian Lance Taylor 2015-11-11 20:26:57 UTC
The patch seems plausible but we'll need a test case, even if that test case only fails with current GCC.  It looks like the GCC change might be due to the early-debug work.  It looks like it should be pretty easy to boil down the test case into a small piece of code that fails.
Comment 7 Dominik Vogt 2015-11-17 09:07:07 UTC
All right, I'll try to extract a minimal test case.
Comment 8 Dominik Vogt 2015-11-18 09:42:58 UTC
Created attachment 36750 [details]
Test case

This is the requested minimal test program.
Comment 9 Ian Lance Taylor 2015-11-20 21:18:33 UTC
Thanks very much for taking the time to narrow down the test case.  That is nice and simple.
Comment 10 Ian Lance Taylor 2015-11-20 22:02:30 UTC
FYI, refiled as https://golang.org/issue/13344 and sent out https://golang.org/cl/17151 , a variant of the patch you suggested.
Comment 11 ian@gcc.gnu.org 2015-11-20 22:49:19 UTC
Author: ian
Date: Fri Nov 20 22:48:47 2015
New Revision: 230685

URL: https://gcc.gnu.org/viewcvs?rev=230685&root=gcc&view=rev
Log:
	PR go/68072
    cmd/cgo: ignore vars with no name or type if they have a AttrSpecification
    
    Backport of master CL https://golang.org/cl/17151.
    
    Fixes https://gcc.gnu.org/PR/68072.
    
    Reviewed-on: https://go-review.googlesource.com/17152

Modified:
    trunk/gcc/go/gofrontend/MERGE
    trunk/libgo/go/cmd/cgo/gcc.go
Comment 12 ian@gcc.gnu.org 2015-11-20 22:49:38 UTC
Author: ian
Date: Fri Nov 20 22:49:06 2015
New Revision: 230686

URL: https://gcc.gnu.org/viewcvs?rev=230686&root=gcc&view=rev
Log:
	PR go/68072
    cmd/cgo: ignore vars with no name or type if they have a AttrSpecification
    
    Backport of master CL https://golang.org/cl/17151.
    
    Fixes https://gcc.gnu.org/PR/68072.
    
    Reviewed-on: https://go-review.googlesource.com/17152

Modified:
    branches/gcc-5-branch/libgo/go/cmd/cgo/gcc.go
Comment 13 Ian Lance Taylor 2015-11-20 22:52:08 UTC
Should be fixed on mainline and GCc 5 branch.