<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Incorrect code generation when using regcall with -fPIC"
   href="https://bugs.llvm.org/show_bug.cgi?id=52181">52181</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect code generation when using regcall with -fPIC
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jakedelmastro@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>