Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgo: malformed DWARF TagVariable entry #53000

Closed
ilovepi opened this issue May 19, 2022 · 11 comments
Closed

cgo: malformed DWARF TagVariable entry #53000

ilovepi opened this issue May 19, 2022 · 11 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ilovepi
Copy link

ilovepi commented May 19, 2022

What version of Go are you using (go version)?

$ go version
go version go1.17.9 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/paulkirth/.cache/go-build"
GOENV="/usr/local/google/home/paulkirth/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/google/home/paulkirth/workspace/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/google/home/paulkirth/workspace/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/google/home/paulkirth/fuchsia/prebuilt/third_party/go/linux-x64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/paulkirth/fuchsia/prebuilt/third_party/go/linux-x64/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.9"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2852963211=/tmp/go-build -gno-record-gcc-switches"

What did you do?

When building Fuchsia we ran into a build error from cgo from malformed DWARF tags.

What did you expect to see?

I expected the build to complete without error

What did you see instead?

build failure

cgo: malformed DWARF TagVariable entry

Fuchsia compiles using ToT LLVM. Recently, LLVM has made some changes to some of the DWARF it emits. In particular, the new change emits debug info for variables it didn't previously, and cgo fails when it encounters a DW_TAG_variable that doesn't have a name, which is allowed by the DWARF standard.

Since this is legal in DWARF, the compiler should be able to handle the change to debug info.

You can find our failed build at: https://luci-milo.appspot.com/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.arm64-debug/b8813791771110373825/overview

Unfortunately, I don't have a smaller reproducer. But this should become more common as other consumers of LLVM update their toolchains.

There is an ongoing discussion on the original change on Phabricator you can find here: https://reviews.llvm.org/D123534

@mknyszek mknyszek changed the title cgo: cgo cgo: malformed DWARF TagVariable entry May 19, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 19, 2022
@mknyszek mknyszek added this to the Backlog milestone May 19, 2022
@mknyszek
Copy link
Contributor

CC @golang/runtime perhaps specifically @thanm and @dr2chase?

@thanm
Copy link
Contributor

thanm commented May 19, 2022

I looked over the Phabricator change. It appears that the main goal is to emit DWARF entries for constant strings, e.g. if you do something like

myFunction(42, "foo")

clang will now emit a DW_TAG_variable DIE for the string constant "foo" (including type and source line, etc). This is so that if the string constant is involves somehow with an ASAN error, ASAN can report its source location.

The business about having a DW_TAG_variable DIE without a name seems to be mostly that they want to save space in the DWARF (no name => DWARF gets smaller).

My 2 cents: while I am sure this is legal DWARF according to the standard, this is going to lead to a never-ending stream of weird bugs and errors from downstream DWARF consumers that are all written to assume that variable DIEs have names (as in the case for cgo).

Should be easy to fix however; we can just teach CGO to ignore nameless variables. I'll look into that.

@thanm thanm self-assigned this May 19, 2022
@thanm
Copy link
Contributor

thanm commented May 19, 2022

@ilovepi could you possibly let me know the specific C compiler command line options for your failing build? Clang has a number of different options/flavors/settings, it would be good to know which one triggers this.

@abrachet
Copy link
Contributor

@thanm I already have a quick fix out https://go-review.googlesource.com/c/go/+/406816

@ilovepi
Copy link
Author

ilovepi commented May 19, 2022

Well I'm not 100% sure this is super helpful. There aren't really any exotic flags we're passing but maybe this will help you. I'm leaving everything in for compleness, but the majority are simply include directories.

