This is an archive of the discontinued LLVM Phabricator instance.

Add Position-independent Code model Module API.
ClosedPublic

Authored by jhibbits on Oct 21 2014, 7:44 AM.

Details

Summary

This makes PIC levels a Module flag attribute, which can be queried by the
backend. The flag is named PIC Level, and can have a value of:

0 - Backend-default
1 - Small-model (-fpic)
2 - Large-model (-fPIC)

These match the `-pic-level' command line argument for clang, and the value of the
preprocessor macro `PIC'.

Diff Detail

Event Timeline

jhibbits updated this revision to Diff 15189.Oct 21 2014, 7:44 AM
jhibbits retitled this revision from to Add Position-independent Code model Module API..
jhibbits updated this object.
jhibbits edited the test plan for this revision. (Show Details)
jhibbits added a reviewer: echristo.
jhibbits set the repository for this revision to rL LLVM.
jhibbits added a subscriber: Unknown Object (MLST).

This should probably include a test showing what llvm-link does when merging these.

tools/llc/llc.cpp
290

Is it intentional that any pre-existing metadata is always discarded?

In D5882#5, @rafael wrote:

This should probably include a test showing what llvm-link does when merging these.

Thanks for the review. I'm updating the patch now, to also fix bugs I found (such as an error being thrown if I specify the command line, as well as the module flag, even if I change it to ModFlagBehavior::Override)

tools/llc/llc.cpp
290

The intent is to allow you to override the module flag with the command line (-pic-level=small/large). So, really, this should have a check for if PLLevel != PICLevel::Default.

jhibbits updated this revision to Diff 15448.Oct 24 2014, 8:35 PM
jhibbits edited the test plan for this revision. (Show Details)

Update the patch to address Rafael's comments. Add some tests.

rafael added inline comments.Oct 26 2014, 7:10 PM
test/Linker/module-flags-pic-1-a.ll
1 ↗(On Diff #15448)

This test has no CHECK line. You also need to pass %s to FileCheck

test/Linker/module-flags-pic-1-b.ll
1 ↗(On Diff #15448)

Please put this in test/Linker/Inputs. That way you don't need the dummy RUN line.

test/Linker/module-flags-pic-2-a.ll
2 ↗(On Diff #15448)

Why XFAIL?

I'll upload a new diff this evening. Thanks!

test/Linker/module-flags-pic-1-a.ll
1 ↗(On Diff #15448)

Oops, wonder how this even passed the test run.

test/Linker/module-flags-pic-1-b.ll
1 ↗(On Diff #15448)

That definitely will make it cleaner.

test/Linker/module-flags-pic-2-a.ll
2 ↗(On Diff #15448)

This test is intended to fail (test merging two different values for !flag_pic). Is there a better way to do this?


rafael wrote:

Why XFAIL?

This test is intended to fail (test merging two different values for !flag_pic). Is there a better way to do this?

Yes, use the not utility (RUN: not llvm-link...). It is probably a
good idea to FileCheck for whatever error message we print.

Cheers,
Rafael

jhibbits updated this revision to Diff 15516.Oct 27 2014, 8:43 PM

Address Rafael's comments, updating the tests.

I think this is fine. We can always change the error to an merge logic in the future if needed. Eric, what do you think?

test/Linker/module-flags-pic-2-a.ll
10 ↗(On Diff #15516)

I think I fixed the "EROR: WARNING" in another patch. This should be just ERROR now.

jhibbits updated this object.Nov 4 2014, 11:10 AM
echristo edited edge metadata.Nov 4 2014, 12:00 PM

One comment inline.

lib/IR/Module.cpp
472

One bike shed: "PIC Level" perhaps? since it's not just -fpic, but also -fPIC?

jhibbits added inline comments.Nov 4 2014, 12:30 PM
lib/IR/Module.cpp
472

Works for me.

jhibbits updated this revision to Diff 15807.Nov 5 2014, 7:20 AM
jhibbits updated this object.
jhibbits edited the test plan for this revision. (Show Details)
jhibbits edited edge metadata.

Rename 'flag_pic' to 'PIC Level'

rafael accepted this revision.Nov 5 2014, 7:31 AM
rafael added a reviewer: rafael.

LGTM

This revision is now accepted and ready to land.Nov 5 2014, 7:31 AM
echristo accepted this revision.Nov 5 2014, 10:00 AM
echristo edited edge metadata.

LGTM.

jhibbits closed this revision.Nov 6 2014, 8:57 PM
jhibbits updated this revision to Diff 15909.

Closed by commit rL221510 (authored by @jhibbits).