]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFw: Add X64 GOTPCREL Support to GenFw
authorZenith432 <zenith432@users.sourceforge.net>
Mon, 9 Jul 2018 12:58:15 +0000 (20:58 +0800)
committerLiming Gao <liming.gao@intel.com>
Wed, 11 Jul 2018 08:22:08 +0000 (16:22 +0800)
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>

No differences found