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

os/user: building fails on Solaris 11.3 #14967

Closed
jtsylve opened this issue Mar 25, 2016 · 17 comments
Closed

os/user: building fails on Solaris 11.3 #14967

jtsylve opened this issue Mar 25, 2016 · 17 comments

Comments

@jtsylve
Copy link
Contributor

jtsylve commented Mar 25, 2016

  1. What version of Go are you using (go version)?
    go version devel +ba333a3 Fri Mar 25 01:09:28 2016 +0000 solaris/amd64
  2. What operating system and processor architecture are you using (go env)?
    SunOS solaris 5.11 11.3 i86pc i386 i86pc
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="solaris"
GOOS="solaris"
GOPATH=""
GORACE=""
GOROOT="/export/home/joe/src/go"
GOTOOLDIR="/export/home/joe/src/go/pkg/tool/solaris_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build162816245=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

GCC:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gcc/4.8/lib/gcc/i386-pc-solaris2.11/4.8.2/lto-wrapper
Target: i386-pc-solaris2.11
Configured with: /builds/hudson/workspace/nightly-update/build/i386/components/gcc48/gcc-4.8.2/configure CC=/usr/gcc/4.7/bin/gcc CXX=/usr/gcc/4.7/bin/g++ --prefix=/usr/gcc/4.8 --mandir=/usr/gcc/4.8/share/man --bindir=/usr/gcc/4.8/bin --libdir=/usr/gcc/4.8/lib --sbindir=/usr/gcc/4.8/sbin --infodir=/usr/gcc/4.8/share/info --libexecdir=/usr/gcc/4.8/lib --enable-languages=c,c++,fortran,objc --enable-shared --with-gmp-include=/usr/include/gmp --with-mpfr-include=/usr/include/mpfr --without-gnu-ld --with-ld=/usr/bin/ld --with-gnu-as --with-as=/usr/gnu/bin/as CFLAGS='-g -O2  -mtune=opteron -march=opteron' CXXFLAGS='-g -O2 -mtune=opteron -march=opteron'
Thread model: posix
gcc version 4.8.2 (GCC) 
  1. What did you do?

Bootstrapping with Go 1.4.3

# os/user
os/user/lookup_unix.go:145: cannot use C.size_t(buf.size) (type C.size_t) as type C.int in argument to _Cfunc_getgrnam_r
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 25, 2016
@ianlancetaylor ianlancetaylor changed the title building fails on Solaris 11.3 os/user: building fails on Solaris 11.3 Mar 25, 2016
@ianlancetaylor
Copy link
Contributor

CC @zombiezen

@zombiezen
Copy link
Contributor

Solaris does not seem to follow the POSIX spec. Seems like overkill to me to have to have a Solaris-specific file just to make an int cast, but I don't see another way. @ianlancetaylor thoughts?

@ianlancetaylor
Copy link
Contributor

