Skip to content

Commit

Permalink
cmd/cgo: remove unused enums
Browse files Browse the repository at this point in the history
Previously, int values of #define macro are retrieved from DWARF via enums.
Currently, those values are retrieved from symbol tables.
It seems that previous code is unused.

Change-Id: Id76c54baa46d6196738ea35aebd5de99b05b9bf8
Reviewed-on: https://go-review.googlesource.com/40072
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
hirochachacha authored and ianlancetaylor committed Apr 12, 2017
1 parent 073247f commit d4a623f
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions src/cmd/cgo/gcc.go
Expand Up @@ -457,10 +457,8 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
}
}

// Apple's LLVM-based gcc does not include the enumeration
// names and values in its DWARF debug output. In case we're
// using such a gcc, create a data block initialized with the values.
// We can read them out of the object file.
// We create a data block initialized with the values,
// so we can read them out of the object file.
fmt.Fprintf(&b, "long long __cgodebug_ints[] = {\n")
for _, n := range names {
if n.Kind == "iconst" {
Expand Down Expand Up @@ -493,7 +491,6 @@ func (p *Package) loadDWARF(f *File, names []*Name) {

// Scan DWARF info for top-level TagVariable entries with AttrName __cgo__i.
types := make([]dwarf.Type, len(names))
enums := make([]dwarf.Offset, len(names))
nameToIndex := make(map[*Name]int)
for i, n := range names {
nameToIndex[n] = i
Expand All @@ -512,26 +509,6 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
break
}
switch e.Tag {
case dwarf.TagEnumerationType:
offset := e.Offset
for {
e, err := r.Next()
if err != nil {
fatalf("reading DWARF entry: %s", err)
}
if e.Tag == 0 {
break
}
if e.Tag == dwarf.TagEnumerator {
entryName := e.Val(dwarf.AttrName).(string)
if strings.HasPrefix(entryName, "__cgo_enum__") {
n, _ := strconv.Atoi(entryName[len("__cgo_enum__"):])
if 0 <= n && n < len(names) {
enums[n] = offset
}
}
}
}
case dwarf.TagVariable:
name, _ := e.Val(dwarf.AttrName).(string)
typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset)
Expand All @@ -558,15 +535,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
if err != nil {
fatalf("malformed __cgo__ name: %s", name)
}
if enums[i] != 0 {
t, err := d.Type(enums[i])
if err != nil {
fatalf("loading DWARF type: %s", err)
}
types[i] = t
} else {
types[i] = t.Type
}
types[i] = t.Type
}
if e.Tag != dwarf.TagCompileUnit {
r.SkipChildren()
Expand All @@ -590,15 +559,6 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
n.FuncType = conv.FuncType(f, pos)
} else {
n.Type = conv.Type(types[i], pos)
if enums[i] != 0 && n.Type.EnumValues != nil {
k := fmt.Sprintf("__cgo_enum__%d", i)
n.Kind = "iconst"
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)
}
// Prefer debug data over DWARF debug output, if we have it.
switch n.Kind {
case "iconst":
if i < len(ints) {
Expand Down

0 comments on commit d4a623f

Please sign in to comment.