add CGO_CFLAGS support#5453
Conversation
|
Is this going to introduce any security issues? If we're pulling it purely from the users environment we're probably fine, but I just want to make sure we're not introducing any issues where additional flags are pulled from the cgo files in a way that could lead to local execution. |
|
No, it purely gets the env variable from the OS environment. This probably does not include anything from cgo files. |
There was a problem hiding this comment.
Regarding CFLAGS splitting, I'm not convinced a simple strings.Fields is sufficient.
Take for example this code:
package main
// int x = FOO;
import "C"
func main() {
println(C.x);
}This works:
$ CGO_CFLAGS='-DFOO=3+3' go run .
6
This does not (which makes sense):
CGO_CFLAGS='-DFOO=3 + 3' go run .
# runtime/cgo
gcc: warning: +: linker input file unused because linking not done
gcc: error: +: linker input file not found: No such file or directory
gcc: warning: 3: linker input file unused because linking not done
gcc: error: 3: linker input file not found: No such file or directory
...but this works, suggesting that it does take the quotes into account:
$ CGO_CFLAGS='"-DFOO=3 + 3"' go run .
6
It's probably a better idea to use the shlex module instead to split these values (also used in the cgo package for example).
Allow CGO_CFLAGS to be set when running tinygo. Usually needed for specifying alternative libc includes.