All of lore.kernel.org
 help / color / mirror / Atom feed
From: J. William Campbell <jwilliamcampbell@comcast.net>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] Changing u-boot relocation scheme
Date: Sat, 26 Jul 2008 17:15:43 -0700	[thread overview]
Message-ID: <488BBE2F.90506@comcast.net> (raw)
In-Reply-To: <20080726235818.3aee9d34@siona.local>

Haavard Skinnemoen wrote:
> On Sat, 26 Jul 2008 14:29:35 -0700
> "J. William Campbell" <jwilliamcampbell@comcast.net> wrote:
>   
>> Haavard Skinnemoen wrote:
>>     
>>> On Fri, 25 Jul 2008 22:51:09 +0200
>>> kenneth johansson <kenneth@southpole.se> wrote:    
>>>       
>>>> Can't see any reason for using this flag over -fPIC for a program like
>>>> u-boot.
>>>>     
>>>>         
>>> You need both. One is a compiler flag, the other is a linker flag. The
>>> linker will probably barf if you try to create a PIC executable from
>>> modules that were not compiled with -fPIC.
>>>   
>>>       
>> No, it won't.
>>     
>
> On some platforms it will. Text relocations are nasty, so some
> platforms (e.g. avr32) just refuse to deal with them. But that's not
> really relevant -- each architecture should decide whether to compile
> with -fPIC or not.
>
>   
>> You just get a module with a lot more relocations to do. I 
>> have verified that all four possible combinations of the compiler -fPIC 
>> and linker -pie work and make sense. FWIW, -fPIC code on IA32 is about 
>> 16% larger than non-PIC code, while on the Blackfin, -fPIC code is about 
>> 2% larger than non-PIC code. This is an average over several large C++ 
>> applications.
>>     
>
> Right...that's counting the whole loadable image or just the .text
> section? Not suprising that a modern architecture like Blackfin likes
> -fPIC a lot better than an old beast like i386 though.
>   
That is the entire loadable image. The percentage will therefore be 
slightly higher as a function of just the .text section. It is pretty 
representative of the effect though. On the "old beast", it is not so good!
>  
>   
>> I agree with this suggestion. This is the only way to ensure a "sane" 
>> environment, because it emulates what the compiler expects to happen. 
>> Looping over all the relocation entries and doing the "right thing" is 
>> architecture specific, but the process is general. The GOT entries can 
>> also be processed this way. Effort spent on this approach will tend to 
>> be more generic than the current PPC specific approach.
>>     
>
> Right...I think the GOT entries already are processed this way, sort of
>   
>>> Ah, of course. The strings are probably read directly from flash.
>>>   
>>>       
>> Maybe not. I have been looking at assembly dumps of short examples on 
>> the IA32 built with -fPIC. It is clear that the method of addressing 
>> static variables and static constants is DIFFERENT from the method used 
>> for global variables. The relationship of the location of the text 
>> segment (executable code), the GOT data, and the static 
>> variables/constants must remain fixed. The location of the entire 
>> program can move, but it must move in one piece. If it does move as one 
>> piece, the lea (load effective address) instructions relative to the GOT 
>> pointer will be relocated to the new address correctly. These references 
>> are based totally on the offset from the point of reference. If the code 
>> is similar on your platform (which I bet it is), then the reference will 
>> not be to the flash but rather the "new" place where the data was 
>> moved..
>>     
>
> Yes, address calculations in the code should be correct, as the whole
> thing was compiled with -fPIC. Data references, however, are usually
> not. The code being discussed here is an array of pointers to strings.
> I'm pretty sure the pointers are still pointing to flash after
> relocation.
>   
You are correct. The contents of initialized pointers are not relocated 
without using the relocation data provided by -pie on the ld script.
>   
>> Global variables, however are referenced indirectly via 32 bit 
>> address pointers in the GOT, and these addresses must be relocated by 
>> the "loader".
>>     
>
> The global variables themselves are accessed through the GOT, yes. But
> the _value_ of a global variable is currently not relocated
> automatically.
>
>   
>> The "loader" also must relocate any initialized pointers, because the 
>> program itself does not. It would be interesting to know how this is 
>> accomplished, via what relocation codes, but it does happen.
>>     
>
> This is what's currently being done manually by adding a fixed offset
> to all the pointers we "know" need to be relocated. When linking with
> -pie, these initialized pointers will get a dynamic relocation entry
> each so that we can replace all these manual fixups by simply iterating
> over the relocations.
>
> To summarize: Address calculations in executable code do not need to
> change since we already compile with -fPIC. Initialized pointers,
> however, are currently handled in a very suboptimal way, and linking
> with -pie might be one piece of the solution to this.
>   
I agree completely. Now we "just" need to add processing the relocation 
data. Also, the relocation vectors differ in contents from platform to 
platform, so a bit of "custom" processing will be needed for each 
architecture.