According to the Solaris man page (https://docs.oracle.com/cd/E19455-01/806-0627/6j9vhfmt1/index.html) you can get the POSIX version by using -D_POSIX_PTHREAD_SEMANTICS. Perhaps we could put that in a #cgo CFLAGS solaris line.

@zombiezen
Copy link
Contributor

@4ad Does 24396da fix this issue?

(Sorry, misread the 2015 on the commit date as 2016.)

@zombiezen
Copy link
Contributor

Odd. lookup_unix.go already has exactly that line in it, so this shouldn't be happening.

@gopherbot
Copy link

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

@binarycrusader
Copy link
Contributor

You're missing something; Solaris does provide the POSIX-compliant definition if the right defines are set. Let me find the right combination for you.

@binarycrusader
Copy link
Contributor

So, the issue is that the Solaris grp.h header checks to see if the current compilers supports symbol renaming and if so, uses that:

#ifdef __PRAGMA_REDEFINE_EXTNAME
...
#pragma redefine_extname getgrnam_r __posix_getgrnam_r
...
  extern int getgrnam_r(const char *, struct group *, char *, size_t,
      struct group **);
#endif

Refer to:
https://gcc.gnu.org/onlinedocs/gcc-4.4.5/gcc/Symbol_002dRenaming-Pragmas.html

Both gcc and Solaris Studio support this extension, and presumably, clang/llvm does as well.

#ifdef __lint
...
#define getgrnam_r __posix_getgrnam_r
#else
...
static int 
getgrnam_r(const char *__cb, struct group *__grp, char *__buf, int __len,
    struct group **__res)
{
        return (__posix_getgrnam_r(__cb, __grp, __buf, __len, __res));
}
#endif

So Go appears to be looking at the wrong symbol; it should be looking at __posix_getgrnam_r, but is looking at getgrnam_r instead.

The following should workaround Go's lack of support for the symbol rename:

diff --git a/src/os/user/lookup_unix.go b/src/os/user/lookup_unix.go
index 97b649c..c7c0356 100644
--- a/src/os/user/lookup_unix.go
+++ b/src/os/user/lookup_unix.go
@@ -16,7 +16,7 @@ import (
 )

 /*
-#cgo solaris CFLAGS: -D_POSIX_PTHREAD_SEMANTICS
+#cgo solaris CFLAGS: -D_POSIX_PTHREAD_SEMANTICS -D__lint
 #include <unistd.h>
 #include <sys/types.h>
 #include <pwd.h>

@jtsylve
Copy link
Contributor Author

jtsylve commented Apr 1, 2016

I can confirm that this patch from @binarycrusader does resolve the issue on my end.

diff --git a/src/os/user/lookup_unix.go b/src/os/user/lookup_unix.go
index 97b649c..c7c0356 100644
--- a/src/os/user/lookup_unix.go
+++ b/src/os/user/lookup_unix.go
@@ -16,7 +16,7 @@ import (
 )

 /*
-#cgo solaris CFLAGS: -D_POSIX_PTHREAD_SEMANTICS
+#cgo solaris CFLAGS: -D_POSIX_PTHREAD_SEMANTICS -D__lint
 #include <unistd.h>
 #include <sys/types.h>
 #include <pwd.h>

@jtsylve
Copy link
Contributor Author

jtsylve commented Apr 1, 2016

@binarycrusader Would you like to submit a CL with this change? If not I can do it for you.

@ianlancetaylor
Copy link
Contributor

I think we should just add mygetgrnam_r to os/user/lookup_unix.go, just as we do for the other functions. I do not think we should define the __lint preprocessor macro.

@binarycrusader
Copy link
Contributor

No opinion on supporting the symbol renaming? Regardlees, either approach works.

@binarycrusader
Copy link
Contributor

Forgot to add, just wanted to be clear that bug summary and the putback should reflect actual issue correctly. Solaris provides posix compliant interfaces here, so whatever fix is applied please be accurate about cause to make sure right fix is applied in the future if this happens again.

@ianlancetaylor
Copy link
Contributor

The cgo command does not contain a C parser. Instead, it passes code to the C compiler and sees what happens. The C compiler does support the symbol renaming. My guess is that the symbol renaming is not expressed in the debug info where the cgo command would look for it. If it is there, then, yes, we should teach cgo about that.

@4ad
Copy link
Member

4ad commented Apr 3, 2016

Let's go the mygetgrnam_r route for now.

@binarycrusader
Copy link
Contributor

I've checked, gcc doesn't include any of this in the dwarf output -- only the pre-processor output. The Solaris Studio compilers do include references to the symbols in their dwarf output.

I did a search through the Solaris headers to see how many things use symbol renaming, and it's more than a few -- (262 instances), so we should probably open a separate bug and add support for this somehow. The mygetgrnam_r route will work for the moment for this particular case.

The symbol renaming is used to guarantee backwards compatibility for older source code and older programs.

@zombiezen
Copy link
Contributor

If we're okay with the mygetgrnam_r route, then https://golang.org/cl/21385 is ready.

@golang golang locked and limited conversation to collaborators Apr 6, 2017
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