unable to link cc_binary: ld.gold: fatal error: -pie and -static are incompatible

14 views
Skip to first unread message

Gregg Reynolds

unread,
Nov 28, 2022, 4:42:48 PM11/28/22
to bazel-discuss
I've got an ordinary cc_binary that depends on an ordinary cc_library. Works great on Mac, worked fine on linux a couple of weeks ago.  I just updated my ubuntu ( 20.04.5 LTS) and now I can't get the link to work. I don't know if this is a problem with Bazel or with gold.

Bazel 6.0 rc1

Adding -verbose to linkopts shows that gcc was configured with `--enable-default-pie`.

I've tried setting linkstatic on and off for both the cc_binary and the cc_library. Nothing works.

I can see `-pie` in COLLECT_GCC_OPTIONS, but I don't know why gold is complaining about -static - there is no trace of that flag in the log, with -verbose and --sandbox_debug. Nor in the link params file.  All of the object files are *.pic.o.

Tried turning off pie by passing `-no-pie`. No effect.

If I set cc_binary to linkstatic = True, then I can pass --verbose in linkopts. But if I set it to false, --verbose is evidently discarded.

I hope somebody can help with this. I've already wasted a good four hours on it. No doubt it will turn out to be a trivial mistake on my part, but I'm completely flummoxed at this point.

Thanks

Gregg
Reply all
Reply to author
Forward
0 new messages