clang++ -MD -MF  obj/src/storage/fshost/block-watcher.pkgfs-launcher.cc.o.d  -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -DNDEBUG=1 -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1 -D_ALL_SOURCE -DFIDL_TRACE_LEVEL=0  -I../.. -Igen -Iobj -I../../sdk -Igen/sdk -Ifidling/gen/sdk/fidl/fuchsia.inspect/fuchsia.inspect/hlcpp -I../../zircon/system/ulib/fidl/include -Ifidling/gen/sdk/fidl/fuchsia.mem/fuchsia.mem/hlcpp -I../../sdk/lib/fit/include -I../../sdk/lib/stdcompat/include -I../../sdk/lib/fit-promise/include -I../../zircon/system/ulib/zx/include -Igen/include -I../../src/zircon/lib/zircon/include -I../../zircon/system/ulib/async/include -I../../zircon/system/ulib/async-default/include -I../../zircon/system/ulib/inspect/include -Ifidling/gen/sdk/fidl/fuchsia.io/fuchsia.io/hlcpp -Ifidling/gen/sdk/fidl/fuchsia.sys/fuchsia.sys/hlcpp -I../../sdk/lib/fdio/include -Ifidling/gen/sdk/fidl/fuchsia.boot/fuchsia.boot/llcpp -I../../zircon/system/ulib/sync/include -I../../zircon/system/ulib/zxc/include -I../../zircon/system/ulib/fbl/include -I../../garnet/public -Ifidling/gen/sdk/fidl/fuchsia.io/fuchsia.io/llcpp -Ifidling/gen/sdk/fidl/fuchsia.mem/fuchsia.mem/llcpp -I../../zircon/system/ulib/fzl/include -Ifidling/gen/sdk/fidl/fuchsia.fs/fuchsia.fs/llcpp -I../../zircon/system/ulib/fidl-async/include -I../../zircon/system/ulib/trace/include -I../../zircon/system/ulib/trace-engine/include -Ifidling/gen/sdk/fidl/fuchsia.device/fuchsia.device/llcpp -Ifidling/gen/sdk/fidl/fuchsia.feedback/fuchsia.feedback/llcpp -Ifidling/gen/sdk/fidl/fuchsia.math/fuchsia.math/llcpp -Ifidling/gen/sdk/fidl/fuchsia.sys/fuchsia.sys/llcpp -Ifidling/gen/sdk/fidl/fuchsia.fshost/fuchsia.fshost/llcpp -Ifidling/gen/sdk/fidl/fuchsia.hardware.block/fuchsia.hardware.block/llcpp -Ifidling/gen/sdk/fidl/fuchsia.storage.metrics/fuchsia.storage.metrics/llcpp -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.partition/fuchsia.hardware.block.partition/llcpp -Ifidling/gen/sdk/fidl/fuchsia.process.lifecycle/fuchsia.process.lifecycle/llcpp -Ifidling/gen/sdk/fidl/fuchsia.ldsvc/fuchsia.ldsvc/llcpp -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.volume/fuchsia.hardware.block.volume/c -Ifidling/gen/sdk/fidl/fuchsia.hardware.block/fuchsia.hardware.block/c -Ifidling/gen/sdk/fidl/fuchsia.io/fuchsia.io/c -Ifidling/gen/sdk/fidl/fuchsia.mem/fuchsia.mem/c -Ifidling/gen/zircon/vdso/zx/zx/c -Ifidling/gen/sdk/fidl/fuchsia.storage.metrics/fuchsia.storage.metrics/c -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.partition/fuchsia.hardware.block.partition/c -Ifidling/gen/sdk/fidl/fuchsia.device/fuchsia.device/c -Ifidling/gen/src/storage/fidl/fuchsia.fs.startup/fuchsia.fs.startup/llcpp -Ifidling/gen/src/storage/fxfs/fuchsia.fxfs/llcpp -I../../zircon/system/ulib/async-loop/include -I../../zircon/system/ulib/fdio-caller/include -I../../zircon/system/ulib/service/include -Ifidling/gen/sdk/fidl/fuchsia.fs/fuchsia.fs/hlcpp -I../../zircon/system/public -I../../zircon/system/ulib/storage/buffer/include -I../../zircon/system/ulib/storage/operation/include -I../../src/lib/storage/block_client/cpp/include -I../../zircon/system/ulib/range/include -I../../zircon/system/ulib/storage-metrics/include -I../../zircon/system/ulib/cobalt-client/include -Ifidling/gen/sdk/fidl/fuchsia.cobalt/fuchsia.cobalt/llcpp -I../../src/storage/lib/disk_inspector/include -I../../src/storage/lib/watchdog/include -I../../zircon/system/ulib/syslog/include -I../../zircon/system/ulib/bitmap/include -I../../zircon/system/ulib/id_allocator/include -I../../zircon/third_party/ulib/safemath/include -Ifidling/gen/src/storage/blobfs/fuchsia.blobfs.internal/hlcpp -Ifidling/gen/src/storage/blobfs/fuchsia.blobfs.internal/llcpp -Ifidling/gen/sdk/fidl/fuchsia.blobfs/fuchsia.blobfs/llcpp -Ifidling/gen/sdk/fidl/fuchsia.device.manager/fuchsia.device.manager/llcpp -Ifidling/gen/sdk/fidl/fuchsia.driver.framework/fuchsia.driver.framework/llcpp -Ifidling/gen/sdk/fidl/fuchsia.component/fuchsia.component/llcpp -Ifidling/gen/sdk/fidl/fuchsia.component.decl/fuchsia.component.decl/llcpp -Ifidling/gen/sdk/fidl/fuchsia.data/fuchsia.data/llcpp -Ifidling/gen/sdk/fidl/fuchsia.url/fuchsia.url/llcpp -Ifidling/gen/sdk/fidl/fuchsia.process/fuchsia.process/llcpp -Ifidling/gen/sdk/fidl/fuchsia.component.runner/fuchsia.component.runner/llcpp -Ifidling/gen/sdk/fidl/fuchsia.diagnostics.types/fuchsia.diagnostics.types/llcpp -Ifidling/gen/sdk/fidl/fuchsia.hardware.power.statecontrol/fuchsia.hardware.power.statecontrol/llcpp -Ifidling/gen/src/sys/pkg/fidl/fuchsia.update.verify/fuchsia.update.verify/llcpp -Ifidling/gen/sdk/fidl/fuchsia.boot/fuchsia.boot/c -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.encrypted/fuchsia.hardware.block.encrypted/c -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.encrypted/fuchsia.hardware.block.encrypted/llcpp -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.verified/fuchsia.hardware.block.verified/llcpp -Ifidling/gen/sdk/fidl/fuchsia.hardware.block.volume/fuchsia.hardware.block.volume/llcpp -I../../src/lib/storage/ramdevice_client/cpp/include -Ifidling/gen/sdk/fidl/fuchsia.hardware.nand/fuchsia.hardware.nand/c -I../../src/storage/gpt/include  -fclang-abi-compat=13.0 -fcolor-diagnostics -fcrash-diagnostics-dir=clang-crashreports -ffp-contract=off --sysroot=gen/zircon/public/sysroot/cpp --target=x86_64-unknown-fuchsia -ffuchsia-api-level=8 -march=x86-64-v2 -mtune=generic -mbranches-within-32B-boundaries -ffile-compilation-dir=. -no-canonical-prefixes -fomit-frame-pointer -fdata-sections -ffunction-sections -Os -gdwarf-5 -Xclang -debug-info-kind=constructor -g3 -Wall -Wextra -Wconversion -Wextra-semi -Wimplicit-fallthrough -Wnewline-eof -Wstrict-prototypes -Wwrite-strings -Wno-sign-conversion -Wno-unused-parameter -Wnonportable-system-include-path -fvisibility=hidden -Werror -Wno-error=deprecated-declarations -Wa,--fatal-warnings -ftrivial-auto-var-init=pattern -Wthread-safety -DFIDL_ALLOW_DEPRECATED_C_BINDINGS -DFIDL_ALLOW_DEPRECATED_C_BINDINGS  -fvisibility-inlines-hidden -std=c++17 -fno-exceptions -fno-rtti -c ../../src/storage/fshost/pkgfs-launcher.cc -o  obj/src/storage/fshost/block-watcher.pkgfs-launcher.cc.o

