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
;
472 adjust
= -sect
->size
;
478 r
->type
= X86_64_RELOC_SUBTRACTOR
;
482 r
->type
= X86_64_RELOC_GOT
;
486 r
->type
= X86_64_RELOC_GOT_LOAD
;
490 r
->type
= fmt
.reloc_tlv
;
495 if (section
== NO_SEG
) {
496 nasm_error(ERR_NONFATAL
, "Unsupported use of use of WRT");
497 } else if (fi
== NO_SECT
) {
499 r
->snum
= raa_read(extsyms
, section
);
502 struct symbol
*sym
= macho_find_gsym(s
, offset
, reltype
!= RL_TLV
);
505 r
->snum
= sym
->initial_snum
;
510 /* NeXT as puts relocs in reversed order (address-wise) into the
511 ** files, so we do the same, doesn't seem to make much of a
512 ** difference either way */
513 r
->next
= sect
->relocs
;
526 static void macho_output(int32_t secto
, const void *data
,
527 enum out_type type
, uint64_t size
,
528 int32_t section
, int32_t wrt
)
531 int64_t addr
, offset
;
532 uint8_t mydata
[16], *p
;
534 enum reltype reltype
;
536 if (secto
== NO_SEG
) {
537 if (type
!= OUT_RESERVE
)
538 nasm_error(ERR_NONFATAL
, "attempt to assemble code in "
543 s
= get_section_by_index(secto
);
546 nasm_error(ERR_WARNING
, "attempt to assemble code in"
547 " section %d: defaulting to `.text'", secto
);
548 s
= get_section_by_name("__TEXT", "__text");
550 /* should never happen */
552 nasm_panic(0, "text section not found");
555 is_bss
= (s
->flags
& SECTION_TYPE
) == S_ZEROFILL
;
557 if (is_bss
&& type
!= OUT_RESERVE
) {
558 nasm_error(ERR_WARNING
, "attempt to initialize memory in "
559 "BSS section: ignored");
560 s
->size
+= realsize(type
, size
);
564 memset(mydata
, 0, sizeof(mydata
));
569 nasm_error(ERR_WARNING
, "uninitialized space declared in"
570 " %s,%s section: zeroing", s
->segname
, s
->sectname
);
572 sect_write(s
, NULL
, size
);
579 if (section
!= NO_SEG
)
580 nasm_panic(0, "OUT_RAWDATA with other than NO_SEG");
582 sect_write(s
, data
, size
);
587 int asize
= abs((int)size
);
589 addr
= *(int64_t *)data
;
590 if (section
!= NO_SEG
) {
592 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
593 " section base references");
594 } else if (wrt
== NO_SEG
) {
595 if (fmt
.ptrsize
== 8 && asize
!= 8) {
596 nasm_error(ERR_NONFATAL
,
597 "Mach-O 64-bit format does not support"
598 " 32-bit absolute addresses");
600 add_reloc(s
, section
, addr
, RL_ABS
, asize
);
603 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
609 WRITEADDR(p
, addr
, asize
);
610 sect_write(s
, mydata
, asize
);
615 nasm_assert(section
!= secto
);
618 offset
= *(int64_t *)data
;
619 addr
= offset
- size
;
621 if (section
!= NO_SEG
&& section
% 2) {
622 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
623 " section base references");
624 } else if (fmt
.ptrsize
== 8) {
625 nasm_error(ERR_NONFATAL
, "Unsupported non-32-bit"
626 " Macho-O relocation [2]");
627 } else if (wrt
!= NO_SEG
) {
628 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
630 wrt
= NO_SEG
; /* we can at least _try_ to continue */
632 addr
+= add_reloc(s
, section
, addr
+size
, RL_REL
, 2);
636 sect_write(s
, mydata
, 2);
640 nasm_assert(section
!= secto
);
643 offset
= *(int64_t *)data
;
644 addr
= offset
- size
;
647 if (section
!= NO_SEG
&& section
% 2) {
648 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
649 " section base references");
650 } else if (wrt
== NO_SEG
) {
651 if (fmt
.ptrsize
== 8 &&
652 (s
->flags
& S_ATTR_SOME_INSTRUCTIONS
)) {
655 opcode
[0] = opcode
[1] = 0;
657 /* HACK: Retrieve instruction opcode */
658 if (likely(s
->data
->datalen
>= 2)) {
659 saa_fread(s
->data
, s
->data
->datalen
-2, opcode
, 2);
660 } else if (s
->data
->datalen
== 1) {
661 saa_fread(s
->data
, 0, opcode
+1, 1);
664 if ((opcode
[0] != 0x0f && (opcode
[1] & 0xfe) == 0xe8) ||
665 (opcode
[0] == 0x0f && (opcode
[1] & 0xf0) == 0x80)) {
666 /* Direct call, jmp, or jcc */
670 } else if (wrt
== macho_gotpcrel_sect
) {
673 if ((s
->flags
& S_ATTR_SOME_INSTRUCTIONS
) &&
674 s
->data
->datalen
>= 3) {
677 /* HACK: Retrieve instruction opcode */
678 saa_fread(s
->data
, s
->data
->datalen
-3, gotload
, 3);
679 if ((gotload
[0] & 0xf8) == 0x48 &&
680 gotload
[1] == 0x8b &&
681 (gotload
[2] & 0307) == 0005) {
682 /* movq <reg>,[rel sym wrt ..gotpcrel] */
683 reltype
= RL_GOTLOAD
;
686 } else if (wrt
== macho_tlvp_sect
) {
689 nasm_error(ERR_NONFATAL
, "Mach-O format does not support"
691 /* continue with RL_REL */
694 addr
+= add_reloc(s
, section
, offset
, reltype
, 4);
696 sect_write(s
, mydata
, 4);
700 nasm_error(ERR_NONFATAL
, "Unrepresentable relocation in Mach-O");
705 static int32_t macho_section(char *name
, int pass
, int *bits
)
707 char *sectionAttributes
;
708 const struct sectmap
*sm
;
710 const char *section
, *segment
;
712 char *currentAttribute
;
718 /* Default to the appropriate number of bits. */
720 *bits
= fmt
.ptrsize
<< 3;
722 sectionAttributes
= NULL
;
724 sectionAttributes
= name
;
725 name
= nasm_strsep(§ionAttributes
, " \t");
728 section
= segment
= NULL
;
731 comma
= strchr(name
, ',');
739 len
= strlen(segment
);
741 nasm_error(ERR_NONFATAL
, "empty segment name\n");
742 } else if (len
>= 16) {
743 nasm_error(ERR_NONFATAL
, "segment name %s too long\n", segment
);
746 len
= strlen(section
);
748 nasm_error(ERR_NONFATAL
, "empty section name\n");
749 } else if (len
>= 16) {
750 nasm_error(ERR_NONFATAL
, "section name %s too long\n", section
);
753 if (!strcmp(section
, "__text")) {
754 flags
= S_REGULAR
| S_ATTR_SOME_INSTRUCTIONS
|
755 S_ATTR_PURE_INSTRUCTIONS
;
756 } else if (!strcmp(section
, "__bss")) {
762 for (sm
= sectmap
; sm
->nasmsect
!= NULL
; ++sm
) {
763 /* make lookup into section name translation table */
764 if (!strcmp(name
, sm
->nasmsect
)) {
765 segment
= sm
->segname
;
766 section
= sm
->sectname
;
771 nasm_error(ERR_NONFATAL
, "unknown section name\n");
776 /* try to find section with that name */
777 s
= get_section_by_name(segment
, section
);
779 /* create it if it doesn't exist yet */
783 s
= *sectstail
= nasm_zalloc(sizeof(struct section
));
784 sectstail
= &s
->next
;
786 s
->data
= saa_init(1L);
787 s
->index
= seg_alloc();
788 s
->fileindex
= ++seg_nsects
;
794 xstrncpy(s
->segname
, segment
);
795 xstrncpy(s
->sectname
, section
);
804 *comma
= ','; /* Restore comma */
806 s
->by_name
= s
->by_name
|| comma
; /* Was specified by name */
808 flags
= (uint32_t)-1;
810 while ((NULL
!= sectionAttributes
)
811 && (currentAttribute
= nasm_strsep(§ionAttributes
, " \t"))) {
812 if (0 != *currentAttribute
) {
813 if (!nasm_strnicmp("align=", currentAttribute
, 6)) {
815 int newAlignment
, value
;
817 value
= strtoul(currentAttribute
+ 6, (char**)&end
, 0);
818 newAlignment
= alignlog2_32(value
);
821 nasm_error(ERR_NONFATAL
,
822 "unknown or missing alignment value \"%s\" "
823 "specified for section \"%s\"",
824 currentAttribute
+ 6,
826 } else if (0 > newAlignment
) {
827 nasm_error(ERR_NONFATAL
,
828 "alignment of %d (for section \"%s\") is not "
834 if (s
->align
< newAlignment
)
835 s
->align
= newAlignment
;
836 } else if (!nasm_stricmp("data", currentAttribute
)) {
838 } else if (!nasm_stricmp("code", currentAttribute
) ||
839 !nasm_stricmp("text", currentAttribute
)) {
840 flags
= S_REGULAR
| S_ATTR_SOME_INSTRUCTIONS
|
841 S_ATTR_PURE_INSTRUCTIONS
;
842 } else if (!nasm_stricmp("mixed", currentAttribute
)) {
843 flags
= S_REGULAR
| S_ATTR_SOME_INSTRUCTIONS
;
844 } else if (!nasm_stricmp("bss", currentAttribute
)) {
847 nasm_error(ERR_NONFATAL
,
848 "unknown section attribute %s for section %s",
854 if (flags
!= (uint32_t)-1) {
855 if (!new_seg
&& s
->flags
!= flags
) {
856 nasm_error(ERR_NONFATAL
,
857 "inconsistent section attributes for section %s\n",
868 static void macho_symdef(char *name
, int32_t section
, int64_t offset
,
869 int is_global
, char *special
)
874 nasm_error(ERR_NONFATAL
, "The Mach-O output format does "
875 "not support any special symbol types");
879 if (is_global
== 3) {
880 nasm_error(ERR_NONFATAL
, "The Mach-O format does not "
881 "(yet) support forward reference fixups.");
885 if (name
[0] == '.' && name
[1] == '.' && name
[2] != '@') {
887 * This is a NASM special symbol. We never allow it into
888 * the Macho-O symbol table, even if it's a valid one. If it
889 * _isn't_ a valid one, we should barf immediately.
891 if (strcmp(name
, "..gotpcrel") && strcmp(name
, "..tlvp"))
892 nasm_error(ERR_NONFATAL
, "unrecognized special symbol `%s'", name
);
896 sym
= *symstail
= nasm_zalloc(sizeof(struct symbol
));
898 symstail
= &sym
->next
;
904 sym
->symv
.key
= offset
;
905 sym
->initial_snum
= -1;
907 /* external and common symbols get N_EXT */
908 if (is_global
!= 0) {
912 if (section
== NO_SEG
) {
913 /* symbols in no section get absolute */
917 /* all absolute symbols are available to use as references */
918 absolute_sect
.gsyms
= rb_insert(absolute_sect
.gsyms
, &sym
->symv
);
920 struct section
*s
= get_section_by_index(section
);
924 /* get the in-file index of the section the symbol was defined in */
925 sym
->sect
= s
? s
->fileindex
: NO_SECT
;
927 /* track the initially allocated symbol number for use in future fix-ups */
928 sym
->initial_snum
= nsyms
;
931 /* remember symbol number of references to external
932 ** symbols, this works because every external symbol gets
933 ** its own section number allocated internally by nasm and
934 ** can so be used as a key */
935 extsyms
= raa_write(extsyms
, section
, nsyms
);
940 /* there isn't actually a difference between global
941 ** and common symbols, both even have their size in
947 /* give an error on unfound section if it's not an
948 ** external or common symbol (assemble_file() does a
949 ** seg_alloc() on every call for them) */
950 nasm_panic(0, "in-file index for section %d not found, is_global = %d", section
, is_global
);
953 } else if (is_global
) {
954 s
->gsyms
= rb_insert(s
->gsyms
, &sym
->symv
);
960 static void macho_sectalign(int32_t seg
, unsigned int value
)
965 nasm_assert(!(seg
& 1));
967 s
= get_section_by_index(seg
);
969 if (!s
|| !is_power2(value
))
972 align
= alignlog2_32(value
);
973 if (s
->align
< align
)
977 static int32_t macho_segbase(int32_t section
)
982 static void macho_filename(char *inname
, char *outname
)
984 standard_extension(inname
, outname
, ".o");
987 extern macros_t macho_stdmac
[];
989 /* Comparison function for qsort symbol layout. */
990 static int layout_compare (const struct symbol
**s1
,
991 const struct symbol
**s2
)
993 return (strcmp ((*s1
)->name
, (*s2
)->name
));
996 /* The native assembler does a few things in a similar function
998 * Remove temporary labels
999 * Sort symbols according to local, external, undefined (by name)
1000 * Order the string table
1002 We do not remove temporary labels right now.
1004 numsyms is the total number of symbols we have. strtabsize is the
1005 number entries in the string table. */
1007 static void macho_layout_symbols (uint32_t *numsyms
,
1008 uint32_t *strtabsize
)
1010 struct symbol
*sym
, **symp
;
1014 *strtabsize
= sizeof (char);
1018 while ((sym
= *symp
)) {
1019 /* Undefined symbols are now external. */
1020 if (sym
->type
== N_UNDF
)
1023 if ((sym
->type
& N_EXT
) == 0) {
1024 sym
->snum
= *numsyms
;
1025 *numsyms
= *numsyms
+ 1;
1029 if ((sym
->type
& N_TYPE
) != N_UNDF
) {
1035 /* If we handle debug info we'll want
1036 to check for it here instead of just
1037 adding the symbol to the string table. */
1038 sym
->strx
= *strtabsize
;
1039 saa_wbytes (strs
, sym
->name
, (int32_t)(strlen(sym
->name
) + 1));
1040 *strtabsize
+= strlen(sym
->name
) + 1;
1042 symp
= &(sym
->next
);
1045 /* Next, sort the symbols. Most of this code is a direct translation from
1046 the Apple cctools symbol layout. We need to keep compatibility with that. */
1047 /* Set the indexes for symbol groups into the symbol table */
1049 iextdefsym
= nlocalsym
;
1050 iundefsym
= nlocalsym
+ nextdefsym
;
1052 /* allocate arrays for sorting externals by name */
1053 extdefsyms
= nasm_malloc(nextdefsym
* sizeof(struct symbol
*));
1054 undefsyms
= nasm_malloc(nundefsym
* sizeof(struct symbol
*));
1061 while ((sym
= *symp
)) {
1063 if((sym
->type
& N_EXT
) == 0) {
1064 sym
->strx
= *strtabsize
;
1065 saa_wbytes (strs
, sym
->name
, (int32_t)(strlen (sym
->name
) + 1));
1066 *strtabsize
+= strlen(sym
->name
) + 1;
1069 if((sym
->type
& N_TYPE
) != N_UNDF
) {
1070 extdefsyms
[i
++] = sym
;
1072 undefsyms
[j
++] = sym
;
1075 symp
= &(sym
->next
);
1078 qsort(extdefsyms
, nextdefsym
, sizeof(struct symbol
*),
1079 (int (*)(const void *, const void *))layout_compare
);
1080 qsort(undefsyms
, nundefsym
, sizeof(struct symbol
*),
1081 (int (*)(const void *, const void *))layout_compare
);
1083 for(i
= 0; i
< nextdefsym
; i
++) {
1084 extdefsyms
[i
]->snum
= *numsyms
;
1087 for(j
= 0; j
< nundefsym
; j
++) {
1088 undefsyms
[j
]->snum
= *numsyms
;
1093 /* Calculate some values we'll need for writing later. */
1095 static void macho_calculate_sizes (void)
1100 /* count sections and calculate in-memory and in-file offsets */
1101 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1104 /* recalculate segment address based on alignment and vm size */
1105 s
->addr
= seg_vmsize
;
1107 /* we need section alignment to calculate final section address */
1109 s
->align
= DEFAULT_SECTION_ALIGNMENT
;
1111 newaddr
= ALIGN(s
->addr
, 1 << s
->align
);
1114 seg_vmsize
= newaddr
+ s
->size
;
1116 /* zerofill sections aren't actually written to the file */
1117 if ((s
->flags
& SECTION_TYPE
) != S_ZEROFILL
) {
1119 * LLVM/Xcode as always aligns the section data to 4
1120 * bytes; there is a comment in the LLVM source code that
1121 * perhaps aligning to pointer size would be better.
1123 s
->pad
= ALIGN(seg_filesize
, 4) - seg_filesize
;
1124 s
->offset
= seg_filesize
+ s
->pad
;
1125 seg_filesize
+= s
->size
+ s
->pad
;
1129 /* calculate size of all headers, load commands and sections to
1130 ** get a pointer to the start of all the raw data */
1131 if (seg_nsects
> 0) {
1133 head_sizeofcmds
+= fmt
.segcmd_size
+ seg_nsects
* fmt
.sectcmd_size
;
1138 head_sizeofcmds
+= MACHO_SYMCMD_SIZE
;
1141 if (seg_nsects
> MAX_SECT
) {
1142 nasm_fatal(0, "MachO output is limited to %d sections\n",
1146 /* Create a table of sections by file index to avoid linear search */
1147 sectstab
= nasm_malloc((seg_nsects
+ 1) * sizeof(*sectstab
));
1148 sectstab
[NO_SECT
] = &absolute_sect
;
1149 for (s
= sects
, fi
= 1; s
!= NULL
; s
= s
->next
, fi
++)
1153 /* Write out the header information for the file. */
1155 static void macho_write_header (void)
1157 fwriteint32_t(fmt
.mh_magic
, ofile
); /* magic */
1158 fwriteint32_t(fmt
.cpu_type
, ofile
); /* CPU type */
1159 fwriteint32_t(CPU_SUBTYPE_I386_ALL
, ofile
); /* CPU subtype */
1160 fwriteint32_t(MH_OBJECT
, ofile
); /* Mach-O file type */
1161 fwriteint32_t(head_ncmds
, ofile
); /* number of load commands */
1162 fwriteint32_t(head_sizeofcmds
, ofile
); /* size of load commands */
1163 fwriteint32_t(0, ofile
); /* no flags */
1164 fwritezero(fmt
.header_size
- 7*4, ofile
); /* reserved fields */
1167 /* Write out the segment load command at offset. */
1169 static uint32_t macho_write_segment (uint64_t offset
)
1171 uint64_t rel_base
= alignptr(offset
+ seg_filesize
);
1172 uint32_t s_reloff
= 0;
1175 fwriteint32_t(fmt
.lc_segment
, ofile
); /* cmd == LC_SEGMENT_64 */
1177 /* size of load command including section load commands */
1178 fwriteint32_t(fmt
.segcmd_size
+ seg_nsects
* fmt
.sectcmd_size
,
1181 /* in an MH_OBJECT file all sections are in one unnamed (name
1182 ** all zeros) segment */
1183 fwritezero(16, ofile
);
1184 fwriteptr(0, ofile
); /* in-memory offset */
1185 fwriteptr(seg_vmsize
, ofile
); /* in-memory size */
1186 fwriteptr(offset
, ofile
); /* in-file offset to data */
1187 fwriteptr(seg_filesize
, ofile
); /* in-file size */
1188 fwriteint32_t(VM_PROT_DEFAULT
, ofile
); /* maximum vm protection */
1189 fwriteint32_t(VM_PROT_DEFAULT
, ofile
); /* initial vm protection */
1190 fwriteint32_t(seg_nsects
, ofile
); /* number of sections */
1191 fwriteint32_t(0, ofile
); /* no flags */
1193 /* emit section headers */
1194 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1196 nasm_assert((s
->flags
& SECTION_TYPE
) != S_ZEROFILL
);
1197 s
->flags
|= S_ATTR_LOC_RELOC
;
1199 s
->flags
|= S_ATTR_EXT_RELOC
;
1200 } else if (!strcmp(s
->segname
, "__DATA") &&
1201 !strcmp(s
->sectname
, "__const") &&
1203 !get_section_by_name("__TEXT", "__const")) {
1205 * The MachO equivalent to .rodata can be either
1206 * __DATA,__const or __TEXT,__const; the latter only if
1207 * there are no relocations. However, when mixed it is
1208 * better to specify the segments explicitly.
1210 xstrncpy(s
->segname
, "__TEXT");
1213 nasm_write(s
->sectname
, sizeof(s
->sectname
), ofile
);
1214 nasm_write(s
->segname
, sizeof(s
->segname
), ofile
);
1215 fwriteptr(s
->addr
, ofile
);
1216 fwriteptr(s
->size
, ofile
);
1218 /* dummy data for zerofill sections or proper values */
1219 if ((s
->flags
& SECTION_TYPE
) != S_ZEROFILL
) {
1220 nasm_assert(s
->pad
!= (uint32_t)-1);
1222 fwriteint32_t(offset
, ofile
);
1224 /* Write out section alignment, as a power of two.
1225 e.g. 32-bit word alignment would be 2 (2^2 = 4). */
1226 fwriteint32_t(s
->align
, ofile
);
1227 /* To be compatible with cctools as we emit
1228 a zero reloff if we have no relocations. */
1229 fwriteint32_t(s
->nreloc
? rel_base
+ s_reloff
: 0, ofile
);
1230 fwriteint32_t(s
->nreloc
, ofile
);
1232 s_reloff
+= s
->nreloc
* MACHO_RELINFO_SIZE
;
1234 fwriteint32_t(0, ofile
);
1235 fwriteint32_t(s
->align
, ofile
);
1236 fwriteint32_t(0, ofile
);
1237 fwriteint32_t(0, ofile
);
1240 fwriteint32_t(s
->flags
, ofile
); /* flags */
1241 fwriteint32_t(0, ofile
); /* reserved */
1242 fwriteptr(0, ofile
); /* reserved */
1245 rel_padcnt
= rel_base
- offset
;
1246 offset
= rel_base
+ s_reloff
;
1251 /* For a given chain of relocs r, write out the entire relocation
1252 chain to the object file. */
1254 static void macho_write_relocs (struct reloc
*r
)
1259 fwriteint32_t(r
->addr
, ofile
); /* reloc offset */
1262 word2
|= r
->pcrel
<< 24;
1263 word2
|= r
->length
<< 25;
1264 word2
|= r
->ext
<< 27;
1265 word2
|= r
->type
<< 28;
1266 fwriteint32_t(word2
, ofile
); /* reloc data */
1271 /* Write out the section data. */
1272 static void macho_write_section (void)
1284 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1285 if ((s
->flags
& SECTION_TYPE
) == S_ZEROFILL
)
1288 /* Like a.out Mach-O references things in the data or bss
1289 * sections by addresses which are actually relative to the
1290 * start of the _text_ section, in the _file_. See outaout.c
1291 * for more information. */
1292 saa_rewind(s
->data
);
1293 for (r
= s
->relocs
; r
!= NULL
; r
= r
->next
) {
1294 len
= (uint32_t)1 << r
->length
;
1295 if (len
> 4) /* Can this ever be an issue?! */
1298 saa_fread(s
->data
, r
->addr
, blk
.buf
, len
);
1300 /* get offset based on relocation type */
1301 #ifdef WORDS_LITTLEENDIAN
1305 l
+= ((int64_t)blk
.buf
[1]) << 8;
1306 l
+= ((int64_t)blk
.buf
[2]) << 16;
1307 l
+= ((int64_t)blk
.buf
[3]) << 24;
1308 l
+= ((int64_t)blk
.buf
[4]) << 32;
1309 l
+= ((int64_t)blk
.buf
[5]) << 40;
1310 l
+= ((int64_t)blk
.buf
[6]) << 48;
1311 l
+= ((int64_t)blk
.buf
[7]) << 56;
1314 /* If the relocation is internal add to the current section
1315 offset. Otherwise the only value we need is the symbol
1316 offset which we already have. The linker takes care
1317 of the rest of the address. */
1319 /* generate final address by section address and offset */
1320 nasm_assert(r
->snum
<= seg_nsects
);
1321 l
+= sectstab
[r
->snum
]->addr
;
1326 /* write new offset back */
1329 saa_fwrite(s
->data
, r
->addr
, blk
.buf
, len
);
1332 /* dump the section data to file */
1333 fwritezero(s
->pad
, ofile
);
1334 saa_fpwrite(s
->data
, ofile
);
1337 /* pad last section up to reloc entries on pointer boundary */
1338 fwritezero(rel_padcnt
, ofile
);
1340 /* emit relocation entries */
1341 for (s
= sects
; s
!= NULL
; s
= s
->next
)
1342 macho_write_relocs (s
->relocs
);
1345 /* Write out the symbol table. We should already have sorted this
1347 static void macho_write_symtab (void)
1352 /* we don't need to pad here since MACHO_RELINFO_SIZE == 8 */
1354 for (sym
= syms
; sym
!= NULL
; sym
= sym
->next
) {
1355 if ((sym
->type
& N_EXT
) == 0) {
1356 fwriteint32_t(sym
->strx
, ofile
); /* string table entry number */
1357 nasm_write(&sym
->type
, 1, ofile
); /* symbol type */
1358 nasm_write(&sym
->sect
, 1, ofile
); /* section */
1359 fwriteint16_t(sym
->desc
, ofile
); /* description */
1361 /* Fix up the symbol value now that we know the final section
1363 if (((sym
->type
& N_TYPE
) == N_SECT
) && (sym
->sect
!= NO_SECT
)) {
1364 nasm_assert(sym
->sect
<= seg_nsects
);
1365 sym
->symv
.key
+= sectstab
[sym
->sect
]->addr
;
1368 fwriteptr(sym
->symv
.key
, ofile
); /* value (i.e. offset) */
1372 for (i
= 0; i
< nextdefsym
; i
++) {
1373 sym
= extdefsyms
[i
];
1374 fwriteint32_t(sym
->strx
, ofile
);
1375 nasm_write(&sym
->type
, 1, ofile
); /* symbol type */
1376 nasm_write(&sym
->sect
, 1, ofile
); /* section */
1377 fwriteint16_t(sym
->desc
, ofile
); /* description */
1379 /* Fix up the symbol value now that we know the final section
1381 if (((sym
->type
& N_TYPE
) == N_SECT
) && (sym
->sect
!= NO_SECT
)) {
1382 nasm_assert(sym
->sect
<= seg_nsects
);
1383 sym
->symv
.key
+= sectstab
[sym
->sect
]->addr
;
1386 fwriteptr(sym
->symv
.key
, ofile
); /* value (i.e. offset) */
1389 for (i
= 0; i
< nundefsym
; i
++) {
1391 fwriteint32_t(sym
->strx
, ofile
);
1392 nasm_write(&sym
->type
, 1, ofile
); /* symbol type */
1393 nasm_write(&sym
->sect
, 1, ofile
); /* section */
1394 fwriteint16_t(sym
->desc
, ofile
); /* description */
1396 /* Fix up the symbol value now that we know the final section
1398 if (((sym
->type
& N_TYPE
) == N_SECT
) && (sym
->sect
!= NO_SECT
)) {
1399 nasm_assert(sym
->sect
<= seg_nsects
);
1400 sym
->symv
.key
+= sectstab
[sym
->sect
]->addr
;
1403 fwriteptr(sym
->symv
.key
, ofile
); /* value (i.e. offset) */
1408 /* Fixup the snum in the relocation entries, we should be
1409 doing this only for externally referenced symbols. */
1410 static void macho_fixup_relocs (struct reloc
*r
)
1416 for (sym
= syms
; sym
!= NULL
; sym
= sym
->next
) {
1417 if (sym
->initial_snum
== r
->snum
) {
1418 r
->snum
= sym
->snum
;
1427 /* Write out the object file. */
1429 static void macho_write (void)
1431 uint64_t offset
= 0;
1433 /* mach-o object file structure:
1439 ** uint32_t mach file type
1440 ** uint32_t number of load commands
1441 ** uint32_t size of all load commands
1442 ** (includes section struct size of segment command)
1446 ** uint32_t command type == LC_SEGMENT[_64]
1447 ** uint32_t size of load command
1448 ** (including section load commands)
1449 ** char[16] segment name
1450 ** pointer in-memory offset
1451 ** pointer in-memory size
1452 ** pointer in-file offset to data area
1453 ** pointer in-file size
1454 ** (in-memory size excluding zerofill sections)
1455 ** int maximum vm protection
1456 ** int initial vm protection
1457 ** uint32_t number of sections
1461 ** char[16] section name
1462 ** char[16] segment name
1463 ** pointer in-memory offset
1464 ** pointer in-memory size
1465 ** uint32_t in-file offset
1466 ** uint32_t alignment
1467 ** (irrelevant in MH_OBJECT)
1468 ** uint32_t in-file offset of relocation entires
1469 ** uint32_t number of relocations
1471 ** uint32_t reserved
1472 ** uint32_t reserved
1474 ** symbol table command
1475 ** uint32_t command type == LC_SYMTAB
1476 ** uint32_t size of load command
1477 ** uint32_t symbol table offset
1478 ** uint32_t number of symbol table entries
1479 ** uint32_t string table offset
1480 ** uint32_t string table size
1484 ** padding to pointer boundary
1486 ** relocation data (struct reloc)
1488 ** uint data (symbolnum, pcrel, length, extern, type)
1490 ** symbol table data (struct nlist)
1491 ** int32_t string table entry number
1493 ** (extern, absolute, defined in section)
1495 ** (0 for global symbols, section number of definition (>= 1, <=
1496 ** 254) for local symbols, size of variable for common symbols
1497 ** [type == extern])
1498 ** int16_t description
1499 ** (for stab debugging format)
1500 ** pointer value (i.e. file offset) of symbol or stab offset
1502 ** string table data
1503 ** list of null-terminated strings
1506 /* Emit the Mach-O header. */
1507 macho_write_header();
1509 offset
= fmt
.header_size
+ head_sizeofcmds
;
1511 /* emit the segment load command */
1513 offset
= macho_write_segment (offset
);
1515 nasm_error(ERR_WARNING
, "no sections?");
1518 /* write out symbol command */
1519 fwriteint32_t(LC_SYMTAB
, ofile
); /* cmd == LC_SYMTAB */
1520 fwriteint32_t(MACHO_SYMCMD_SIZE
, ofile
); /* size of load command */
1521 fwriteint32_t(offset
, ofile
); /* symbol table offset */
1522 fwriteint32_t(nsyms
, ofile
); /* number of symbol
1524 offset
+= nsyms
* fmt
.nlist_size
;
1525 fwriteint32_t(offset
, ofile
); /* string table offset */
1526 fwriteint32_t(strslen
, ofile
); /* string table size */
1529 /* emit section data */
1531 macho_write_section ();
1533 /* emit symbol table if we have symbols */
1535 macho_write_symtab ();
1537 /* we don't need to pad here, we are already aligned */
1539 /* emit string table */
1540 saa_fpwrite(strs
, ofile
);
1542 /* We do quite a bit here, starting with finalizing all of the data
1543 for the object file, writing, and then freeing all of the data from
1546 static void macho_cleanup(void)
1552 /* Sort all symbols. */
1553 macho_layout_symbols (&nsyms
, &strslen
);
1555 /* Fixup relocation entries */
1556 for (s
= sects
; s
!= NULL
; s
= s
->next
) {
1557 macho_fixup_relocs (s
->relocs
);
1560 /* First calculate and finalize needed values. */
1561 macho_calculate_sizes();
1564 /* free up everything */
1565 while (sects
->next
) {
1567 sects
= sects
->next
;
1570 while (s
->relocs
!= NULL
) {
1572 s
->relocs
= s
->relocs
->next
;
1588 nasm_free(extdefsyms
);
1589 nasm_free(undefsyms
);
1590 nasm_free(sectstab
);
1594 static const struct macho_fmt macho32_fmt
= {
1604 GENERIC_RELOC_VANILLA
,
1605 GENERIC_RELOC_VANILLA
,
1609 static void macho32_init(void)
1614 macho_gotpcrel_sect
= NO_SEG
;
1617 struct ofmt of_macho32
= {
1618 "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files",
1639 static const struct macho_fmt macho64_fmt
= {
1644 MACHO_HEADER64_SIZE
,
1645 MACHO_SEGCMD64_SIZE
,
1646 MACHO_SECTCMD64_SIZE
,
1649 X86_64_RELOC_UNSIGNED
,
1650 X86_64_RELOC_SIGNED
,
1654 static void macho64_init(void)
1659 /* add special symbol for ..gotpcrel */
1660 macho_gotpcrel_sect
= seg_alloc() + 1;
1661 define_label("..gotpcrel", macho_gotpcrel_sect
, 0L, NULL
, false, false);
1664 struct ofmt of_macho64
= {
1665 "NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files",