public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos_odonell@mentor.com>
To: Mike Frysinger <vapier@gentoo.org>
Cc: Carlos O'Donell <carlos_odonell@mentor.com>, <libc-ports@sourceware.org>
Subject: Re: [patch] handle unaligned arm abs relocs
Date: Wed, 14 Dec 2011 22:44:00 -0000	[thread overview]
Message-ID: <4EE926AB.30200@mentor.com> (raw)
In-Reply-To: <201112141729.19045.vapier@gentoo.org>

On 12/14/2011 5:29 PM, Mike Frysinger wrote:
> On Wednesday 14 December 2011 17:05:25 Carlos O'Donell wrote:
>> On 12/12/2011 7:20 PM, Mike Frysinger wrote:
>>> background can be found here:
>>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51456
>>>
>>> 2011-12-12  Mike Frysinger  <vapier@gentoo.org>
>>>
>>> 	* dl-machine.h (elf_machine_rel, R_ARM_ABS32): Declare "reloc_value".
>>> 	Replace reloc_addr addition with memcpy's.
>>>
>>> diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
>>> index 5ceeaa9..fe64800 100644
>>> --- a/sysdeps/arm/dl-machine.h
>>> +++ b/sysdeps/arm/dl-machine.h
>>> @@ -413,6 +413,7 @@ elf_machine_rel (struct link_map *map, const
>>>  	  break;
>>>  	case R_ARM_ABS32:
>>>  	  {
>>> +	    Elf32_Addr reloc_value;
>>>  # ifndef RTLD_BOOTSTRAP
>>>  	   /* This is defined in rtld.c, but nowhere in the static
>>>  	      libc.a; make the reference weak so static programs can
>>> @@ -431,7 +432,10 @@ elf_machine_rel (struct link_map *map, const
>>>  		 used while loading those libraries.  */
>>>  	      value -= map->l_addr + refsym->st_value;
>>>  # endif
>>> -	    *reloc_addr += value;
>>> +	    /* Support relocations on mis-aligned offsets.  */
>>> +	    memcpy (&reloc_value, reloc_addr_arg, sizeof (reloc_value));
>>> +	    reloc_value += value;
>>> +	    memcpy (reloc_addr_arg, &reloc_value, sizeof (reloc_value));
>>
>> I don't believe that memcpy is safe this early in the loader.
>>
>> You might be lucky and get an inlined memcpy or builtin, but you
>> might not and if you go through the PLT you'll fault since
>> it's not yet setup.
> 
> i thought it should be OK because R_ARM_COPY already calls memcpy() a few 
> lines up, but i don't know the ARM loader that well to say what is necessary

COPY relocs are only for non-PIC executables accessing data from other
PIC objects. Almost all executables have a COPY reloc against stderr/stdout.

See this for some hand waving:
http://docs.oracle.com/cd/E19082-01/819-0690/chapter4-84604/index.html
 
> looking at the relocs that exist on my local arm ldso and i only see:
> 	R_ARM_RELATIVE
> 	R_ARM_GLOB_DAT
> 	R_ARM_JUMP_SLOT
> 
> hopefully someone who understands ARM better can comment ...

If it works, and you test that it works, then you're fine.

If you use mempcy and it's inlined then that's great, but it's
a possible point of failure when compiling glibc (or eglibc)
with options that don't inline memcpy e.g. -Os.

My warning to you is this: be very very careful calling any
library functions in dl-machine.h.

Cheers
Carlos.
-- 
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos@codesourcery.com
+1 (613) 963 1026

  reply	other threads:[~2011-12-14 22:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-13  0:20 Mike Frysinger
2011-12-14 22:05 ` Carlos O'Donell
2011-12-14 22:29   ` Mike Frysinger
2011-12-14 22:44     ` Carlos O'Donell [this message]
2011-12-15 17:48   ` Richard Henderson
2011-12-19 17:45 ` Joseph S. Myers
2011-12-19 18:27   ` Mike Frysinger
2011-12-19 19:57     ` Joseph S. Myers
2012-08-12  5:50 ` [PATCH v2] arm: handle unaligned ABS relocs Mike Frysinger
2012-08-12 13:01   ` Joseph S. Myers
2012-08-12 14:35     ` Mike Frysinger
2012-08-12 15:55       ` Joseph S. Myers
2012-08-12 18:51         ` Mike Frysinger
2012-08-12 13:26   ` Carlos O'Donell
2012-08-12 14:05     ` Andreas Schwab
2012-08-12 15:57     ` Joseph S. Myers
2012-08-14 21:49   ` Roland McGrath
2012-08-15  1:38     ` Mike Frysinger

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=4EE926AB.30200@mentor.com \
    --to=carlos_odonell@mentor.com \
    --cc=libc-ports@sourceware.org \
    --cc=vapier@gentoo.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).