[llvm-bugs] [Bug 37598] clang emitting RIP-relative relocation for weak external on Windows x86-64

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 8 14:25:50 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=37598

Reid Kleckner <rnk at google.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Reid Kleckner <rnk at google.com> ---
Fixed for x86 in r360207. I checked AArch64 and it also seems to use
.refptr.sym for extern_weak symbols.

C code:

int __attribute__((weak)) optionalFoo(int x); // { return x; }
int main() {
  if (optionalFoo)
    return optionalFoo(0);
  return 13;
}

relevant asm -O1:

main:                                   ; @main
.seh_proc main
; %bb.0:                                ; %entry
        adrp    x8, .refptr.optionalFoo
        ldr     x8, [x8, .refptr.optionalFoo]
        cbz     x8, .LBB1_2
; %bb.1:                                ; %if.then
        mov     w0, wzr
        b       optionalFoo
.LBB1_2:                                ; %return
        mov     w0, #13
        ret

relevant asm -O0:

main:                                   ; @main
.seh_proc main
; %bb.0:                                ; %entry
        sub     sp, sp, #32             ; =32
        str     x30, [sp, #16]          ; 8-byte Folded Spill
        adrp    x8, .refptr.optionalFoo
        ldr     x8, [x8, .refptr.optionalFoo]
        mov     x9, #0
        cmp     x8, x9
        cset    w10, ne
        str     wzr, [sp, #12]
        tbnz    w10, #0, .LBB1_1
        b       .LBB1_2
.LBB1_1:                                ; %if.then
        mov     w0, #0
        bl      optionalFoo
        str     w0, [sp, #12]
        b       .LBB1_3
.LBB1_2:                                ; %if.end
        mov     w8, #13
        str     w8, [sp, #12]
.LBB1_3:                                ; %return
        ldr     w0, [sp, #12]
        ldr     x30, [sp, #16]          ; 8-byte Folded Reload
        add     sp, sp, #32             ; =32
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190508/774a82e1/attachment.html>


More information about the llvm-bugs mailing list