From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk0-x242.google.com (mail-vk0-x242.google.com [IPv6:2607:f8b0:400c:c05::242]) (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 4824D219FFEF1 for ; Wed, 24 May 2017 04:15:55 -0700 (PDT) Received: by mail-vk0-x242.google.com with SMTP id x71so9077665vkd.2 for ; Wed, 24 May 2017 04:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=zzOdV7uvthiw8+MFGkdS++aoJvicZ+O1XpydXU+JyUQ=; b=YjB7yfamv81Sb4HGFsiTuzmVytuRKdi8boK3zDbAy8GtQjMW8T9BwdDbrteVyZkuYZ vD1CoBL98AZfw1beCV8gFXvEum+vWU+zZ7p+CfHamFtCMHjH+8Hq63qVBCzyisEnvx1S Iw4PII2XxqTHK0n3SrhbAaX8a5GiWELLI7H00CjpS1LGn1jPk5aHIU0cnW3m3DgzSKxF uTJGvf/TCSt4dn49Z0QVF/aj9ZdiidNf0BxRJB6Xereevu+ZpzS3SAh7kWLPxhNC3jnX eCUyHqnf8hbHaJlBRhGkVd5TqiSc+da5FRE38LWLZCG4NbjXTp8YYgN9+liHDKbszH33 SnJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=zzOdV7uvthiw8+MFGkdS++aoJvicZ+O1XpydXU+JyUQ=; b=kpa+I/0n2TAtKLNFH2rkzRFV1XrWx1sPoAuhZYs1udTpfgVFaQ9uDl2Ua5YCdpAURw aVB8qL5AlVSczMVtdcT04hJ39c7YM6lgL1If1DcgglZ/DPH1rUnwRvbQoE9fnXXF271x D3M/ux08PRrlZEB+KBDtkTeoRzKNzOrmLt/1y5ofcggOCznV5+sHvgtBxwT36cDXeWea IbaBCQMcuct2FBwyXXrVAaVUGaykQExCt9eWAdYNSh5HPGGCidBQjSQUnqeXJ3lMjfPV ze9V7lRTeoRBxMxWJfM/hkKPW73SvXzZuK3+2mR5XYXazVi7ySIfHt1Cwz5JypfeeQvE R51g== X-Gm-Message-State: AODbwcAcU6tejre5eX8Sab+P3oscWGGjNKevTmNDBzgIUZPGLPjcyppn xFY6PCXGwL4BvfM0BiIBCNtKaYjgpw== X-Received: by 10.31.129.144 with SMTP id c138mr14048037vkd.36.1495624553605; Wed, 24 May 2017 04:15:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.159.35.78 with HTTP; Wed, 24 May 2017 04:15:53 -0700 (PDT) In-Reply-To: References: <1494903391-716-1-git-send-email-s.temerkhanov@gmail.com> <1494903391-716-2-git-send-email-s.temerkhanov@gmail.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14D72E8BC@shsmsx102.ccr.corp.intel.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14D733532@shsmsx102.ccr.corp.intel.com> From: Sergei Temerkhanov Date: Wed, 24 May 2017 14:15:53 +0300 Message-ID: To: "Kinney, Michael D" Cc: "Gao, Liming" , Laszlo Ersek , "edk2-devel@lists.01.org" Subject: Re: [PATCH] MdePkg: Fix undefined behavior on variadic parameters 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: Wed, 24 May 2017 11:15:55 -0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 24, 2017 at 5:46 AM, Kinney, Michael D wrote: > Sergey, > > We also need to do a full search for use of variadic parameters to make > sure we have a solution for all of them and update the EDK II C coding > standard to make sure the rules for use of variadic parameters for > maximum compiler compatibility are captured correctly. I've sent another patch for MdePkg with a similar change but there might be more. > > Did you try Andrew Fish's suggestion to add -Wno-varargs to the component= s > that have this issue to see if that is a temporary workaround for your > specific build failures? For my projects, using these 2 changes have been sufficient . > > Thanks, > > Mike > >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of G= ao, Liming >> Sent: Tuesday, May 23, 2017 7:14 PM >> To: 'Laszlo Ersek' ; Sergei Temerkhanov >> Cc: edk2-devel@lists.01.org >> Subject: Re: [edk2] [PATCH] MdePkg: Fix undefined behavior on variadic p= arameters >> >> Sergey: >> This patch updates API interface. I still need to verify its functiona= lity on other >> tool chain. I will give you feedback after I am done. >> >> Thanks >> Liming >> >-----Original Message----- >> >From: Laszlo Ersek [mailto:lersek@redhat.com] >> >Sent: Friday, May 19, 2017 4:16 PM >> >To: Sergei Temerkhanov >> >Cc: Gao, Liming ; edk2-devel@lists.01.org >> >Subject: Re: [edk2] [PATCH] MdePkg: Fix undefined behavior on variadic >> >parameters >> > >> >On 05/19/17 04:45, Sergei Temerkhanov wrote: >> >> On Thu, May 18, 2017 at 1:19 PM, Laszlo Ersek wro= te: >> >>> On 05/16/17 14:10, Sergei Temerkhanov wrote: >> >>>> On Tue, May 16, 2017 at 8:10 AM, Gao, Liming >> >wrote: >> >>>>> Sergey: >> >>>>> Could you give more detail on the undefined behavior on variadic >> >parameters? >> >>>>> >> >>>>> I see https://bugzilla.tianocore.org/show_bug.cgi?id=3D410 descr= ibe this >> >issues found in the latest CLANG tool chain. Do you find other tool cha= in >> >reports it? >> >>>> >> >>>> Yes, this is exactly the bug this patch fixes. >> >>>> >> >>>> As per the C99 standard: >> >>>> "The parameter parmN is the identifier of the rightmost parameter i= n >> >>>> the variable parameter list in the function definition (the one jus= t >> >>>> before the , ...). If the parameter parmN is declared with the >> >>>> register storage class, with a function or array type, or with a ty= pe >> >>>> that is not compatible with the type that results after application= of >> >>>> the default argument promotions, the behavior is undefined." >> >>>> >> >>>> That's exactly the case here since BOOLEAN is a typedef for unsigne= d >> >>>> char. It undergoes a promotion to an unsigned int >> >>> >> >>> Side topic: >> >>> >> >>> It is promoted, but not to "unsigned int". >> >>> >> >>> The standard says, in "6.3.1.1 Boolean, characters, and integers", >> >>> paragraph 2, >> >>> >> >>> The following may be used in an expression wherever an /int/ or >> >>> /unsigned int/ may be used: >> >>> >> >>> =E2=80=94 An object or expression with an integer type whose int= eger >> >>> conversion rank is less than or equal to the rank of /int/ and >> >>> /unsigned int/. >> >>> =E2=80=94 A bit-field of type /_Bool/, /int/, /signed int/, or >> >>> /unsigned int/. >> >>> >> >>> If an /int/ can represent all values of the original type, the v= alue >> >>> is converted to an /int/; otherwise, it is converted to an >> >>> /unsigned int/. These are called the /integer promotions/. [...] >> >>> >> >>> On all supported edk2 platforms, "unsigned char"'s range is 0..255 >> >>> inclusive, which can be represented by "int" (again on all supported >> >>> edk2 platforms). So the promotion occurs to "int", not "unsigned int= " >> >>> >> >>> >> >>> Furthermore, in place of the suggested UINTN type (which is fine), t= he >> >>> following further types would be correct: INT32, UINT32, INT64, UINT= 64, >> >>> INTN. >> >> >> >> On 32-bit architectures, using 64-bit types here may change the ABI. = Which >> >might >> >> affect some corner cases like linking precompiled object files to the >> >> library in question. >> > >> >True. >> > >> >I missed the fact that in edk2 you can have binary-only library >> >instances. I should have remembered, after all I had filed >> > :) >> > >> >So yes, UINTN is the best choice; it keeps binary compat beyond >> >everything else. >> > >> >Thanks! >> >Laszlo >> > >> >> >> >>> The reason is that all of these map to standard C types, on all >> >>> edk2 platforms, whose integer conversion ranks are not less than tha= t of >> >>> "int" and "unsigned int". Hence they are all unaffected by the integ= er >> >>> promotions. >> >>> >> >>> (This digression does not affect your main point, which remains corr= ect; >> >>> I just wanted to be precise here, since we're quoting the standard.) >> >>> >> >>> Thanks >> >>> Laszlo >> >>> >> >>>> which is not a >> >>>> compatible type for unsigned char. Correct me if I'm wrong. >> >>>> >> >>>> Regards, >> >>>> Sergey >> >>>> >> >>>>> >> >>>>> Thanks >> >>>>> Liming >> >>>>>> -----Original Message----- >> >>>>>> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Beha= lf >> >Of Sergey Temerkhanov >> >>>>>> Sent: Tuesday, May 16, 2017 10:57 AM >> >>>>>> To: edk2-devel@lists.01.org >> >>>>>> Subject: [edk2] [PATCH] MdePkg: Fix undefined behavior on variadi= c >> >parameters >> >>>>>> >> >>>>>> Fix undefined behavior by avoiding parameter type promotion >> >>>>>> >> >>>>>> Signed-off-by: Sergey Temerkhanov >> >>>>>> --- >> >>>>>> MdePkg/Include/Library/UefiLib.h | 2 +- >> >>>>>> MdePkg/Library/UefiLib/UefiLib.c | 2 +- >> >>>>>> 2 files changed, 2 insertions(+), 2 deletions(-) >> >>>>>> >> >>>>>> diff --git a/MdePkg/Include/Library/UefiLib.h >> >b/MdePkg/Include/Library/UefiLib.h >> >>>>>> index 0b14792..4e4697c 100644 >> >>>>>> --- a/MdePkg/Include/Library/UefiLib.h >> >>>>>> +++ b/MdePkg/Include/Library/UefiLib.h >> >>>>>> @@ -818,7 +818,7 @@ CHAR8 * >> >>>>>> EFIAPI >> >>>>>> GetBestLanguage ( >> >>>>>> IN CONST CHAR8 *SupportedLanguages, >> >>>>>> - IN BOOLEAN Iso639Language, >> >>>>>> + IN UINTN Iso639Language, >> >>>>>> ... >> >>>>>> ); >> >>>>>> >> >>>>>> diff --git a/MdePkg/Library/UefiLib/UefiLib.c >> >b/MdePkg/Library/UefiLib/UefiLib.c >> >>>>>> index a7eee01..74528ec 100644 >> >>>>>> --- a/MdePkg/Library/UefiLib/UefiLib.c >> >>>>>> +++ b/MdePkg/Library/UefiLib/UefiLib.c >> >>>>>> @@ -1514,7 +1514,7 @@ CHAR8 * >> >>>>>> EFIAPI >> >>>>>> GetBestLanguage ( >> >>>>>> IN CONST CHAR8 *SupportedLanguages, >> >>>>>> - IN BOOLEAN Iso639Language, >> >>>>>> + IN UINTN Iso639Language, >> >>>>>> ... >> >>>>>> ) >> >>>>>> { >> >>>>>> -- >> >>>>>> 2.7.4 >> >>>>>> >> >>>>>> _______________________________________________ >> >>>>>> edk2-devel mailing list >> >>>>>> edk2-devel@lists.01.org >> >>>>>> https://lists.01.org/mailman/listinfo/edk2-devel >> >>>> _______________________________________________ >> >>>> edk2-devel mailing list >> >>>> edk2-devel@lists.01.org >> >>>> https://lists.01.org/mailman/listinfo/edk2-devel >> >>>> >> >>> >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel