[Nasm-commits] [nasm:macho64] Changes to be committed: (use "git reset HEAD <file>..." to unstage)
nasm-bot for Keith Kanios
keith at kanios.net
Thu Jun 4 19:56:14 PDT 2020
Commit-ID: dce2209cac70932cb082c8171aac6f2ab74a1bb6
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=dce2209cac70932cb082c8171aac6f2ab74a1bb6
Author: Keith Kanios <keith at kanios.net>
AuthorDate: Mon, 8 Sep 2008 19:17:01 -0500
Committer: Keith Kanios <keith at kanios.net>
CommitDate: Mon, 8 Sep 2008 19:17:01 -0500
Changes to be committed: (use "git reset HEAD <file>..." to unstage)
---
output/{outmacho.c => outmacho32.c} | 0
output/{outmacho.c => outmacho64.c} | 399 +++++++++++++++++++++---------------
2 files changed, 231 insertions(+), 168 deletions(-)
diff --git a/output/outmacho.c b/output/outmacho32.c
similarity index 100%
copy from output/outmacho.c
copy to output/outmacho32.c
diff --git a/output/outmacho.c b/output/outmacho64.c
similarity index 80%
rename from output/outmacho.c
rename to output/outmacho64.c
index 5e9ad8e1..79b6a451 100644
--- a/output/outmacho.c
+++ b/output/outmacho64.c
@@ -1,5 +1,5 @@
-/* outmacho.c output routines for the Netwide Assembler to produce
- * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files
+/* outmacho64.c output routines for the Netwide Assembler to produce
+ * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
*
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
* Julian Hall. All rights reserved. The software is
@@ -25,23 +25,23 @@
#include "outform.h"
#include "compiler.h"
-#if defined(OF_MACHO)
+#if defined(OF_MACHO64)
/* Mach-O in-file header structure sizes */
-#define MACHO_HEADER_SIZE (28)
-#define MACHO_SEGCMD_SIZE (56)
-#define MACHO_SECTCMD_SIZE (68)
-#define MACHO_SYMCMD_SIZE (24)
-#define MACHO_NLIST_SIZE (12)
-#define MACHO_RELINFO_SIZE (8)
+#define MACHO_HEADER64_SIZE (32)
+#define MACHO_SEGCMD64_SIZE (72)
+#define MACHO_SECTCMD64_SIZE (80)
+#define MACHO_SYMCMD_SIZE (24)
+#define MACHO_NLIST64_SIZE (16)
+#define MACHO_RELINFO64_SIZE (8)
/* Mach-O file header values */
-#define MH_MAGIC (0xfeedface)
-#define CPU_TYPE_I386 (7) /* x86 platform */
+#define MH_MAGIC_64 (0xfeedfacf)
+#define CPU_TYPE_X86_64 (0x01000007) /* x86-64 platform */
#define CPU_SUBTYPE_I386_ALL (3) /* all-x86 compatible */
#define MH_OBJECT (0x1) /* object file */
-#define LC_SEGMENT (0x1) /* segment load command */
+#define LC_SEGMENT_64 (0x19) /* segment load command */
#define LC_SYMTAB (0x2) /* symbol table load command */
#define VM_PROT_NONE (0x00)
@@ -63,7 +63,7 @@ struct section {
/* data that goes into the file */
char sectname[16]; /* what this section is called */
char segname[16]; /* segment this section will be in */
- uint32_t size; /* in-memory and -file size */
+ uint64_t size; /* in-memory and -file size */
uint32_t nreloc; /* relocation entry count */
uint32_t flags; /* type and attributes (masked) */
};
@@ -80,7 +80,8 @@ struct section {
relocation entries */
#define S_ATTR_LOC_RELOC 0x00000100 /* section has local
relocation entries */
-
+#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section uses pure
+ machine instructions */
static struct sectmap {
const char *nasmsect;
@@ -88,7 +89,7 @@ static struct sectmap {
const char *sectname;
const int32_t flags;
} sectmap[] = {
- {".text", "__TEXT", "__text", S_REGULAR|S_ATTR_SOME_INSTRUCTIONS},
+ {".text", "__TEXT", "__text", S_REGULAR|S_ATTR_SOME_INSTRUCTIONS|S_ATTR_PURE_INSTRUCTIONS},
{".data", "__DATA", "__data", S_REGULAR},
{".rodata", "__DATA", "__const", S_REGULAR},
{".bss", "__DATA", "__bss", S_ZEROFILL},
@@ -101,13 +102,13 @@ struct reloc {
/* data that goes into the file */
int32_t addr; /* op's offset in section */
- unsigned int snum:24, /* contains symbol index if
+ uint32_t snum:24, /* contains symbol index if
** ext otherwise in-file
** section number */
pcrel:1, /* relative relocation */
- length:2, /* 0=byte, 1=word, 2=int32_t */
+ length:2, /* 0=byte, 1=word, 2=int32_t, 3=int64_t */
ext:1, /* external symbol referenced */
- type:4; /* reloc type, 0 for us */
+ type:4; /* reloc type */
};
#define R_ABS 0 /* absolute relocation */
@@ -123,11 +124,11 @@ struct symbol {
int32_t snum; /* true snum for reloc */
/* data that goes into the file */
- int32_t strx; /* string table index */
+ uint32_t strx; /* string table index */
uint8_t type; /* symbol type */
uint8_t sect; /* NO_SECT or section number */
int16_t desc; /* for stab debugging, 0 for us */
- uint32_t value; /* offset of symbol in section */
+ uint64_t value; /* offset of symbol in section */
};
/* symbol type bits */
@@ -185,12 +186,12 @@ extern struct ofmt of_macho;
/* Global file information. This should be cleaned up into either
a structure or as function arguments. */
-uint32_t head_ncmds = 0;
-uint32_t head_sizeofcmds = 0;
-uint32_t seg_filesize = 0;
-uint32_t seg_vmsize = 0;
-uint32_t seg_nsects = 0;
-uint32_t rel_padcnt = 0;
+uint32_t head_ncmds64 = 0;
+uint32_t head_sizeofcmds64 = 0;
+uint64_t seg_filesize64 = 0;
+uint64_t seg_vmsize64 = 0;
+uint32_t seg_nsects64 = 0;
+uint64_t rel_padcnt64 = 0;
#define xstrncpy(xdst, xsrc) \
@@ -204,6 +205,9 @@ uint32_t rel_padcnt = 0;
#define alignint32_t(x) \
align(x, sizeof(int32_t)) /* align x to int32_t boundary */
+#define alignint64_t(x) \
+ align(x, sizeof(int64_t)) /* align x to int64_t boundary */
+
static void debug_reloc (struct reloc *);
static void debug_section_relocs (struct section *) _unused;
@@ -303,11 +307,12 @@ static void macho_init(FILE * fp, efunc errfunc, ldfunc ldef,
{
char zero = 0;
+ maxbits = 64;
machofp = fp;
error = errfunc;
evaluate = eval;
- (void)ldef; /* placate optimisers */
+ (void)ldef; /* placate optimizers */
sects = NULL;
sectstail = §s;
@@ -359,33 +364,62 @@ static void add_reloc(struct section *sect, int32_t section,
** sure we don't make the symbol scattered by setting the highest
** bit by accident */
r->addr = sect->size & ~R_SCATTERED;
- r->ext = 0;
- r->pcrel = pcrel;
-
- /* match byte count 1, 2, 4 to length codes 0, 1, 2 respectively */
- r->length = bytes >> 1;
-
- /* vanilla relocation (GENERIC_RELOC_VANILLA) */
- r->type = 0;
-
- if (section == NO_SEG) {
- /* absolute local symbol if no section index given */
- r->snum = R_ABS;
- } else {
- fi = get_section_fileindex_by_index(section);
-
- if (fi == NO_SECT) {
- /* external symbol if no section with that index known,
- ** symbol number was saved in macho_symdef() */
- r->snum = raa_read(extsyms, section);
- r->ext = 1;
- } else {
- /* local symbol in section fi */
- r->snum = fi;
- }
- }
+ r->ext = 1;
+ r->pcrel = (pcrel ? 1 : 0);
+
+ /* match byte count 1, 2, 4, 8 to length codes 0, 1, 2, 3 respectively */
+ switch(bytes){
+ case 1:
+ r->length = 0;
+ break;
+ case 2:
+ r->length = 1;
+ break;
+ case 4:
+ r->length = 2;
+ break;
+ case 8:
+ r->length = 3;
+ break;
+ default:
+ break;
+ }
- ++sect->nreloc;
+ /* absolute relocation */
+ r->type = 0; // X86_64_RELOC_UNSIGNED
+ r->snum = R_ABS; // Absolute Symbol (indicates no relocation)
+
+ /* relative relocation */
+ if (pcrel == 1) {
+
+ /* intra-section */
+ if (section == NO_SEG) {
+ r->type = 1; // X86_64_RELOC_SIGNED
+
+ /* inter-section */
+ } else {
+ fi = get_section_fileindex_by_index(section);
+
+ /* external */
+ if (fi == NO_SECT) {
+ r->snum = raa_read(extsyms, section);
+
+ /* local */
+ } else {
+ r->type = 2; // X86_64_RELOC_BRANCH
+ r->snum = fi;
+
+ /* standard relocation */
+ r->type = 1; // X86_64_RELOC_SIGNED
+
+ }
+ }
+
+ /* subtractor */
+ } else if(pcrel == 2) {
+ r->type = 5; // X86_64_RELOC_SUBTRACTOR
+ }
+ ++sect->nreloc;
}
static void macho_output(int32_t secto, const void *data,
@@ -394,7 +428,7 @@ static void macho_output(int32_t secto, const void *data,
{
struct section *s, *sbss;
int32_t addr;
- uint8_t mydata[4], *p;
+ uint8_t mydata[8], *p;
if (wrt != NO_SEG) {
wrt = NO_SEG;
@@ -472,12 +506,22 @@ static void macho_output(int32_t secto, const void *data,
if (section % 2) {
error(ERR_NONFATAL, "Mach-O format does not support"
" section base references");
- } else
- add_reloc(s, section, 0, size);
- }
+ } else {
+ if (wrt == NO_SEG) {
+ if (size < 8) {
+// add_reloc(s, section, 2, size);
+// sect_write(s, data, size);
+ }
+ add_reloc(s, section, 0, size);
+ }else{
+ error(ERR_NONFATAL, "Mach-O format does not support"
+ " this... um... thingy right now...");
+ }
+ }
+ }
p = mydata;
- WRITEADDR(p, addr, size);
+ WRITEADDR(p, addr, size);
sect_write(s, mydata, size);
break;
@@ -488,8 +532,9 @@ static void macho_output(int32_t secto, const void *data,
if (section != NO_SEG && section % 2) {
error(ERR_NONFATAL, "Mach-O format does not support"
" section base references");
- } else
+ } else {
add_reloc(s, section, 1, 2);
+ }
p = mydata;
WRITESHORT(p, *(int32_t *)data - (size + s->size));
@@ -497,14 +542,15 @@ static void macho_output(int32_t secto, const void *data,
break;
case OUT_REL4ADR:
- if (section == secto)
- error(ERR_PANIC, "intra-section OUT_REL4ADR");
+// if (section == secto)
+// error(ERR_PANIC, "intra-section OUT_REL4ADR");
if (section != NO_SEG && section % 2) {
error(ERR_NONFATAL, "Mach-O format does not support"
" section base references");
- } else
+ } else {
add_reloc(s, section, 1, 4);
+ }
p = mydata;
WRITELONG(p, *(int32_t *)data - (size + s->size));
@@ -526,9 +572,9 @@ static int32_t macho_section(char *name, int pass, int *bits)
(void)pass;
- /* Default to 32 bits. */
+ /* Default to 64 bits. */
if (!name) {
- *bits = 32;
+ *bits = 64;
name = ".text";
sectionAttributes = NULL;
} else {
@@ -654,10 +700,11 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
sym->desc = 0;
sym->value = offset;
sym->initial_snum = -1;
-
+
/* external and common symbols get N_EXT */
- if (is_global != 0)
+ if (is_global != 0) {
sym->type |= N_EXT;
+ }
if (section == NO_SEG) {
/* symbols in no section get absolute */
@@ -674,8 +721,8 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
** symbols, this works because every external symbol gets
** its own section number allocated internally by nasm and
** can so be used as a key */
- extsyms = raa_write(extsyms, section, nsyms);
- sym->initial_snum = nsyms;
+ extsyms = raa_write(extsyms, section, nsyms);
+ sym->initial_snum = nsyms;
switch (is_global) {
case 1:
@@ -695,7 +742,6 @@ static void macho_symdef(char *name, int32_t section, int64_t offset,
}
}
}
-
++nsyms;
}
@@ -831,23 +877,23 @@ static void macho_calculate_sizes (void)
for (s = sects; s != NULL; s = s->next) {
/* zerofill sections aren't actually written to the file */
if ((s->flags & SECTION_TYPE) != S_ZEROFILL)
- seg_filesize += s->size;
+ seg_filesize64 += s->size;
- seg_vmsize += s->size;
- ++seg_nsects;
+ seg_vmsize64 += s->size;
+ ++seg_nsects64;
}
/* calculate size of all headers, load commands and sections to
** get a pointer to the start of all the raw data */
- if (seg_nsects > 0) {
- ++head_ncmds;
- head_sizeofcmds +=
- MACHO_SEGCMD_SIZE + seg_nsects * MACHO_SECTCMD_SIZE;
+ if (seg_nsects64 > 0) {
+ ++head_ncmds64;
+ head_sizeofcmds64 +=
+ MACHO_SEGCMD64_SIZE + seg_nsects64 * MACHO_SECTCMD64_SIZE;
}
if (nsyms > 0) {
- ++head_ncmds;
- head_sizeofcmds += MACHO_SYMCMD_SIZE;
+ ++head_ncmds64;
+ head_sizeofcmds64 += MACHO_SYMCMD_SIZE;
}
}
@@ -855,79 +901,82 @@ static void macho_calculate_sizes (void)
static void macho_write_header (void)
{
- fwriteint32_t(MH_MAGIC, machofp); /* magic */
- fwriteint32_t(CPU_TYPE_I386, machofp); /* CPU type */
+ fwriteint32_t(MH_MAGIC_64, machofp); /* magic */
+ fwriteint32_t(CPU_TYPE_X86_64, machofp); /* CPU type */
fwriteint32_t(CPU_SUBTYPE_I386_ALL, machofp); /* CPU subtype */
fwriteint32_t(MH_OBJECT, machofp); /* Mach-O file type */
- fwriteint32_t(head_ncmds, machofp); /* number of load commands */
- fwriteint32_t(head_sizeofcmds, machofp); /* size of load commands */
+ fwriteint32_t(head_ncmds64, machofp); /* number of load commands */
+ fwriteint32_t(head_sizeofcmds64, machofp); /* size of load commands */
fwriteint32_t(0, machofp); /* no flags */
+ fwriteint32_t(0, machofp); /* reserved for future use */
}
/* Write out the segment load command at offset. */
-static uint32_t macho_write_segment (uint32_t offset)
+static uint32_t macho_write_segment (uint64_t offset)
{
- uint32_t s_addr = 0;
- uint32_t rel_base = alignint32_t (offset + seg_filesize);
+ uint64_t s_addr = 0;
+ uint64_t rel_base = alignint64_t (offset + seg_filesize64);
uint32_t s_reloff = 0;
struct section *s;
- fwriteint32_t(LC_SEGMENT, machofp); /* cmd == LC_SEGMENT */
+ fwriteint32_t(LC_SEGMENT_64, machofp); /* cmd == LC_SEGMENT_64 */
/* size of load command including section load commands */
- fwriteint32_t(MACHO_SEGCMD_SIZE + seg_nsects *
- MACHO_SECTCMD_SIZE, machofp);
+ fwriteint32_t(MACHO_SEGCMD64_SIZE + seg_nsects64 *
+ MACHO_SECTCMD64_SIZE, machofp);
/* in an MH_OBJECT file all sections are in one unnamed (name
** all zeros) segment */
fwrite("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16, 1, machofp);
- fwriteint32_t(0, machofp); /* in-memory offset */
- fwriteint32_t(seg_vmsize, machofp); /* in-memory size */
- fwriteint32_t(offset, machofp); /* in-file offset to data */
- fwriteint32_t(seg_filesize, machofp); /* in-file size */
+ fwriteint64_t(0, machofp); /* in-memory offset */
+ fwriteint64_t(seg_vmsize64, machofp); /* in-memory size */
+ fwriteint64_t(offset, machofp); /* in-file offset to data */
+ fwriteint64_t(seg_filesize64, machofp); /* in-file size */
fwriteint32_t(VM_PROT_DEFAULT, machofp); /* maximum vm protection */
fwriteint32_t(VM_PROT_DEFAULT, machofp); /* initial vm protection */
- fwriteint32_t(seg_nsects, machofp); /* number of sections */
+ fwriteint32_t(seg_nsects64, machofp); /* number of sections */
fwriteint32_t(0, machofp); /* no flags */
/* emit section headers */
for (s = sects; s != NULL; s = s->next) {
- fwrite(s->sectname, sizeof(s->sectname), 1, machofp);
- fwrite(s->segname, sizeof(s->segname), 1, machofp);
- fwriteint32_t(s_addr, machofp);
- fwriteint32_t(s->size, machofp);
-
- /* dummy data for zerofill sections or proper values */
- if ((s->flags & SECTION_TYPE) != S_ZEROFILL) {
- fwriteint32_t(offset, machofp);
- /* Write out section alignment, as a power of two.
- e.g. 32-bit word alignment would be 2 (2^^2 = 4). */
- if (s->align == -1)
- s->align = DEFAULT_SECTION_ALIGNMENT;
- fwriteint32_t(s->align, machofp);
- /* To be compatible with cctools as we emit
- a zero reloff if we have no relocations. */
- fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp);
- fwriteint32_t(s->nreloc, machofp);
-
- offset += s->size;
- s_reloff += s->nreloc * MACHO_RELINFO_SIZE;
- } else {
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- fwriteint32_t(0, machofp);
- }
-
- fwriteint32_t(s->flags, machofp); /* flags */
- fwriteint32_t(0, machofp); /* reserved */
- fwriteint32_t(0, machofp); /* reserved */
-
- s_addr += s->size;
+ fwrite(s->sectname, sizeof(s->sectname), 1, machofp);
+ fwrite(s->segname, sizeof(s->segname), 1, machofp);
+ fwriteint64_t(s_addr, machofp);
+ fwriteint64_t(s->size, machofp);
+
+ /* dummy data for zerofill sections or proper values */
+ if ((s->flags & SECTION_TYPE) != S_ZEROFILL) {
+ fwriteint32_t(offset, machofp);
+ /* Write out section alignment, as a power of two.
+ e.g. 32-bit word alignment would be 2 (2^^2 = 4). */
+ if (s->align == -1)
+ s->align = DEFAULT_SECTION_ALIGNMENT;
+ fwriteint32_t(s->align, machofp);
+ /* To be compatible with cctools as we emit
+ a zero reloff if we have no relocations. */
+ fwriteint32_t(s->nreloc ? rel_base + s_reloff : 0, machofp);
+ fwriteint32_t(s->nreloc, machofp);
+
+ offset += s->size;
+ s_reloff += s->nreloc * MACHO_RELINFO64_SIZE;
+ } else {
+ fwriteint32_t(0, machofp);
+ fwriteint32_t(0, machofp);
+ fwriteint32_t(0, machofp);
+ fwriteint32_t(0, machofp);
+ }
+
+ if(s->nreloc) s->flags |= S_ATTR_LOC_RELOC;
+ fwriteint32_t(s->flags, machofp); /* flags */
+ fwriteint32_t(0, machofp); /* reserved */
+ fwriteint32_t(0, machofp); /* reserved */
+
+ fwriteint32_t(0, machofp); /* align */
+ s_addr += s->size;
}
- rel_padcnt = rel_base - offset;
+ rel_padcnt64 = rel_base - offset;
offset = rel_base + s_reloff;
return offset;
@@ -959,9 +1008,10 @@ static void macho_write_section (void)
{
struct section *s, *s2;
struct reloc *r;
- char *rel_paddata = "\0\0\0";
- uint8_t fi, *p, *q, blk[4];
- int32_t l;
+ char *rel_paddata = "\0\0\0\0\0\0\0";
+ uint8_t fi, *p, *q, blk[8];
+ int32_t len;
+ int64_t l;
for (s = sects; s != NULL; s = s->next) {
if ((s->flags & SECTION_TYPE) == S_ZEROFILL)
@@ -975,18 +1025,29 @@ static void macho_write_section (void)
* for more information. */
saa_rewind(s->data);
for (r = s->relocs; r != NULL; r = r->next) {
- saa_fread(s->data, r->addr, blk, (int32_t)r->length << 1);
+ len = (int32_t)r->length << 1;
+ if(len > 4) len = 8;
+ saa_fread(s->data, r->addr, blk, len);
p = q = blk;
l = *p++;
/* get offset based on relocation type */
if (r->length > 0) {
- l += ((int32_t)*p++) << 8;
-
- if (r->length == 2) {
- l += ((int32_t)*p++) << 16;
- l += ((int32_t)*p++) << 24;
- }
+ l += ((int64_t)*p++) << 8;
+
+ if (r->length > 1) {
+ l += ((int64_t)*p++) << 16;
+ l += ((int64_t)*p++) << 24;
+ }
+
+ if (r->length > 2) {
+ l += ((int64_t)*p++) << 32;
+ l += ((int64_t)*p++) << 40;
+ l += ((int64_t)*p++) << 48;
+ l += ((int64_t)*p++) << 56;
+ }
+
+
}
/* If the relocation is internal add to the current section
@@ -1001,22 +1062,24 @@ static void macho_write_section (void)
}
/* write new offset back */
- if (r->length == 2)
+ if (r->length == 3)
+ WRITEDLONG(q, l);
+ else if (r->length == 2)
WRITELONG(q, l);
else if (r->length == 1)
WRITESHORT(q, l);
else
*q++ = l & 0xFF;
- saa_fwrite(s->data, r->addr, blk, (int32_t)r->length << 1);
+ saa_fwrite(s->data, r->addr, blk, len);
}
/* dump the section data to file */
saa_fpwrite(s->data, machofp);
}
- /* pad last section up to reloc entries on int32_t boundary */
- fwrite(rel_paddata, rel_padcnt, 1, machofp);
+ /* pad last section up to reloc entries on int64_t boundary */
+ fwrite(rel_paddata, rel_padcnt64, 1, machofp);
/* emit relocation entries */
for (s = sects; s != NULL; s = s->next)
@@ -1029,8 +1092,8 @@ static void macho_write_symtab (void)
{
struct symbol *sym;
struct section *s;
- int32_t fi;
- uint32_t i;
+ int64_t fi;
+ uint64_t i;
/* we don't need to pad here since MACHO_RELINFO_SIZE == 8 */
@@ -1049,7 +1112,7 @@ static void macho_write_symtab (void)
sym->value += s->size;
}
- fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */
}
}
@@ -1068,26 +1131,26 @@ static void macho_write_symtab (void)
sym->value += s->size;
}
- fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint64_t(sym->value, machofp); /* value (i.e. offset) */
}
for (i = 0; i < nundefsym; i++) {
sym = undefsyms[i];
fwriteint32_t(sym->strx, machofp);
- fwrite(&sym->type, 1, 1, machofp); /* symbol type */
- fwrite(&sym->sect, 1, 1, machofp); /* section */
- fwriteint16_t(sym->desc, machofp); /* description */
+ fwrite(&sym->type, 1, 1, machofp); // symbol type
+ fwrite(&sym->sect, 1, 1, machofp); // section
+ fwriteint16_t(sym->desc, machofp); // description
- /* Fix up the symbol value now that we know the final section
- sizes. */
+ // Fix up the symbol value now that we know the final section sizes.
if (((sym->type & N_TYPE) == N_SECT) && (sym->sect != NO_SECT)) {
for (s = sects, fi = 1;
s != NULL && fi < sym->sect; s = s->next, ++fi)
sym->value += s->size;
}
- fwriteint32_t(sym->value, machofp); /* value (i.e. offset) */
+ fwriteint64_t(sym->value, machofp); // value (i.e. offset)
}
+
}
/* Fixup the snum in the relocation entries, we should be
@@ -1115,7 +1178,7 @@ static void macho_fixup_relocs (struct reloc *r)
static void macho_write (void)
{
- uint32_t offset = 0;
+ uint64_t offset = 0;
/* mach-o object file structure:
**
@@ -1130,14 +1193,14 @@ static void macho_write (void)
** uint32_t flags
**
** segment command
- ** uint32_t command type == LC_SEGMENT
+ ** uint32_t command type == LC_SEGMENT_64
** uint32_t size of load command
** (including section load commands)
** char[16] segment name
- ** uint32_t in-memory offset
- ** uint32_t in-memory size
- ** uint32_t in-file offset to data area
- ** uint32_t in-file size
+ ** uint64_t in-memory offset
+ ** uint64_t in-memory size
+ ** uint64_t in-file offset to data area
+ ** uint64_t in-file size
** (in-memory size excluding zerofill sections)
** int maximum vm protection
** int initial vm protection
@@ -1147,8 +1210,8 @@ static void macho_write (void)
** section commands
** char[16] section name
** char[16] segment name
- ** uint32_t in-memory offset
- ** uint32_t in-memory size
+ ** uint64_t in-memory offset
+ ** uint64_t in-memory size
** uint32_t in-file offset
** uint32_t alignment
** (irrelevant in MH_OBJECT)
@@ -1168,7 +1231,7 @@ static void macho_write (void)
**
** raw section data
**
- ** padding to int32_t boundary
+ ** padding to int64_t boundary
**
** relocation data (struct reloc)
** int32_t offset
@@ -1184,7 +1247,7 @@ static void macho_write (void)
** [type == extern])
** int16_t description
** (for stab debugging format)
- ** uint32_t value (i.e. file offset) of symbol or stab offset
+ ** uint64_t value (i.e. file offset) of symbol or stab offset
**
** string table data
** list of null-terminated strings
@@ -1193,10 +1256,10 @@ static void macho_write (void)
/* Emit the Mach-O header. */
macho_write_header();
- offset = MACHO_HEADER_SIZE + head_sizeofcmds;
+ offset = MACHO_HEADER64_SIZE + head_sizeofcmds64;
/* emit the segment load command */
- if (seg_nsects > 0)
+ if (seg_nsects64 > 0)
offset = macho_write_segment (offset);
else
error(ERR_WARNING, "no sections?");
@@ -1209,20 +1272,20 @@ static void macho_write (void)
fwriteint32_t(nsyms, machofp); /* number of symbol
** table entries */
- offset += nsyms * MACHO_NLIST_SIZE;
+ offset += nsyms * MACHO_NLIST64_SIZE;
fwriteint32_t(offset, machofp); /* string table offset */
fwriteint32_t(strslen, machofp); /* string table size */
}
/* emit section data */
- if (seg_nsects > 0)
+ if (seg_nsects64 > 0)
macho_write_section ();
/* emit symbol table if we have symbols */
if (nsyms > 0)
macho_write_symtab ();
- /* we don't need to pad here since MACHO_NLIST_SIZE == 12 */
+ /* we don't need to pad here since MACHO_NLIST64_SIZE == 16 */
/* emit string table */
saa_fpwrite(strs, machofp);
@@ -1306,9 +1369,9 @@ static void debug_section_relocs (struct section *s)
}
}
-struct ofmt of_macho = {
- "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files",
- "macho",
+struct ofmt of_macho64 = {
+ "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files",
+ "macho64",
NULL,
null_debug_arr,
&null_debug_form,
More information about the Nasm-commits
mailing list