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

cmd/cgo: build warning from freebsd/clang: DWARF2 only supports one section per compilation unit #14705

Closed
wheelcomplex opened this issue Mar 8, 2016 · 26 comments

Comments

@wheelcomplex
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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

go version devel +beabd87 Tue Mar 8 06:02:15 2016 +0000 freebsd/amd64

  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN="/home/rhinofly/home/ds/sandspace/go/bin.freebsd-amd64"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GOPATH="/home/rhinofly/home/ds/sandspace/external/:/home/rhinofly/home/ds/sandspace/golibs/"
GORACE=""
GOROOT="/home/rhinofly/home/ds/sandspace/go"
GOTOOLDIR="/home/rhinofly/home/ds/sandspace/go/pkg/tool/freebsd_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches"
CXX="clang++"
CGO_ENABLED="1"
$ ifconfig -a
em0: flags=8843 metric 0 mtu 1500
    options=209b
    ether 66:30:38:38:64:30
    inet 10.236.12.201 netmask 0xffffff00 broadcast 10.236.12.255 
    nd6 options=29
    media: Ethernet autoselect (1000baseT )
    status: active
lo0: flags=8049 metric 0 mtu 16384
    options=600003
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
    inet 127.0.0.1 netmask 0xff000000 
    nd6 options=21
    groups: lo 
$ uname -a
FreeBSD rhinofly-devel-800201.localdomain 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r295683: Wed Feb 17 02:07:17 UTC 2016     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
  1. What did you do?
    (Use play.golang.org to provide a runnable example, if possible.)

git clone https://github.com/golang/go.git tips-go && cd tips-go/src && ./all.bash

  1. What did you expect to see?

build done without error and warning.

  1. What did you see instead?
    # runtime/cgo
    runtime/cgo/gcc_amd64.S:47:1: warning: DWARF2 only supports one section per compilation unit
    .section .note.GNU-stack,"",@progbits
    
    (all others build is ok)
@ianlancetaylor ianlancetaylor changed the title cgo: tips build warning: DWARF2 only supports one section per compilation unit cmd/cgo: tips build warning: DWARF2 only supports one section per compilation unit Mar 8, 2016
@ianlancetaylor
Copy link
Contributor

What does clang --version print?

This kind of sounds like a bug in clang. What do you see if you compile a simple C program with the -gdwarf-2 option?

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 8, 2016
@wheelcomplex
Copy link
Contributor Author

clang --version

FreeBSD clang version 3.7.1 (tags/RELEASE_371/final 255217) 20151225
Target: x86_64-unknown-freebsd11.0
Thread model: posix

hello.c

// Hello world
#include 
int main(void){
    printf("Hello, world!\n");
    return 0;
}
clang -gdwarf-2 hello.c
[NOTE: nothing printed]

@rsc
Copy link
Contributor

rsc commented May 17, 2016

@wheelcomplex, has there been a clang update on FreeBSD since the report? Did it fix this?

@rsc
Copy link
Contributor

rsc commented May 17, 2016

Also, does this stop the build or just print a warning?
If it's just a warning (not an error stopping the build), we can easily postpone it to Go 1.8.
Thanks.

@rsc rsc changed the title cmd/cgo: tips build warning: DWARF2 only supports one section per compilation unit cmd/cgo: build warning from freebsd/clang: DWARF2 only supports one section per compilation unit May 17, 2016
@wheelcomplex
Copy link
Contributor Author

@rsc

Re-try in a new snapshot version of FreeBSD 11(r297692) and most recent tip(+ cdcb827), the warning generated as before.

It only warning when CGO_ENABLED="1" and not an error stopping the build, postpone it to Go 1.8 would be OK.

clang -version:

FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin

uname -a:

FreeBSD n550jk.localdomain 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r297692: Fri Apr  8 03:07:13 UTC 2016     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

@ianlancetaylor
Copy link
Contributor

I can recreate the warning with clang 3.6:

foo:
    ret

.section .note.GNU-stack,"",@progbits

clang -c -gdwarf-2 ~/foo.s
foo.s:4:1: warning: DWARF2 only supports one section per compilation unit
.section .note.GNU-stack,"",@progbits

But what I don't know is where the -gdwarf-2 option is coming from. I don't see it being passed to the assembler myself. Do you have CGO_CFLAGS set in your environment?

@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Go1.7 May 18, 2016
@rsc
Copy link
Contributor

rsc commented May 18, 2016

@ianlancetaylor, -gdwarf-2 is set by both cmd/cgo and cmd/link. I think the original motivation was to avoid some dwarf extensions we didn't understand. We could try changing it to -gdwarf and see what happens. There's certainly some dwarf 4 code in debug/dwarf now, with a comment:

