mirror_edk2/BaseTools/Source/C
Zenith432 ecbaa856da BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw
Adds support for the following X64 ELF relocations to GenFw
  R_X86_64_GOTPCREL
  R_X86_64_GOTPCRELX
  R_X86_64_REX_GOTPCRELX

Background:
The GCC49 and GCC5 toolchains use the small pie model for X64.  In the
small pie model, gcc emits a GOTPCREL relocation whenever C code takes
the address of a global function.  The emission of GOTPCREL is mitigated
by several factors
1. In GCC49, all global symbols are declared hidden thereby eliminating
the emission of GOTPCREL.
2. In GCC5, LTO is used.  In LTO, the complier first creates intermediate
representation (IR) files.  During the static link stage, the LTO compiler
combines all IR files as a single compilation unit, using linker symbol
assistance to generate code.  Any global symbols defined in the IR that
are not referenced from outside the IR are converted to local symbols -
thereby eliminating the emission of GOTPCREL for them.
3. The linker (binutils ld) further transforms any GOTPCREL used with
the movq opcode to a direct rip-relative relocation used with the leaq
opcode.  This linker optimization can be disabled with the option
-Wl,--no-relax.  Furthermore, gcc is able to emit GOTPCREL with other
opcodes
  - pushq opcode for passing arguments to functions.
  - addq/subq opcodes for pointer arithmetic.
These other opcode uses are not transformed by the linker.
Ultimately, in GCC5 there are some emissions of GOTPCREL that survive
all these mitigations - if C code takes the address of a global function
defined in assembly code - and performs pointer arithmetic on the
address - then the GOTPCREL remains in the final linker product.
A GOTPCREL relocation today causes the build to stop since GenFw does
not handle them.  It is possible to eliminate any remaining GOTPCREL
emissions by manually declaring the global symbols causing them to have
hidden visibility.  This patch is offered instead to allow GenFw to
handle any residual GOTPCREL.

Cc: Shi Steven <steven.shi@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zenith432 <zenith432@users.sourceforge.net>
Reviewed-by: Liming Gao <liming.gao@intel.com>
2018-07-11 16:22:08 +08:00
..
BootSectImage BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
BrotliCompress BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
Common BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
DevicePath BaseTools: Fix byte orders when handling 8-byte array 2018-03-03 15:41:16 +08:00
EfiLdrImage BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
EfiRom BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenBootSector BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenCrc32 BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenFfs BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenFv BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenFw BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw 2018-07-11 16:22:08 +08:00
GenPage BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenSec BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GenVtf BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GnuGenBootSector BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
Include BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
LzmaCompress BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
Makefiles BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
PyEfiCompressor BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
PyUtility BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
Split BaseTools GNUmakefile: Remove HOST_ARCH in every tool Makefile 2018-02-06 13:44:42 +08:00
TianoCompress BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
VfrCompile BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
VolInfo BaseTools: Clean up source files 2018-07-09 10:25:47 +08:00
GNUmakefile BaseTools: Add DevicePath support for PCD values 2017-12-31 13:10:49 +08:00
Makefile BaseTools: Add DevicePath support for PCD values 2017-12-31 13:10:49 +08:00