Skip to content

Commit

Permalink
cmd/compile, misc/cgo: fix fortran tests on aix/ppc64
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
Clément Chigot authored and ianlancetaylor committed Mar 22, 2019
1 parent 83d90bb commit 08692be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion misc/cgo/fortran/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/compile/internal/gc/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 08692be

Please sign in to comment.