// New in DWARF 4, but clang can generate them with -gdwarf-2.

:-)

@rsc
Copy link
Contributor

rsc commented May 18, 2016

Since this is only a warning, let's leave it for now and address this in Go 1.8.

@rsc rsc modified the milestones: Go1.8, Unplanned May 18, 2016
@ianlancetaylor
Copy link
Contributor

-gdwarf-2 is set when compiling cgo generated files, yes, but I don't see where it is used when compiling an ordinary input file like runtime/cgo/gcc_amd64.S. That file is just passed to clang with the options in builder.ccompilerCmd.

@ianlancetaylor
Copy link
Contributor

I can recreate the warning by running

CGO_CFLAGS=-gdwarf-2 CC=clang go build runtime/cgo

but I can't recreate it without setting CGO_CFLAGS.

@wheelcomplex
Copy link
Contributor Author

No CGO_CFLAGS found in env command, would you please to tell me where is the source code line that invoke "CC=clang go build runtime/cgo" in $GOROOT/src/, so I can make a local change to print out the real command and all current environment at time.

@ianlancetaylor
Copy link
Contributor

There is no such source code in $GOROOT/src. I typed it myself into the shell.

Try running go build -x -a runtime/cgo to see exactly what options are being passed when compiling the file runtime/cgo/gcc_amd64.S.

@wheelcomplex
Copy link
Contributor Author

Thanks for reply @ianlancetaylor , I mean the command invoke by runOut() at https://github.com/golang/go/blob/master/src/cmd/go/build.go#L2039

Following log is the real command and all environment when build runtime/cgo:

This issue has postpone to Go 1.8, just save relative information for analysis late.

$ clang --version
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564) (based on LLVM 3.8.0)
Target: x86_64-unknown-freebsd11.0
Thread model: posix
InstalledDir: /usr/bin

./all.bash invoke command:
CC=clang /home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64/go_bootstrap install -gcflags -ldflags -v std cmd

##### Building packages and commands for freebsd/amd64.
runtime/internal/sys
runtime/internal/atomic
runtime
errors
internal/race
sync/atomic
....
cmd/internal/bio
cmd/compile/internal/big
runtime/cgo
cd /home/rhinofly/sandspace/go/src/runtime/cgo
CGO_LDFLAGS="-g" "-O2" "-lpthread" /home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64/cgo -objdir $WORK/runtime/cgo/_obj/ -importpath runtime/cgo -import_runtime_cgo=false -import_syscall=false -- -I $WORK/runtime/cgo/_obj/ -Wall -Werror cgo.go
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/_cgo_main.o -c $WORK/runtime/cgo/_obj/_cgo_main.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/_cgo_export.o -c $WORK/runtime/cgo/_obj/_cgo_export.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/cgo.cgo2.o -c $WORK/runtime/cgo/_obj/cgo.cgo2.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/gcc_context.o -c ./gcc_context.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/gcc_freebsd_amd64.o -c ./gcc_freebsd_amd64.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/gcc_libinit.o -c ./gcc_libinit.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/gcc_setenv.o -c ./gcc_setenv.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/gcc_util.o -c ./gcc_util.c
 --- environment for src/runtime/cgo
