From patchwork Mon Aug 1 14:49:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 73106 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2741223qga; Mon, 1 Aug 2016 07:49:53 -0700 (PDT) X-Received: by 10.67.22.137 with SMTP id hs9mr95987799pad.50.1470062993064; Mon, 01 Aug 2016 07:49:53 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id g192si35471906pfb.119.2016.08.01.07.49.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Aug 2016 07:49:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 547641A1E3C; Mon, 1 Aug 2016 07:49:52 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-io0-x22c.google.com (mail-io0-x22c.google.com [IPv6:2607:f8b0:4001:c06::22c]) (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 DF8AD1A1E12 for ; Mon, 1 Aug 2016 07:49:50 -0700 (PDT) Received: by mail-io0-x22c.google.com with SMTP id q83so185531185iod.1 for ; Mon, 01 Aug 2016 07:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=bhNGlfIwiv+O7P0L6RDm2WYm1Dab6ZeTUWmmCAyi/wI=; b=YXShqN5G1iwUL3gbUkCVPdtLjY53t1JSzN8CZ0c3OqN8zjLiAE+J1dRfRF/v6T66GY WhXNqRHRzXTyemtV+o/cZ3m5bEeoJj/VM+ExxN3XGTrG3cLhYtBOnXCP64kvqX8/cAtc CpbboGZi0wEpAGaMaTJ2GIUHizFL7IeVT6sgw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=bhNGlfIwiv+O7P0L6RDm2WYm1Dab6ZeTUWmmCAyi/wI=; b=AmbfIILNFLiWEGoi4VbbztJOwjmUe+QeZ0ZfpTgzyi6P6kH6Ul5hHvGllf0447do8i 3qCNCnw5O/d8ARAMKKU280ne0HFosL8n+4aPtgt723Vi9fvjYcRp2HNd+dvCnjvvlTvm VTnJWxqPdykplxvkx4ES+wtijiZ/H0b3KKT86NAdeeugAjHYDVXhKjxpUuIaDrxb7lYf W4Bnmr+eMaPpS+lOpyhDSiECHqJvDawgp2x3PKWH//PsVaZk597thvCpb7U4f/cFjGdf RYJNVBLqiqhf7723p09NZBbZdwb8Z3sx7TRTD539x1kouWaHd5nnIrrI3GaOlyXvhIT9 db3A== X-Gm-Message-State: AEkoouu4Ow0UKDVWbh6LrMNREpMZUHLVXUnPUPGU61xhii0Zq98z8ACBetUmtUC3ouHS5LYfbEvevoPkJGydcQLl X-Received: by 10.107.135.22 with SMTP id j22mr64751757iod.56.1470062990225; Mon, 01 Aug 2016 07:49:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.204.195 with HTTP; Mon, 1 Aug 2016 07:49:49 -0700 (PDT) In-Reply-To: <4A89E2EF3DFEDB4C8BFDE51014F606A1155E30DE@shsmsx102.ccr.corp.intel.com> References: <1470038497-2536-1-git-send-email-ard.biesheuvel@linaro.org> <1470038497-2536-8-git-send-email-ard.biesheuvel@linaro.org> <4A89E2EF3DFEDB4C8BFDE51014F606A1155E30DE@shsmsx102.ccr.corp.intel.com> From: Ard Biesheuvel Date: Mon, 1 Aug 2016 16:49:49 +0200 Message-ID: To: "Gao, Liming" Subject: Re: [edk2] [PATCH v5 7/8] MdePkg GCC/X64: avoid 'hidden' visibility for module entry points X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Justen, Jordan L" , "edk2-devel@lists.01.org" , "leif.lindholm@linaro.org" , "lersek@redhat.com" Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" On 1 August 2016 at 16:18, Gao, Liming wrote: > Ard: > I don't think it is good way to define GCC_VISIBILITY_PROTECTED and apply it in EntryPointLib. We only need to expose _ModuleEntryPoint. It has been specified in LINK_FLAGS in tools_def.txt. Could we also specify its attribute in CC_FLAGS or LINK_FLAGS in tools_def.txt? > It seems this does the trick as well Note that * at the end: this is necessary since _ModuleEntryPoint will be called _ModuleEntryPoint.lto_priv.xxx in the LTO objects. I will drop this patch, and add this hunk to GccBase.lds instead. -- Ard. > Thanks > Liming >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of >> Ard Biesheuvel >> Sent: Monday, August 01, 2016 4:02 PM >> To: Shi, Steven ; Zhu, Yonghong >> ; Gao, Liming ; Justen, >> Jordan L ; edk2-devel@lists.01.org >> Cc: lersek@redhat.com; leif.lindholm@linaro.org; Ard Biesheuvel >> >> Subject: [edk2] [PATCH v5 7/8] MdePkg GCC/X64: avoid 'hidden' visibility for >> module entry points >> >> When building with LTO enabled, the LTO routines infer from the 'hidden' >> visibility of the _ModuleEntryPoint symbol that its code only needs to be >> retained if it is referenced internally, and disregards the fact that >> it is referenced by the entry point field in the ELF metadata. >> >> This is arguably a bug in LTO, but we can work around it by ensuring that >> the _ModuleEntryPoint symbol is emitted with protected visibility instead. >> >> Contributed-under: TianoCore Contribution Agreement 1.0 >> Signed-off-by: Ard Biesheuvel >> --- >> MdePkg/Include/X64/ProcessorBind.h | 9 ++++++++- >> MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf | 2 ++ >> MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf | 2 ++ >> MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf | 2 ++ >> MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf | 2 >> ++ >> MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf | 2 ++ >> 6 files changed, 18 insertions(+), 1 deletion(-) >> >> diff --git a/MdePkg/Include/X64/ProcessorBind.h >> b/MdePkg/Include/X64/ProcessorBind.h >> index 666cc8e8bd16..e45b9cba2bb3 100644 >> --- a/MdePkg/Include/X64/ProcessorBind.h >> +++ b/MdePkg/Include/X64/ProcessorBind.h >> @@ -29,13 +29,20 @@ >> >> #if defined(__GNUC__) && defined(__pic__) >> // >> -// Mark all symbol declarations and references as hidden, meaning they will >> +// Mark all symbol declarations and references as hidden*, meaning they >> will >> // not be subject to symbol preemption. This allows the compiler to refer to >> // symbols directly using relative references rather than via the GOT, which >> // contains absolute symbol addresses that are subject to runtime relocation. >> // >> +// * Under LTO, the entry point of a module must have protected or default >> +// visibility to prevent it from being pruned. >> +// >> +#ifdef GCC_VISIBILITY_PROTECTED >> +#pragma GCC visibility push (protected) >> +#else >> #pragma GCC visibility push (hidden) >> #endif >> +#endif >> >> #if defined(__INTEL_COMPILER) >> // >> diff --git a/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf >> b/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf >> index 01f64c34c7a1..2d6f87ed062e 100644 >> --- a/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf >> +++ b/MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf >> @@ -39,3 +39,5 @@ [LibraryClasses] >> BaseLib >> DebugLib >> >> +[BuildOptions] >> + GCC:*_*_X64_CC_FLAGS = -DGCC_VISIBILITY_PROTECTED >> diff --git a/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf >> b/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf >> index d920306713c5..4e61783b3bd5 100644 >> --- a/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf >> +++ b/MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf >> @@ -37,3 +37,5 @@ [LibraryClasses] >> BaseLib >> DebugLib >> >> +[BuildOptions] >> + GCC:*_*_X64_CC_FLAGS = -DGCC_VISIBILITY_PROTECTED >> diff --git a/MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf >> b/MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf >> index a2db9e058bbe..adfd91bdc57e 100644 >> --- a/MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf >> +++ b/MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf >> @@ -37,3 +37,5 @@ [Packages] >> [LibraryClasses] >> DebugLib >> >> +[BuildOptions] >> + GCC:*_*_X64_CC_FLAGS = -DGCC_VISIBILITY_PROTECTED >> diff --git >> a/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf >> b/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf >> index be92b3dc0760..9525c55c2051 100644 >> --- >> a/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf >> +++ >> b/MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf >> @@ -38,3 +38,5 @@ [LibraryClasses] >> DebugLib >> BaseLib >> >> +[BuildOptions] >> + GCC:*_*_X64_CC_FLAGS = -DGCC_VISIBILITY_PROTECTED >> diff --git a/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf >> b/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf >> index 7a9dcbcd4df2..8d30b1197850 100644 >> --- a/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf >> +++ b/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf >> @@ -65,3 +65,5 @@ [Depex.common.UEFI_DRIVER] >> gEfiVariableArchProtocolGuid AND >> gEfiWatchdogTimerArchProtocolGuid >> >> +[BuildOptions] >> + GCC:*_*_X64_CC_FLAGS = -DGCC_VISIBILITY_PROTECTED >> -- >> 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 diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds index 281af8a9bd33..02387d4f8d6f 100644 --- a/BaseTools/Scripts/GccBase.lds +++ b/BaseTools/Scripts/GccBase.lds @@ -80,3 +80,7 @@ SECTIONS { *(COMMON) } } + +VERSION { + { global: _ModuleEntryPoint*; }; +};