lld generates wrong binary files for object files generated via icecc |
|||||
Issue descriptionChrome Version : 63.0.3239.9 OS Version: Linux In our project we use icecc to speed up compilation time. The problem is that binaries linked with lld (which is default linker on linux now) crashes during access to static variables (segmentation fault). What's interesting when icecc is disabled everything is fine so it seems that lld generates wrong code when it links object files generated via icecc. I was able to create minimal test case to reproduce the problem. I've attached source file, object file generated by icecc and binary file linked with lld. If this file is linked with lld value of s.i is 0 (you can check it with debugger). If it's linked with gold s.i has proper value: 1.
,
Oct 25 2017
Can you also paste the commands you ran to compile and link? Attaching the unzipped from from that tar.
,
Oct 25 2017
,
Oct 25 2017
Looking at that object file, it appears to contain a section named .ctors, which is an older mechanism for calling constructors at startup time (the new mechanism uses a section named .init_array). On Linux, Clang will use .ctors by default if it detects a GCC installation older than 4.7.0 [1]. I guess it's possible that you have an old GCC installation on your build slaves. I thought that lld had support for .ctors, but it may be buggy (which is probably something that we should fix). For the moment, you can work around the issue by passing -fuse-init-array to the compiler, which should force it to use .init_array. [1] http://llvm-cs.pcc.me.uk/tools/clang/lib/Driver/ToolChains/Gnu.cpp#2360
,
Oct 25 2017
Thanks Peter for taking a look. I think I had a WIP patch to support .ctor, and it needs to be landed before the next major release.
,
Oct 25 2017
In the meantime, could lld error out on .ctor with some "error: not yet implemented" instead of silently doing the wrong thing?
,
Oct 25 2017
It may worth doing. (It should warn when we see both .ctors/.dtors and .init/fini, as I believe lld works fine if we do not mix the two.)
,
Oct 25 2017
icecc runs the compiler in a chroot with very little inside, so maybe nothing at all gets detected as a candidate gcc
,
Oct 25 2017
The question is what method Generic_GCC::GCCVersion::isOlderThan returns when there is no gcc detected. If it returns true (and probably it should) it explains why older mechanism is used.
,
Oct 25 2017
Isn't there a compiler flag to force .init/.fini?
,
Oct 25 2017
Maybe the compiler should default to .init/.fini if no gcc installation can be detected?
,
Oct 25 2017
Yes, -fuse-init-array
,
Oct 25 2017
Nico, I think that's a reasonable change. .ctors/.dtors are pretty old and mostly obsolete, and if clang is the only compiler installed to a system, it implies that the system is really new.
,
Oct 25 2017
So, plan: 1. Make clang use .init/.fini if no gcc detected (pcc, want to do this, or should I?) 2. Make lld error on mixed .ctors/.init instead of silently mislinking (ruiu?) 3. (At some point in the future) .ctors support in lld ?
,
Oct 25 2017
The clang change makes sense to me. Nico, could you take care of it, please?
,
Oct 26 2017
,
Oct 26 2017
I can confirm that -fuse-init-array fixes the protoc crash when icecc and lld are used.
,
Oct 26 2017
-fuse-init-array fixes problem with example attached to the bug.
,
Oct 26 2017
comment 17 landed in llvm r316713, this will be better after the next clang roll. ruiu, are you adding the error message to lld or do you think it might not be necessary?
,
Oct 26 2017
I am actually trying to finish up my patch to convert .ctors/dtors to .init/fini.
,
Dec 22 2017
Let's call this fixed. I don't know if the ctors/dtors part is landed yet, but since clang no longer defaults to ctors/dtors this bug has been fixed for a while. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by tsniatow...@vewd.com
, Oct 25 2017