Re: Inserting new segment and section in mach-o file
Re: Inserting new segment and section in mach-o file
- Subject: Re: Inserting new segment and section in mach-o file
- From: Terry Lambert <email@hidden>
- Date: Wed, 2 Aug 2006 16:09:19 -0700
On Aug 2, 2006, at 4:29 AM, Jonathan Guy wrote:
Hi folks
If I have an existing relocatable mach object file is there a way of
inserting a new segment and section therein. I've looked at
relinking but don't seem to be getting anywhere.
Any help would be great thanks
Open the file, rewrite the Universal header (if necessary), rewrite
the Mach-o header (or more than one, if universal) to add the segment
(s), and then write the segment and section(s) to where you said you
were writing them, using a relative offset in the Mach-o header.
This should work fine for all known section types (for example, if you
wanted another LC_SEGMENT loaded by the kernel), and if there's room
in the first 4K for your extra mach_header data before the first
segment, you won't even have to relocate all the other segments in the
file. That's basically what I did to bring up the kern_exec.c code
for 64 bit programs on G5 for Tiger before there was a 64 bit compiler/
linker available; I just converted the existing binaries file formats.
-
But if you do this for anything other than something already known and
well understood (i.e. you start making up section names or load
command commands)...
o You should expect your binary to break, either immediately, or in
some future release of Mac OS X, if you end up making dyld or the
kernel unhappy by using magic numbers it already knows about, or
starts knowing about later because something, somewhere changes.
o You should also expect your software or someone else's software to
come unglued in various nasty ways, should you happen to pick some
magic numbers that someone else is already using for the stuff they
are adding, just like you, and both of your changes end up on a single
machine.
o You should also potentially expect CrashReporter to come unglued
when it sees your stuff.
My recommendation in that case would be to tell the compiler folks
what you are doing, and if it's not entirely insane, you might get
them to allocate you a load_command "cmd" number or a section
"sectname", and promise that dyld will ignore it. Worst case, asking
never hurts, and you are in no worse position than you were in before.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden