]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: permit missing dynamic symbol section
authorPeter Gonda <pgonda@google.com>
Wed, 24 Jan 2018 22:45:28 +0000 (14:45 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 2 Jul 2018 17:50:00 +0000 (17:50 +0000)
Allow static complication of cgo enabled libraries.

Fixes #16651

Change-Id: I0729ee4e6e5f9bd1cbdb1bc2dcbfe34463df547c
Reviewed-on: https://go-review.googlesource.com/89655
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/test/issue4029.c
misc/cgo/test/issue4029.go
misc/cgo/test/issue4029w.go
src/cmd/cgo/out.go
src/cmd/dist/test.go

index 7205c5a5a2505250adf5bfa54909f37bb27b8798..30646ade021d84441329452092d2df5b6b045a99 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !windows
+// +build !windows,!static
 
 #include <stdint.h>
 #include <dlfcn.h>
index 8e468d367d1ec9d9ad21ae6b564e64293bc93057..1bf029d760ab0c50844356a0ac128098e26d7052 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !windows
+// +build !windows,!static
 
 package cgotest
 
index 18c720191be397dbc0c9a8c759b29054a49247c0..eee33f7010191de587efdd54651dc3045474c0f3 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build windows
+// +build windows static
 
 package cgotest
 
index dbc17d2d56f6556e7e84310eccb827c801a8f9ef..384791d07727688b498096bb1aa90f9dd23c2d35 100644 (file)
@@ -272,10 +272,7 @@ func dynimport(obj string) {
                                }
                        }
                }
-               sym, err := f.ImportedSymbols()
-               if err != nil {
-                       fatalf("cannot load imported symbols from ELF file %s: %v", obj, err)
-               }
+               sym, _ := f.ImportedSymbols()
                for _, s := range sym {
                        targ := s.Name
                        if s.Version != "" {
@@ -283,10 +280,7 @@ func dynimport(obj string) {
                        }
                        fmt.Fprintf(stdout, "//go:cgo_import_dynamic %s %s %q\n", s.Name, targ, s.Library)
                }
-               lib, err := f.ImportedLibraries()
-               if err != nil {
-                       fatalf("cannot load imported libraries from ELF file %s: %v", obj, err)
-               }
+               lib, _ := f.ImportedLibraries()
                for _, l := range lib {
                        fmt.Fprintf(stdout, "//go:cgo_import_dynamic _ _ %q\n", l)
                }
@@ -294,20 +288,14 @@ func dynimport(obj string) {
        }
 
        if f, err := macho.Open(obj); err == nil {
-               sym, err := f.ImportedSymbols()
-               if err != nil {
-                       fatalf("cannot load imported symbols from Mach-O file %s: %v", obj, err)
-               }
+               sym, _ := f.ImportedSymbols()
                for _, s := range sym {
                        if len(s) > 0 && s[0] == '_' {
                                s = s[1:]
                        }
                        fmt.Fprintf(stdout, "//go:cgo_import_dynamic %s %s %q\n", s, s, "")
                }
-               lib, err := f.ImportedLibraries()
-               if err != nil {
-                       fatalf("cannot load imported libraries from Mach-O file %s: %v", obj, err)
-               }
+               lib, _ := f.ImportedLibraries()
                for _, l := range lib {
                        fmt.Fprintf(stdout, "//go:cgo_import_dynamic _ _ %q\n", l)
                }
@@ -315,10 +303,7 @@ func dynimport(obj string) {
        }
 
        if f, err := pe.Open(obj); err == nil {
-               sym, err := f.ImportedSymbols()
-               if err != nil {
-                       fatalf("cannot load imported symbols from PE file %s: %v", obj, err)
-               }
+               sym, _ := f.ImportedSymbols()
                for _, s := range sym {
                        ss := strings.Split(s, ":")
                        name := strings.Split(ss[0], "@")[0]
index 5be4bcfa65e74c440bf779e14804ec32174a584e..a6c0f387ff1ff524bdd168d5d30b5075f24b5ca6 100644 (file)
@@ -1065,6 +1065,12 @@ func (t *tester) cgoTest(dt *distTest) error {
                                t.addCmd(dt, "misc/cgo/nocgo", t.goTest(), "-ldflags", `-linkmode=external`)
                                if goos != "android" {
                                        t.addCmd(dt, "misc/cgo/nocgo", t.goTest(), "-ldflags", `-linkmode=external -extldflags "-static -pthread"`)
+                                       t.addCmd(dt, "misc/cgo/test", t.goTest(), "-tags=static", "-ldflags", `-linkmode=external -extldflags "-static -pthread"`)
+                                       // -static in CGO_LDFLAGS triggers a different code path
+                                       // than -static in -extldflags, so test both.
+                                       // See issue #16651.
+                                       cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-tags=static")
+                                       cmd.Env = append(os.Environ(), "CGO_LDFLAGS=-static -pthread")
                                }
                        }