FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
cgo: use debug data section for ELF

When generating enums use the debug data section instead of the
DWARF debug info, if it is available in the ELF file. This allows
mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.

Fixes issue 2470.

Please review this at http://codereview.appspot.com/6495090/

Affected files:
M src/cmd/cgo/gcc.go


Index: src/cmd/cgo/gcc.go
===================================================================
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -616,15 +616,16 @@
n.FuncType = conv.FuncType(f, pos)
} else {
n.Type = conv.Type(types[i], pos)
- if enums[i] != 0 && n.Type.EnumValues != nil {
+ // Prefer debug data over DWARF debug output, if we have it.
+ if n.Kind == "const" && i < len(enumVal) {
+ n.Const = fmt.Sprintf("%#x", enumVal[i])
+ } else if enums[i] != 0 && n.Type.EnumValues != nil {
k := fmt.Sprintf("__cgo_enum__%d", i)
n.Kind = "const"
n.Const = fmt.Sprintf("%#x", n.Type.EnumValues[k])
// Remove injected enum to ensure the value will deep-compare
// equally in future loads of the same constant.
delete(n.Type.EnumValues, k)
- } else if n.Kind == "const" && i < len(enumVal) {
- n.Const = fmt.Sprintf("%#x", enumVal[i])
}
}
}
@@ -802,17 +803,35 @@
return d, f.ByteOrder, data
}

- // Can skip debug data block in ELF and PE for now.
- // The DWARF information is complete.
-
if f, err := elf.Open(gccTmp()); err == nil {
d, err := f.DWARF()
if err != nil {
fatalf("cannot load DWARF output from %s: %v", gccTmp(), err)
}
- return d, f.ByteOrder, nil
+ var data []byte
+ symtab, err := f.Symbols()
+ if err == nil {
+ for i := range symtab {
+ s := &symtab[i]
+ if s.Name == "__cgodebug_data" {
+ // Found it. Now find data section.
+ if i := int(s.Section); 0 <= i && i < len(f.Sections) {
+ sect := f.Sections[i]
+ if sect.Addr <= s.Value && s.Value < sect.Addr+sect.Size {
+ if sdat, err := sect.Data(); err == nil {
+ data = sdat[s.Value-sect.Addr:]
+ }
+ }
+ }
+ }
+ }
+ }
+ return d, f.ByteOrder, data
}

