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

pkgconfig problem #55

Closed
Zaryob opened this issue Oct 31, 2020 · 8 comments
Closed

pkgconfig problem #55

Zaryob opened this issue Oct 31, 2020 · 8 comments
Labels

Comments

@Zaryob
Copy link

Zaryob commented Oct 31, 2020

go get github.com/rthornton128/goncurses
github.com/rthornton128/goncurses
go build github.com/rthornton128/goncurses: invalid flag in pkg-config --libs: -Wl,-O2
@Zaryob
Copy link
Author

Zaryob commented Oct 31, 2020

go version
go version go1.14.10 linux/amd64

I'm running in opensuse. and goncurses cannot compiled due to belown issue. I controlled all ncurses installation and other stuff. ncurses C applications can compiled with same ncurses.

@Zaryob
Copy link
Author

Zaryob commented Oct 31, 2020

ncursesw6-config --cflags --libs
-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -I/usr/include/ncursesw
-Wl,-O2 -Wl,-Bsymbolic-functions -Wl,--as-needed -lncursesw -ltinfo

@rthornton128
Copy link
Owner

This is due to a limitation in CGO not accepting the flags.

For security reasons, only a limited set of flags are allowed, notably -D, -U, -I, and -l. To allow additional flags, set CGO_CFLAGS_ALLOW to a regular expression matching the new flags. To disallow flags that would otherwise be allowed, set CGO_CFLAGS_DISALLOW to a regular expression matching arguments that must be disallowed. In both cases the regular expression must match a full argument: to allow -mfoo=bar, use CGO_CFLAGS_ALLOW='-mfoo.*', not just CGO_CFLAGS_ALLOW='-mfoo'. Similarly named variables control the allowed CPPFLAGS, CXXFLAGS, FFLAGS, and LDFLAGS.

See the go docs for details.

I'm not sure there's anything can can be done for this package. Possibly the #cgo directives can be used to this affect.

Related issue: #50

@scrouthtv
Copy link

If you don't want to dive into the depths of CGO compilation and that stuff here's a quick and insecure "workaround" using the fix mentioned above:

export CGO_CFLAGS_ALLOW=".*"
export CGO_LDFLAGS_ALLOW=".*"
go get github.com/rthornton128/goncurses
export CGO_CFLAGS_ALLOW=
export CGO_LDFLAGS_ALLOW=

It is important to reset the allowed flags again for security reasons.

@Zaryob
Copy link
Author

Zaryob commented Nov 7, 2020

export CGO_CFLAGS_ALLOW="."
export CGO_LDFLAGS_ALLOW=".
"
go get github.com/rthornton128/goncurses
export CGO_CFLAGS_ALLOW=
export CGO_LDFLAGS_ALLOW=

with trying these. I will re-comment.

@scrouthtv
Copy link

@Zaryob note that there is an asterisk after the dot in the first two lines.
As rthornton mentioned, the CGO_*FLAGS_ALLOW are basically filters for which arguments are passed to the C compiler used by CGo. The form of these variables is a regular expression of patterns, .* in RegEx means anything.

@Zaryob Zaryob closed this as completed Dec 14, 2020
@scrouthtv
Copy link

Keep in mind that it's a workaround and by no means a production-ready fix.
Technically, you'd need to check which tool in the chain needs which flags and allow them separately.
.* also allows unwanted or potentially malicious compiler flags to be passed through CGO to gcc.

@rthornton128
Copy link
Owner

This warrants updating the wiki: https://github.com/rthornton128/goncurses/wiki/KnownIssues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants