This is an archive of the discontinued LLVM Phabricator instance.

[mips] Add support for .option pic2.
AbandonedPublic

Authored by matheusalmeida on Mar 11 2014, 10:06 AM.

Details

Reviewers
jacksprat
Summary

[mips] Add support for .option pic2.

Diff Detail

Event Timeline

jacksprat accepted this revision.Mar 11 2014, 11:22 AM

LGTM

lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
306

In the world we live in now, CPIC means that the object observes PIC calling conventions so it can communicate with PIC dsos. PIC means the code is truly position independent.

Comment inline.

lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
306

Yes, that's is also my understanding.

Note however that the SysV ABI states that:

"EF_MIPS_CPIC This bit is asserted when the file contains code
that follows standard calling sequence rules for
calling position-independent code. The code in
this file is not necessarily position independent.
The EF_MIPS_PIC and EF_MIPS_CPIC flags
must be mutually exclusive"

And this is not happening...
.abicalls and .pic2 are equivalent (in GAS which means we have to replicate in LLVM) and they both set the EF_MIPS_PIC and EF_MIPS_CPIC bits. The only way to only set the EF_MIPS_CPIC bit is by doing:
.abicalls
.option pic0

Matheus,

I am tainted. At MIPS/SGI the 2 were incompatible. GCC decided to go another way for whatever reason and we (MIPS) have to live with it. It is good/necessary to note the discrepancy, but it is not a fixme.

CPIC is our default mode, at least on LLVM. Thus, it does not need to be explicitly stated in a directive. That said, if GCC sets CPIC when you set PIC then go for it. But you will need a way to have non-PIC code marked in the ehdr flags for CPIC.

I say this with so much confidence, but after the Rafael wars, I don't know what to think. I ended up getting the directive vs. commandline wrong when it came to ISA and EISA markings of the ehdr flags. Only the commandline and defaults can mark them. I believe this is also an GCC ism, but it may be older.

Jack

"CPIC is our default mode, at least on LLVM. Thus, it does not need to be explicitly stated in a directive. That said, if GCC sets CPIC when you set PIC then go for it. But you will need a way to have non-PIC code marked in the ehdr flags for CPIC."

The way to achieve that in GCC and LLVM using assembly directives is by having:
.abicalls.
.option pic0

(because .abicalls set PIC and CPIC ehdr bits...).

The command-line option in the GCC world is -call_nonpic or similar (-non_pic ?).

And thus my abi wiki declaration ;-)

Follow what you see in gcc/gas and if possible state you findings to binutils@sourceware.org. If you are not a member of that list, become one. Once you have the behavior accepted by the binutils folks and reality, document that information at a minimum to our wiki.

You will be da man!

Oh yeah, it would be nice to point to what CPIC really means in calling conventions, but that is for extra credit. Our ABI wiki was suppose to have pages for the various calling conventions too.

Jack

matheusalmeida abandoned this revision.Apr 4 2014, 6:22 AM