• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Linker is driving me nuts, relocating the start address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linker is driving me nuts, relocating the start address


  • Subject: Linker is driving me nuts, relocating the start address
  • From: Nat! <email@hidden>
  • Date: Sat, 19 Dec 2009 17:28:50 +0100

I have the problem, that for testing purposes I want to place an Objective-C message at a certain place in memory.

Now my plan is, that I link my foundation console project with -seg1addr 0x35203000 and I have another method in front of the method, that contains a lot of dummy code, that I want to shrink or expand to hit the proper address.

+ (int) bogus1:(int) x
{
    x = x * x;
    x = x * x;
    // and hundreds more...
    //    x = x * x;
    return( x);
}

- (id) key
{
   return( _key);
}



It's not working as I hoped it would be, although the -seg1addr in itself works.

The reason being, that the first __text start address changes unpredictably.
Here is an example of a link with _more_ bogus1 code:

Load command 1
      cmd LC_SEGMENT
  cmdsize 396
  segname __TEXT
   vmaddr 0x35203000
   vmsize 0x00002000
  fileoff 0
 filesize 8192
  maxprot 0x00000007
 initprot 0x00000005
   nsects 5
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x35204544
      size 0x000009cd
    offset 5444
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0

and here with less bogus1 code, as you can see the __text address counterintuitively moved down! I would have expected it to stay the same really.

Load command 1
      cmd LC_SEGMENT
  cmdsize 396
  segname __TEXT
   vmaddr 0x35203000
   vmsize 0x00002000
  fileoff 0
 filesize 8192
  maxprot 0x00000007
 initprot 0x00000005
   nsects 5
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x35204684
      size 0x0000089b
    offset 5764
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0

Most of the space between 0x35204684 and 0x35203000 is filled with beautiful nils. So apparently the linker somehow tail aligns the code ?

I then added a method bogus2 behind the -key method, but I still can't nail the exact address. I can come close to one byte offset with nops though.

I need a clue...

Ciao
    Nat!

P.S. If you think this is crazy, see this :) (http://www.mulle-kybernetik.com/weblog/2009/12/my_best_bug_ever.html), the reason I am trying this at all.
------------------------------------------------------
When vanity and rivalry disappear, all the lines go
out of your stomach and you slow down and coast
slowly to a stop in the middle. -- DLR

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Linker is driving me nuts, relocating the start address
      • From: Nat! <email@hidden>
  • Prev by Date: Re: ucontext switch problem
  • Next by Date: Re: Linker is driving me nuts, relocating the start address
  • Previous by thread: Re: OT: scriptually? create custom folder icon
  • Next by thread: Re: Linker is driving me nuts, relocating the start address
  • Index(es):
    • Date
    • Thread