-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: clang AddressSanitizer does not work #8788
Comments
Kostya, the is in clang driver, it incorrectly handles -r linker flag. One of the objects is build as: clang -I . -fsanitize=address -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -o $WORK/command-line-arguments/_obj/_all.o $WORK/command-line-arguments/_obj/_cgo_export.o $WORK/command-line-arguments/_obj/src.cgo2.o -g -O2 -Wl,-r -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a It's kind of linking, but this object is later linked again: pack r $WORK/command-line-arguments.a $WORK/command-line-arguments/_obj/_cgo_import.6 $WORK/command-line-arguments/_obj/_cgo_defun.6 $WORK/command-line-arguments/_obj/_all.o # internal cd . /usr/lib/google-golang/pkg/tool/linux_amd64/6l -o $WORK/command-line-arguments/_obj/exe/src -L $WORK -w -extld=clang -extldflags=-fsanitize=address $WORK/command-line-arguments.a So one asan runtime comes from _all.o (incorrectly) and another from implicitly added by driver -lasan. Driver must not link in asan runtime if -Wl,-r is present. |
Moved to asan tracker: https://code.google.com/p/address-sanitizer/issues/detail?id=344 Status changed to Invalid. |
I don't see a reason to get into complex handling of the CC environment variable. We have enough flexibility without requiring that. For example: CC=clang CGO_CFLAGS=-fsanitize-address go run src.go I don't know if it will work, but it should cause -fsanitize-address to be used when compiling but not for the -Wl,-r step. |
Change the handling of bareLDFLAGS in cgo in cmd/go/build.go to strip -fsanitize options (this is not the same as what you suggested in comment #4, or at least not the same as what I understand you to be suggesting, because we already have to strip options from CGO_LDFLAGS when using -r). |
That's what I meant. https://golang.org/cl/142470043 |
CL https://golang.org/cl/142470043 mentions this issue. |
This issue was closed by revision 39cd39b. Status changed to Fixed. |
Just a quick question: do you strip -fsanitize=address from linker flags unconditionally, or only when you additionally pass "-r"? I don't think you should do the former. |
The -fsanitize options are only removed when the link is going to use -Wl,-r. This only happens when building a package that uses cgo (http://golang.org/cmd/cgo), as part of the steps of implementing the C/Go interface. |
Right, thanks for clarifications! |
Fixes golang#8788. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/142470043
Fixes golang#8788. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/142470043
Fixes golang#8788. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/142470043
Fixes golang#8788. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/142470043
The text was updated successfully, but these errors were encountered: