[llvm-dev] va_arg on Windows 64

Shi, Steven via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 20 21:07:39 PDT 2016


Both LLVM and GCC have a workaround to support va_list with MS ABI on x64 platform. 

Use
  __builtin_ms_va_list ap;
  __builtin_ms_va_start (ap, n);
  __builtin_ms_va_end (ap);

instead of

  __builtin_va_list ap;
  __builtin_va_start (ap, n);
  __builtin_va_end (ap);

I use above workaround in my Uefi firmware code building, and it works. You can see detail info in below links:
http://lists.llvm.org/pipermail/llvm-dev/2016-January/093778.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50818

CLANG3.8 is better than GCC7.0 on this issue because CLANG3.8 will give a compiler error message like below to explicitly ban the va_list builtins with MS ABI, but GCC has no warning and continue to confuse user.

test.c:15:3: error: 'va_start' used in Win64 ABI function
  va_start (Marker, Format);
  ^


Steven Shi
Intel\SSG\STO\UEFI Firmware


> -----Original Message-----
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Tim
> Northover via llvm-dev
> Sent: Thursday, April 21, 2016 4:56 AM
> To: Gaël Jobin <gael.jobin at switzerlandmail.ch>
> Cc: LLVM Developers Mailing List <llvm-dev at lists.llvm.org>
> Subject: Re: [llvm-dev] va_arg on Windows 64
> 
> Hi Gaël,
> 
> On 20 April 2016 at 13:23, Gaël Jobin via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > Is there some kind of attributes to force function parameters to be
> > aligned contiguously? Or could it be that va_arg alignment is wrongly
> > made using DL.getABITypeAlignment?
> 
> It looks like support for the Windows ABI hasn't really been added to
> LLVM's va_arg instruction at all, so it's falling back to the generic
> implementation in SelectionDAG. To change that, you'll probably want
> to hook into X86TargetLowering::LowerVAARG. You ought to be able to
> override the alignment of 32-bit types there. (Beware, it'll never be
> able to handle the full breadth of C/C++ use-cases, there's a reason
> Clang implements it directly and it's not purely for efficiency).
> 
> Alternatively, you might be able to get away with always doing an i64
> va_arg and truncating the result if you control the front-end and
> don't want to fully expand va_arg.
> 
> Cheers.
> 
> Tim.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list