This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Let -static override the toolchain default PIC setting.
ClosedPublic

Authored by friss on Dec 11 2015, 9:23 AM.

Details

Summary

In r245667 -static was changed not to disable -fPIC as they control
2 different concepts. On toolchains that enable -fPIC by default,
this means that now you have to pass "-static -fno-PIC" to get the
previous behavior.

As static usually means that we do not need PIC, this patches allows
-static to override the toolchain default. You can still build all the
combinations, but -static doesn't require -fno-PIC anymore on default-PIC
toolchains.

Diff Detail

Event Timeline

friss updated this revision to Diff 42529.Dec 11 2015, 9:23 AM
friss retitled this revision from to [Driver] Let -static override the toolchain default PIC setting..
friss updated this object.
friss added reviewers: jyknight, rnk, joerg.
friss added a subscriber: cfe-commits.
joerg edited edge metadata.Dec 11 2015, 11:15 AM

As before, I don't see why a linker flag should change code generation. That seems to be a gross violation of layering and quite surprising.

Just because it makes the behavior more intuitive? If you toolchain does PIC by default, it's because you are mostly building shared objects. When you are building a static object, it's highly likely that you don't need PIC. There should be a way to enable it, but I find it really awkward to have to spell "clang -static -fno-PIC" to get the intuitive behavior.

Adding some SCE people, as their platform would be impacted by that change.

jyknight edited edge metadata.Dec 11 2015, 12:16 PM

As before, I don't see why a linker flag should change code generation. That seems to be a gross violation of layering and quite surprising.

I agree.

probinson edited edge metadata.Dec 11 2015, 6:18 PM

PS4 rejects -static unconditionally, so in that sense changing what it means doesn't matter to us. (But I really appreciate being asked!)

Still, abstractly it seems like -static doesn't really imply noPIC.

There has been a long-standing convention in both gcc and clang for Darwin that -static changes the default for PIC. Changing that convention is breaking stuff for us. The commit message for r245667 says "This new behavior also matches GCC", but that is not correct, at least for Darwin. I just tried compiling a simple test file with gcc-4.8.2 for OS X. If you run "gcc -v" with and without -static, you'll see that the gcc driver adds -fPIC to the cc1 command only when you do not use -static. I only have access to the GCC sources from an old version, but the config/i386/darwin.h file has this:

/* We want -fPIC by default, unless we're using -static to compile for

the kernel or some such.  */

#undef CC1_SPEC
#define CC1_SPEC "%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}}
....

We can change this to be Darwin-specific if you prefer, but we should maintain compatibility with GCC and previous Clang releases in this behavior.

#define CC1_SPEC "%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}}

That's sad.

We can change this to be Darwin-specific if you prefer, but we should maintain compatibility with GCC and previous Clang releases in this behavior.

Yes, the broken behavior should be reinstated for Darwin only.

bob.wilson accepted this revision.Jan 5 2016, 11:29 AM
bob.wilson added a reviewer: bob.wilson.

I applied a Darwin-specific change for this to clang in r256026.

This revision is now accepted and ready to land.Jan 5 2016, 11:29 AM
bob.wilson closed this revision.Jan 5 2016, 11:30 AM