grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ijc@hellion.org.uk>
To: Francesco Lavra <francescolavra.fl@gmail.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	Vladimir Serbinenko <phcoder@gmail.com>
Subject: Re: [PATCH 6/7] mkimage: support images which require full relocation at mkimage time.
Date: Tue, 31 Dec 2013 16:44:32 +0000	[thread overview]
Message-ID: <1388508272.22802.21.camel@hastur.hellion.org.uk> (raw)
In-Reply-To: <52C2D262.9050202@gmail.com>

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
> 




  reply	other threads:[~2013-12-31 16:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-29 18:47 [PATCH 0/7] arm-uboot: support for different RAM bases Ian Campbell
2013-12-29 18:47 ` [PATCH 1/7] mkimage: Refactor IMAGE_EFI checks into a function grub_image_needs_reloc Ian Campbell
2013-12-29 18:47 ` [PATCH 2/7] mkimage: Replace hardcoded 0x400 in R_ARM_ABS32 relocation Ian Campbell
2013-12-29 18:47 ` [PATCH 3/7] mkimage: account for space for trampolines earlier Ian Campbell
2013-12-29 18:47 ` [PATCH 4/7] mkimage: make R_ARM_ABS32 debug output more consistent Ian Campbell
2013-12-29 18:47 ` [PATCH 5/7] mkimage: allow linking at address 0 Ian Campbell
2013-12-29 18:47 ` [PATCH 6/7] mkimage: support images which require full relocation at mkimage time Ian Campbell
2013-12-29 22:53   ` Leif Lindholm
2013-12-30  3:49     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-30 10:54     ` Ian Campbell
2013-12-30 15:46   ` Andrey Borzenkov
2013-12-31 14:19   ` Francesco Lavra
2013-12-31 16:44     ` Ian Campbell [this message]
2013-12-29 18:47 ` [PATCH 7/7] arm-uboot: support relocation at installation time Ian Campbell
2013-12-29 19:10 ` [PATCH 0/7] arm-uboot: support for different RAM bases Ian Campbell
2013-12-29 23:04 ` Leif Lindholm
2013-12-30  1:55 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-30 10:48   ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1388508272.22802.21.camel@hastur.hellion.org.uk \
    --to=ijc@hellion.org.uk \
    --cc=francescolavra.fl@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=leif.lindholm@linaro.org \
    --cc=phcoder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).