|
| 1 | +From e66f895667cd51d0d28c42d369a803c12db8bb35 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alex Brachet <abrachet@google.com> |
| 3 | +Date: Thu, 19 May 2022 16:58:46 +0000 |
| 4 | +Subject: [PATCH] cmd/cgo: allow DW_TAG_variable's with no name |
| 5 | + |
| 6 | +https://reviews.llvm.org/D123534 is emitting DW_TAG_variable's |
| 7 | +that don't have a DW_AT_name. This is allowed in the DWARF |
| 8 | +standard. It is adding DIE's for string literals for better |
| 9 | +symbolization on buffer overlows etc on these strings. They |
| 10 | +no associated name because they are not user provided variables. |
| 11 | + |
| 12 | +Fixes #53000 |
| 13 | + |
| 14 | +Change-Id: I2cf063160508687067c7672cef0517bccd707d7b |
| 15 | +Reviewed-on: https://go-review.googlesource.com/c/go/+/406816 |
| 16 | +TryBot-Result: Gopher Robot <gobot@golang.org> |
| 17 | +Run-TryBot: Ian Lance Taylor <iant@google.com> |
| 18 | +Auto-Submit: Ian Lance Taylor <iant@google.com> |
| 19 | +Reviewed-by: Ian Lance Taylor <iant@google.com> |
| 20 | +--- |
| 21 | + src/cmd/cgo/gcc.go | 17 ++++++++++++++++- |
| 22 | + 1 file changed, 16 insertions(+), 1 deletion(-) |
| 23 | + |
| 24 | +diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go |
| 25 | +index 855309edfa255..4d1a5bd8de1f3 100644 |
| 26 | +--- a/src/cmd/cgo/gcc.go |
| 27 | ++++ b/src/cmd/cgo/gcc.go |
| 28 | +@@ -576,8 +576,23 @@ func (p *Package) loadDWARF(f *File, conv *typeConv, names []*Name) { |
| 29 | + switch e.Tag { |
| 30 | + case dwarf.TagVariable: |
| 31 | + name, _ := e.Val(dwarf.AttrName).(string) |
| 32 | ++ // As of https://reviews.llvm.org/D123534, clang |
| 33 | ++ // now emits DW_TAG_variable DIEs that have |
| 34 | ++ // no name (so as to be able to describe the |
| 35 | ++ // type and source locations of constant strings |
| 36 | ++ // like the second arg in the call below: |
| 37 | ++ // |
| 38 | ++ // myfunction(42, "foo") |
| 39 | ++ // |
| 40 | ++ // If a var has no name we won't see attempts to |
| 41 | ++ // refer to it via "C.<name>", so skip these vars |
| 42 | ++ // |
| 43 | ++ // See issue 53000 for more context. |
| 44 | ++ if name == "" { |
| 45 | ++ break |
| 46 | ++ } |
| 47 | + typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset) |
| 48 | +- if name == "" || typOff == 0 { |
| 49 | ++ if typOff == 0 { |
| 50 | + if e.Val(dwarf.AttrSpecification) != nil { |
| 51 | + // Since we are reading all the DWARF, |
| 52 | + // assume we will see the variable elsewhere. |
0 commit comments