From owner-svn-src-head@freebsd.org Fri Oct 7 16:17:52 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 48F59C04F70; Fri, 7 Oct 2016 16:17:52 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0F529252; Fri, 7 Oct 2016 16:17:51 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u97GHpp4005855; Fri, 7 Oct 2016 16:17:51 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u97GHpLf005854; Fri, 7 Oct 2016 16:17:51 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201610071617.u97GHpLf005854@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Fri, 7 Oct 2016 16:17:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306812 - head/sys/boot/common X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2016 16:17:52 -0000 Author: andrew Date: Fri Oct 7 16:17:51 2016 New Revision: 306812 URL: https://svnweb.freebsd.org/changeset/base/306812 Log: 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 Modified: head/sys/boot/common/self_reloc.c Modified: head/sys/boot/common/self_reloc.c ============================================================================== --- head/sys/boot/common/self_reloc.c Fri Oct 7 15:42:20 2016 (r306811) +++ head/sys/boot/common/self_reloc.c Fri Oct 7 16:17:51 2016 (r306812) @@ -108,12 +108,18 @@ self_reloc(Elf_Addr baseaddr, ElfW_Dyn * 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: