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

gccgo: Seems to ignore "#cgo pkg-config" lines. #23666

Closed
hillu opened this issue Feb 2, 2018 · 2 comments
Closed

gccgo: Seems to ignore "#cgo pkg-config" lines. #23666

hillu opened this issue Feb 2, 2018 · 2 comments
Milestone

Comments

@hillu
Copy link
Contributor

hillu commented Feb 2, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10rc1 gccgo (Debian 8-20180130-1) 8.0.1 20180130 (experimental) [trunk revision 257194] linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/bengen/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/bengen/go"
GORACE=""
GOROOT="/usr"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/gcc/x86_64-linux-gnu/8"
GCCGO="/usr/bin/x86_64-linux-gnu-gccgo-8"
CC="x86_64-linux-gnu-gcc-8"
CXX="x86_64-linux-gnu-g++-8"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build151317498=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

What did you do?

I treid to build the following simple program, using go-8 build main.go:

package main

import (
	_ "github.com/hillu/go-yara"
)

func main() {
	print("hello\n")
}

What did you expect to see?

A working binary that is (uselessly) linked against libyara.so.3, like so:

$ ldd main
	linux-vdso.so.1 (0x00007fff5fde4000)
	libyara.so.3 => /usr/lib/x86_64-linux-gnu/libyara.so.3 (0x00007f58e5af3000)
	libgo.so.13 => /usr/lib/x86_64-linux-gnu/libgo.so.13 (0x00007f58e3ffd000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f58e3cb2000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f58e3a9a000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f58e36e4000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f58e5fc3000)
	libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f58e3253000)
	libmagic.so.1 => /usr/lib/x86_64-linux-gnu/libmagic.so.1 (0x00007f58e3031000)
	libjansson.so.4 => /usr/lib/x86_64-linux-gnu/libjansson.so.4 (0x00007f58e2e24000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f58e2c06000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f58e29ec000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f58e27e8000)

What did you see instead?

Instead I get a number of linker errors about missing symbols from libyara, such as:

/tmp/go-build548616898/b001/_pkg1_.a(_x013.o): In function `_cgo_5e5c217eb5fc_Cfunc_yr_rules_define_boolean_variable':
/tmp/go-build/cgo-gcc-prolog:46: undefined reference to `yr_rules_define_boolean_variable'

The go-yara library contains a file cgo.go that contains the following lines:

// #cgo !no_pkg_config,!yara_static  pkg-config: yara
// #cgo !no_pkg_config,yara_static   pkg-config: --static yara
// #cgo no_pkg_config                LDFLAGS:    -lyara

Some things I have tried:

  1. Bypassing pkg-config, by either setting CGO_LDFLAGS or passing the no_pkg_config build tag, results in a working binary.
  2. Replacing the three lines with
    // #cgo pkg-config: yara
    
    does not work.
  3. Running go-8 build -a -x main.go shows that pkg-config --cflags yara and pkg-config --libs yara are executed. The latter corretctly emits -lyara, but that string appears only in the cgo call...
    CGO_LDFLAGS='"-g" "-O2" "-lyara"' /usr/lib/gcc/x86_64-linux-gnu/8/cgo -objdir $WORK/b002/ -importpath github.com/hillu/go-yara -gccgo -gccgopkgpath=github.com/hillu/go-yara -- -I $WORK/b002/ -g -O2 -fsplit-stack ./cgo.go ./compiler.go ./compiler_yara37.go ./error.go ./error_yara34.go ./error_yara35.go ./error_yara36.go ./error_yara37.go ./object.go ./rule.go ./rule_yara37.go ./rules.go ./rules_callback.go ./rules_yara34.go ./stream.go
    
    ... not when the final executable is linked:
    /usr/bin/x86_64-linux-gnu-gccgo-8 -o $WORK/b001/exe/a.out "-Wl,-(" -m64 -Wl,--whole-archive $WORK/b001/_pkg_.a $WORK/b001/_pkg1_.a -Wl,--no-whole-archive "-Wl,-)" -Wl,--build-id=0x426c6a6b36534c5a757443584844514f36694b5a2f653744656354746d66456f4c3430614f487571662f71385636454e4d733644623854306c6b774b67622f426c6a6b36534c5a757443584844514f36694b5a -Wl,-E
    
@gopherbot gopherbot added this to the Gccgo milestone Feb 2, 2018
@gopherbot
Copy link

Change https://golang.org/cl/91655 mentions this issue: cmd/go: don't lose last flag from _cgo_flags

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Feb 5, 2018
    
    The quoting code that read _cgo_flags, currently only in the gccgo
    version of cmd/go, was losing the last flag read from the file.
    
    Fixes golang/go#23666
    
    Reviewed-on: https://go-review.googlesource.com/91655


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257373 138bc75d-0d04-0410-961f-82ee72b054a4
@hillu
Copy link
Contributor Author

hillu commented Feb 20, 2018

Yes, I can confirm that the issue has been fixed as of

go version go1.10rc2 gccgo (Debian 8-20180218-1) 8.0.1 20180218 (experimental) [trunk revision 257787] linux/amd64

Thank you.

@golang golang locked and limited conversation to collaborators Feb 20, 2019
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
    
    The quoting code that read _cgo_flags, currently only in the gccgo
    version of cmd/go, was losing the last flag read from the file.
    
    Fixes golang/go#23666
    
    Reviewed-on: https://go-review.googlesource.com/91655

From-SVN: r257373
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

2 participants