[LLVMdev] Typo in IsLegalToCallImmediateAddr?

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Fri Jul 1 23:54:22 PDT 2011


On 2011-07-01 17:13, David Meyer wrote:
> It seems that the || should be && here?
> 
> /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
> /// to immediate address.
> bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
>   if (Is64Bit)
>     return false;
>   return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
> }
> 
> For example, if you are doing ELF PIC (i.e. for a shared library), it
> is not valid to use a call immediate.

I think that on 32 bits it is legal, just not profitable.

I tried compiling two .c files without -fPIC:

---------------
int g(void) {
        return 42;
}
--------------
int g(void);
int f(void) {
        return g();
}
-------------

When they get combined into a .so, the code of f has:

452:   e9 fc ff ff ff          jmp    453 <f+0x7>

and readelf shows

00000453  00000802 R_386_PC32        00000458   g

so the dynamic linker will patch the code segment (making it non sharable)

So maybe the problem is that this function is being called in a place
that really wants a "IsProfitableToCallImmediateAddr"?

> - David

Cheers,
Rafael



More information about the llvm-dev mailing list