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

debug/dwarf: fails on files with unknown formSecOffset attributes #12592

Closed
aclements opened this issue Sep 11, 2015 · 5 comments
Closed

debug/dwarf: fails on files with unknown formSecOffset attributes #12592

aclements opened this issue Sep 11, 2015 · 5 comments

Comments

@aclements
Copy link
Member

If the .debug_abbrev section of an ELF file contains attributes that aren't known to the dwarf package and that have form formSecOffset, debug/dwarf.New will fail with an error like "decoding dwarf section abbrev at offset 0x17: cannot determine class of unknown attribute with formSecOffset". This worked with Go 1.4 because Go 1.4 didn't try to disambiguate formSecOffset.

To reproduce this, create a trivial C file, build it with -gsplit-dwarf, and then attempt to load the DWARF info:

echo "void main() {}" > x.c
gcc -gsplit-dwarf x.c
cat >x.go <<EOF
package main

import (
    "debug/elf"
    "fmt"
)

func main() {
    elff, _ := elf.Open("a.out")
    _, err := elff.DWARF()
    fmt.Println(err)
}
EOF
go run x.go

With Go 1.5, this will fail with the aforementioned error because a.out contains an abbrev with the unknown attribute DW_AT_GNU_addr_base, which has form DW_FORM_sec_offset. But in Go 1.4 it will succeed.

We could simply add these attributes. I believe they're being standardized in DWARF v5 anyway. But perhaps we need to more gracefully handle this case, rather than refusing to read the entire DWARF info when there's something we don't recognize. We could introduce a ClassUnknown, or perhaps more specifically ClassUnknownPtr, to use in this case. Currently formSecOffset is the only case where we must know the attribute to map the form to a class.

@aclements
Copy link
Member Author

/cc @ianlancetaylor, @jcd2. I'm happy to implement whatever we decide the right fix is.

Also, given that this is a regression, should this be in 1.5.2? Adding a ClassUnknown is a low-risk, trivial change. Presumably we wouldn't want to add the v5 attributes in 1.5.2.

@ianlancetaylor
Copy link
Contributor

ClassUnknown SGTM.

I don't think this qualifies for 1.5.2, unless you have an example of a program that built before but no longer does (because of how cmd/cgo uses debug/dwarf). Otherwise it seems to me like a minor regression.

@aclements
Copy link
Member Author

As far as I know this doesn't affect cgo, unless GCC or LLVM start emitting vendor attributes with the debug flags cgo uses. It's a minor regression, but my concern is that a single attribute like this anywhere in an image prevents debug/dwarf from opening the entire image. I ran in to this when I tried to use my memory latency tool on a google3 binary. It doesn't care about any of these vendor attributes, but it couldn't open the image at all.

@gopherbot
Copy link

CL https://golang.org/cl/14542 mentions this issue.

@gopherbot
Copy link

CL https://golang.org/cl/14541 mentions this issue.

mk0x9 pushed a commit to mk0x9/go that referenced this issue Sep 15, 2015
This adds a test that debug/dwarf can read the skeleton DWARF data
from a split DWARF image (though it doesn't currently support piecing
the external DWARF data back together). This should work because
there's nothing particularly different about skeleton DWARF data, but
previously failed because of poor handling of unrecognized attributes.

Updates golang#12592.

Change-Id: I2fc5f4679883b05ebd7ec9f0b5c398a758181a32
Reviewed-on: https://go-review.googlesource.com/14542
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: jcd . <jcd@golang.org>
@golang golang locked and limited conversation to collaborators Sep 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants