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: Michael Smith <email@hidden>
- Date: Thu, 3 Aug 2006 01:40:04 -0700
On Aug 2, 2006, at 4:29 AM, Jonathan Guy wrote:
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
As far as I'm aware, the -sectcreate option works as documented:
[Cooper:/tmp] msmith% ld -r -o /tmp/test -sectcreate test test /
mach_kernel
ld: warning no object files specified, only command line created
symbols and/or sections created from files will appear in the output
file
[Cooper:/tmp] msmith% ls -l /tmp/test
-rwxr-xr-x 1 msmith wheel 8380020 Aug 3 01:37 /tmp/test
[Cooper:/tmp] msmith% otool -l /tmp/test
/tmp/test:
Load command 0
cmd LC_SEGMENT
cmdsize 124
segname
vmaddr 0x00000000
vmsize 0x007fddc0
fileoff 176
filesize 8379840
maxprot 0x00000007
initprot 0x00000003
nsects 1
flags 0x4
Section
sectname test
segname test
addr 0x00000000
size 0x007fddc0
offset 176
align 2^4 (16)
reloff 0
nreloc 0
flags 0x00000000
reserved1 0
reserved2 0
Load command 1
cmd LC_SYMTAB
cmdsize 24
symoff 8380016
nsyms 0
stroff 8380016
strsize 4
[Cooper:/tmp] msmith% touch test.c
[Cooper:/tmp] msmith% cc -c -o test.o test.c
[Cooper:/tmp] msmith% ld -r -o test.2 test test.o
[Cooper:/tmp] msmith% ls -l test*
-rwxr-xr-x 1 msmith wheel 8380020 Aug 3 01:37 test
-rwxr-xr-x 1 msmith wheel 8380168 Aug 3 01:39 test.2
-rw-r--r-- 1 msmith wheel 0 Aug 3 01:39 test.c
-rw-r--r-- 1 msmith wheel 152 Aug 3 01:39 test.o
[Cooper:/tmp] msmith% otool -l test.2
test.2:
Load command 0
cmd LC_SEGMENT
cmdsize 192
segname
vmaddr 0x00000000
vmsize 0x007fddc0
fileoff 324
filesize 8379840
maxprot 0x00000003
initprot 0x00000003
nsects 2
flags 0x4
Section
sectname test
segname test
addr 0x00000000
size 0x007fddc0
offset 324
align 2^4 (16)
reloff 0
nreloc 0
flags 0x00000000
reserved1 0
reserved2 0
Section
sectname __text
segname __TEXT
addr 0x007fddc0
size 0x00000000
offset 8380164
align 2^0 (1)
reloff 0
nreloc 0
flags 0x80000000
reserved1 0
reserved2 0
Load command 1
cmd LC_SYMTAB
cmdsize 24
symoff 8380164
nsyms 0
stroff 8380164
strsize 4
Load command 2
cmd LC_UNIXTHREAD
cmdsize 80
flavor i386_THREAD_STATE
count i386_THREAD_STATE_COUNT
eax 0x00000000 ebx 0x00000000 ecx 0x00000000 edx
0x00000000
edi 0x00000000 esi 0x00000000 ebp 0x00000000 esp
0x00000000
ss 0x0000001f eflags 0x00000000 eip 0x00000000 cs
0x00000017
ds 0x0000001f es 0x0000001f fs 0x00000000 gs
0x00000000
= Mike
_______________________________________________
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