CC=clang
GOHOSTARCH=amd64
LC_MONETARY=en_US.UTF-8
GLADE_PIXMAP_PATH=:
XDG_MENU_PREFIX=xfce-
SHELL=/usr/local/bin/bash
TERM=dumb
XDG_SESSION_COOKIE=12deea0229a14da431e00f8d57332f61-1463131597.699032-679227067
GOBIN=/home/rhinofly/sandspace/go/bin
LC_NUMERIC=en_US.UTF-8
WINDOWID=44040196
GNOME_KEYRING_CONTROL=/home/rhinofly/home/.cache/keyring-N2ZOHY
OLDPWD=/home/rhinofly/sandspace/go/src
LC_ALL=en_US.UTF-8
USER=rhinofly
GOROOT_BOOTSTRAP=/home/rhinofly/home/sandspace/bootstrap.official/freebsd_amd64
GLADE_MODULE_PATH=:
SSH_AUTH_SOCK=/tmp/ssh-hytb0ID0idxx/agent.1203
USERNAME=rhinofly
SESSION_MANAGER=local/n550jk.localdomain:/tmp/.ICE-unix/1216
GOSPACE=/home/rhinofly/home/sandspace
XDG_CONFIG_DIRS=/etc/xdg:/usr/local/etc/xdg
DESKTOP_SESSION=xfce
PATH=/home/rhinofly/sandspace/go/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/games:/usr/local/games
LC_MESSAGES=en_US.UTF-8
QT_IM_MODULE=fcitx
LC_COLLATE=en_US.UTF-8
GOARM=7
PWD=/home/rhinofly/sandspace/go/src
XDG_SESSION_TYPE=x11
XMODIFIERS=@im=fcitx
GOARCH=amd64
LANG=en_US.UTF-8
GDMSESSION=xfce
CGO_ENABLED=1
HOME=/home/rhinofly/home
SHLVL=4
GOROOT=/home/rhinofly/sandspace/go
GOOS=freebsd
LOGNAME=rhinofly
XDG_SESSION_DESKTOP=xfce
LC_CTYPE=en_US.UTF-8
XDG_DATA_DIRS=/usr/local/share:/usr/share
GOHOSTOS=freebsd
GOPATH=
WINDOWPATH=9
DISPLAY=:0.0
GTK3_IM_MODULE=fcitx
GLADE_CATALOG_PATH=:
GTK_IM_MODULE=fcitx
XDG_CURRENT_DESKTOP=XFCE
LC_TIME=en_US.UTF-8
XAUTHORITY=/var/run/gdm/auth-for-rhinofly-5ZAgcz/database
COLORTERM=xfce4-terminal
_=/home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64/go_bootstrap
GOTOOLDIR=/home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64
GOGCCFLAGS=-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/home/rhinofly/home/sandspace/tmp/go-build049237945=/tmp/go-build -gno-record-gcc-switches
CXX=clang++
 ---
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/runtime/cgo/_obj/ -g -O2 -Wall -Werror -o $WORK/runtime/cgo/_obj/gcc_amd64.o -c ./gcc_amd64.S
# runtime/cgo
runtime/cgo/gcc_amd64.S:47:1: warning: DWARF2 only supports one section per compilation unit
.section .note.GNU-stack,"",@progbits
^
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/runtime/cgo/_obj/_cgo_.o $WORK/runtime/cgo/_obj/_cgo_main.o $WORK/runtime/cgo/_obj/_cgo_export.o $WORK/runtime/cgo/_obj/cgo.cgo2.o $WORK/runtime/cgo/_obj/gcc_context.o $WORK/runtime/cgo/_obj/gcc_freebsd_amd64.o $WORK/runtime/cgo/_obj/gcc_libinit.o $WORK/runtime/cgo/_obj/gcc_setenv.o $WORK/runtime/cgo/_obj/gcc_util.o $WORK/runtime/cgo/_obj/gcc_amd64.o -g -O2 -lpthread
/home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64/cgo -objdir $WORK/runtime/cgo/_obj/ -dynpackage cgo -dynimport $WORK/runtime/cgo/_obj/_cgo_.o -dynout $WORK/runtime/cgo/_obj/_cgo_import.go -dynlinker
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/runtime/cgo/_obj/_all.o $WORK/runtime/cgo/_obj/_cgo_export.o $WORK/runtime/cgo/_obj/cgo.cgo2.o $WORK/runtime/cgo/_obj/gcc_context.o $WORK/runtime/cgo/_obj/gcc_freebsd_amd64.o $WORK/runtime/cgo/_obj/gcc_libinit.o $WORK/runtime/cgo/_obj/gcc_setenv.o $WORK/runtime/cgo/_obj/gcc_util.o $WORK/runtime/cgo/_obj/gcc_amd64.o -g -O2 -Wl,-r -nostdlib
/home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64/compile -o $WORK/runtime/cgo.a -trimpath $WORK -p runtime/cgo -buildid f6d80b347c15845bdb589d38b0202f637d2e07c0 -D _/home/rhinofly/sandspace/go/src/runtime/cgo -I $WORK -pack -asmhdr $WORK/runtime/cgo/_obj/go_asm.h ./callbacks.go ./freebsd.go ./iscgo.go ./setenv.go $WORK/runtime/cgo/_obj/_cgo_gotypes.go $WORK/runtime/cgo/_obj/cgo.cgo1.go $WORK/runtime/cgo/_obj/_cgo_import.go
/home/rhinofly/sandspace/go/pkg/tool/freebsd_amd64/asm -o $WORK/runtime/cgo/_obj/asm_amd64.o -trimpath $WORK -I $WORK/runtime/cgo/_obj/ -I /home/rhinofly/sandspace/go/pkg/include -D GOOS_freebsd -D GOARCH_amd64 ./asm_amd64.s
go/importer
net
os/user
cmd/asm/internal/arch
cmd/compile/internal/ssa
...
...

