New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 778209 link

Starred by 8 users

Issue metadata

Status: Fixed
Owner:
Closed: Dec 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 3
Type: Bug



Sign in to add a comment

lld generates wrong binary files for object files generated via icecc

Project Member Reported by ckulakow...@opera.com, Oct 25 2017

Issue description

Chrome 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.
 
icecc.tar.xz
3.5 KB Download
Cc: ptwo...@vewd.com tsniatow...@vewd.com
We're also seeing lld+icecc issues here in Vewd. Originally it looked like a build-time protoc crash -- protoc compiled during the build for the host and linked with lld would die with a "protoc returned -8". Looks like the same underlying issue.

Comment 2 by thakis@chromium.org, Oct 25 2017

Cc: ruiu@google.com
Can you also paste the commands you ran to compile and link?

Attaching the unzipped from from that tar.
icecc_test
25.9 KB View Download
main.cc
83 bytes View Download
main.o
4.8 KB Download

Comment 3 by thakis@chromium.org, Oct 25 2017

Components: Build

Comment 4 by p...@chromium.org, 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

Comment 5 by ruiu@google.com, 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.

Comment 6 by thakis@chromium.org, 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?

Comment 7 by ruiu@google.com, 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.)
icecc runs the compiler in a chroot with very little inside, so maybe nothing at all gets detected as a candidate gcc
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.

Comment 10 by ruiu@google.com, Oct 25 2017

Isn't there a compiler flag to force .init/.fini?
Maybe the compiler should default to .init/.fini if no gcc installation can be detected?

Comment 12 Deleted

Comment 13 by p...@chromium.org, Oct 25 2017

Yes, -fuse-init-array

Comment 14 by ruiu@google.com, 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.
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

?

Comment 16 by p...@chromium.org, Oct 25 2017

The clang change makes sense to me. Nico, could you take care of it, please?
I can confirm that -fuse-init-array fixes the protoc crash when icecc and lld are used.
-fuse-init-array fixes problem with example attached to the bug.
Owner: thakis@chromium.org
Status: Started (was: Unconfirmed)
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?

Comment 21 by ruiu@google.com, Oct 26 2017

I am actually trying to finish up my patch to convert .ctors/dtors to .init/fini.
Status: Fixed (was: Started)
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