implementing PIC for linux x86-64

I have been playing a bit with LLVM again and it looks like the
current major missing feature on Linux x86-64 is PIC.

Is anyone working on it? If not, I would like to do so. I have the ABI
documentation (http://www.x86-64.org/documentation/abi.pdf), but would
be glad if someone had some LLVM specific pointers. For example, from
the targets that do have support for PIC, which one is the one to be
copied? :slight_smile:

Cheers,

Some comments from what I have seen so far:

On linux X86_64, calls to local but externally visible functions
should use the PLT. Access to local (same compilation unit), variables
can just use RIP relative access.

For example

Hello, Rafael

On linux X86_64, calls to local but externally visible functions
should use the PLT. Access to local (same compilation unit), variables
can just use RIP relative access.

Right, this is just optimization. AFAIR, current code already does this
for 'normal' PIC - it just checks for linkage and doesn't assemble call
via PLT for stuff with internal linkage.

Looks like we need a second variable (say PICCallStyle). With it we
would have something like:

This seems to be PIC vs Dynamic-No-PIC relocation style issue, I don't
see, why something new is needed here.

Right, this is just optimization. AFAIR, current code already does this
for 'normal' PIC - it just checks for linkage and doesn't assemble call
via PLT for stuff with internal linkage.

It is not using the PLT even for externally visible ones. Try

; RUN: llvm-as < %s | \
; RUN: llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
; RUN: grep {call f@plt} %t1

define void @g() {
entry:
        call void @f( )
        ret void
}

declare void @f()

Cheers,