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/link: external linking can fail on Solaris 11.2+ #14957

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

cmd/link: external linking can fail on Solaris 11.2+ #14957

jtsylve opened this issue Mar 25, 2016 · 21 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

##### Testing packages.
ok      archive/tar 0.023s
ok      archive/zip 0.074s
ok      bufio   0.044s
ok      bytes   0.062s
ok      compress/bzip2  0.062s
ok      compress/flate  0.851s
ok      compress/gzip   0.013s
ok      compress/lzw    0.008s
ok      compress/zlib   0.021s
ok      container/heap  0.006s
ok      container/list  0.006s
ok      container/ring  0.013s
ok      crypto/aes  0.024s
ok      crypto/cipher   0.006s
ok      crypto/des  0.013s
ok      crypto/dsa  0.007s
ok      crypto/ecdsa    0.018s
ok      crypto/elliptic 0.027s
ok      crypto/hmac 0.006s
ok      crypto/md5  0.006s
ok      crypto/rand 0.012s
ok      crypto/rc4  0.055s
ok      crypto/rsa  0.058s
ok      crypto/sha1 0.006s
ok      crypto/sha256   0.006s
ok      crypto/sha512   0.006s
ok      crypto/subtle   0.007s
ok      crypto/tls  0.471s
ok      crypto/x509 0.658s
ok      database/sql    0.035s
ok      database/sql/driver 0.006s
ok      debug/dwarf 0.015s
ok      debug/elf   0.025s
ok      debug/gosym 0.220s
ok      debug/macho 0.008s
ok      debug/pe    0.025s
ok      debug/plan9obj  0.006s
ok      encoding/ascii85    0.006s
ok      encoding/asn1   0.007s
ok      encoding/base32 0.011s
ok      encoding/base64 0.007s
ok      encoding/binary 0.006s
ok      encoding/csv    0.007s
ok      encoding/gob    0.033s
ok      encoding/hex    0.006s
ok      encoding/json   0.105s
ok      encoding/pem    0.013s
ok      encoding/xml    0.012s
ok      errors  0.007s
ok      expvar  0.008s
ok      flag    0.008s
ok      fmt 0.073s
ok      go/ast  0.011s
ok      go/build    0.153s
ok      go/constant 0.007s
ok      go/doc  0.034s
ok      go/format   0.009s
ok      go/internal/gccgoimporter   0.007s
ok      go/internal/gcimporter  0.354s
ok      go/parser   0.028s
ok      go/printer  0.185s
ok      go/scanner  0.006s
ok      go/token    0.016s
ok      go/types    0.317s
ok      hash/adler32    0.011s
ok      hash/crc32  0.006s
ok      hash/crc64  0.007s
ok      hash/fnv    0.005s
ok      html    0.007s
ok      html/template   0.026s
ok      image   0.076s
ok      image/color 0.038s
ok      image/draw  0.042s
ok      image/gif   0.053s
ok      image/jpeg  0.095s
ok      image/png   0.028s
ok      index/suffixarray   0.014s
ok      internal/singleflight   0.017s
ok      internal/trace  0.006s
ok      io  0.025s
ok      io/ioutil   0.006s
ok      log 0.008s
ok      log/syslog  2.029s
ok      math    0.007s
ok      math/big    0.181s
ok      math/cmplx  0.006s
ok      math/rand   0.055s
ok      mime    0.009s
ok      mime/multipart  0.171s
ok      mime/quotedprintable    0.077s
ok      net 3.225s
ok      net/http    9.887s
ok      net/http/cgi    0.226s
ok      net/http/cookiejar  0.010s
ok      net/http/fcgi   0.009s
ok      net/http/httptest   0.011s
ok      net/http/httputil   0.032s
ok      net/http/internal   0.006s
ok      net/internal/socktest   0.006s
ok      net/mail    0.007s
ok      net/rpc 0.015s
ok      net/rpc/jsonrpc 0.012s
ok      net/smtp    0.027s
ok      net/textproto   0.007s
ok      net/url 0.010s
ok      os  0.306s
ok      os/exec 0.595s
ok      os/signal   4.398s
ok      os/user 0.006s
ok      path    0.007s
ok      path/filepath   0.044s
ok      reflect 0.045s
ok      regexp  0.077s
ok      regexp/syntax   0.224s
--- FAIL: TestCgoCrashHandler (1.40s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoSignalDeadlock (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoTraceback (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoCallbackGC (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoExternalThreadPanic (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoExternalThreadSIGPROF (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoExternalThreadSignal (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoExecSignalMask (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestEnsureDropM (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoCheckBytes (0.00s)
    crash_cgo_test.go:162: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoPanicDeadlock (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


--- FAIL: TestCgoCCodeSIGPROF (0.00s)
    crash_test.go:66: building testprogcgo: exit status 2
        # _/export/home/joe/src/go/src/runtime/testdata/testprogcgo
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


FAIL
FAIL    runtime 7.737s
ok      runtime/debug   0.008s
ok      runtime/internal/atomic 0.055s
ok      runtime/pprof   1.285s
ok      runtime/trace   3.394s
ok      sort    0.044s
ok      strconv 0.298s
ok      strings 0.069s
ok      sync    0.104s
ok      sync/atomic 0.016s
ok      syscall 0.024s
ok      testing 2.330s
ok      testing/quick   0.110s
ok      text/scanner    0.007s
ok      text/tabwriter  0.007s
ok      text/template   0.020s
ok      text/template/parse 0.008s
ok      time    2.319s
ok      unicode 0.007s
ok      unicode/utf16   0.006s
ok      unicode/utf8    0.008s
ok      vendor/golang.org/x/net/http2/hpack 0.008s
ok      cmd/addr2line   0.603s
ok      cmd/api 0.012s
ok      cmd/asm/internal/asm    0.144s
ok      cmd/asm/internal/lex    0.007s
ok      cmd/compile/internal/big    0.436s
ok      cmd/compile/internal/gc 12.885s
ok      cmd/compile/internal/ssa    0.151s
ok      cmd/cover   1.121s
ok      cmd/doc 0.023s
ok      cmd/fix 0.012s
--- FAIL: TestCoverageWithCgo (0.64s)
    go_test.go:244: running testgo [test -short -cover ./testdata/cgocover]
    go_test.go:259: standard output:
    go_test.go:260: FAIL    _/export/home/joe/src/go/src/cmd/go/testdata/cgocover [build failed]

    go_test.go:263: standard error:
    go_test.go:264: # testmain
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


    go_test.go:273: go [test -short -cover ./testdata/cgocover] failed unexpectedly: exit status 2
--- FAIL: TestNoteReading (0.33s)
    go_test.go:244: running testgo [build -ldflags -buildid=TestNoteReading-Build-ID -o /tmp/gotest401197282/hello.exe /tmp/gotest401197282/hello.go]
    go_test.go:244: running testgo [build -ldflags -buildid=TestNoteReading-Build-ID -linkmode=external -o /tmp/gotest401197282/hello.exe /tmp/gotest401197282/hello.go]
    go_test.go:263: standard error:
    go_test.go:264: # command-line-arguments
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


    go_test.go:273: go [build -ldflags -buildid=TestNoteReading-Build-ID -linkmode=external -o /tmp/gotest401197282/hello.exe /tmp/gotest401197282/hello.go] failed unexpectedly: exit status 2
--- FAIL: TestNoteReading2K (0.36s)
    go_test.go:244: running testgo [build -ldflags -buildid=TestNoteReading-Build-ID -o /tmp/gotest764207321/hello.exe /tmp/gotest764207321/hello.go]
    go_test.go:244: running testgo [build -ldflags -buildid=TestNoteReading-Build-ID -linkmode=external -o /tmp/gotest764207321/hello.exe /tmp/gotest764207321/hello.go]
    go_test.go:263: standard error:
    go_test.go:264: # command-line-arguments
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status


    go_test.go:273: go [build -ldflags -buildid=TestNoteReading-Build-ID -linkmode=external -o /tmp/gotest764207321/hello.exe /tmp/gotest764207321/hello.go] failed unexpectedly: exit status 2
FAIL
FAIL    cmd/go  42.164s
ok      cmd/gofmt   0.031s
ok      cmd/internal/goobj  0.006s
ok      cmd/internal/obj    0.006s
ok      cmd/internal/obj/x86    0.007s
ok      cmd/internal/unvendor/golang.org/x/arch/arm/armasm  0.008s
ok      cmd/internal/unvendor/golang.org/x/arch/x86/x86asm  0.124s
ok      cmd/nm  0.551s
--- FAIL: TestDisasmExtld (0.76s)
    objdump_test.go:71: go build fmthello.go: exit status 2
        # command-line-arguments
        /export/home/joe/src/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
        ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to .dynsym
        collect2: error: ld returned 1 exit status

FAIL
FAIL    cmd/objdump 1.516s
ok      cmd/pack    1.345s
ok      cmd/pprof/internal/profile  0.006s
ok      cmd/vet 2.004s
2016/03/24 21:25:34 Failed: exit status 1
@ianlancetaylor ianlancetaylor changed the title Go doesn't build on Solaris 11.3 cmd/link: external linking fails on Solaris 11.3 Mar 25, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 25, 2016
@jtsylve
Copy link
Contributor Author

jtsylve commented Mar 25, 2016

Should I open a separate issue for the compile failure in os/user/lookup_unix.go and keep this one specific to the linking issue?

@ianlancetaylor
Copy link
Contributor

@jtsylve Good idea, thanks.

@binarycrusader
Copy link
Contributor

This is a regression compared to 1.5; I will add this to the list of things to investigate.

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Apr 1, 2016
Fixes a problem when using the external linker on Solaris.  The Solaris
external linker still doesn't work due to issue #14957.

The problem is, for example, with `go test cmd/objdump`:

        objdump_test.go:71: go build fmthello.go: exit status 2
                # command-line-arguments
                /var/gcc/iant/go/pkg/tool/solaris_amd64/link: running gcc failed: exit status 1
                Undefined                       first referenced
                 symbol                             in file
                x_cgo_callers                       /tmp/go-link-355600608/go.o
                ld: fatal: symbol referencing errors
                collect2: error: ld returned 1 exit status

Change-Id: I54917cfd5c288ee77ea25c439489bd2c9124fe73
Reviewed-on: https://go-review.googlesource.com/21392
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
@jtsylve
Copy link
Contributor Author

jtsylve commented Apr 1, 2016

Might it be wise to add a Sun Solaris build bot? I'm not sure which distro the two bots are currently running, but it's surprising that the automated build tests didn't catch this regression.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 1, 2016

@jtsylve, are you volunteering to run it or help set it up?

Both the current ones are SmartOS I think.

@jtsylve
Copy link
Contributor Author

jtsylve commented Apr 1, 2016

Shoot me some info about the process and I might be able to help -- depending on how much work it involves. I'm currently on paternity leave, so I have my hands a little full these days, but I could eventually get there.

@binarycrusader
Copy link
Contributor

Unfortunately, Go just happens to be the victim of a bug in the Solaris 11.2 and later linker. This issue is also trivially reproducible using gcc alone without Go:

$ echo 'int main(int argc, char **argv) { return 0; }' | \
   gcc -x c -o a.out -
ld: fatal: bad section layout: .SUNW_ldynsym must precede and be adjacent to
.dynsym
collect2: error: ld returned 1 exit status

The reason we are seeing this issue with Go is due to the changes applied for issue #13247 which added this seemingly innocuous logic to src/cmd/link/internal/ld/symtab.go:

       // Some linkers will add a FILE sym if one is not present.
       // Avoid having the working directory inserted into the symbol table.
       putelfsyment(0, 0, 0, STB_LOCAL<<4|STT_FILE, SHN_ABS, 0)

This adds a NULL STT_FILE entry to the symtab; this seems to be allowed per the System V ABI, so probably is a valid thing to do. However, this in turn triggers a silent bug that has existed for a few years (since sometime in the Solaris 11.2 release cycle) in the Solaris linker; ld(1)'s local symbol counting is being thrown off in some manner. This in turn trips up logic added during the Solaris 11.2 release cycle to ensure that elf output sections are in the expected order:

           secadj
               ELF  objects  require  certain  sections to be adjacent to each
               other in a specified order in the output object. This automatic
               layout can be disrupted by link-editor mapfiles that explicitly
               layout sections. An invalid layout results in  a  fatal  error.
               The -z  relax=secadj option suppresses layout verification.

In versions of Solaris that have this functionality, this can be worked around by using "-z relax=secadj".

However, the simplest workaround is likely to simply have STT_FILE use a name of some sort:

    putelfsyment(putelfstr("go.go"), 0, 0, STB_LOCAL<<4|STT_FILE, SHN_ABS, 0)

...which avoids the issue. This issue will be resolved in a future update to Solaris, but a workaround seems appropriate.

I will happily contribute a CL based on whatever the preferred solution is.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 7, 2016

Workaround is probably okay (@crawshaw?) but I'd love to see it pass on a builder (#15072).

@crawshaw
Copy link
Member

crawshaw commented Apr 7, 2016

That workaround sounds OK to me.

@minux
Copy link
Member

minux commented Apr 7, 2016 via email

@crawshaw
Copy link
Member

crawshaw commented Apr 7, 2016

@minux why? that involves the linker working out what version of solaris it is on.

@binarycrusader
Copy link
Contributor

@minux I did not choose the path of using "-z relax-secadj" for the following reasons:

  • it is only available in Oracle Solaris starting in later versions of 11.2, which means it would cause build failures for the builders running Illumos
  • it actually disables a correctness checking mechanism in the linker, which should actually be generally applied
  • I felt that simply naming the STT_FILE symbol was preferable since it works for all operating systems instead of requiring a special Solaris code path

@minux
Copy link
Member

minux commented Apr 7, 2016 via email

@binarycrusader
Copy link
Contributor

@minux not as far as I'm aware, and not in testing; at most, I suppose it might cause a warning, but I haven't encountered a case where it will

@binarycrusader
Copy link
Contributor

@bradfitz I'd like to see it pass on a builder too, but I can't solve that problem at the moment; the best I can do is provide output of test results from a Solaris box and ensure that it hasn't broken any existing builders, as has been the case for all of my contributions thus far. Thanks.

@binarycrusader
Copy link
Contributor

Can someone with editing privileges please update the bug title to:

cmd/link: external linking can fail on Solaris 11.2+

...so that it accurately reflects the issue?

@jtsylve jtsylve changed the title cmd/link: external linking fails on Solaris 11.3 cmd/link: external linking can fail on Solaris 11.2+ Apr 8, 2016
@gopherbot
Copy link

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

@jtsylve
Copy link
Contributor Author

jtsylve commented Apr 11, 2016

Patch is currently listed as DO NOT SUBMIT. Test builder is up and running now. Is there anything else we're waiting for?

@binarycrusader
Copy link
Contributor

I expect to receive approval from my employer to submit my patches Monday.

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Jun 24, 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

7 participants