Closed pcj closed 7 years ago
This looks like a bug (we should detect if the toolchain supports --start-lib
and --end-lib
) but in the meantime, you should be able to workaround it by specifying --nostart_end_lib
.
Assigning to Damien since he's the one most familiar with cc_configure.bzl
.
Tentatively fixed by mid year, no time for it currently, feel free to add this check to cc_configure (contribution welcome) :)
So this would be additional logic here to establish a separate boolean value than supports_gold_linker = _is_gold_supported(repository_ctx, cc)
?
I am at my limit to understand what is going on there.
I would suggest adding a test to see if the linker support -start-lib and put it where you suggested. Send the change to @mhlopko (who should be back next week).
Hi @pcj, this is interesting. As gold is elf-only linker it shouldn't be used by your osx clang (unless you're cross compiling, please let me know if you do), and the autodetection in cc_configure.bzl should fail. Gold supports --start-lib --end-lib since 2010, so I hope we can assume that when gold is available, --start-lib --end-lib is available too. Of course if this assumption is wrong and you hitting this case, we can fix it together. Let me know.
Would you mind investigating why cc_configure.bzl thinks gold is available? Maybe the autodetection is wrong for older clang releases.
Anyway, thank you Paul for reporting and spending time on this!
To repeat what I wrote on the dup. issue:
Can you investigate why cc_configure.bzl#_is_gold_supported returns true when it actually should return false. The logic is quite simple, it runs clang -fuse-ld=gold -o /dev/null empty.cc
(empty.cc contains just int main() {}
), and returns true when exit code is 0. Testing locally it returns 1 for me. Can you try to run the command and see what happens?
Sorry I haven't had time to address your question @mhlopko. I'll take a look at this again this weekend.
Yes, getting zero exit status:
$ clang -fuse-ld=gold -o /dev/null empty.cc
$ echo $?
0
Reading http://llvm.org/docs/GoldPlugin.html...
$ which ld
/usr/bin/ld
$ /usr/bin/ld -v
@(#)PROGRAM:ld PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
LTO support using: LLVM version 3.5svn
$ /usr/bin/ld -plugin
ld: unknown option: -plugin
$ echo $?
1
So this ld
does not have plugin support. Trying to wrap my head around by use-ld=gold
would not complain about that...
Workaround for cc_configure.bzl
might be to drop gold support for darwin, or test ld
directly, but I'm not sure how brittle that would be.
Workaround for me is to use --nostart_end_lib
as @kchodorow suggests or get an ld that supports gold.
Will edit comment as I get more info...
I assume your ld
is not gold
. -fuse-ld=gold
finds gold using magic :) I'd take a look at ld.gold
or gold
.
You can have gold
installed, but clang
might not use it. That's why we detect gold
through clang
. That is also what bazel does, it invokes clang and lets clang delegate to the linker.
I'd like to keep gold enabled for macs, mainly so we can use --start/--end-lib
:)
How about we made the command line something funnier, like:
clang -fuse-ld=gold -o /dev/null -Wl,-start-lib -Wl,-end-lib empty.cc
Could you test that for me?
Sure:
$ clang -fuse-ld=gold -o /dev/null -Wl,-start-lib -Wl,-end-lib empty.cc
warning: unknown warning option '-Wl-end-lib'; did you mean '-Wlong-long'? [-Wunknown-warning-option]
1 warning generated.
ld: unknown option: -start-lib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld.gold
does not exist on my path.
Does it help?
Interesting, so I assume old macos clang silently ignores -fuse-ld=gold. Thanks Paul! I'm gonna upload the fix.
Thanks for working on this @mhlopko
Thank you for your help @pcj! :)
Under bazel 0.4.4, I get the following error on osx while trying to build/link google/protobuf:protoc