зеркало из https://github.com/CryptoPro/go.git
cmd/go: fix LDFLAGS handling, enable misc/cgo/testso on Darwin
Fixes #5479. R=golang-dev, dave CC=golang-dev https://golang.org/cl/9416047
This commit is contained in:
Родитель
c3294049c3
Коммит
bea7b51872
|
@ -5,7 +5,15 @@
|
|||
package cgosotest
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -L. -lcgosotest
|
||||
// intentionally write the same LDFLAGS differently
|
||||
// to test correct handling of LDFLAGS.
|
||||
#cgo linux LDFLAGS: -L. -lcgosotest
|
||||
#cgo freebsd LDFLAGS: -L. -l cgosotest
|
||||
#cgo openbsd LDFLAGS: -L. -l cgosotest
|
||||
#cgo netbsd LDFLAGS: -L. libcgosotest.so
|
||||
#cgo darwin LDFLAGS: -L. libcgosotest.dylib
|
||||
#cgo windows LDFLAGS: -L. libcgosotest.dll
|
||||
|
||||
void init(void);
|
||||
void sofunc(void);
|
||||
*/
|
||||
|
|
|
@ -4,7 +4,19 @@
|
|||
# license that can be found in the LICENSE file.
|
||||
|
||||
set -e
|
||||
$(go env CC) $(go env GOGCCFLAGS) -shared -o libcgosotest.so cgoso_c.c
|
||||
|
||||
args=
|
||||
dyld_envvar=LD_LIBRARY_PATH
|
||||
ext=so
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
args="-undefined suppress -flat_namespace"
|
||||
dyld_envvar=DYLD_LIBRARY_PATH
|
||||
ext=dylib
|
||||
fi
|
||||
|
||||
dylib=libcgosotest.$ext
|
||||
$(go env CC) $(go env GOGCCFLAGS) -shared $args -o $dylib cgoso_c.c
|
||||
go build main.go
|
||||
LD_LIBRARY_PATH=. ./main
|
||||
rm -f libcgosotest.so main
|
||||
|
||||
eval "$dyld_envvar"=. ./main
|
||||
rm -rf $dylib main *.dSYM
|
||||
|
|
|
@ -1855,14 +1855,24 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, gccfiles []string) (outGo,
|
|||
var linkobj []string
|
||||
|
||||
var bareLDFLAGS []string
|
||||
// filter out -lsomelib, and -framework X if on Darwin
|
||||
// filter out -lsomelib, -l somelib, *.{so,dll,dylib}, and (on Darwin) -framework X
|
||||
for i := 0; i < len(cgoLDFLAGS); i++ {
|
||||
f := cgoLDFLAGS[i]
|
||||
if !strings.HasPrefix(f, "-l") {
|
||||
if goos == "darwin" && f == "-framework" { // skip the -framework X
|
||||
i += 1
|
||||
continue
|
||||
switch {
|
||||
// skip "-lc" or "-l somelib"
|
||||
case strings.HasPrefix(f, "-l"):
|
||||
if f == "-l" {
|
||||
i++
|
||||
}
|
||||
// skip "-framework X" on Darwin
|
||||
case goos == "darwin" && f == "-framework":
|
||||
i++
|
||||
// skip "*.{dylib,so,dll}"
|
||||
case strings.HasSuffix(f, ".dylib"),
|
||||
strings.HasSuffix(f, ".so"),
|
||||
strings.HasSuffix(f, ".dll"):
|
||||
continue
|
||||
default:
|
||||
bareLDFLAGS = append(bareLDFLAGS, f)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,6 @@ esac
|
|||
|
||||
[ "$CGO_ENABLED" != 1 ] ||
|
||||
[ "$GOHOSTOS" == windows ] ||
|
||||
[ "$GOHOSTOS" == darwin ] ||
|
||||
(xcd ../misc/cgo/testso
|
||||
./test.bash
|
||||
) || exit $?
|
||||
|
|
Загрузка…
Ссылка в новой задаче