Bill Campbell
> Haavard
>
>
>   

  reply	other threads:[~2008-07-27  0:15 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-23 17:39 [U-Boot-Users] Changing u-boot relocation scheme vb
2008-07-23 21:46 ` Jerry Van Baren
2008-07-23 22:46   ` vb
2008-07-24  3:18     ` Wolfgang Denk
2008-07-24  6:45       ` vb
2008-07-24  9:58         ` Haavard Skinnemoen
2008-07-24 13:47           ` vb
2008-07-24 12:23         ` Jerry Van Baren
2008-07-24 12:47         ` Kenneth Johansson
2008-07-24 13:50           ` vb
2008-07-24 13:01         ` Wolfgang Denk
2008-07-24 13:17           ` Kenneth Johansson
2008-07-24 16:57             ` Haavard Skinnemoen
2008-07-24 17:12               ` Kenneth Johansson
2008-07-25  9:16                 ` Haavard Skinnemoen
2008-07-24 17:37               ` vb
2008-07-24 18:09                 ` Kenneth Johansson
2008-07-24 18:26                   ` vb
2008-07-24 18:32                     ` Joakim Tjernlund
2008-07-24 18:41                     ` Kenneth Johansson
2008-07-25  4:28                   ` Wolfgang Denk
2008-07-26  5:48                   ` Grant Likely
2008-07-26  7:53                     ` kenneth johansson
2008-07-26 12:48                       ` Grant Likely
2008-07-25  4:28               ` Wolfgang Denk
2008-07-25  9:10                 ` Haavard Skinnemoen
2008-07-25 11:55                   ` kenneth johansson
2008-07-25 12:19                     ` Haavard Skinnemoen
2008-07-25 13:30                       ` Joakim Tjernlund
2008-07-26  5:36                         ` Wolfgang Denk
2008-07-25 14:33                       ` kenneth johansson
2008-07-25 14:51                         ` vb
2008-07-25 15:21                           ` Jerry Van Baren
2008-07-25 18:50                             ` Haavard Skinnemoen
2008-07-25 19:03                               ` Jerry Van Baren
2008-07-26  5:36                               ` Wolfgang Denk
2008-07-26 16:09                                 ` Haavard Skinnemoen
2008-07-26  6:06                               ` Grant Likely
2008-07-26  6:11                                 ` Grant Likely
2008-07-26 12:49                                 ` Wolfgang Denk
2008-07-26  5:36                           ` Wolfgang Denk
2008-07-26  5:51                             ` vb
2008-07-25 15:23                         ` Haavard Skinnemoen
2008-07-25 16:31                           ` kenneth johansson
2008-07-25 17:02                             ` Jerry Van Baren
2008-07-25 17:28                               ` kenneth johansson
2008-07-25 18:35                                 ` Haavard Skinnemoen
2008-07-25 19:57                                   ` J. William Campbell
2008-07-25 20:51                                   ` kenneth johansson
2008-07-26 15:54                                     ` Haavard Skinnemoen
2008-07-26 21:29                                       ` J. William Campbell
2008-07-26 21:58                                         ` Haavard Skinnemoen
2008-07-27  0:15                                           ` J. William Campbell [this message]
2008-07-26  5:36                                 ` Wolfgang Denk
2008-07-26  7:41                                   ` kenneth johansson
2008-07-26 12:49                                     ` Wolfgang Denk
2008-07-26  5:57                                 ` Grant Likely
2008-07-26 14:03                                   ` Jean-Christophe PLAGNIOL-VILLARD
2008-07-26 14:29                                     ` Joakim Tjernlund
2008-07-25 16:48                           ` J. William Campbell
2008-07-25  4:28             ` Wolfgang Denk
2008-07-24 13:45         ` Jon Loeliger
2008-07-24 13:52           ` vb
2008-07-26  5:43         ` Grant Likely
2008-07-26  5:54           ` vb
2008-07-26  6:20             ` Grant Likely
2008-07-24  3:18 ` Wolfgang Denk
2008-07-24  6:20 ` Robert Schwebel
2008-09-15 14:56 ` [U-Boot] " vb

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=488BBE2F.90506@comcast.net \
    --to=jwilliamcampbell@comcast.net \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.