On Tue, May 19, 2015 at 12:11 PM, Richard Henderson <r...@redhat.com> wrote: > On 05/19/2015 12:06 PM, H.J. Lu wrote: >> On Tue, May 19, 2015 at 11:59 AM, Richard Henderson <r...@redhat.com> wrote: >>> On 05/19/2015 11:06 AM, Rich Felker wrote: >>>> I'm still mildly worried that concerns for supporting >>>> relaxation might lead to decisions not to optimize code in ways that >>>> would be difficult to relax (e.g. certain types of address load >>>> reordering or hoisting) but I don't understand GCC internals >>>> sufficiently to know if this concern is warranted or not. >>> >>> It is. The relaxation that HJ is working on requires that the reads from >>> the >>> got not be hoisted. I'm not especially convinced that what he's working on >>> is >>> a win. >>> >>> With LTO, the compiler can do the same job that he's attempting in the >>> linker, >>> without an extra nop. Without LTO, leaving it to the linker means that you >>> can't hoist the load and hide the memory latency. >>> >> >> My relax approach won't take away any optimization done by compiler. >> It simply turns indirect branch into direct branch with a nop prefix at >> link-time. I am having a hard time to understand why we shouldn't do it. > > I well understand what you're doing. > > But my point is that the only time the compiler should present you with the > form of indirect branch you're looking for is when there's no place to hoist > the load. > > At which point, is it really worth adding a new relocation to the ABI? Is it > really worth adding new code to the linker that won't be exercised often?
I believe there are plenty of indirect branches via GOT when compiling PIE/PIC with -fno-plt: [hjl@gnu-6 gcc]$ cat /tmp/x.c extern void foo (void); void bar (void) { foo (); } [hjl@gnu-6 gcc]$ ./xgcc -B./ -fPIC -O3 -S /tmp/x.c -fno-plt [hjl@gnu-6 gcc]$ cat x.s .file "x.c" .section .text.unlikely,"ax",@progbits .LCOLDB0: .text .LHOTB0: .p2align 4,,15 .globl bar .type bar, @function bar: .LFB0: .cfi_startproc jmp *foo@GOTPCREL(%rip) .cfi_endproc .LFE0: .size bar, .-bar -- H.J.