1 /* ppc-darwin-mkrospace.c - write a .o which makes sure we get our desired address range */
5 #include <mach-o/loader.h>
13 struct simple_object_file
15 struct mach_header theheader;
16 struct segment_command thesegment;
17 struct section thesection;
20 int main(int argc, char** argv)
22 struct simple_object_file *theobj;
24 theobj = (struct simple_object_file*) malloc(sizeof(struct simple_object_file));
25 theobj->theheader.magic = MH_MAGIC;
26 theobj->theheader.cputype = CPU_TYPE_POWERPC;
27 theobj->theheader.cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
28 theobj->theheader.filetype = MH_OBJECT;
29 theobj->theheader.ncmds = 1;
30 theobj->theheader.sizeofcmds = sizeof(struct segment_command) + sizeof(struct section);
31 theobj->theheader.flags = MH_NOUNDEFS;
32 theobj->thesegment.cmd = LC_SEGMENT;
33 theobj->thesegment.cmdsize = sizeof(struct segment_command) + sizeof(struct section);
34 memcpy(theobj->thesegment.segname, "", sizeof(char));
35 theobj->thesegment.fileoff = sizeof(struct mach_header);
36 theobj->thesegment.vmaddr = READ_ONLY_SPACE_START;
37 theobj->thesegment.vmsize = READ_ONLY_SPACE_END - READ_ONLY_SPACE_START;
38 theobj->thesegment.maxprot = VM_PROT_ALL;
39 theobj->thesegment.initprot = VM_PROT_ALL;
40 theobj->thesegment.nsects = 1;
41 theobj->thesegment.flags = 0;
42 memcpy(theobj->thesection.sectname, "core", 5);
43 memcpy(theobj->thesection.segname, "SBCLRO", 7);
44 theobj->thesection.addr = READ_ONLY_SPACE_START;
45 theobj->thesection.size = READ_ONLY_SPACE_END - READ_ONLY_SPACE_START;
46 theobj->thesection.offset = sizeof(struct mach_header) + sizeof(struct segment_command) + sizeof(struct section);
47 theobj->thesection.align = 0;
48 theobj->thesection.reloff = 0;
49 theobj->thesection.nreloc = 0;
50 theobj->thesection.flags = S_ZEROFILL | S_REGULAR | S_ATTR_SOME_INSTRUCTIONS;
51 theobj->thesection.reserved1 = 0;
52 theobj->thesection.reserved2 = 0;
53 fd = open("ppc-darwin-rospace.o", O_WRONLY | O_CREAT, 0644);
54 write(fd, theobj, sizeof(struct simple_object_file));
56 printf("-Wl,-segaddr,SBCLRO,0x%x\n",READ_ONLY_SPACE_START);