[cfe-dev] Windows x86_64 ABI issue with va_list
Andrew Fish
afish at apple.com
Fri Apr 29 18:10:36 PDT 2011
I think I'm seeing some Windows ABI code gen issues. My guess is it is related to having the va_start key off an argument that is not in a register. Most of my EFI firmware code runs fine, but the new EFI shell crashes all over the place and prints out lots of garbage. Here is the gist of the print function:
int
ShellPrintHiiEx (
int Col,
int Row,
const char *Language,
const void *HiiFormatStringId,
const void *HiiFormatHandle,
...
)
{
VA_LIST Marker;
int Value;
VA_START (Marker, HiiFormatHandle);
Value = ReturnMarker (Marker);
VA_END(Marker);
return Value;
}
The Windows compiler spills the arguments passed in registers back to the the callers stack frame per the ABI. The clang version spills locally?
_ShellPrintHiiEx: ## @ShellPrintHiiEx
Leh_func_begin1:
## BB#0:
pushq %rbp
Ltmp1:
movq %rsp, %rbp
Ltmp2:
subq $80, %rsp
Ltmp3:
movq 48(%rbp), %rax
movl %ecx, -4(%rbp)
movl %edx, -8(%rbp)
movq %r8, -16(%rbp)
movq %r9, -24(%rbp)
movq %rax, -32(%rbp)
leaq -24(%rbp), %rax
movq %rax, -40(%rbp)
movq %rax, %rcx
callq _ReturnMarker
movl %eax, -44(%rbp)
movq $0, -40(%rbp)
movl -44(%rbp), %eax
addq $80, %rsp
popq %rbp
ret
Also I can't figure out what this code is doing in main()
movl $0, -4(%rbp)
Andrew Fish
clang -ccc-host-triple x86_64-pc-win32-macho -S v.c
cl /FAcs v.c
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.40310.41
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
_DATA SEGMENT
$SG520 DB 'MARKER', 00H
ORG $+1
$SG521 DB 'Handle', 00H
ORG $+1
$SG522 DB 'StringId', 00H
ORG $+3
$SG523 DB 'Lang', 00H
_DATA ENDS
PUBLIC ReturnMarker
; Function compile flags: /Odtp
; File c:\work\loki\toolchain\bin\x64\winddk_amd64\v.c
_TEXT SEGMENT
Marker$ = 8
ReturnMarker PROC NEAR
; 65 : {
00000 48 89 4c 24 08 mov QWORD PTR [rsp+8], rcx
; 66 : return VA_ARG (Marker, int);
00005 48 8b 44 24 08 mov rax, QWORD PTR Marker$[rsp]
0000a 48 83 c0 08 add rax, 8
0000e 48 89 44 24 08 mov QWORD PTR Marker$[rsp], rax
00013 48 8b 44 24 08 mov rax, QWORD PTR Marker$[rsp]
00018 8b 40 f8 mov eax, DWORD PTR [rax-8]
; 67 : }
0001b c3 ret 0
ReturnMarker ENDP
_TEXT ENDS
PUBLIC ShellPrintHiiEx
xdata SEGMENT
$unwind$ShellPrintHiiEx DD 011601H
DD 06216H
xdata ENDS
pdata SEGMENT
$pdata$ShellPrintHiiEx DD @imagerel($LN3#)
DD @imagerel($LN3#+64)
DD @imagerel($unwind$ShellPrintHiiEx#)
; Function compile flags: /Odtp
pdata ENDS
_TEXT SEGMENT
Value$ = 32
Marker$ = 40
Col$ = 64
Row$ = 72
Language$ = 80
HiiFormatStringId$ = 88
HiiFormatHandle$ = 96
ShellPrintHiiEx PROC NEAR
; 78 : {
$LN3:
00030 4c 89 4c 24 20 mov QWORD PTR [rsp+32], r9
00035 4c 89 44 24 18 mov QWORD PTR [rsp+24], r8
0003a 89 54 24 10 mov DWORD PTR [rsp+16], edx
0003e 89 4c 24 08 mov DWORD PTR [rsp+8], ecx
00042 48 83 ec 38 sub rsp, 56 ; 00000038H
; 79 : VA_LIST Marker;
; 80 : int Value;
; 81 :
; 82 : VA_START (Marker, HiiFormatHandle);
00046 48 8d 44 24 68 lea rax, QWORD PTR HiiFormatHandle$[rsp+8]
0004b 48 89 44 24 28 mov QWORD PTR Marker$[rsp], rax
; 83 : Value = ReturnMarker (Marker);
00050 48 8b 4c 24 28 mov rcx, QWORD PTR Marker$[rsp]
00055 e8 00 00 00 00 call ReturnMarker
0005a 89 44 24 20 mov DWORD PTR Value$[rsp], eax
; 84 : VA_END(Marker);
0005e 48 c7 44 24 28
00 00 00 00 mov QWORD PTR Marker$[rsp], 0
; 85 :
; 86 : return Value;
00067 8b 44 24 20 mov eax, DWORD PTR Value$[rsp]
; 87 : }
0006b 48 83 c4 38 add rsp, 56 ; 00000038H
0006f c3 ret 0
ShellPrintHiiEx ENDP
_TEXT ENDS
PUBLIC main
xdata SEGMENT
$unwind$main DD 010401H
DD 08204H
xdata ENDS
pdata SEGMENT
$pdata$main DD @imagerel($LN3#)
DD @imagerel($LN3#+78)
DD @imagerel($unwind$main#)
; Function compile flags: /Odtp
pdata ENDS
_TEXT SEGMENT
main PROC NEAR
; 91 : {
$LN3:
00080 48 83 ec 48 sub rsp, 72 ; 00000048H
; 92 : return ShellPrintHiiEx (1, 2, (void *)"Lang", (void *)"StringId", (void *)"Handle", "MARKER", 7, 8);
00084 c7 44 24 38 08
00 00 00 mov DWORD PTR [rsp+56], 8
0008c c7 44 24 30 07
00 00 00 mov DWORD PTR [rsp+48], 7
00094 48 8d 05 00 00
00 00 lea rax, OFFSET FLAT:$SG520
0009b 48 89 44 24 28 mov QWORD PTR [rsp+40], rax
000a0 48 8d 05 00 00
00 00 lea rax, OFFSET FLAT:$SG521
000a7 48 89 44 24 20 mov QWORD PTR [rsp+32], rax
000ac 4c 8d 0d 00 00
00 00 lea r9, OFFSET FLAT:$SG522
000b3 4c 8d 05 00 00
00 00 lea r8, OFFSET FLAT:$SG523
000ba ba 02 00 00 00 mov edx, 2
000bf b9 01 00 00 00 mov ecx, 1
000c4 e8 00 00 00 00 call ShellPrintHiiEx
; 93 : }
000c9 48 83 c4 48 add rsp, 72 ; 00000048H
000cd c3 ret 0
main ENDP
_TEXT ENDS
END
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110429/e10d6b0b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v.c
Type: application/octet-stream
Size: 3011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110429/e10d6b0b/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110429/e10d6b0b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v.s
Type: application/octet-stream
Size: 5226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110429/e10d6b0b/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110429/e10d6b0b/attachment-0002.html>
More information about the cfe-dev
mailing list