This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: pseudo-relocations for pe targets

Hello all,

I did some research about the pseudo-relocation implementation in ld (used 
by cygwin and mingw AFAICS). For w64 there must be a different structure 
to be used, because there are different wide relocation types used (in 
common ip-relative 32-bit and 64-bit, and 64-bit absolute relocations). By 
the current implementation there are several problems I see.
a) Auto-imported variables do not work in all cases (e.g. structure field 
addresses, etc).
b) Each relocation leads to additional code needed.
c) For 64-bit different relocation sizes are possible.
d) If the relocations are placed within custom read-only sections the 
pseudo-relocator produces an assertation by attempting to write to 
read-only addresses.

So I would suggest to extend the structure used for pseudo-relocations by 
two new members that it looks like that
  .long addend
  .long target
  .long fixup_sym
  .long flags

The new fixup_symbol points to the iat entry of the referenced import 
element, or to the stub function.
The flags value has at the moment just the following meaning: Bit 0-7: 
Relocation size in bytes, the bit 8 indicates that an fixup_sym 
dereferencing is necessary (for data elements).

The code in runtimes of the pseudo-relocator would do the following steps:
1) If "addend" is zero and flag:8 is zero continue to the next element 
(nothing to be done).
2) Read the existing relocation as value at "target" as ("rel").
3) Substract from "rel" the "addend" and the "fixup_sym".
4) Read the final destination address from "fixup_sym" as "dst".
5) Add to "dst" the "addend" value.
6) Add to "rel" the "dst"
7) Check for overflow
8) Write "rel" back to "target" by using protect() to make sure that no 
memory exception appears.

This should enable even pe targets to auto-import even variables in all 
cases and speed-up execution, too.

I am interested in your opinion about this and also would like to know, if 
there is for the existing 32-bit targets also an interest to have this 
change, otherwise I will implement it just for the 64-bit case.

 i.A. Kai Tietz

|  (\_/)  This is Bunny. Copy and paste Bunny
| (='.'=) into your signature to help him gain
| (")_(") world domination.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]