1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2016 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * outmacho.c output routines for the Netwide Assembler to produce
36 * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files
52 #include "output/outform.h"
53 #include "output/outlib.h"
55 #if defined(OF_MACHO) || defined(OF_MACHO64)
57 /* Mach-O in-file header structure sizes */
58 #define MACHO_HEADER_SIZE 28
59 #define MACHO_SEGCMD_SIZE 56
60 #define MACHO_SECTCMD_SIZE 68
61 #define MACHO_SYMCMD_SIZE 24
62 #define MACHO_NLIST_SIZE 12
63 #define MACHO_RELINFO_SIZE 8
65 #define MACHO_HEADER64_SIZE 32
66 #define MACHO_SEGCMD64_SIZE 72
67 #define MACHO_SECTCMD64_SIZE 80
68 #define MACHO_NLIST64_SIZE 16
70 /* Mach-O file header values */
71 #define MH_MAGIC 0xfeedface
72 #define MH_MAGIC_64 0xfeedfacf
73 #define CPU_TYPE_I386 7 /* x86 platform */
74 #define CPU_TYPE_X86_64 0x01000007 /* x86-64 platform */
75 #define CPU_SUBTYPE_I386_ALL 3 /* all-x86 compatible */
76 #define MH_OBJECT 0x1 /* object file */
78 /* Mach-O load commands */
79 #define LC_SEGMENT 0x1 /* 32-bit segment load cmd */
80 #define LC_SEGMENT_64 0x19 /* 64-bit segment load cmd */
81 #define LC_SYMTAB 0x2 /* symbol table load command */
83 /* Mach-O relocations numbers */
85 /* Generic relocs, used by i386 Mach-O */
86 #define GENERIC_RELOC_VANILLA 0 /* Generic relocation */
87 #define GENERIC_RELOC_TLV 5 /* Thread local */
89 #define X86_64_RELOC_UNSIGNED 0 /* Absolute address */
90 #define X86_64_RELOC_SIGNED 1 /* Signed 32-bit disp */
91 #define X86_64_RELOC_BRANCH 2 /* CALL/JMP with 32-bit disp */
92 #define X86_64_RELOC_GOT_LOAD 3 /* MOVQ of GOT entry */
93 #define X86_64_RELOC_GOT 4 /* Different GOT entry */
94 #define X86_64_RELOC_SUBTRACTOR 5 /* Subtracting two symbols */
95 #define X86_64_RELOC_SIGNED_1 6 /* SIGNED with -1 addend */
96 #define X86_64_RELOC_SIGNED_2 7 /* SIGNED with -2 addend */
97 #define X86_64_RELOC_SIGNED_4 8 /* SIGNED with -4 addend */
98 #define X86_64_RELOC_TLV 9 /* Thread local */
100 /* Mach-O VM permission constants */
101 #define VM_PROT_NONE (0x00)
102 #define VM_PROT_READ (0x01)
103 #define VM_PROT_WRITE (0x02)
104 #define VM_PROT_EXECUTE (0x04)
106 #define VM_PROT_DEFAULT (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)
107 #define VM_PROT_ALL (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)
109 /* Our internal relocation types */
111 RL_ABS
, /* Absolute relocation */
112 RL_REL
, /* Relative relocation */
113 RL_TLV
, /* Thread local */
114 RL_BRANCH
, /* Relative direct branch */
115 RL_SUB
, /* X86_64_RELOC_SUBTRACT */
116 RL_GOT
, /* X86_64_RELOC_GOT */
117 RL_GOTLOAD
/* X86_64_RELOC_GOT_LOAD */
119 #define RL_MAX_32 RL_TLV
120 #define RL_MAX_64 RL_GOTLOAD
123 uint32_t ptrsize
; /* Pointer size in bytes */
124 uint32_t mh_magic
; /* Which magic number to use */
125 uint32_t cpu_type
; /* Which CPU type */
126 uint32_t lc_segment
; /* Which segment load command */
127 uint32_t header_size
; /* Header size */
128 uint32_t segcmd_size
; /* Segment command size */
129 uint32_t sectcmd_size
; /* Section command size */
130 uint32_t nlist_size
; /* Nlist (symbol) size */
131 enum reltype maxreltype
; /* Maximum entry in enum reltype permitted */
132 uint32_t reloc_abs
; /* Absolute relocation type */
133 uint32_t reloc_rel
; /* Relative relocation type */
134 uint32_t reloc_tlv
; /* Thread local relocation type */
137 static struct macho_fmt fmt
;
139 static void fwriteptr(uint64_t data
, FILE * fp
)
141 fwriteaddr(data
, fmt
.ptrsize
, fp
);
145 /* nasm internal data */
146 struct section
*next
;
150 struct reloc
*relocs
;
151 struct rbtree
*gsyms
; /* Global symbols in section */
153 bool by_name
; /* This section was specified by full MachO name */
155 /* data that goes into the file */
156 char sectname
[16]; /* what this section is called */
157 char segname
[16]; /* segment this section will be in */
158 uint64_t addr
; /* in-memory address (subject to alignment) */
159 uint64_t size
; /* in-memory and -file size */
160 uint64_t offset
; /* in-file offset */
161 uint32_t pad
; /* padding bytes before section */
162 uint32_t nreloc
; /* relocation entry count */
163 uint32_t flags
; /* type and attributes (masked) */
164 uint32_t extreloc
; /* external relocations */
167 #define SECTION_TYPE 0x000000ff /* section type mask */
169 #define S_REGULAR (0x0) /* standard section */
170 #define S_ZEROFILL (0x1) /* zerofill, in-memory only */
172 #define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */
173 #define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some
174 machine instructions */
175 #define S_ATTR_EXT_RELOC 0x00000200 /* section has external
176 relocation entries */
177 #define S_ATTR_LOC_RELOC 0x00000100 /* section has local
178 relocation entries */
179 #define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section uses pure
180 machine instructions */
182 /* Fake section for absolute symbols, *not* part of the section linked list */
183 static struct section absolute_sect
;
185 static const struct sectmap
{
186 const char *nasmsect
;
188 const char *sectname
;
191 {".text", "__TEXT", "__text", S_REGULAR
|S_ATTR_SOME_INSTRUCTIONS
|S_ATTR_PURE_INSTRUCTIONS
},
192 {".data", "__DATA", "__data", S_REGULAR
},
193 {".rodata", "__DATA", "__const", S_REGULAR
},
194 {".bss", "__DATA", "__bss", S_ZEROFILL
},
195 {NULL
, NULL
, NULL
, 0}
199 /* nasm internal data */
202 /* data that goes into the file */
203 int32_t addr
; /* op's offset in section */
204 uint32_t snum
:24, /* contains symbol index if
205 ** ext otherwise in-file
207 pcrel
:1, /* relative relocation */
208 length
:2, /* 0=byte, 1=word, 2=int32_t, 3=int64_t */
209 ext
:1, /* external symbol referenced */
210 type
:4; /* reloc type */
213 #define R_ABS 0 /* absolute relocation */
214 #define R_SCATTERED 0x80000000 /* reloc entry is scattered if
215 ** highest bit == 1 */
218 /* nasm internal data */
219 struct rbtree symv
; /* Global symbol rbtree; "key" contains the
221 struct symbol
*next
; /* next symbol in the list */
222 char *name
; /* name of this symbol */
223 int32_t initial_snum
; /* symbol number used above in reloc */
224 int32_t snum
; /* true snum for reloc */
226 /* data that goes into the file */
227 uint32_t strx
; /* string table index */
228 uint8_t type
; /* symbol type */
229 uint8_t sect
; /* NO_SECT or section number */
230 uint16_t desc
; /* for stab debugging, 0 for us */
233 /* symbol type bits */
234 #define N_EXT 0x01 /* global or external symbol */
236 #define N_UNDF 0x0 /* undefined symbol | n_sect == */
237 #define N_ABS 0x2 /* absolute symbol | NO_SECT */
238 #define N_SECT 0xe /* defined symbol, n_sect holds
241 #define N_TYPE 0x0e /* type bit mask */
243 #define DEFAULT_SECTION_ALIGNMENT 0 /* byte (i.e. no) alignment */
245 /* special section number values */
246 #define NO_SECT 0 /* no section, invalid */
247 #define MAX_SECT 255 /* maximum number of sections */
249 static struct section
*sects
, **sectstail
, **sectstab
;
250 static struct symbol
*syms
, **symstail
;
251 static uint32_t nsyms
;
253 /* These variables are set by macho_layout_symbols() to organize
254 the symbol table and string table in order the dynamic linker
255 expects. They are then used in macho_write() to put out the
256 symbols and strings in that order.
258 The order of the symbol table is:
260 defined external symbols (sorted by name)
261 undefined external symbols (sorted by name)
263 The order of the string table is:
264 strings for external symbols
265 strings for local symbols
267 static uint32_t ilocalsym
= 0;
268 static uint32_t iextdefsym
= 0;
269 static uint32_t iundefsym
= 0;
270 static uint32_t nlocalsym
;
271 static uint32_t nextdefsym
;
272 static uint32_t nundefsym
;
273 static struct symbol
**extdefsyms
= NULL
;
274 static struct symbol
**undefsyms
= NULL
;
276 static struct RAA
*extsyms
;
277 static struct SAA
*strs
;
278 static uint32_t strslen
;
280 /* Global file information. This should be cleaned up into either
281 a structure or as function arguments. */
282 static uint32_t head_ncmds
= 0;
283 static uint32_t head_sizeofcmds
= 0;
284 static uint64_t seg_filesize
= 0;
285 static uint64_t seg_vmsize
= 0;
286 static uint32_t seg_nsects
= 0;
287 static uint64_t rel_padcnt
= 0;
289 #define xstrncpy(xdst, xsrc) \
290 memset(xdst, '\0', sizeof(xdst)); /* zero out whole buffer */ \
291 strncpy(xdst, xsrc, sizeof(xdst)); /* copy over string */ \
292 xdst[sizeof(xdst) - 1] = '\0'; /* proper null-termination */
294 #define alignint32_t(x) \
295 ALIGN(x, sizeof(int32_t)) /* align x to int32_t boundary */
297 #define alignint64_t(x) \
298 ALIGN(x, sizeof(int64_t)) /* align x to int64_t boundary */
300 #define alignptr(x) \
301 ALIGN(x, fmt.ptrsize) /* align x to output format width */
303 static struct section
*get_section_by_name(const char *segname
,
304 const char *sectname
)
308 for (s
= sects
; s
!= NULL
; s
= s
->next
)
309 if (!strcmp(s
->segname
, segname
) && !strcmp(s
->sectname
, sectname
))
315 static struct section
*get_section_by_index(const int32_t index
)
319 for (s
= sects
; s
!= NULL
; s
= s
->next
)
320 if (index
== s
->index
)
327 * Special section numbers which are used to define Mach-O special
328 * symbols, which can be used with WRT to provide PIC relocation
331 static int32_t macho_tlvp_sect
;
332 static int32_t macho_gotpcrel_sect
;
334 static void macho_init(void)
339 /* Fake section for absolute symbols */
340 absolute_sect
.index
= NO_SEG
;
349 extsyms
= raa_init();
352 /* string table starts with a zero byte so index 0 is an empty string */
353 saa_wbytes(strs
, zero_buffer
, 1);
356 /* add special symbol for TLVP */
357 macho_tlvp_sect
= seg_alloc() + 1;
358 define_label("..tlvp", macho_tlvp_sect
, 0L, NULL
, false, false);
362 static void sect_write(struct section
*sect
,
363 const uint8_t *data
, uint32_t len
)
365 saa_wbytes(sect
->data
, data
, len
);
370 * Find a suitable global symbol for a ..gotpcrel or ..tlvp reference
372 static struct symbol
*macho_find_gsym(struct section
*s
,
373 uint64_t offset
, bool exact
)
377 srb
= rb_search(s
->gsyms
, offset
);
379 if (!srb
|| (exact
&& srb
->key
!= offset
)) {
380 nasm_error(ERR_NONFATAL
, "unable to find a suitable %s symbol"
381 " for this reference",
382 s
== &absolute_sect
? "absolute" : "global");
386 return container_of(srb
, struct symbol
, symv
);
389 static int64_t add_reloc(struct section
*sect
, int32_t section
,
391 enum reltype reltype
, int bytes
)
398 /* Double check this is a valid relocation type for this platform */
399 nasm_assert(reltype
<= fmt
.maxreltype
);
401 /* the current end of the section will be the symbol's address for
402 ** now, might have to be fixed by macho_fixup_relocs() later on. make
403 ** sure we don't make the symbol scattered by setting the highest
404 ** bit by accident */
405 r
= nasm_malloc(sizeof(struct reloc
));
406 r
->addr
= sect
->size
& ~R_SCATTERED
;
410 /* match byte count 1, 2, 4, 8 to length codes 0, 1, 2, 3 respectively */
411 r
->length
= ilog2_32(bytes
);
413 /* set default relocation values */
414 r
->type
= fmt
.reloc_abs
;
419 if (section
!= NO_SEG
)
420 s
= get_section_by_index(section
);
421 fi
= s
? s
->fileindex
: NO_SECT
;
423 /* absolute relocation */
426 if (section
== NO_SEG
) {
427 /* absolute (can this even happen?) */
430 } else if (fi
== NO_SECT
) {
432 r
->snum
= raa_read(extsyms
, section
);
437 adjust
= -sect
->size
;
443 r
->type
= fmt
.reloc_rel
;
445 if (section
== NO_SEG
) {
446 /* absolute - seems to produce garbage no matter what */
447 nasm_error(ERR_NONFATAL
, "Mach-O does not support relative "
448 "references to absolute addresses");
451 /* This "seems" to be how it ought to work... */
453 struct symbol
*sym
= macho_find_gsym(&absolute_sect
,
460 adjust
= -sect
->size
;
462 } else if (fi
== NO_SECT
) {
465 r
->snum
= raa_read(extsyms
, section
);
466 if (reltype
== RL_BRANCH
)
467 r
->type
= X86_64_RELOC_BRANCH
;
468 else if (reltype
== GENERIC_RELOC_VANILLA
)
469 adjust
= -sect
->size
;
474 adjust
= -sect
->size
;
480 r
->type
= X86_64_RELOC_SUBTRACTOR
;
484 r
->type
= X86_64_RELOC_GOT
;
488 r
->type
= X86_64_RELOC_GOT_LOAD
;
492 r
->type
= fmt
.reloc_tlv
;
497 if (section
== NO_SEG
) {
498 nasm_error(ERR_NONFATAL
, "Unsupported use of use of WRT");
499 } else if (fi
== NO_SECT
) {
501 r
->snum
= raa_read(extsyms
, section
);
504 struct symbol
*sym
= macho_find_gsym(s
, offset
, reltype
!= RL_TLV
);
507 r
->snum
= sym
->initial_snum
;
512 /* NeXT as puts relocs in reversed order (address-wise) into the
513 ** files, so we do the same, doesn't seem to make much of a
514 ** difference either way */
515 r
->next
= sect
->relocs
;
528 static void macho_output(int32_t secto
, const void *data
,
529 enum out_type type
, uint64_t size
,
530 int32_t section
, int32_t wrt
)
533 int64_t addr
, offset
;
534 uint8_t mydata
[16], *p
;
536 enum reltype reltype
;
538 if (secto
== NO_SEG
) {
539 if (type
!= OUT_RESERVE
)
540 nasm_error(ERR_NONFATAL
, "attempt to assemble code in "
545 s
= get_section_by_index(secto
);
548 nasm_error(ERR_WARNING
, "attempt to assemble code in"
549 " section %d: defaulting to `.text'", secto
);
550 s
= get_section_by_name("__TEXT", "__text");
552 /* should never happen */
554 nasm_panic(0, "text section not found");
557 is_bss
= (s
->flags
& SECTION_TYPE
) == S_ZEROFILL
;
559 if (is_bss
&& type
!= OUT_RESERVE
) {
560 nasm_error(ERR_WARNING
, "attempt to initialize memory in "
561 "BSS section: ignored");
562 s
->size
+= realsize(type
, size
);
566 memset(mydata
, 0, sizeof(mydata
));
571 nasm_error(ERR_WARNING
, "uninitialized space declared in"
572 " %s,%s section: zeroing", s
->segname
, s
->sectname
);
574 sect_write(s
, NULL
, size
);
581 if (section
!= NO_SEG
)
582 nasm_panic(0, "OUT_RAWDATA with other than NO_SEG");
584 sect_write(s
, data
, size
);
589 int asize
= abs((int)size
);
591 addr
= *(int64_t *)data
;
592 if (section
!= NO_SEG
) {
594 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
595 " section base references");
596 } else if (wrt
== NO_SEG
) {
597 if (fmt
.ptrsize
== 8 && asize
!= 8) {
598 nasm_error(ERR_NONFATAL
,
599 "Mach-O 64-bit format does not support"
600 " 32-bit absolute addresses");
602 add_reloc(s
, section
, addr
, RL_ABS
, asize
);
605 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
611 WRITEADDR(p
, addr
, asize
);
612 sect_write(s
, mydata
, asize
);
617 nasm_assert(section
!= secto
);
620 offset
= *(int64_t *)data
;
621 addr
= offset
- size
;
623 if (section
!= NO_SEG
&& section
% 2) {
624 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
625 " section base references");
626 } else if (fmt
.ptrsize
== 8) {
627 nasm_error(ERR_NONFATAL
, "Unsupported non-32-bit"
628 " Macho-O relocation [2]");
629 } else if (wrt
!= NO_SEG
) {
630 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
632 wrt
= NO_SEG
; /* we can at least _try_ to continue */
634 addr
+= add_reloc(s
, section
, addr
+size
, RL_REL
, 2);
638 sect_write(s
, mydata
, 2);
642 nasm_assert(section
!= secto
);
645 offset
= *(int64_t *)data
;
646 addr
= offset
- size
;
649 if (section
!= NO_SEG
&& section
% 2) {
650 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
651 " section base references");
652 } else if (wrt
== NO_SEG
) {
653 if (fmt
.ptrsize
== 8 &&
654 (s
->flags
& S_ATTR_SOME_INSTRUCTIONS
)) {
657 opcode
[0] = opcode
[1] = 0;
659 /* HACK: Retrieve instruction opcode */
660 if (likely(s
->data
->datalen
>= 2)) {
661 saa_fread(s
->data
, s
->data
->datalen
-2, opcode
, 2);
662 } else if (s
->data
->datalen
== 1) {
663 saa_fread(s
->data
, 0, opcode
+1, 1);
666 if ((opcode
[0] != 0x0f && (opcode
[1] & 0xfe) == 0xe8) ||
667 (opcode
[0] == 0x0f && (opcode
[1] & 0xf0) == 0x80)) {
668 /* Direct call, jmp, or jcc */
672 } else if (wrt
== macho_gotpcrel_sect
) {
675 if ((s
->flags
& S_ATTR_SOME_INSTRUCTIONS
) &&
676 s
->data
->datalen
>= 3) {
679 /* HACK: Retrieve instruction opcode */
680 saa_fread(s
->data
, s
->data
->datalen
-3, gotload
, 3);
681 if ((gotload
[0] & 0xf8) == 0x48 &&
682 gotload
[1] == 0x8b &&
683 (gotload
[2] & 0307) == 0005) {
684 /* movq <reg>,[rel sym wrt ..gotpcrel] */
685 reltype
= RL_GOTLOAD
;
688 } else if (wrt
== macho_tlvp_sect
) {
691 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
693 /* continue with RL_REL */
696 addr
+= add_reloc(s
, section
, offset
, reltype
, 4);
698 sect_write(s
, mydata
, 4);
702 nasm_error(ERR_NONFATAL
, "Unrepresentable relocation in Mach-O");
707 static int32_t macho_section(char *name
, int pass
, int *bits
)
709 char *sectionAttributes
;
710 const struct sectmap
*sm
;
712 const char *section
, *segment
;
714 char *currentAttribute
;
720 /* Default to the appropriate number of bits. */
722 *bits
= fmt
.ptrsize
<< 3;
724 sectionAttributes
= NULL
;
726 sectionAttributes
= name
;
727 name
= nasm_strsep(§ionAttributes
, " \t");
730 section
= segment
= NULL
;
733 comma
= strchr(name
, ',');
741 len
= strlen(segment
);
743 nasm_error(ERR_NONFATAL
, "empty segment name\n");
744 } else if (len
>= 16) {
745 nasm_error(ERR_NONFATAL
, "segment name %s too long\n", segment
);
748 len
= strlen(section
);
750 nasm_error(ERR_NONFATAL
, "empty section name\n");
751 } else if (len
>= 16) {
752 nasm_error(ERR_NONFATAL
, "section name %s too long\n", section
);
755 if (!strcmp(section
, "__text")) {
756 flags
= S_REGULAR
| S_ATTR_SOME_INSTRUCTIONS
|
757 S_ATTR_PURE_INSTRUCTIONS
;
758 } else if (!strcmp(section
, "__bss")) {
764 for (sm
= sectmap
; sm
->nasmsect
!= NULL
; ++sm
) {
765 /* make lookup into section name translation table */
766 if (!strcmp(name
, sm
->nasmsect
)) {
767 segment
= sm
->segname
;
768 section
= sm
->sectname
;
773 nasm_error(ERR_NONFATAL
, "unknown section name\n");
778 /* try to find section with that name */
779 s
= get_section_by_name(segment
, section
);
781 /* create it if it doesn't exist yet */
785 s
= *sectstail
= nasm_zalloc(sizeof(struct section
));
786 sectstail
= &s
->next
;
788 s
->data
= saa_init(1L);
789 s
->index
= seg_alloc();
790 s
->fileindex
= ++seg_nsects
;
796 xstrncpy(s
->segname
, segment
);
797 xstrncpy(s
->sectname
, section
);
806 *comma
= ','; /* Restore comma */
808 s
->by_name
= s
->by_name
|| comma
; /* Was specified by name */
810 flags
= (uint32_t)-1;
812 while ((NULL
!= sectionAttributes
)
813 && (currentAttribute
= nasm_strsep(§ionAttributes
, " \t"))) {
814 if (0 != *currentAttribute
) {
815 if (!nasm_strnicmp("align=", currentAttribute
, 6)) {
817 int newAlignment
, value
;
819 value
= strtoul(currentAttribute
+ 6, (char**)&end
, 0);
820 newAlignment
= alignlog2_32(value
);
823 nasm_error(ERR_NONFATAL
,
824 "unknown or missing alignment value \"%s\" "
825 "specified for section \"%s\"",
826 currentAttribute
+ 6,
828 } else if (0 > newAlignment
) {
829 nasm_error(ERR_NONFATAL
,
830 "alignment of %d (for section \"%s\") is not "
836 if (s
->align
< newAlignment
)
837 s
->align
= newAlignment
;
838 } else if (!nasm_stricmp("data", currentAttribute
)) {
840 } else if (!nasm_stricmp("code", currentAttribute
) ||
841 !nasm_stricmp("text", currentAttribute
)) {
842 flags
= S_REGULAR
| S_ATTR_SOME_INSTRUCTIONS
|
843 S_ATTR_PURE_INSTRUCTIONS
;
844 } else if (!nasm_stricmp("mixed", currentAttribute
)) {
845 flags
= S_REGULAR
| S_ATTR_SOME_INSTRUCTIONS
;
846 } else if (!nasm_stricmp("bss", currentAttribute
)) {
849 nasm_error(ERR_NONFATAL
,
850 "unknown section attribute %s for section %s",
856 if (flags
!= (uint32_t)-1) {
857 if (!new_seg
&& s
->flags
!= flags
) {
858 nasm_error(ERR_NONFATAL
,
859 "inconsistent section attributes for section %s\n",
870 static void macho_symdef(char *name
, int32_t section
, int64_t offset
,
871 int is_global
, char *special
)
876 nasm_error(ERR_NONFATAL
, "The Mach-O output format does "
877 "not support any special symbol types");
881 if (is_global
== 3) {
882 nasm_error(ERR_NONFATAL
, "The Mach-O format does not "
883 "(yet) support forward reference fixups.");
887 if (name
[0] == '.' && name
[1] == '.' && name
[2] != '@') {
889 * This is a NASM special symbol. We never allow it into
890 * the Macho-O symbol table, even if it's a valid one. If it
891 * _isn't_ a valid one, we should barf immediately.
893 if (strcmp(name
, "..gotpcrel") && strcmp(name
, "..tlvp"))
894 nasm_error(ERR_NONFATAL
, "unrecognized special symbol `%s'", name
);
898 sym
= *symstail
= nasm_zalloc(sizeof(struct symbol
));
900 symstail
= &sym
->next
;
906 sym
->symv
.key
= offset
;
907 sym
->initial_snum
= -1;
909 /* external and common symbols get N_EXT */
910 if (is_global
!= 0) {
914 if (section
== NO_SEG
) {
915 /* symbols in no section get absolute */
919 /* all absolute symbols are available to use as references */
920 absolute_sect
.gsyms
= rb_insert(absolute_sect
.gsyms
, &sym
->symv
);
922 struct section
*s
= get_section_by_index(section
);
926 /* get the in-file index of the section the symbol was defined in */
927 sym
->sect
= s
? s
->fileindex
: NO_SECT
;
929 /* track the initially allocated symbol number for use in future fix-ups */
930 sym
->initial_snum
= nsyms
;
933 /* remember symbol number of references to external
934 ** symbols, this works because every external symbol gets
935 ** its own section number allocated internally by nasm and
936 ** can so be used as a key */
937 extsyms
= raa_write(extsyms
, section
, nsyms
);
942 /* there isn't actually a difference between global
943 ** and common symbols, both even have their size in
949 /* give an error on unfound section if it's not an
950 ** external or common symbol (assemble_file() does a
951 ** seg_alloc() on every call for them) */
952 nasm_panic(0, "in-file index for section %d not found, is_global = %d", section
, is_global
);
955 } else if (is_global
) {
956 s
->gsyms
= rb_insert(s
->gsyms
, &sym
->symv
);
962 static void macho_sectalign(int32_t seg
, unsigned int value
)
967 nasm_assert(!(seg
& 1));
969 s
= get_section_by_index(seg
);
971 if (!s
|| !is_power2(value
))
974 align
= alignlog2_32(value
);
975 if (s
->align
< align
)
979 static int32_t macho_segbase(int32_t section
)
984 static void macho_filename(char *inname
, char *outname
)
986 standard_extension(inname
, outname
, ".o");
989 extern macros_t macho_stdmac
[];
991 /* Comparison function for qsort symbol layout. */
992 static int layout_compare (const struct symbol
**s1
,
993 const struct symbol
**s2
)
995 return (strcmp ((*s1
)->name
, (*s2
)->name
));
998 /* The native assembler does a few things in a similar function
1000 * Remove temporary labels
1001 * Sort symbols according to local, external, undefined (by name)
1002 * Order the string table
1004 We do not remove temporary labels right now.
1006 numsyms is the total number of symbols we have. strtabsize is the
1007 number entries in the string table. */
1009 static void macho_layout_symbols (uint32_t *numsyms
,
1010 uint32_t *strtabsize
)
1012 struct symbol
*sym
, **symp
;
1016 *strtabsize
= sizeof (char);
1020 while ((sym
= *symp
)) {
1021 /* Undefined symbols are now external. */
1022 if (sym
->type
== N_UNDF
)
1025 if ((sym
->type
& N_EXT
) == 0) {
1026 sym
->snum
= *numsyms
;
1027 *numsyms
= *numsyms
+ 1;
1031 if ((sym
->type
& N_TYPE
) != N_UNDF
) {
1037 /* If we handle debug info we'll want
1038 to check for it here instead of just
1039 adding the symbol to the string table. */
1040 sym
->strx
= *strtabsize
;
1041 saa_wbytes (strs
, sym
->name
, (int32_t)(strlen(sym
->name
) + 1));
1042 *strtabsize
+= strlen(sym
->name
) + 1;
1044 symp
= &(sym
->next
);
1047 /* Next, sort the symbols. Most of this code is a direct translation from
1048 the Apple cctools symbol layout. We need to keep compatibility with that. */
1049 /* Set the indexes for symbol groups into the symbol table */
1051 iextdefsym
= nlocalsym
;
1052 iundefsym
= nlocalsym
+ nextdefsym
;
1054 /* allocate arrays for sorting externals by name */
1055 extdefsyms
= nasm_malloc(nextdefsym
* sizeof(struct symbol
*));
1056 undefsyms
= nasm_malloc(nundefsym
* sizeof(struct symbol
*));
1063 while ((sym
= *symp
)) {
1065 if((sym
->type
& N_EXT
) == 0) {
1066 sym
->strx
= *strtabsize
;
1067 saa_wbytes (strs
, sym
->name
, (int32_t)(strlen (sym
->name
) + 1));
1068 *strtabsize
+= strlen(sym
->name
) + 1;
1071 if((sym
->type
& N_TYPE
) != N_UNDF
) {
1072 extdefsyms
[i
++] = sym
;
1074 undefsyms
[j
++] = sym
;
1077 symp
= &(sym
->next
);
1080 qsort(extdefsyms
, nextdefsym
, sizeof(struct symbol
*),
1081 (int (*)(const void *, const void *))layout_compare
);
1082 qsort(undefsyms
, nundefsym
, sizeof(struct symbol
*),
1083 (int (*)(const void *, const void *))layout_compare
);
1085 for(i
= 0; i
< nextdefsym
; i
++) {
1086 extdefsyms
[i
]->snum
= *numsyms
;
1089 for(j
= 0; j
< nundefsym
; j
++) {
1090 undefsyms
[j
]->snum
= *numsyms
;
1095 /* Calculate some values we'll need for writing later. */
1097 static void macho_calculate_sizes (void)
1102 /* count sections and calculate in-memory and in-file offsets */
1103 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1106 /* recalculate segment address based on alignment and vm size */
1107 s
->addr
= seg_vmsize
;
1109 /* we need section alignment to calculate final section address */
1111 s
->align
= DEFAULT_SECTION_ALIGNMENT
;
1113 newaddr
= ALIGN(s
->addr
, 1 << s
->align
);
1116 seg_vmsize
= newaddr
+ s
->size
;
1118 /* zerofill sections aren't actually written to the file */
1119 if ((s
->flags
& SECTION_TYPE
) != S_ZEROFILL
) {
1121 * LLVM/Xcode as always aligns the section data to 4
1122 * bytes; there is a comment in the LLVM source code that
1123 * perhaps aligning to pointer size would be better.
1125 s
->pad
= ALIGN(seg_filesize
, 4) - seg_filesize
;
1126 s
->offset
= seg_filesize
+ s
->pad
;
1127 seg_filesize
+= s
->size
+ s
->pad
;
1131 /* calculate size of all headers, load commands and sections to
1132 ** get a pointer to the start of all the raw data */
1133 if (seg_nsects
> 0) {
1135 head_sizeofcmds
+= fmt
.segcmd_size
+ seg_nsects
* fmt
.sectcmd_size
;
1140 head_sizeofcmds
+= MACHO_SYMCMD_SIZE
;
1143 if (seg_nsects
> MAX_SECT
) {
1144 nasm_fatal(0, "MachO output is limited to %d sections\n",
1148 /* Create a table of sections by file index to avoid linear search */
1149 sectstab
= nasm_malloc((seg_nsects
+ 1) * sizeof(*sectstab
));
1150 sectstab
[NO_SECT
] = &absolute_sect
;
1151 for (s
= sects
, fi
= 1; s
!= NULL
; s
= s
->next
, fi
++)
1155 /* Write out the header information for the file. */
1157 static void macho_write_header (void)
1159 fwriteint32_t(fmt
.mh_magic
, ofile
); /* magic */
1160 fwriteint32_t(fmt
.cpu_type
, ofile
); /* CPU type */
1161 fwriteint32_t(CPU_SUBTYPE_I386_ALL
, ofile
); /* CPU subtype */
1162 fwriteint32_t(MH_OBJECT
, ofile
); /* Mach-O file type */
1163 fwriteint32_t(head_ncmds
, ofile
); /* number of load commands */
1164 fwriteint32_t(head_sizeofcmds
, ofile
); /* size of load commands */
1165 fwriteint32_t(0, ofile
); /* no flags */
1166 fwritezero(fmt
.header_size
- 7*4, ofile
); /* reserved fields */
1169 /* Write out the segment load command at offset. */
1171 static uint32_t macho_write_segment (uint64_t offset
)
1173 uint64_t rel_base
= alignptr(offset
+ seg_filesize
);
1174 uint32_t s_reloff
= 0;
1177 fwriteint32_t(fmt
.lc_segment
, ofile
); /* cmd == LC_SEGMENT_64 */
1179 /* size of load command including section load commands */
1180 fwriteint32_t(fmt
.segcmd_size
+ seg_nsects
* fmt
.sectcmd_size
,
1183 /* in an MH_OBJECT file all sections are in one unnamed (name
1184 ** all zeros) segment */
1185 fwritezero(16, ofile
);
1186 fwriteptr(0, ofile
); /* in-memory offset */
1187 fwriteptr(seg_vmsize
, ofile
); /* in-memory size */
1188 fwriteptr(offset
, ofile
); /* in-file offset to data */
1189 fwriteptr(seg_filesize
, ofile
); /* in-file size */
1190 fwriteint32_t(VM_PROT_DEFAULT
, ofile
); /* maximum vm protection */
1191 fwriteint32_t(VM_PROT_DEFAULT
, ofile
); /* initial vm protection */
1192 fwriteint32_t(seg_nsects
, ofile
); /* number of sections */
1193 fwriteint32_t(0, ofile
); /* no flags */
1195 /* emit section headers */
1196 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1198 nasm_assert((s
->flags
& SECTION_TYPE
) != S_ZEROFILL
);
1199 s
->flags
|= S_ATTR_LOC_RELOC
;
1201 s
->flags
|= S_ATTR_EXT_RELOC
;
1202 } else if (!strcmp(s
->segname
, "__DATA") &&
1203 !strcmp(s
->sectname
, "__const") &&
1205 !get_section_by_name("__TEXT", "__const")) {
1207 * The MachO equivalent to .rodata can be either
1208 * __DATA,__const or __TEXT,__const; the latter only if
1209 * there are no relocations. However, when mixed it is
1210 * better to specify the segments explicitly.
1212 xstrncpy(s
->segname
, "__TEXT");
1215 nasm_write(s
->sectname
, sizeof(s
->sectname
), ofile
);
1216 nasm_write(s
->segname
, sizeof(s
->segname
), ofile
);
1217 fwriteptr(s
->addr
, ofile
);
1218 fwriteptr(s
->size
, ofile
);
1220 /* dummy data for zerofill sections or proper values */
1221 if ((s
->flags
& SECTION_TYPE
) != S_ZEROFILL
) {
1222 nasm_assert(s
->pad
!= (uint32_t)-1);
1224 fwriteint32_t(offset
, ofile
);
1226 /* Write out section alignment, as a power of two.
1227 e.g. 32-bit word alignment would be 2 (2^2 = 4). */
1228 fwriteint32_t(s
->align
, ofile
);
1229 /* To be compatible with cctools as we emit
1230 a zero reloff if we have no relocations. */
1231 fwriteint32_t(s
->nreloc
? rel_base
+ s_reloff
: 0, ofile
);
1232 fwriteint32_t(s
->nreloc
, ofile
);
1234 s_reloff
+= s
->nreloc
* MACHO_RELINFO_SIZE
;
1236 fwriteint32_t(0, ofile
);
1237 fwriteint32_t(s
->align
, ofile
);
1238 fwriteint32_t(0, ofile
);
1239 fwriteint32_t(0, ofile
);
1242 fwriteint32_t(s
->flags
, ofile
); /* flags */
1243 fwriteint32_t(0, ofile
); /* reserved */
1244 fwriteptr(0, ofile
); /* reserved */
1247 rel_padcnt
= rel_base
- offset
;
1248 offset
= rel_base
+ s_reloff
;
1253 /* For a given chain of relocs r, write out the entire relocation
1254 chain to the object file. */
1256 static void macho_write_relocs (struct reloc
*r
)
1261 fwriteint32_t(r
->addr
, ofile
); /* reloc offset */
1264 word2
|= r
->pcrel
<< 24;
1265 word2
|= r
->length
<< 25;
1266 word2
|= r
->ext
<< 27;
1267 word2
|= r
->type
<< 28;
1268 fwriteint32_t(word2
, ofile
); /* reloc data */
1273 /* Write out the section data. */
1274 static void macho_write_section (void)
1286 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1287 if ((s
->flags
& SECTION_TYPE
) == S_ZEROFILL
)
1290 /* Like a.out Mach-O references things in the data or bss
1291 * sections by addresses which are actually relative to the
1292 * start of the _text_ section, in the _file_. See outaout.c
1293 * for more information. */
1294 saa_rewind(s
->data
);
1295 for (r
= s
->relocs
; r
!= NULL
; r
= r
->next
) {
1296 len
= (uint32_t)1 << r
->length
;
1297 if (len
> 4) /* Can this ever be an issue?! */
1300 saa_fread(s
->data
, r
->addr
, blk
.buf
, len
);
1302 /* get offset based on relocation type */
1303 #ifdef WORDS_LITTLEENDIAN
1307 l
+= ((int64_t)blk
.buf
[1]) << 8;
1308 l
+= ((int64_t)blk
.buf
[2]) << 16;
1309 l
+= ((int64_t)blk
.buf
[3]) << 24;
1310 l
+= ((int64_t)blk
.buf
[4]) << 32;
1311 l
+= ((int64_t)blk
.buf
[5]) << 40;
1312 l
+= ((int64_t)blk
.buf
[6]) << 48;
1313 l
+= ((int64_t)blk
.buf
[7]) << 56;
1316 /* If the relocation is internal add to the current section
1317 offset. Otherwise the only value we need is the symbol
1318 offset which we already have. The linker takes care
1319 of the rest of the address. */
1321 /* generate final address by section address and offset */
1322 nasm_assert(r
->snum
<= seg_nsects
);
1323 l
+= sectstab
[r
->snum
]->addr
;
1326 } else if (r
->pcrel
&& r
->type
== GENERIC_RELOC_VANILLA
) {
1330 /* write new offset back */
1333 saa_fwrite(s
->data
, r
->addr
, blk
.buf
, len
);
1336 /* dump the section data to file */
1337 fwritezero(s
->pad
, ofile
);
1338 saa_fpwrite(s
->data
, ofile
);
1341 /* pad last section up to reloc entries on pointer boundary */
1342 fwritezero(rel_padcnt
, ofile
);
1344 /* emit relocation entries */
1345 for (s
= sects
; s
!= NULL
; s
= s
->next
)
1346 macho_write_relocs (s
->relocs
);
1349 /* Write out the symbol table. We should already have sorted this
1351 static void macho_write_symtab (void)
1356 /* we don't need to pad here since MACHO_RELINFO_SIZE == 8 */
1358 for (sym
= syms
; sym
!= NULL
; sym
= sym
->next
) {
1359 if ((sym
->type
& N_EXT
) == 0) {
1360 fwriteint32_t(sym
->strx
, ofile
); /* string table entry number */
1361 nasm_write(&sym
->type
, 1, ofile
); /* symbol type */
1362 nasm_write(&sym
->sect
, 1, ofile
); /* section */
1363 fwriteint16_t(sym
->desc
, ofile
); /* description */
1365 /* Fix up the symbol value now that we know the final section
1367 if (((sym
->type
& N_TYPE
) == N_SECT
) && (sym
->sect
!= NO_SECT
)) {
1368 nasm_assert(sym
->sect
<= seg_nsects
);
1369 sym
->symv
.key
+= sectstab
[sym
->sect
]->addr
;
1372 fwriteptr(sym
->symv
.key
, ofile
); /* value (i.e. offset) */
1376 for (i
= 0; i
< nextdefsym
; i
++) {
1377 sym
= extdefsyms
[i
];
1378 fwriteint32_t(sym
->strx
, ofile
);
1379 nasm_write(&sym
->type
, 1, ofile
); /* symbol type */
1380 nasm_write(&sym
->sect
, 1, ofile
); /* section */
1381 fwriteint16_t(sym
->desc
, ofile
); /* description */
1383 /* Fix up the symbol value now that we know the final section
1385 if (((sym
->type
& N_TYPE
) == N_SECT
) && (sym
->sect
!= NO_SECT
)) {
1386 nasm_assert(sym
->sect
<= seg_nsects
);
1387 sym
->symv
.key
+= sectstab
[sym
->sect
]->addr
;
1390 fwriteptr(sym
->symv
.key
, ofile
); /* value (i.e. offset) */
1393 for (i
= 0; i
< nundefsym
; i
++) {
1395 fwriteint32_t(sym
->strx
, ofile
);
1396 nasm_write(&sym
->type
, 1, ofile
); /* symbol type */
1397 nasm_write(&sym
->sect
, 1, ofile
); /* section */
1398 fwriteint16_t(sym
->desc
, ofile
); /* description */
1400 /* Fix up the symbol value now that we know the final section
1402 if (((sym
->type
& N_TYPE
) == N_SECT
) && (sym
->sect
!= NO_SECT
)) {
1403 nasm_assert(sym
->sect
<= seg_nsects
);
1404 sym
->symv
.key
+= sectstab
[sym
->sect
]->addr
;
1407 fwriteptr(sym
->symv
.key
, ofile
); /* value (i.e. offset) */
1412 /* Fixup the snum in the relocation entries, we should be
1413 doing this only for externally referenced symbols. */
1414 static void macho_fixup_relocs (struct reloc
*r
)
1420 for (sym
= syms
; sym
!= NULL
; sym
= sym
->next
) {
1421 if (sym
->initial_snum
== r
->snum
) {
1422 r
->snum
= sym
->snum
;
1431 /* Write out the object file. */
1433 static void macho_write (void)
1435 uint64_t offset
= 0;
1437 /* mach-o object file structure:
1443 ** uint32_t mach file type
1444 ** uint32_t number of load commands
1445 ** uint32_t size of all load commands
1446 ** (includes section struct size of segment command)
1450 ** uint32_t command type == LC_SEGMENT[_64]
1451 ** uint32_t size of load command
1452 ** (including section load commands)
1453 ** char[16] segment name
1454 ** pointer in-memory offset
1455 ** pointer in-memory size
1456 ** pointer in-file offset to data area
1457 ** pointer in-file size
1458 ** (in-memory size excluding zerofill sections)
1459 ** int maximum vm protection
1460 ** int initial vm protection
1461 ** uint32_t number of sections
1465 ** char[16] section name
1466 ** char[16] segment name
1467 ** pointer in-memory offset
1468 ** pointer in-memory size
1469 ** uint32_t in-file offset
1470 ** uint32_t alignment
1471 ** (irrelevant in MH_OBJECT)
1472 ** uint32_t in-file offset of relocation entires
1473 ** uint32_t number of relocations
1475 ** uint32_t reserved
1476 ** uint32_t reserved
1478 ** symbol table command
1479 ** uint32_t command type == LC_SYMTAB
1480 ** uint32_t size of load command
1481 ** uint32_t symbol table offset
1482 ** uint32_t number of symbol table entries
1483 ** uint32_t string table offset
1484 ** uint32_t string table size
1488 ** padding to pointer boundary
1490 ** relocation data (struct reloc)
1492 ** uint data (symbolnum, pcrel, length, extern, type)
1494 ** symbol table data (struct nlist)
1495 ** int32_t string table entry number
1497 ** (extern, absolute, defined in section)
1499 ** (0 for global symbols, section number of definition (>= 1, <=
1500 ** 254) for local symbols, size of variable for common symbols
1501 ** [type == extern])
1502 ** int16_t description
1503 ** (for stab debugging format)
1504 ** pointer value (i.e. file offset) of symbol or stab offset
1506 ** string table data
1507 ** list of null-terminated strings
1510 /* Emit the Mach-O header. */
1511 macho_write_header();
1513 offset
= fmt
.header_size
+ head_sizeofcmds
;
1515 /* emit the segment load command */
1517 offset
= macho_write_segment (offset
);
1519 nasm_error(ERR_WARNING
, "no sections?");
1522 /* write out symbol command */
1523 fwriteint32_t(LC_SYMTAB
, ofile
); /* cmd == LC_SYMTAB */
1524 fwriteint32_t(MACHO_SYMCMD_SIZE
, ofile
); /* size of load command */
1525 fwriteint32_t(offset
, ofile
); /* symbol table offset */
1526 fwriteint32_t(nsyms
, ofile
); /* number of symbol
1528 offset
+= nsyms
* fmt
.nlist_size
;
1529 fwriteint32_t(offset
, ofile
); /* string table offset */
1530 fwriteint32_t(strslen
, ofile
); /* string table size */
1533 /* emit section data */
1535 macho_write_section ();
1537 /* emit symbol table if we have symbols */
1539 macho_write_symtab ();
1541 /* we don't need to pad here, we are already aligned */
1543 /* emit string table */
1544 saa_fpwrite(strs
, ofile
);
1546 /* We do quite a bit here, starting with finalizing all of the data
1547 for the object file, writing, and then freeing all of the data from
1550 static void macho_cleanup(void)
1556 /* Sort all symbols. */
1557 macho_layout_symbols (&nsyms
, &strslen
);
1559 /* Fixup relocation entries */
1560 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1561 macho_fixup_relocs (s
->relocs
);
1564 /* First calculate and finalize needed values. */
1565 macho_calculate_sizes();
1568 /* free up everything */
1569 while (sects
->next
) {
1571 sects
= sects
->next
;
1574 while (s
->relocs
!= NULL
) {
1576 s
->relocs
= s
->relocs
->next
;
1592 nasm_free(extdefsyms
);
1593 nasm_free(undefsyms
);
1594 nasm_free(sectstab
);
1598 static const struct macho_fmt macho32_fmt
= {
1608 GENERIC_RELOC_VANILLA
,
1609 GENERIC_RELOC_VANILLA
,
1613 static void macho32_init(void)
1618 macho_gotpcrel_sect
= NO_SEG
;
1621 struct ofmt of_macho32
= {
1622 "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files",
1643 static const struct macho_fmt macho64_fmt
= {
1648 MACHO_HEADER64_SIZE
,
1649 MACHO_SEGCMD64_SIZE
,
1650 MACHO_SECTCMD64_SIZE
,
1653 X86_64_RELOC_UNSIGNED
,
1654 X86_64_RELOC_SIGNED
,
1658 static void macho64_init(void)
1663 /* add special symbol for ..gotpcrel */
1664 macho_gotpcrel_sect
= seg_alloc() + 1;
1665 define_label("..gotpcrel", macho_gotpcrel_sect
, 0L, NULL
, false, false);
1668 struct ofmt of_macho64
= {
1669 "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files",