From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VxLP1-000197-Eg for mharc-grub-devel@gnu.org; Sun, 29 Dec 2013 13:47:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxLOu-0000zD-6e for grub-devel@gnu.org; Sun, 29 Dec 2013 13:47:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VxLOo-0008IJ-6I for grub-devel@gnu.org; Sun, 29 Dec 2013 13:47:48 -0500 Received: from benson.vm.bytemark.co.uk ([212.110.190.137]:37724) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VxLOn-0008I7-W4 for grub-devel@gnu.org; Sun, 29 Dec 2013 13:47:42 -0500 Received: from cpc22-cmbg14-2-0-cust482.5-4.cable.virginm.net ([86.6.25.227] helo=hastur.hellion.org.uk) by benson.vm.bytemark.co.uk with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1VxLOm-0000KP-Ev; Sun, 29 Dec 2013 18:47:41 +0000 Received: by hastur.hellion.org.uk (sSMTP sendmail emulation); Sun, 29 Dec 2013 18:47:39 +0000 From: Ian Campbell To: grub-devel@gnu.org Subject: [PATCH 3/7] mkimage: account for space for trampolines earlier Date: Sun, 29 Dec 2013 18:47:32 +0000 Message-Id: <1388342856-18317-3-git-send-email-ijc@hellion.org.uk> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1388342839.32105.25.camel@hastur.hellion.org.uk> References: <1388342839.32105.25.camel@hastur.hellion.org.uk> 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: Vladimir Serbinenko , Leif Lindholm , Ian Campbell 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: Sun, 29 Dec 2013 18:47:54 -0000 In particular we will want to do this before assigning space for .bss, otherwise the trampoline will potentially overlap the start of .bss and might be cleared before it is used. I'm in two minds about whether this is fixing and actual (perhaps latent) bug or not. AFAICT none of the existing targets which need trampolines require a .bss assignment here (e.g. they generate PE images which means the .bss gets taken care of at load time). Apart from duplicating the surrounding if statement this is pure code motion. Signed-off-by: Ian Campbell --- util/grub-mkimagexx.c | 77 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index f5e514f..399ff6a 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -1481,6 +1481,46 @@ SUFFIX (load_image) (const char *kernel_path, size_t *exec_size, exec_size, kernel_sz, align, image_target); + if (grub_image_needs_reloc(image_target)) + { +#ifdef MKIMAGE_ELF32 + if (image_target->elf_target == EM_ARM) + { + grub_size_t tramp; + + *kernel_sz = ALIGN_UP (*kernel_sz, 16); + + tramp = arm_get_trampoline_size (e, sections, section_entsize, + num_sections, image_target); + + tramp_off = *kernel_sz; + *kernel_sz += ALIGN_UP (tramp, 16); + } +#endif + +#ifdef MKIMAGE_ELF64 + if (image_target->elf_target == EM_IA_64) + { + grub_size_t tramp; + + *kernel_sz = ALIGN_UP (*kernel_sz, 16); + + grub_ia64_dl_get_tramp_got_size (e, &tramp, &got); + + tramp_off = *kernel_sz; + *kernel_sz += ALIGN_UP (tramp, 16); + + ia64jmp_off = *kernel_sz; + ia64jmpnum = SUFFIX (count_funcs) (e, symtab_section, + image_target); + *kernel_sz += 16 * ia64jmpnum; + + ia64_got_off = *kernel_sz; + *kernel_sz += ALIGN_UP (got, 16); + } +#endif + } + section_vaddresses = xmalloc (sizeof (*section_addresses) * num_sections); for (i = 0; i < num_sections; i++) @@ -1540,43 +1580,6 @@ SUFFIX (load_image) (const char *kernel_path, size_t *exec_size, break; } -#ifdef MKIMAGE_ELF32 - if (image_target->elf_target == EM_ARM) - { - grub_size_t tramp; - - *kernel_sz = ALIGN_UP (*kernel_sz, 16); - - tramp = arm_get_trampoline_size (e, sections, section_entsize, - num_sections, image_target); - - tramp_off = *kernel_sz; - *kernel_sz += ALIGN_UP (tramp, 16); - } -#endif - -#ifdef MKIMAGE_ELF64 - if (image_target->elf_target == EM_IA_64) - { - grub_size_t tramp; - - *kernel_sz = ALIGN_UP (*kernel_sz, 16); - - grub_ia64_dl_get_tramp_got_size (e, &tramp, &got); - - tramp_off = *kernel_sz; - *kernel_sz += ALIGN_UP (tramp, 16); - - ia64jmp_off = *kernel_sz; - ia64jmpnum = SUFFIX (count_funcs) (e, symtab_section, - image_target); - *kernel_sz += 16 * ia64jmpnum; - - ia64_got_off = *kernel_sz; - *kernel_sz += ALIGN_UP (got, 16); - } -#endif - if (! symtab_section) grub_util_error ("%s", _("no symbol table")); } -- 1.8.4.rc3