]> git.proxmox.com Git - mirror_edk2.git/commit
BaseTools/GenFw RVCT: fix relocation processing of PT_DYNAMIC sections
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Mon, 14 Dec 2015 07:56:02 +0000 (07:56 +0000)
committerabiesheuvel <abiesheuvel@Edk2>
Mon, 14 Dec 2015 07:56:02 +0000 (07:56 +0000)
commit088dc2450860a64f58a5c0f2b1623f1c1252c006
tree0d39a897479b97d252b4cdd1d2f4e467bebcdd16
parentb12ef6b964f8fc0532432ebffd67748648487133
BaseTools/GenFw RVCT: fix relocation processing of PT_DYNAMIC sections

Unlike GNU ld, which can be instructed to emit symbol based static
relocations into fully linked binaries using the --emit-relocs command
line switch, the RVCT armlink tool can only emit dynamic relocations
into the PT_DYNAMIC segment.

This has two consequences
. we can only identify absolute relocations, so there is no way to fix
  up relative relocations between sections, or check their validity in
  the PE/COFF layout
. the r_offset fields of the PT_DYNAMIC DT_REL entries are relative
  either to the base of the image or to any of its segments but *not* to
  the base of the input section that contains the location they refer
  to, and converting them to PE/COFF image offsets is non-trivial unless
  the sections are laid out in the same way in the ELF and PE/COFF
  versions of the binary.

There is really only one way to deal with this, and that is to require
that the ELF and PE/COFF versions of the binary are identical in memory.
So enforce that in the code.

Also, fix the utterly broken relocation fixup code that dereferences
ELF32_R_SYM(r_info) both as a 1-based program header index and a 0-based
section header index. If this code ever produced working binaries, it
was purely by chance.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19236 6f19259b-4bc3-4df7-8a09-765794883524
BaseTools/Source/C/GenFw/Elf32Convert.c