The bootloader self relocation code was slightly wrong for the

R_AARCH64_RELATIVE relocation found on arm64. It would try to add the
contents of the memory location being relocated to the base address and
the relocation addend. This worked when the contents was zero, however
this now seems to be set to the value of the addend so we add this twice.
Fix this by just setting the memory to the computed value.

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8177
This commit is contained in:
Andrew Turner 2016-10-07 16:17:51 +00:00
parent 0974f66d06
commit f2af6f7bf1

View file

@ -108,12 +108,18 @@ self_reloc(Elf_Addr baseaddr, ElfW_Dyn *dynamic)
break;
case RELOC_TYPE_RELATIVE:
/* Address relative to the base address. */
newaddr = (Elf_Addr *)(rel->r_offset + baseaddr);
*newaddr += baseaddr;
/* Add the addend when the ABI uses them */
#ifdef ELF_RELA
*newaddr += rel->r_addend;
/*
* For R_AARCH64_RELATIVE we need to calculate the
* delta between the address we are run from and the
* address we are linked at. As the latter is 0 we
* just use the address we are run from for this.
*/
*newaddr = baseaddr + rel->r_addend;
#else
/* Address relative to the base address. */
*newaddr += baseaddr;
#endif
break;
default: