"-relocation-model=static" does not work in llc compiler ?

Hi LLVM,

When I compile code using llc with options " -relocation-model=static", the generated code still has
relative addressing using *rip* frame pointer. May I know how to get rid of frame pointer and totally
using absolute addressing ?

E.g.
    callq *addr(%rip).
Here *addr* is a global variable, and I want the global address shows up here,
instead of relative addressing.
In this sense, can we say " -relocation-model=static" doesn't work ?

One more thing,
When I compile with O0, O1, the generated code is absolute addressing. like, callq *addr.
but when compiling with O2, O3, the generated code is relative addressing, callq *addr(%rip).

How could I make it always absolute addressing ?

Thanks,

- Pengcheng

Hi Pengcheng,

When I compile code using llc with options " -relocation-model=static", the generated code still has
relative addressing using *rip* frame pointer. May I know how to get rid of frame pointer and totally
using absolute addressing ?

E.g.
    callq *addr(%rip).
Here *addr* is a global variable, and I want the global address shows up here,
instead of relative addressing.
In this sense, can we say " -relocation-model=static" doesn't work ?

I think you may be misinterpreting "static". It doesn't mean "only use
absolute relocations" but rather "you don't *have* to use
position-independent relocations" (as PIC requires to make shared
libraries work).

In this case, the default ("small") code model in x86-64 guarantees
that all code and data will be in the low 2GB of the address space so
it's more efficient for the compiler to use PC-relative addressing
anyway.

If you also give "-code-model=large" then LLVM won't assume that
"addr" is nearby so it'll use a movabsq with a static relocation.

Cheers.

Tim.

If you also give "-code-model=large" then LLVM won't assume that
"addr" is nearby so it'll use a movabsq with a static relocation.

Actually, it seems our own Eli has written rather a good description
of these code models:
http://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models/.

Well worth the read (the default models he talks about at the top are
essentially "static").

Cheers.

Tim.

Yep. I tried it. It used a movabsq instruction instead and a static allocation.
Thanks a lot.

I will read it immediately. Again thanks.

- Pengcheng

Another finding is when I use both -code-model=large and -relocation-model=pic (!!!!!note changed),
it still generate the static relocation. So does it mean -relocation-model=pic does not like to work
with -code-model=large ?

Thanks,
-Pengcheng

I agree it looks like that doesn't work. I'd expect to see some GOT
references in the output, though possibly still technically absolute
relocations (since movabsq is still likely to be the instruction
used).

Strange, I thought I'd seen patches trying to get that combination
working in the JIT recently, but apparently not.

Cheers.

Tim.