-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][clang-cl][x86]In Windows 32-bit, the program generated using assembly language cannot run properly. #62010
Comments
The generated assembly is call dword ptr [__imp__MessageBoxW@16] When compiling from the source to binary directly, this is the disassembly: 007d103f ff1510417e00 call dword ptr [test62010+0x14110 (007e4110)] When compiling from the assembly, this is what I got instead: 00b8103f e8cc300100 call test62010_b+0x14110 (00b94110) Looks like LLVM may be doing something odd with Intel asm syntax: https://godbolt.org/z/YWvrn75YG |
https://godbolt.org/z/PP8W9W3W7
_main: # @main
push ebp
mov ebp, esp
sub esp, 16
xor eax, eax
lea eax, ["??_C@_1BI@HHJHKLLN@?$AAh?$AAe?$AAl?$AAl?$AAo?$AA?5?$AAw?$AAo?$AAr?$AAl?$AAd?$AA?$AA@"]
mov dword ptr [esp], 0
mov dword ptr [esp + 4], 0
mov dword ptr [esp + 8], eax
mov dword ptr [esp + 12], 0
call dword ptr [__imp__MessageBoxW@16]
sub esp, 16
xor eax, eax
add esp, 16
pop ebp
ret
"??_C@_1BI@HHJHKLLN@?$AAh?$AAe?$AAl?$AAl?$AAo?$AA?5?$AAw?$AAo?$AAr?$AAl?$AAd?$AA?$AA@":
main: # @main
sub rsp, 40
xor eax, eax
mov edx, eax
lea r8, [rip + "??_C@_1BI@HHJHKLLN@?$AAh?$AAe?$AAl?$AAl?$AAo?$AA?5?$AAw?$AAo?$AAr?$AAl?$AAd?$AA?$AA@"]
xor r9d, r9d
mov rcx, rdx
call qword ptr [rip + __imp_MessageBoxW]
xor eax, eax
add rsp, 40
ret
"??_C@_1BI@HHJHKLLN@?$AAh?$AAe?$AAl?$AAl?$AAo?$AA?5?$AAw?$AAo?$AAr?$AAl?$AAd?$AA?$AA@": 64 will use rip relocation |
the assembly generated by gcc can be compiled and run normally .file "test.cpp"
.intel_syntax noprefix
.text
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "hello world\0"
.align 2
LC1:
.ascii "h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d\0\0\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
LFB516:
.cfi_startproc
lea ecx, [esp+4]
.cfi_def_cfa 1, 0
and esp, -16
push DWORD PTR [ecx-4]
push ebp
.cfi_escape 0x10,0x5,0x2,0x75,0
mov ebp, esp
push ecx
.cfi_escape 0xf,0x3,0x75,0x7c,0x6
sub esp, 20
call ___main
mov DWORD PTR [esp], OFFSET FLAT:LC0
call _printf
mov DWORD PTR [esp+12], 0
mov DWORD PTR [esp+8], OFFSET FLAT:LC1
mov DWORD PTR [esp+4], 0
mov DWORD PTR [esp], 0
mov eax, DWORD PTR __imp__MessageBoxW@16
call eax
sub esp, 16
mov eax, 0
mov ecx, DWORD PTR [ebp-4]
.cfi_def_cfa 1, 0
leave
.cfi_restore 5
lea esp, [ecx-4]
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE516:
.ident "GCC: (i686-win32-dwarf-rev0, Built by MinGW-W64 project) 8.1.0"
.def _printf; .scl 2; .type 32; .endef
|
@llvm/issue-subscribers-backend-x86 |
Clang on Windows targets often requires indirect calls through the import address table (IAT), and also .refptr stubs for MinGW target. On 32-bit this generates assembly in the form of `call dword ptr [__imp__func]`, which MC had failed to handle correctly. 64-bit targets are not affected because rip-relative addressing is used. Reported on: #62010 Depends on D149695, D149920 Differential Revision: https://reviews.llvm.org/D149579
Should be fixed in trunk. |
test.cpp
test32.exe
, it crashes upon callingMessageBoxW
, indicating a failure to properly relocate imported functions. However, the same command runs successfully on the 64-bit version of the program.The text was updated successfully, but these errors were encountered: