Currently, the medium code model for x86_64 emits position-dependent relocations (R_X86_64_64) for local functions, regardless of PIC or no-PIC mode. (This means generically that code compiled with the medium model cannot be linked into a position-independent executable.)
Example:
static int g(int n) { return 2 * n + 3; } void f(int(**p)(int)) { *p = g; }
This results in:
Disassembly of section .text: 0000000000000000 <f>: 0: 48 b8 00 00 00 00 00 00 00 00 movabs rax, 0x0 a: 48 89 07 mov qword ptr [rdi], rax d: c3 ret
Relocation section '.rela.text' at offset 0xf0 contains 1 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000000002 0000000200000001 R_X86_64_64 0000000000000000 .text + 10
This patch changes the behaviour to unconditionally emit a RIP-relative access, both in PIC and non-PIC mode. This fixes PIC mode, and is perhaps an improvement in non-PIC mode, too, since it results in a shorter instruction. A 32-bit relocation should suffice since the medium memory model demands that all code fit within 2GiB.
Delete this blank line.