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. - David
Rafael Ávila de Espíndola
2011-Jul-02 06:54 UTC
[LLVMdev] Typo in IsLegalToCallImmediateAddr?
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"?> - DavidCheers, Rafael
Rafael, I believe your example is not related to IsLegalToCallImmediateAddr. This is an example of calling to an immediate address: typedef int (*funcptr)(void); int main() { funcptr foo = (funcptr)0x100; foo(); } If IsLegalToCallImmedateAddr is true, this generates a call to absolute address 0x100: call 0x100 This requires a relocation of the value 0x100 - PC. (NOTE: this is NOT the same as: "foo: call foo+0x100", which requires no relocation) This can't be done correctly in PIC mode. If you do this in a shared library, the relocation is ignored and you get a jump to module_start + 0x100 instead of absolute 0x100. - pdox