]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: allow DW_TAG_variable's with no name
authorAlex Brachet <abrachet@google.com>
Thu, 19 May 2022 16:58:46 +0000 (16:58 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 20 May 2022 21:03:28 +0000 (21:03 +0000)
https://reviews.llvm.org/D123534 is emitting DW_TAG_variable's
that don't have a DW_AT_name. This is allowed in the DWARF
standard. It is adding DIE's for string literals for better
symbolization on buffer overlows etc on these strings. They
no associated name because they are not user provided variables.

Fixes #53000

Change-Id: I2cf063160508687067c7672cef0517bccd707d7b
Reviewed-on: https://go-review.googlesource.com/c/go/+/406816
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/cgo/gcc.go

index 855309edfa255006f5b6939fa69b8ed7afbde716..4d1a5bd8de1f393defaf773718588a20f5dbf34a 100644 (file)
@@ -576,8 +576,23 @@ func (p *Package) loadDWARF(f *File, conv *typeConv, names []*Name) {
                switch e.Tag {
                case dwarf.TagVariable:
                        name, _ := e.Val(dwarf.AttrName).(string)
+                       // As of https://reviews.llvm.org/D123534, clang
+                       // now emits DW_TAG_variable DIEs that have
+                       // no name (so as to be able to describe the
+                       // type and source locations of constant strings
+                       // like the second arg in the call below:
+                       //
+                       //     myfunction(42, "foo")
+                       //
+                       // If a var has no name we won't see attempts to
+                       // refer to it via "C.<name>", so skip these vars
+                       //
+                       // See issue 53000 for more context.
+                       if name == "" {
+                               break
+                       }
                        typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset)
-                       if name == "" || typOff == 0 {
+                       if typOff == 0 {
                                if e.Val(dwarf.AttrSpecification) != nil {
                                        // Since we are reading all the DWARF,
                                        // assume we will see the variable elsewhere.