+ // Can skip debug data block in PE for now.
+ // The DWARF information is complete.
+
if f, err := pe.Open(gccTmp()); err == nil {
d, err := f.DWARF()
if err != nil {

Search Discussions

  • Minux Ma at Sep 6, 2012 at 4:33 pm
    LGTM, also tested on darwin/arm which is also affected by issue 2470.

    http://codereview.appspot.com/6495090/
  • Jsing at Sep 7, 2012 at 3:33 am
    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***

    cgo: use debug data section for ELF

    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.

    Fixes issue 2470.

    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090


    http://codereview.appspot.com/6495090/
  • Fullung at Sep 7, 2012 at 6:31 am
    Hello

    Unfortunately this change broke stuff for us.

    If you have two .go files in the same package that use the same
    C.SOMETHING constant, your build fails with:

    inconsistent definitions for C.SOMETHING

    One way to work around this is to define a const in one file, but maybe
    it wasn't intended to break?

    Regards,

    Albert
    On 2012/09/07 03:33:02, jsing wrote:
    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***
    cgo: use debug data section for ELF
    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.
    Fixes issue 2470.
    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090
    http://codereview.appspot.com/6495090/
  • Dave Cheney at Sep 7, 2012 at 6:36 am
    Urk, this sounds serious. fullung, could you please log an issue with
    a simple test case (assuming you haven't already done so)
    On Fri, Sep 7, 2012 at 4:31 PM, wrote:
    Hello

    Unfortunately this change broke stuff for us.

    If you have two .go files in the same package that use the same
    C.SOMETHING constant, your build fails with:

    inconsistent definitions for C.SOMETHING

    One way to work around this is to define a const in one file, but maybe
    it wasn't intended to break?

    Regards,

    Albert

    On 2012/09/07 03:33:02, jsing wrote:

    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***
    cgo: use debug data section for ELF
    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.
    Fixes issue 2470.
    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090

    http://codereview.appspot.com/6495090/
  • Albert Strasheim at Sep 7, 2012 at 7:06 am
    Hello

    Seems related to enums. Working on reducing a test case now. Quite tricky.

    Cheers

    Albert
    On Friday, September 7, 2012 8:36:04 AM UTC+2, Dave Cheney wrote:

    Urk, this sounds serious. fullung, could you please log an issue with
    a simple test case (assuming you haven't already done so)
    On Fri, Sep 7, 2012 at 4:31 PM, <ful...@gmail.com <javascript:>> wrote:
    Hello

    Unfortunately this change broke stuff for us.

    If you have two .go files in the same package that use the same
    C.SOMETHING constant, your build fails with:

    inconsistent definitions for C.SOMETHING

    One way to work around this is to define a const in one file, but maybe
    it wasn't intended to break?

    Regards,

    Albert

    On 2012/09/07 03:33:02, jsing wrote:

    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***
    cgo: use debug data section for ELF
    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.
    Fixes issue 2470.
    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090

    http://codereview.appspot.com/6495090/
  • Albert Strasheim at Sep 7, 2012 at 9:01 am
    http://code.google.com/p/go/issues/detail?id=4054
    On Fri, Sep 7, 2012 at 9:00 AM, Albert Strasheim wrote:
    Hello

    Seems related to enums. Working on reducing a test case now. Quite tricky.

    Cheers

    Albert

    On Friday, September 7, 2012 8:36:04 AM UTC+2, Dave Cheney wrote:

    Urk, this sounds serious. fullung, could you please log an issue with
    a simple test case (assuming you haven't already done so)
    On Fri, Sep 7, 2012 at 4:31 PM, wrote:
    Hello

    Unfortunately this change broke stuff for us.

    If you have two .go files in the same package that use the same
    C.SOMETHING constant, your build fails with:

    inconsistent definitions for C.SOMETHING

    One way to work around this is to define a const in one file, but maybe
    it wasn't intended to break?

    Regards,

    Albert

    On 2012/09/07 03:33:02, jsing wrote:

    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***
    cgo: use debug data section for ELF
    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.
    Fixes issue 2470.
    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090

    http://codereview.appspot.com/6495090/
  • Joel Sing at Sep 7, 2012 at 11:50 am

    On 7 September 2012 19:00, Albert Strasheim wrote:
    http://code.google.com/p/go/issues/detail?id=4054
    Thanks for the report and the test case. This is not expected and I
    should have a fix soon.
    On Fri, Sep 7, 2012 at 9:00 AM, Albert Strasheim wrote:
    Hello

    Seems related to enums. Working on reducing a test case now. Quite tricky.

    Cheers

    Albert

    On Friday, September 7, 2012 8:36:04 AM UTC+2, Dave Cheney wrote:

    Urk, this sounds serious. fullung, could you please log an issue with
    a simple test case (assuming you haven't already done so)
    On Fri, Sep 7, 2012 at 4:31 PM, wrote:
    Hello

    Unfortunately this change broke stuff for us.

    If you have two .go files in the same package that use the same
    C.SOMETHING constant, your build fails with:

    inconsistent definitions for C.SOMETHING

    One way to work around this is to define a const in one file, but maybe
    it wasn't intended to break?

    Regards,

    Albert

    On 2012/09/07 03:33:02, jsing wrote:

    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***
    cgo: use debug data section for ELF
    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.
    Fixes issue 2470.
    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090

    http://codereview.appspot.com/6495090/
  • Joel Sing at Sep 7, 2012 at 2:43 pm

    On 7 September 2012 21:50, Joel Sing wrote:
    On 7 September 2012 19:00, Albert Strasheim wrote:
    http://code.google.com/p/go/issues/detail?id=4054
    Thanks for the report and the test case. This is not expected and I
    should have a fix soon.
    Should be fixed by:

    http://codereview.appspot.com/6501101
    On Fri, Sep 7, 2012 at 9:00 AM, Albert Strasheim wrote:
    Hello

    Seems related to enums. Working on reducing a test case now. Quite tricky.

    Cheers

    Albert

    On Friday, September 7, 2012 8:36:04 AM UTC+2, Dave Cheney wrote:

    Urk, this sounds serious. fullung, could you please log an issue with
    a simple test case (assuming you haven't already done so)
    On Fri, Sep 7, 2012 at 4:31 PM, wrote:
    Hello

    Unfortunately this change broke stuff for us.

    If you have two .go files in the same package that use the same
    C.SOMETHING constant, your build fails with:

    inconsistent definitions for C.SOMETHING

    One way to work around this is to define a const in one file, but maybe
    it wasn't intended to break?

    Regards,

    Albert

    On 2012/09/07 03:33:02, jsing wrote:

    *** Submitted as
    http://code.google.com/p/go/source/detail?r=41976e2fec9b ***
    cgo: use debug data section for ELF
    When generating enums use the debug data section instead of the
    DWARF debug info, if it is available in the ELF file. This allows
    mkerrors.sh to work correctly on OpenBSD/386 and NetBSD/386.
    Fixes issue 2470.
    R=golang-dev, minux.ma
    CC=golang-dev
    http://codereview.appspot.com/6495090

    http://codereview.appspot.com/6495090/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 6, '12 at 2:19p
activeSep 7, '12 at 2:43p
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase