diff mbox series

[edk2,RFC,11/11] MdePkg/ProcessorBind.h X64: drop non-LTO limitation on visiblity override

Message ID 20180612152306.25998-12-ard.biesheuvel@linaro.org
State New
Headers show
Series GCC/X64: use hidden visibility for LTO PIE code | expand

Commit Message

Ard Biesheuvel June 12, 2018, 3:23 p.m. UTC
When LTO is in effect, overriding the symbol visibility to 'hidden'
using a GCC pragma used to result in module entry points being discarded,
and along with them all other code in the binary.

Now that we annotated all module entry points explicitly as having
'default' visibility, this is no longer the case, and we can drop this
restriction. This prevents GCC's LTO code generator from emitting GOT
based relocations that are non-trivial to deal with in GenFw.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 MdePkg/Include/X64/ProcessorBind.h | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

-- 
2.17.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/MdePkg/Include/X64/ProcessorBind.h b/MdePkg/Include/X64/ProcessorBind.h
index 38ef2665390f..7f78489bc2c4 100644
--- a/MdePkg/Include/X64/ProcessorBind.h
+++ b/MdePkg/Include/X64/ProcessorBind.h
@@ -27,18 +27,24 @@ 
 #pragma pack()
 #endif
 
-#if defined(__GNUC__) && defined(__pic__) && !defined(USING_LTO)
+#if defined(__GNUC__) && defined(__pic__)
 //
 // 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.
 //
-// The LTO linker will not emit GOT based relocations when all symbol
-// references can be resolved locally, and so there is no need to set the
-// pragma in that case (and doing so will cause other issues).
-//
 #pragma GCC visibility push (hidden)
+
+//
+// When LTO is in effect, symbols with hidden visibility will get discarded,
+// since by definition, they cannot be referenced externally, even if they
+// are the entry point of the executable. So we will have to change the
+// visibility back to 'default' explicitly for all such entry points.
+//
+#ifdef USING_LTO
+#define EFI_ENTRYPOINT __attribute__((__visibility__("default")))
+#endif
 #endif
 
 #if defined(__INTEL_COMPILER)