golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.89k stars 17.65k forks source link

cmd/link: TestDWARF failing under all.bash on OSX 10.13.6 #30236

Open timothyham opened 5 years ago

timothyham commented 5 years ago

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

$ go version
go version go1.11.5 darwin/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tham/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tham/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/tham/opt/go"
GOTMPDIR=""
GOTOOLDIR="/Users/tham/opt/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build179495697=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Try to build go from source.

  1. Clone from github mirror
  2. checkout 52d020260
  3. run all.bash from src directory

What did you expect to see?

successful build

What did you see instead?

--- FAIL: TestDWARF (3.88s) --- FAIL: TestDWARF/testprogcgo (1.95s) dwarf_test.go:98: decoding dwarf section info at offset 0x0: too short FAIL FAIL cmd/link 5.179s --- FAIL: TestRuntimeTypeAttrExternal (1.02s) dwarf_test.go:945: error reading DWARF: decoding dwarf section info at offset 0x0: too short FAIL FAIL cmd/link/internal/ld 2.336s

timothyham commented 5 years ago

$ clang --version Apple LLVM version 10.0.0 (clang-1000.10.44.4) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

thanm commented 5 years ago

I am unable to reproduce this on my mac -- which is at 10.13.6 but a slightly different clang version:

Apple LLVM version 10.0.0 (clang-1000.11.45.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

The error you're seeing is one that happens very early in the .debug_info read, seeming to indicate that the DWARF is truncated or missing.

FWIW I can't find your clang version in

https://gist.github.com/yamaya/2924292 or https://trac.macports.org/wiki/XcodeVersionInfo

is there anything unusual about it?

bcmills commented 5 years ago

CC @cherrymui @mdempsky @ianlancetaylor

timothyham commented 5 years ago

FWIW I can't find your clang version in

https://gist.github.com/yamaya/2924292 or https://trac.macports.org/wiki/XcodeVersionInfo

is there anything unusual about it?

I didn't do anything unusual. That is the version I get when I uninstall (rm -rf /Library/CommandLineTools) and type 'clang --version' and following the prompts.

I also uninstalled and downloaded the most recent version from: https://developer.apple.com/download/more/

Command Line Tools (macOS 10.13) for Xcode 10.1 Nov 2, 2018

This installer installs the exact same version.

googling for "Apple LLVM version 10.0.0 (clang-1000.10.44.4)" leads me to this: https://gist.github.com/yamaya/2924292#gistcomment-2801685

timothyham commented 5 years ago

Interestingly, I uninstalled CommandLineTools and installed Xcode from the App store. App store information says Update: Oct 30, 2018, Version: 10.1

and got a different clang version:

Apple LLVM version 10.0.0 (clang-1000.11.45.5) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I still get the same test error though.

thanm commented 5 years ago

@timothyham are you willing to try a few examples to gather more info?
For a small himom.go type program, try this:

rm himom
go clean -cache
rm -rf /tmp/xxx
mkdir /tmp/xxx
go build -x -work "-ldflags=-tmpdir=/tmp/xxx -linkmode=external -v" himom.go

In the output from the go build line there should be a "host link:" execution -- what does that look like?

Also, what do you get when you run "objdump -section-headers" on the resulting executable (himom)?

I'm grasping at straws here; without a way to reproduce the problem on my own machine it's hard to know what to suggest.

timothyham commented 5 years ago

@thanm Thanks for your help. I am happy to run whatever to diagnose this problem.

Here is my output:

0.14 host link: "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" "-Wl,-pagezero_size,4
000000" "-o" "/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build355345930/b001/exe
/a.out" "-Qunused-arguments" "/tmp/xxx/go.o" "/tmp/xxx/000000.o" "/tmp/xxx/000001.o" "/tm
p/xxx/000002.o" "/tmp/xxx/000003.o" "/tmp/xxx/000004.o" "/tmp/xxx/000005.o" "/tmp/xxx/000
006.o" "/tmp/xxx/000007.o" "/tmp/xxx/000008.o" "/tmp/xxx/000009.o" "/tmp/xxx/000010.o" "-
g" "-O2" "-g" "-O2" "-lpthread" "-no-pie"
 0.20 cpu time
44998 symbols
48508 liveness data
mv $WORK/b001/exe/a.out himom
tham-ltm:himom$ objdump -section-headers himom

himom:  file format Mach-O 64-bit x86-64

Sections:
Idx Name          Size      Address          Type
  0 __text        000911b8 0000000004001d80 TEXT
  1 __stubs       00000126 0000000004092f38 TEXT
  2 __stub_helper 000001fa 0000000004093060 TEXT
  3 __rodata      000471d1 0000000004093260 DATA
  4 __typelink    00000be8 00000000040da440 DATA
  5 __itablink    00000060 00000000040db028 DATA
  6 __gosymtab    00000000 00000000040db088 DATA
  7 __gopclntab   00075e51 00000000040db0a0 DATA
  8 __cstring     0000006e 0000000004150ef1 DATA
  9 __const       00000008 0000000004150f60 DATA
 10 __unwind_info 00000090 0000000004150f68 DATA
 11 __nl_symbol_ptr 00000010 0000000004151000 DATA
 12 __got         00000010 0000000004151010 DATA
 13 __la_symbol_ptr 00000188 0000000004151020 DATA
 14 __noptrdata   0000cc3c 00000000041511c0 DATA
 15 __data        000069c0 000000000415de00 DATA
 16 __bss         0001c760 00000000041647c0 BSS
 17 __noptrbss    00002598 0000000004180f20 BSS

my himom.go:

package main

import (
        "C"
        "fmt"
)

func main() {
        fmt.Println("hi mom!")
}
thanm commented 5 years ago

Clang invocation looks fine, but in spite of the "-g" flags, the resulting executable has no DWARF (which is obviously not what we're expecting).

One more experiment if you can manage, please. After running the "go build" command, just replay the clang host link invocation, but tack on a "-v", e.g.

"clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" "-Wl,-pagezero_size,4 000000" "-o" "/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build355345930/b001/exe /a.out" "-Qunused-arguments" "/tmp/xxx/go.o" "/tmp/xxx/000000.o" "/tmp/xxx/000001.o" "/tm p/xxx/000002.o" "/tmp/xxx/000003.o" "/tmp/xxx/000004.o" "/tmp/xxx/000005.o" "/tmp/xxx/000 006.o" "/tmp/xxx/000007.o" "/tmp/xxx/000008.o" "/tmp/xxx/000009.o" "/tmp/xxx/000010.o" "- g" "-O2" "-g" "-O2" "-lpthread" "-no-pie"

Then look at the section headers again with objdump. [This will hopefully tell us whether the problem is with clang or with dsymutil]

timothyham commented 5 years ago

Here is my interactive session. I tried to follow what you were saying about "-v":

tham-ltm:himom$ rm himom
tham-ltm:himom$ go clean -cache
tham-ltm:himom$ rm -rf /tmp/xxx
tham-ltm:himom$ mkdir /tmp/xxx
tham-ltm:himom$ go build -x -work "-ldflags=-tmpdir=/tmp/xxx -linkmode=external -v" himom
.go
WORK=/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060
mkdir -p $WORK/b001/
.   [snip here]
 0.06 sym
 0.06 headr
 0.14 host link: "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" "-Wl,-pagezero_size,4
000000" "-o" "/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060/b001/exe
/a.out" "-Qunused-arguments" "/tmp/xxx/go.o" "/tmp/xxx/000000.o" "/tmp/xxx/000001.o" "/tm
p/xxx/000002.o" "/tmp/xxx/000003.o" "/tmp/xxx/000004.o" "/tmp/xxx/000005.o" "/tmp/xxx/000
006.o" "/tmp/xxx/000007.o" "/tmp/xxx/000008.o" "/tmp/xxx/000009.o" "/tmp/xxx/000010.o" "-
g" "-O2" "-g" "-O2" "-lpthread" "-no-pie"
 0.19 cpu time
44998 symbols
48508 liveness data
mv $WORK/b001/exe/a.out himom
tham-ltm:himom$
tham-ltm:himom$
tham-ltm:himom$ "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" "-Wl,-pagezero_size,40
00000" "-o" "/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060/b001/exe/
a.out" "-Qunused-arguments" "/tmp/xxx/go.o" "/tmp/xxx/000000.o" "/tmp/xxx/000001.o" "/tmp
/xxx/000002.o" "/tmp/xxx/000003.o" "/tmp/xxx/000004.o" "/tmp/xxx/000005.o" "/tmp/xxx/0000
06.o" "/tmp/xxx/000007.o" "/tmp/xxx/000008.o" "/tmp/xxx/000009.o" "/tmp/xxx/000010.o" "-g
" "-O2" "-g" "-O2" "-lpthread" "-no-pie" "-v"
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolch
ain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDef
ault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -macosx_version_min 10.13.0 -
o /var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060/b001/exe/a.out -head
erpad 1144 -no_pie -pagezero_size 4000000 /tmp/xxx/go.o /tmp/xxx/000000.o /tmp/xxx/000001
.o /tmp/xxx/000002.o /tmp/xxx/000003.o /tmp/xxx/000004.o /tmp/xxx/000005.o /tmp/xxx/00000
6.o /tmp/xxx/000007.o /tmp/xxx/000008.o /tmp/xxx/000009.o /tmp/xxx/000010.o -lpthread -lS
ystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/
lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
tham-ltm:himom$ objdump -section-headers himom

himom:  file format Mach-O 64-bit x86-64

Sections:
Idx Name          Size      Address          Type
  0 __text        000911b8 0000000004001d80 TEXT
  1 __stubs       00000126 0000000004092f38 TEXT
  2 __stub_helper 000001fa 0000000004093060 TEXT
  3 __rodata      000471d1 0000000004093260 DATA
  4 __typelink    00000be8 00000000040da440 DATA
  5 __itablink    00000060 00000000040db028 DATA
  6 __gosymtab    00000000 00000000040db088 DATA
  7 __gopclntab   00075e51 00000000040db0a0 DATA
  8 __cstring     0000006e 0000000004150ef1 DATA
  9 __const       00000008 0000000004150f60 DATA
 10 __unwind_info 00000090 0000000004150f68 DATA
 11 __nl_symbol_ptr 00000010 0000000004151000 DATA
 12 __got         00000010 0000000004151010 DATA
 13 __la_symbol_ptr 00000188 0000000004151020 DATA
 14 __noptrdata   0000cc3c 00000000041511c0 DATA
 15 __data        000069c0 000000000415de00 DATA
 16 __bss         0001c760 00000000041647c0 BSS
 17 __noptrbss    00002598 0000000004180f20 BSS
thanm commented 5 years ago

Thanks, but I think you need to run objdump on /var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060/b001/exe/a.out (that's the output of the clang invocation you ran).

timothyham commented 5 years ago

here you go:

tham-ltm:himom$ objdump -section-headers /var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060/b001/exe/a.out

/var/folders/jw/jl09r8zn7yxcg04glntytrl07k6c17/T/go-build400191060/b001/exe/a.out:      file format Mach-O 64-bit x86-64

Sections:
Idx Name          Size      Address          Type
  0 __text        000911b8 0000000004001d80 TEXT
  1 __stubs       00000126 0000000004092f38 TEXT
  2 __stub_helper 000001fa 0000000004093060 TEXT
  3 __rodata      000471d1 0000000004093260 DATA
  4 __typelink    00000be8 00000000040da440 DATA
  5 __itablink    00000060 00000000040db028 DATA
  6 __gosymtab    00000000 00000000040db088 DATA
  7 __gopclntab   00075e51 00000000040db0a0 DATA
  8 __cstring     0000006e 0000000004150ef1 DATA
  9 __const       00000008 0000000004150f60 DATA
 10 __unwind_info 00000090 0000000004150f68 DATA
 11 __nl_symbol_ptr 00000010 0000000004151000 DATA
 12 __got         00000010 0000000004151010 DATA
 13 __la_symbol_ptr 00000188 0000000004151020 DATA
 14 __noptrdata   0000cc3c 00000000041511c0 DATA
 15 __data        000069c0 000000000415de00 DATA
 16 __bss         0001c760 00000000041647c0 BSS
 17 __noptrbss    00002598 0000000004180f20 BSS
thanm commented 5 years ago

@timothyham thanks for that.

I am stumped at this point -- I will ask around and see what I can discover. Stay tuned.

timothyham commented 5 years ago

Thanks for looking. Since you cannot reproduce the problem, it must be something different about my machine. Can't imagine what though.

thanm commented 5 years ago

@timothyham Is this issue still causing problems for you -- can it be closed out?