From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vy2R2-0003vX-Aw for mharc-grub-devel@gnu.org; Tue, 31 Dec 2013 11:44:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vy2Qt-0003pz-8k for grub-devel@gnu.org; Tue, 31 Dec 2013 11:44:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vy2Ql-0001eJ-RX for grub-devel@gnu.org; Tue, 31 Dec 2013 11:44:43 -0500 Received: from benson.vm.bytemark.co.uk ([212.110.190.137]:58746) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vy2Ql-0001e9-IT for grub-devel@gnu.org; Tue, 31 Dec 2013 11:44:35 -0500 Received: from host86-160-140-160.range86-160.btcentralplus.com ([86.160.140.160] helo=[192.168.1.72]) by benson.vm.bytemark.co.uk with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1Vy2Qj-0000nX-1i; Tue, 31 Dec 2013 16:44:33 +0000 Message-ID: <1388508272.22802.21.camel@hastur.hellion.org.uk> Subject: Re: [PATCH 6/7] mkimage: support images which require full relocation at mkimage time. From: Ian Campbell To: Francesco Lavra Date: Tue, 31 Dec 2013 16:44:32 +0000 In-Reply-To: <52C2D262.9050202@gmail.com> References: <1388342839.32105.25.camel@hastur.hellion.org.uk> <1388342856-18317-6-git-send-email-ijc@hellion.org.uk> <52C2D262.9050202@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4-4+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.110.190.137 Cc: The development of GNU GRUB , Leif Lindholm , Vladimir Serbinenko X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Dec 2013 16:44:50 -0000 On Tue, 2013-12-31 at 15:19 +0100, Francesco Lavra wrote: > On 12/29/2013 07:47 PM, Ian Campbell wrote: > > diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c > > index b4216ff..186d259 100644 > > --- a/util/grub-mkimagexx.c > > +++ b/util/grub-mkimagexx.c > > @@ -378,6 +378,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, > > Elf_Shdr *symtab_section, Elf_Addr *section_addresses, > > Elf_Half section_entsize, Elf_Half num_sections, > > void *jumpers, Elf_Addr jumpers_addr, > > + Elf_Addr bss_addr, size_t bss_size, > > const struct grub_install_image_target_desc *image_target) > > { > > Elf_Word symtab_size, sym_size, num_syms; > > @@ -416,10 +417,14 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections, > > } > > else if (cur_index == STN_UNDEF) > > { > > - if (sym->st_name) > > + if (strcmp (name, "__bss_start") == 0 && bss_addr) > > + sym->st_value = bss_addr; > > + else if (strcmp (name, "_end") == 0 && bss_addr) > > + sym->st_value = bss_addr + bss_size; > > + else if (sym->st_name) > > grub_util_error ("undefined symbol %s", name); > > - else > > - continue; > > + > > + continue; > > } > > else if (cur_index >= num_sections) > > grub_util_error ("section %d does not exist", cur_index); > > @@ -584,7 +589,7 @@ static void > > SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, > > Elf_Addr *section_addresses, > > Elf_Half section_entsize, Elf_Half num_sections, > > - const char *strtab, > > + const char *strtab, grub_uint64_t target_address, > > char *pe_target, Elf_Addr tramp_off, > > Elf_Addr got_off, > > const struct grub_install_image_target_desc *image_target) > > @@ -867,6 +872,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, > > { > > case R_ARM_ABS32: > > { > > + sym_addr += target_address; > > grub_util_info (" ABS32:\ttarget=0x%08lx\toffset=(0x%08x)", > > (unsigned long) ((char *) target > > - (char *) e), > > @@ -928,7 +934,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, > > grub_uint32_t tr_addr; > > grub_int32_t new_offset; > > tr_addr = (char *) tr - (char *) pe_target > > - - target_section_addr; > > + - (target_address - target_section_addr); > > target_section_addr was being subtracted from tr before, now it's being > added; I guess this is not intentional. Hrm, yes, it does look suspicious. Good spot. I added some debug prints to all of this and it came out correct, i.e. with this change tr_addr (which is actually an offset) is 0x9290 and without it tr_addr is 0xb8009290, which is clearly nonsense. The trampolines are placed at 0x9290-0x92a0 (n.b. .bss, which is supposed to be right after the trampolines, is from offset 0x92a0, which matches). I suppose something elsewhere accounts for this offset the other way around and everything comes out in the wash. I'll investigate properly in the new year. The R_ARM_THM_{CALL,JUMP*} case is also unchanged, but I don't actually see any interworking in that direction so that case never triggers, it should certainly be changed to be the same in both cases, whatever that turns out to be. Ian. > > -- > Francesco >