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: mark cgo generated wrappers hidden #28340
Comments
I have the exact same problem with |
I think this is because the generated C function isn't marked with the same visibility attribute: CGO_NO_SANITIZE_THREAD
void
_cgo_ce009a93dc37_Cfunc_some_c_func(void *v)
{
struct {
char unused;
} __attribute__((__packed__)) *_cgo_a = v;
_cgo_tsan_acquire();
some_c_func();
_cgo_tsan_release();
} Looking at https://github.com/golang/go/blob/master/src/cmd/cgo/out.go#L618, it seems the CGo wrappers are not generated with hidden attributes. Is there a reason to that ? |
Reading https://github.com/bazelbuild/rules_go/blob/master/go/private/rules/cgo.bzl#L672-L683, it seems this is because the symbols are needed to generate |
Adding
Marking them with
So I'm guessing it's may not be an easy fix. Finally, reading |
It seems we could get away with patching https://github.com/golang/go/blob/master/src/cmd/cgo/out.go#L283 to use Even if they existed I'm not even sure it would work. |
I actually managed to make the wrapper hidden by leveraging /*
#pragma GCC visibility push(hidden)
static void some_c_func()
{
}
*/
import "C"
and without the
Not sure how safe that is, though. |
Actually, it's better to put it right before the end of the comment, or else inludes have it defined and errors such as /*
static void some_c_func()
{
}
#pragma GCC visibility push(hidden)
*/
import "C" |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version devel +c2a8d5972f Sat Sep 22 10:58:54 2018 +0200 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/elias/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/elias/dev/go"
GOPROXY=""
GORACE=""
GOROOT="/home/elias/dev/go-release"
GOTMPDIR=""
GOTOOLDIR="/home/elias/dev/go-release/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build186016377=/tmp/go-build -gno-record-gcc-switches"
What did you do?
What did you expect to see?
All cgo wrappers for
some_c_func
marked local.What did you see instead?
The
_cgo_1622f853b35c_Cfunc_some_c_func
function is global, not local as I would expect. I would expect it to be local even ifsome_c_func
itself is not.The text was updated successfully, but these errors were encountered: