From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-x232.google.com (mail-ua0-x232.google.com [IPv6:2607:f8b0:400c:c08::232]) (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 B9B7921A16EF8 for ; Wed, 17 May 2017 17:26:41 -0700 (PDT) Received: by mail-ua0-x232.google.com with SMTP id e28so2651495uah.0 for ; Wed, 17 May 2017 17:26:41 -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; bh=EMjpvnTAp8+2HNkBydZ9duhYFqgeOatUCTIieauKquU=; b=tsJmWXeTi45ne6D38vGIH/zQaupwtkTsTytV7agkxqLAcKPNcIxXLtw6j61birwpdw QWFDkggUf287RX3zBO9cydK6+VODbh/35uEtwAo7szLnOcOIpjrvaI2Eq6qSL/RIp6RS AkjuoA/tFo3pyWWcKWGzYKbnk7AX8qKuKH5A8VcfbNsBCtyGyjDlfFRONbVZtaEP+YIO ccvmYwJx3XX2p521F9gex5gFg83VRBj5ylb1+AGCOZ/R0Y/Xpm6f+Ba7ugltMI8KYXtk gRp3o3ByJpeRNXJWgdDlT+NPaDVCPSnfjb38siKR/O5LlnMy40SMyEGhYKGtpGh+GSIL M08Q== 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; bh=EMjpvnTAp8+2HNkBydZ9duhYFqgeOatUCTIieauKquU=; b=eJutiY9scy7jmyzUx6sdY5Donr3kmd1dg4tRvVi0+f6zleHWJvPSJar/5YTrp0u9Av nbA9rJRQhNA0AL37+tQHqjyuX9d15555E67H2nCkW3wmckP60b2ybeiK3dhN1ttXMV9O DiHp8RwOOn/7nNwiy+BJQctetLXir9R77y/+xW/wsOmcydTacLeuEpuOwFNgZYCuCaKL Hv4e1OC+8GmXUg9SNXNsN/hD2GTA8gV81e5n6NBvuCLVApQXEfNppeWNm6G2m3IpqfrV TtxOZA/QINGNKe8wrB8m4oV3T8u5zz5ifyV0Km9zkSlj+inaQHLfUGjwbbQ4qaGRtj/Y 4WKw== X-Gm-Message-State: AODbwcBJuPVApyi2LHEnUr2EH7uk0MeeQ+oWREpIU0L/J3DAFZ0RB93Q F0YUEloMBucapQP5VA8GQLlsY3tmzA== X-Received: by 10.176.76.206 with SMTP id e14mr403139uag.135.1495067200674; Wed, 17 May 2017 17:26:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.159.35.78 with HTTP; Wed, 17 May 2017 17:26:40 -0700 (PDT) In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A14D730154@shsmsx102.ccr.corp.intel.com> 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> <4A89E2EF3DFEDB4C8BFDE51014F606A14D730154@shsmsx102.ccr.corp.intel.com> From: Sergei Temerkhanov Date: Thu, 18 May 2017 03:26:40 +0300 Message-ID: To: "Gao, Liming" Cc: "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: Thu, 18 May 2017 00:26:42 -0000 Content-Type: text/plain; charset="UTF-8" On Wed, May 17, 2017 at 6:30 PM, Gao, Liming wrote: > Sergey: > Now, VS and GCC don't report such issue. How do you find them? Clang build for ARM64 revealed it. > And, this change modifies the function API, does it impact the consumer code? No changes to the consumer code are needed - integer promotions are handled by the compilers. In fact, even the ABI remains the same b/c full words are passed as function parameters. Regards, Sergey > > Thanks > Liming >> -----Original Message----- >> From: Sergei Temerkhanov [mailto:s.temerkhanov@gmail.com] >> Sent: Tuesday, May 16, 2017 8:11 PM >> To: Gao, Liming >> Cc: edk2-devel@lists.01.org >> Subject: Re: [edk2] [PATCH] MdePkg: Fix undefined behavior on variadic parameters >> >> 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=410 describe this issues found in the latest CLANG tool chain. Do you find >> other tool chain 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 in >> the variable parameter list in the function definition (the one just >> before the , ...). If the parameter parmN is declared with the >> register storage class, with a function or array type, or with a type >> 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 unsigned >> char. It undergoes a promotion to an unsigned int 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 Behalf 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 variadic 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