public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
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 <ard.biesheuvel@linaro.org>
Subject: [PATCH v5 7/8] MdePkg GCC/X64: avoid 'hidden' visibility for module entry points
Date: Mon,  1 Aug 2016 10:01:36 +0200	[thread overview]
Message-ID: <1470038497-2536-8-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1470038497-2536-1-git-send-email-ard.biesheuvel@linaro.org>

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 <ard.biesheuvel@linaro.org>
---
 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



  parent reply	other threads:[~2016-08-01  8:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-01  8:01 [PATCH v5 0/8] BaseTools: add support for GCC5 in LTO mode Ard Biesheuvel
2016-08-01  8:01 ` [PATCH v5 1/8] BaseTools CLANG35: drop problematic use-movt and save-temps options Ard Biesheuvel
2016-08-01  8:01 ` [PATCH v5 2/8] ArmVirtPkg/ArmVirtPrePiUniCoreRelocatable: ignore .hash and .note sections Ard Biesheuvel
2016-08-01  8:01 ` [PATCH v5 3/8] BaseTools UNIXGCC ELFGCC CYGGCC: clone GCC build rule family into GCCLD Ard Biesheuvel
2016-08-01  8:01 ` [PATCH v5 4/8] BaseTools GCC: use 'gcc' as the linker command for GCC44 and later Ard Biesheuvel
2016-08-01  8:01 ` [PATCH v5 5/8] ArmPkg: add prebuilt glue binaries for GCC5 LTO support Ard Biesheuvel
2016-08-02  8:50   ` Leif Lindholm
2016-08-01  8:01 ` [PATCH v5 6/8] BaseTools GCC: drop GNU notes section from EFI image Ard Biesheuvel
2016-08-01  8:01 ` Ard Biesheuvel [this message]
2016-08-01 14:18   ` [PATCH v5 7/8] MdePkg GCC/X64: avoid 'hidden' visibility for module entry points Gao, Liming
2016-08-01 14:49     ` Ard Biesheuvel
2016-08-01 14:56       ` Ard Biesheuvel
2016-08-01 15:51         ` Ard Biesheuvel
2016-08-01 16:11           ` Ard Biesheuvel
2016-08-02  2:39             ` Gao, Liming
2016-08-02  5:26               ` Gao, Liming
2016-08-01  8:01 ` [PATCH v5 8/8] BaseTools GCC: introduce GCC5 toolchain to support GCC v5.x in LTO mode Ard Biesheuvel
2016-08-01 14:01 ` [PATCH v5 0/8] BaseTools: add support for GCC5 " Shi, Steven
2016-08-01 14:04   ` Ard Biesheuvel
2016-08-02  9:03 ` Ard Biesheuvel
2016-08-02 10:57   ` Laszlo Ersek
2016-08-02 11:13     ` Ard Biesheuvel
2016-08-02 11:41   ` Shi, Steven
2016-08-02 11:42     ` Ard Biesheuvel
2016-08-02 13:55       ` Michael Zimmermann
2016-08-02 13:56         ` Ard Biesheuvel
2016-08-02 14:39           ` Michael Zimmermann
2016-08-02 14:46             ` Michael Zimmermann
2016-08-02 14:51               ` Michael Zimmermann
2016-08-02 14:47             ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470038497-2536-8-git-send-email-ard.biesheuvel@linaro.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox