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

            Bug ID: 52181
           Summary: Incorrect code generation when using regcall with
                    -fPIC
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

So I have a simple example here for x86 (-m32) where a regular cdecl function
is trying to call a function using the regcall convention.

__attribute__((regcall)) void bar();

void foo()
{
    bar();
}

When this is compiled with -fPIC, the required loading of ebx table offsets by
the caller is incorrectly omitted. 

foo():                                # @foo()
        push    ebp
        mov     ebp, esp
        sub     esp, 8
        call    __regcall3__bar()@PLT
        add     esp, 8
        pop     ebp
        ret

arguments are -m32 -fPIC -target i386-linux-elf, this happens in both C & C++

when the same code is compiled in GCC 13 we get correct code:

foo():
        push    ebp
        mov     ebp, esp
        push    ebx
        sub     esp, 4
        call    __x86.get_pc_thunk.ax
        add     eax, OFFSET FLAT:_GLOBAL_OFFSET_TABLE_
        mov     ebx, eax
        call    bar()@PLT
        nop
        mov     ebx, DWORD PTR -4[ebp]
        leave
        ret
__x86.get_pc_thunk.ax:
        mov     eax, DWORD PTR [esp]
        ret

note the loading of ebx with the offset of the GOT

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to