mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: remove unused enums
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>
This commit is contained in:
parent
073247f11f
commit
d4a623f99b
1 changed files with 3 additions and 43 deletions
|
|
@ -457,10 +457,8 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apple's LLVM-based gcc does not include the enumeration
|
// We create a data block initialized with the values,
|
||||||
// names and values in its DWARF debug output. In case we're
|
// so we can read them out of the object file.
|
||||||
// using such a gcc, create a data block initialized with the values.
|
|
||||||
// We can read them out of the object file.
|
|
||||||
fmt.Fprintf(&b, "long long __cgodebug_ints[] = {\n")
|
fmt.Fprintf(&b, "long long __cgodebug_ints[] = {\n")
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
if n.Kind == "iconst" {
|
if n.Kind == "iconst" {
|
||||||
|
|
@ -493,7 +491,6 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
||||||
|
|
||||||
// Scan DWARF info for top-level TagVariable entries with AttrName __cgo__i.
|
// Scan DWARF info for top-level TagVariable entries with AttrName __cgo__i.
|
||||||
types := make([]dwarf.Type, len(names))
|
types := make([]dwarf.Type, len(names))
|
||||||
enums := make([]dwarf.Offset, len(names))
|
|
||||||
nameToIndex := make(map[*Name]int)
|
nameToIndex := make(map[*Name]int)
|
||||||
for i, n := range names {
|
for i, n := range names {
|
||||||
nameToIndex[n] = i
|
nameToIndex[n] = i
|
||||||
|
|
@ -512,26 +509,6 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
switch e.Tag {
|
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:
|
case dwarf.TagVariable:
|
||||||
name, _ := e.Val(dwarf.AttrName).(string)
|
name, _ := e.Val(dwarf.AttrName).(string)
|
||||||
typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset)
|
typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset)
|
||||||
|
|
@ -558,15 +535,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalf("malformed __cgo__ name: %s", name)
|
fatalf("malformed __cgo__ name: %s", name)
|
||||||
}
|
}
|
||||||
if enums[i] != 0 {
|
types[i] = t.Type
|
||||||
t, err := d.Type(enums[i])
|
|
||||||
if err != nil {
|
|
||||||
fatalf("loading DWARF type: %s", err)
|
|
||||||
}
|
|
||||||
types[i] = t
|
|
||||||
} else {
|
|
||||||
types[i] = t.Type
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if e.Tag != dwarf.TagCompileUnit {
|
if e.Tag != dwarf.TagCompileUnit {
|
||||||
r.SkipChildren()
|
r.SkipChildren()
|
||||||
|
|
@ -590,15 +559,6 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
||||||
n.FuncType = conv.FuncType(f, pos)
|
n.FuncType = conv.FuncType(f, pos)
|
||||||
} else {
|
} else {
|
||||||
n.Type = conv.Type(types[i], pos)
|
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 {
|
switch n.Kind {
|
||||||
case "iconst":
|
case "iconst":
|
||||||
if i < len(ints) {
|
if i < len(ints) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue