From 08692bed1e796b5395b6e321c5adcd32f6fc43bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20Chigot?= Date: Fri, 22 Mar 2019 12:48:31 +0100 Subject: [PATCH] cmd/compile, misc/cgo: fix fortran tests on aix/ppc64 Enable pattern lib.a/shared.so.X in cgo_import_dynamic as on AIX, archive files (.a) often have shared objects (.so) inside them. Change-Id: I21096c75eb7fbcc7064b0b832bfa8ed862142051 Reviewed-on: https://go-review.googlesource.com/c/go/+/168877 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- misc/cgo/fortran/test.bash | 7 ++++++- src/cmd/compile/internal/gc/lex.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/misc/cgo/fortran/test.bash b/misc/cgo/fortran/test.bash index 1e0d59ea1c..9498da0208 100755 --- a/misc/cgo/fortran/test.bash +++ b/misc/cgo/fortran/test.bash @@ -14,12 +14,17 @@ goos=$(go env GOOS) libext="so" if [ "$goos" = "darwin" ]; then libext="dylib" +elif [ "$goos" = "aix" ]; then + libtext="a" fi case "$FC" in *gfortran*) libpath=$(dirname $($FC -print-file-name=libgfortran.$libext)) - export CGO_LDFLAGS="$CGO_LDFLAGS -Wl,-rpath,$libpath -L $libpath" + if [ "$goos" != "aix" ]; then + RPATH_FLAG="-Wl,-rpath,$libpath" + fi + export CGO_LDFLAGS="$CGO_LDFLAGS $RPATH_FLAG -L $libpath" ;; esac diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index bd68ebffff..557f98604d 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -116,8 +116,9 @@ func (p *noder) pragcgo(pos syntax.Pos, text string) { f[3] = strings.Trim(f[3], `"`) if objabi.GOOS == "aix" && f[3] != "" { // On Aix, library pattern must be "lib.a/object.o" + // or "lib.a/libname.so.X" n := strings.Split(f[3], "/") - if len(n) != 2 || !strings.HasSuffix(n[0], ".a") || !strings.HasSuffix(n[1], ".o") { + if len(n) != 2 || !strings.HasSuffix(n[0], ".a") || (!strings.HasSuffix(n[1], ".o") && !strings.Contains(n[1], ".so.")) { p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_import_dynamic local [remote ["lib.a/object.o"]]`}) return } -- 2.48.1