BTW: ./all.bash does not PASS at present, effected by #15405

@ianlancetaylor
Copy link
Contributor

Thanks for the detail. I have no explanation. I can't recreate the problem. I don't understand why clang is saying anything about DWARF-2 at all. Nothing in the command line you show is telling clang to use DWARF-2.

@wheelcomplex
Copy link
Contributor Author

May be I have fingered it out:
http://reviews.llvm.org/rL211273 introduced a new error "DWARF2 only supports one section per compilation unit" and FreeBSD 11-CURRENT using a new clang(version 3.8.0) based on LLVM 3.8.0 come with this change.

http://comments.gmane.org/gmane.os.freebsd.devel.toolchain/1982 saying "these are harmless" and can not disabled.

tested with CGO_CFLAGS=-gdwarf-4, the waring is gone.

Should we use -gdwarf-4 by default? Or just change the Milestone to "Unplanned " and wait for FreeBSD 11 reach it's release day(it's in -CURRENT now)?

@ianlancetaylor
Copy link
Contributor

Our only reasonable default is -g, and that is what we use. In the command line you showed, nothing is passing -gdwarf-2 to clang. Why does clang default to -gdwarf-2?

I'll note that it's also pointless to issue a warning about a .note section, particularly a .note.GNU-stack section. The warning may be harmless but it's completely pointless. Those sections are essentially required on GNU/Linux, and have no contents so the lack of debug info is irrelevant.

@wheelcomplex
Copy link
Contributor Author

wheelcomplex commented May 21, 2016

Current freebsd source code showed the dwarf version is default to version 2 when only -g was specified:

  1. initial to zero: https://github.com/freebsd/freebsd/blob/master/contrib/llvm/tools/clang/tools/driver/cc1as_main.cpp#L149
  2. when only -g was specified and current value of version is zero try to fetch default value by GetDefaultDwarfVersion():
    https://github.com/freebsd/freebsd/blob/master/contrib/llvm/tools/clang/lib/Driver/Tools.cpp#L5976-5990
  3. default is 2: https://github.com/freebsd/freebsd/blob/master/contrib/llvm/tools/clang/lib/Driver/ToolChains.h#L731

BTW: They change default value from 3 to 2 at: freebsd/freebsd-src@a65c336

@ianlancetaylor
Copy link
Contributor

I'm dropping this to unplanned, because the problem seems to be due to a set of bugs in tools other than Go. If somebody figures out a clean fix, great. Otherwise, it's just a warning.

@ianlancetaylor
Copy link
Contributor

If FreeBSD does not support the .note.GNU-stack section, or, equivalently, if FreeBSD defaults to non-executable stacks, then we could avoid the warning by using a copy of gcc_amd64.S on FreeBSD only.

@bradfitz
Copy link
Contributor

@ianlancetaylor, we have FreeBSD 11 builders accessible via gomote now.

@bradfitz
Copy link
Contributor

@ianlancetaylor, should I just disable the compiler-warnings-promoted-to-errors-on-builders feature for our FreeBSD 11 builders for now?

@ianlancetaylor
Copy link
Contributor

I think this is clearly a bug in clang's assembler, which should not issue a warning about an empty section regardless of the DWARF version. But I will send a CL to work around the problem.

@gopherbot
Copy link

CL https://golang.org/cl/38072 mentions this issue.

@bradfitz bradfitz modified the milestones: Go1.8.2, Go1.9 May 3, 2017
@bradfitz
Copy link
Contributor

bradfitz commented May 3, 2017

Reopening for Go 1.8 backport.

@bradfitz bradfitz reopened this May 3, 2017
@gopherbot
Copy link

CL https://golang.org/cl/42500 mentions this issue.

gopherbot pushed a commit that referenced this issue May 4, 2017
… try without -g

Backport of CL 38072

Fixes #14705

Change-Id: Ie66a19d406c80e011e9918d6eddafbfc4abf95e4
Reviewed-on: https://go-review.googlesource.com/42500
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@bradfitz bradfitz modified the milestones: Go1.8.2, Go1.8.3 May 18, 2017
@gopherbot
Copy link

CL https://golang.org/cl/43995 mentions this issue.

@broady broady closed this as completed May 23, 2017
gopherbot pushed a commit that referenced this issue May 23, 2017
… try without -g

Backport of CL 38072

Fixes #14705

Reviewed-on: https://go-review.googlesource.com/42500
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>

Change-Id: Ia6ce2a41434aef2f8745a6a862ea66608b1e25f7
Reviewed-on: https://go-review.googlesource.com/43995
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@golang golang locked and limited conversation to collaborators May 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants