From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=98.137.64.217; helo=sonic303-36.consmr.mail.gq1.yahoo.com; envelope-from=zenith432@users.sourceforge.net; receiver=edk2-devel@lists.01.org Received: from sonic303-36.consmr.mail.gq1.yahoo.com (sonic303-36.consmr.mail.gq1.yahoo.com [98.137.64.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7FE6F2214E321 for ; Mon, 11 Dec 2017 06:53:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1513004262; bh=LAp3t52HhimfGPQTUPJzYDzMWflKrvxuNB4RhwVeVCU=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=mhHw9GKTOMUvIjJH8kH714O5tWbAttf4YHyBGnZ/BSx6UZSwYjB2a/GjUs7v7WIPM57Op2kFeV+JrG+NsyI7I4wEBaWp3KCGsPR5guAB7b7U5ATdbyDxyeXf0WLQjymMV1+AefVtrNbFyGqjB5N7kvNMZNoWA/P5sHhG32i+Jgwomfx5lH1Cud3UekGSDZRXH/wSfa5rJ0G++ht7rtEDBEFF449UnYGNnZ3rg7uy0T4edL2dg0AFcBLR9anP7A2ixcYGJSpaWjDG9yYe7KqutHiPqCIXVa2ln6JVPIevrM6p0p44Csnr2Ve0PUMbc3u2AFiwpFulkJ0L2l/teneq5w== X-YMail-OSG: Se2977MVM1lMbBRmNDti_fQ4o8vIrVU22Eq.tzkA3XwalpDKGVHzeOGBM6sPUZF MqI4u2vRx2fVU0icZSndJkdnxePZPzR78o65y1hoYbE4h3bG30LMtXMJQyTPXMKT3IYCCTYfWGtP IDk09NWF6U1GPmzo8lRPUjDPpCVeS_01LMtN.80iYr6wdaZo62nVmZ24KMbOcVtcV0mv0FaFmyyZ S3.m.zS0btsLEvUjcAULdLDOoZcM3dJvYuj5Rx5n3gmgoeYc2I70Iahlyx9WU7VHzreftLb3Dmgw 5QrKJHnXGmKn9Db0dx0XTj7oXPMQFczpage.rNrdUHGc.Tn4ib73btHnFhKXOr.cS3Ebef70DV7t 32FVyuFIHAdjL61Nzwzg57aQZ4AV8sf_rVqXpKSZ9scJec3OjxyplUP54PopI1t3R9TQA3M3nI9v 2Lcie5S7t7PX6ccZ5r3jHftjENGukRhDlvR8v0KWGpdEZ5AIs0VNiL5ycVxJAbBCUtH6xClWOwAk yt3uA91dSn2znA38OaZFr3PjFUKF3 Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.gq1.yahoo.com with HTTP; Mon, 11 Dec 2017 14:57:42 +0000 Received: from smtp104.rhel.mail.gq1.yahoo.com (EHLO robicon.homeip.net) ([216.39.57.214]) by smtp404.mail.gq1.yahoo.com (JAMES SMTP Server ) with ESMTPA ID -1701856891; Mon, 11 Dec 2017 14:57:39 +0000 (UTC) To: "Gao, Liming" , "edk2-devel@lists.01.org" Cc: "Kinney, Michael D" References: <1667068483.2112668.1512898346914.ref@mail.yahoo.com> <1667068483.2112668.1512898346914@mail.yahoo.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E18E2A8@SHSMSX104.ccr.corp.intel.com> <2dfbe819-78d5-e328-dd10-9c614e901d05@users.sourceforge.net> <4A89E2EF3DFEDB4C8BFDE51014F606A14E18FDF5@SHSMSX104.ccr.corp.intel.com> From: Zenith432 Message-ID: <101f64da-99b1-a542-bae0-794e4fd1d25b@users.sourceforge.net> Date: Mon, 11 Dec 2017 16:57:35 +0200 User-Agent: Thunderbird/52.5 MIME-Version: 1.0 In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14E18FDF5@SHSMSX104.ccr.corp.intel.com> Subject: Re: [PATCH] MdePkg: correct and clarify documentation of VA_LIST in Base.h X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Dec 2017 14:53:06 -0000 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Yes, that's right, in mixed ABI on GCC 7.2 (which is what GCC5 toolchain in tools_def.sample creates...), VA_COPY when used inside native (non-EFIAPI) function causes incorrect code generation that leads to crash (it mistreats the __builtin_ms_va_list as a __builtin_sysv_va_list). The same source code works in current versions of LLVM and Apple clang - so it's a compiler-specific bug. The text I wrote >> +// -- VA_END, VA_ARG, VA_COPY, va_end, va_arg, and va_copy may be used >> +// in functions of either calling conventions. is the hypothetical desired condition, but it depends on compilers generating proper code in mixed ABI. It obviously does not hold for current GCC. However, the part of the documentation to add EFIAPI to ExampleVarArg should definitely be fixed. Using __builtin_ms_va_list (=VA_LIST) in a sysv_abi (native) function probably yields a compile-time diagnostic, and if not - generates code that crashes for sure. On 11/12/2017 04:35 PM, Gao, Liming wrote: > Hi, > I see you and Laszlo are still in discussion on GCC behavior. Because there is one bug in GCC compiler, the following functions in edk2 must be EFIAPI. Right? > > - functions that have a variable argument list and call VA_START / VA_END > - functions that call VA_COPY > > Thanks > Liming >> -----Original Message----- >> From: Zenith432 [mailto:zenith432@users.sourceforge.net] >> Sent: Sunday, December 10, 2017 11:43 PM >> To: Gao, Liming ; edk2-devel@lists.01.org >> Cc: Kinney, Michael D >> Subject: Re: [PATCH] MdePkg: correct and clarify documentation of VA_LIST in Base.h >> >> On 10/12/2017 03:53 PM, Gao, Liming wrote: >>> Could you add bug 457 link in the commit message? >> --- >> Subject: [PATCH] MdePkg: correct and clarify documentation of VA_LIST in Base.h >> >> This is to resolve bug 457. >> https://bugzilla.tianocore.org/show_bug.cgi?id=457 >> >> Contributed-under: TianoCore Contribution Agreement 1.1 >> Signed-off-by: Zenith432 >> --- >> MdePkg/Include/Base.h | 24 ++++++++++++++++++++---- >> 1 file changed, 20 insertions(+), 4 deletions(-) >> >> diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h >> index 02140a5a..19f36872 100644 >> --- a/MdePkg/Include/Base.h >> +++ b/MdePkg/Include/Base.h >> @@ -560,13 +560,14 @@ struct _LIST_ENTRY { >> // VA_LIST - typedef for argument list. >> // VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use. >> // VA_END (VA_LIST Marker) - Clear Marker >> -// VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argument from >> -// the ... list. You must know the size and pass it in this macro. >> +// VA_ARG (VA_LIST Marker, var arg type) - Use Marker to get an argument from >> +// the ... list. You must know the type and pass it in this macro. >> // VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start. >> // >> -// example: >> +// Example: >> // >> // UINTN >> +// EFIAPI >> // ExampleVarArg ( >> // IN UINTN NumberOfArgs, >> // ... >> @@ -582,7 +583,7 @@ struct _LIST_ENTRY { >> // VA_START (Marker, NumberOfArgs); >> // for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) { >> // // >> -// // The ... list is a series of UINTN values, so average them up. >> +// // The ... list is a series of UINTN values, so sum them up. >> // // >> // Result += VA_ARG (Marker, UINTN); >> // } >> @@ -591,6 +592,21 @@ struct _LIST_ENTRY { >> // return Result >> // } >> // >> +// Notes: >> +// >> +// This set of macros is intended to support variadic functions that >> +// use the EFIAPI calling convention. Variadic functions that use a >> +// native calling convention should use stdarg.h. >> +// In particular: >> +// -- VA_START may only be used in a variadic EFIAPI function. >> +// -- va_start may only be used in a variadic native function. >> +// -- VA_START, VA_END, VA_ARG and VA_COPY may only be used on a VA_LIST. >> +// -- va_start, va_end, va_arg and va_copy may only be used on a va_list. >> +// -- Both VA_LIST or va_list may be passed as arguments to functions >> +// of either EFIAPI or native calling conventions. >> +// -- VA_END, VA_ARG, VA_COPY, va_end, va_arg, and va_copy may be used >> +// in functions of either calling conventions. >> +// >> >> /** >> Return the size of argument that has been aligned to sizeof (UINTN). >> -- >> 2.14.3 >