@gopherbot
Copy link

Change https://go.dev/cl/406816 mentions this issue: cmd/cgo: allow DW_TAG_variable's with no name

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 19, 2022
@dmitshur dmitshur modified the milestones: Backlog, Go1.19 May 19, 2022
@rsc rsc unassigned abrachet and thanm Jun 22, 2022
@crazy-max
Copy link

@gopherbot please backport to 1.18.

@gopherbot
Copy link

Backport issue(s) opened: #57044 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@thaJeztah
Copy link
Contributor

^^ to add some context:

We started running into this issue after the official docker golang alpine image updated to alpine 3.17, which comes with a newer version of clang (see moby/moby#44570);

With alpine 3.16:

docker run -it --rm golang:1.18.8-alpine3.16 sh -c 'apk add --quiet --no-cache clang && clang --version'
Alpine clang version 13.0.1
Target: aarch64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/bin

With alpine 3.17:

docker run -it --rm golang:1.18.8-alpine3.17 sh -c 'apk add --quiet --no-cache clang && clang --version'
Alpine clang version 15.0.6
Target: aarch64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/bin

If you have docker installed, the issue can be reproduced with this Dockerfile;

ARG ALPINE_VERSION

FROM golang:1.18.8-alpine${ALPINE_VERSION} AS golatest
RUN apk add --no-cache clang lld git musl-dev gcc
WORKDIR /containerd
RUN set -ex \
 && git clone https://github.com/containerd/containerd.git . \
 && git fetch origin \
 && git checkout -q v1.5.11 \
 && CGO_ENABLED=1 CC=clang go build -tags no_btrfs ./cmd/containerd

With alpine 3.16 (clang 13), it passes;

docker build -t example --build-arg ALPINE_VERSION=3.16 .
...

And with alpine 3.17 (clang 15), it fails:

docker build -t example --build-arg ALPINE_VERSION=3.17 .
...
 > [4/4] RUN set -ex  && git clone https://github.com/containerd/containerd.git .  && git fetch origin  && git checkout -q v1.5.11  && CGO_ENABLED=1 CC=clang go build -tags no_btrfs ./cmd/containerd:
#8 0.261 + git clone https://github.com/containerd/containerd.git .
#8 0.271 Cloning into '.'...
#8 15.91 + git fetch origin
#8 16.44 + git checkout -q v1.5.11
#8 17.02 + CGO_ENABLED=1 CC=clang go build -tags no_btrfs ./cmd/containerd
#8 28.33 # github.com/miekg/pkcs11
#8 28.33 cgo: malformed DWARF TagVariable entry
------
process "/bin/sh -c set -ex  && git clone https://github.com/containerd/containerd.git .  && git fetch origin  && git checkout -q v1.5.11  && CGO_ENABLED=1 CC=clang go build -tags no_btrfs ./cmd/containerd" did not complete successfully: exit code: 2

We noticed that #53013 (https://go.dev/cl/454415 ) was accepted to be backported, which seems related, so we would like to request https://go.dev/cl/406816 to be backported as well.

thaJeztah pushed a commit to thaJeztah/go that referenced this issue Dec 3, 2022
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 golang#57044
Updates golang#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>
(cherry picked from commit e66f895)
@gopherbot
Copy link

Change https://go.dev/cl/455055 mentions this issue: [release-branch.go1.18] cmd/cgo: allow DW_TAG_variable's with no name

@gopherbot
Copy link

Change https://go.dev/cl/455056 mentions this issue: [release-branch.go1.18] cmd/cgo: allow DW_TAG_variable's with no name

gopherbot pushed a commit that referenced this issue Dec 19, 2022
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 #57044
Updates #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>
(cherry picked from commit e66f895)

Change-Id: I2cf063160508687067c7672cef0517bccd707d7b
GitHub-Last-Rev: 32208e4
GitHub-Pull-Request: #57067
Reviewed-on: https://go-review.googlesource.com/c/go/+/455055
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Dec 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants