This is an archive of the discontinued LLVM Phabricator instance.

Add PIC-level support to Clang.
ClosedPublic

Authored by jhibbits on Sep 18 2014, 10:23 AM.

Details

Summary

This distinguishes between -fpic and -fPIC now, with the additions in LLVM for
PIC level support.

Diff Detail

Event Timeline

jhibbits updated this revision to Diff 13838.Sep 18 2014, 10:23 AM
jhibbits retitled this revision from to Add PIC-level support to Clang..
jhibbits updated this object.
jhibbits edited the test plan for this revision. (Show Details)
jhibbits added reviewers: echristo, rafael.
jhibbits added a subscriber: Unknown Object (MLST).
emaste added a subscriber: emaste.Sep 18 2014, 10:42 AM
jhibbits updated this revision to Diff 14425.Oct 4 2014, 8:18 AM

ParseStmtAsm.cpp was missing, fix that as well.

rafael added inline comments.Oct 14 2014, 1:44 PM
lib/CodeGen/BackendUtil.cpp
428

Don't you want to produce an error if -pic-level is not 1 or 2?

jhibbits updated this revision to Diff 16293.Nov 17 2014, 9:04 AM

Update to use the Module PIC Level API.

rafael added inline comments.Nov 17 2014, 9:45 AM
lib/CodeGen/CodeGenModule.cpp
401 ↗(On Diff #16293)

We use llvm_unreachble instead of assert(0).

jhibbits added inline comments.Nov 17 2014, 9:53 AM
lib/CodeGen/CodeGenModule.cpp
401 ↗(On Diff #16293)

d'oh, fail :(

jhibbits updated this revision to Diff 16295.Nov 17 2014, 10:19 AM

Use llvm_unreachable() instead of assert(0).

rafael accepted this revision.Nov 17 2014, 11:29 AM
rafael edited edge metadata.

LGTM with a nit.

lib/CodeGen/CodeGenModule.cpp
395 ↗(On Diff #16295)

You can fold the variable declaration into the if:

if (uint32_t PLevel = Context.getLangOpts().PICLevel) {

This revision is now accepted and ready to land.Nov 17 2014, 11:29 AM
rnk added a subscriber: rnk.Nov 17 2014, 11:59 AM
rnk added inline comments.
lib/CodeGen/BackendUtil.cpp
428

It's too easy for the user to try to do something like clang -cc1 -pic-level 3 t.c and crash the compiler with assert or llvm_unreachable. We should either clamp the level to [0-2] or issue a diagnostic in lib/Frontend/CompilerInvocation.cpp.

Thanks for the review, Rafael!

lib/CodeGen/CodeGenModule.cpp
395 ↗(On Diff #16295)

That may be legal C++, but it makes me really uncomfortable, and makes it (trivially, I guess) less readable, I think.

jhibbits closed this revision.Nov 17 2014, 10:17 PM
jhibbits updated this revision to Diff 16318.

Closed by commit rL222227 (authored by @jhibbits).

rafael wrote:

Don't you want to produce an error if -pic-level is not 1 or 2?

It's too easy for the user to try to do something like clang -cc1 -pic-level 3 t.c and crash the compiler with assert or llvm_unreachable. We should either clamp the level to [0-2] or issue a diagnostic in lib/Frontend/CompilerInvocation.cpp.

I don't think -cc1 options are considered user visible. Having another
value in here means a bug somewhere else in clang.

Cheers,
Rafael