From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) (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 6BC2F1A1E36 for ; Mon, 1 Aug 2016 01:02:05 -0700 (PDT) Received: by mail-wm0-x230.google.com with SMTP id o80so231400649wme.1 for ; Mon, 01 Aug 2016 01:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NVjIudhY/P4S4ZbDb0Zy0X48ki/F7S8rxP08Ka+NckU=; b=A2PrG/uVCFwMx4pBbER0cr5SkOxAH9fonV3K9/5I+DnnbGMdJN2wOQhSD6TR53agEp dDLZFhAYHNi/JNYh6OGVCktSHBgwBD+jCEXAdKdr4gTL1yTP+lKj5GrbTl2XH+pZfQsM 1puKoqv7wBIhoBMm1RJDusxoQx/uo8Q1NPx+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NVjIudhY/P4S4ZbDb0Zy0X48ki/F7S8rxP08Ka+NckU=; b=P43w3hXYY/VaUTtbThiqaismKag7wVIE1R5ZUon7tWaOLpl5SvJCzURjPt1JO7XPw5 99Zdpu9Y+Gdpk3kGl6m+3OouSgAaof4d+iXaig9iWX/WECbeQZVEnCcm3BKCcmGymOAJ 3JI7bx3tm+MV8EVtvT0lNeu3IzJgt10pxuqyz3Vti1nwEh8TQpPp3s1VFXeIrSy2rJh3 yMb58AKUoWnda6W+pkxXJt8ZFrZNiY4Mo8B84AmZhUC8vseEw0HFTCUxLVFFoDa7AckU iGnpc51j0YnhVBH67f1rBHjqcSnl6DfpdybAnVOFOEvIwTt5X5xsnrOtpqeIJuMMID7X /wzQ== X-Gm-Message-State: AEkoouvHqY4UsPaRdkOzG+oGvoiG+kSc3C4Ory7CJs2SEQlBlZOQS1/0LaJVMVrDxF4x573v X-Received: by 10.194.35.42 with SMTP id e10mr49472868wjj.107.1470038523973; Mon, 01 Aug 2016 01:02:03 -0700 (PDT) Received: from localhost.localdomain (3.red-81-34-118.dynamicip.rima-tde.net. [81.34.118.3]) by smtp.gmail.com with ESMTPSA id m62sm15671943wmm.24.2016.08.01.01.02.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Aug 2016 01:02:03 -0700 (PDT) From: Ard Biesheuvel To: steven.shi@intel.com, yonghong.zhu@intel.com, liming.gao@intel.com, jordan.l.justen@intel.com, edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, lersek@redhat.com, Ard Biesheuvel Date: Mon, 1 Aug 2016 10:01:36 +0200 Message-Id: <1470038497-2536-8-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470038497-2536-1-git-send-email-ard.biesheuvel@linaro.org> References: <1470038497-2536-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [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: , X-List-Received-Date: Mon, 01 Aug 2016 08:02:05 -0000 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