#include "compiler.h"
#include "nctype.h"
#include "nasm.h"
#include "nasmlib.h"
#include "ilog2.h"
#include "labels.h"
#include "error.h"
#include "saa.h"
#include "raa.h"
#include "rbtree.h"
#include "hashtbl.h"
#include "outform.h"
#include "outlib.h"
#include "ver.h"
#include "dwarf.h"
#include "macho.h"
#if defined(OF_MACHO) || defined(OF_MACHO64)
#define MACHO_HEADER_SIZE …
#define MACHO_SEGCMD_SIZE …
#define MACHO_SECTCMD_SIZE …
#define MACHO_SYMCMD_SIZE …
#define MACHO_NLIST_SIZE …
#define MACHO_RELINFO_SIZE …
#define MACHO_BUILDVERSION_SIZE …
#define MACHO_HEADER64_SIZE …
#define MACHO_SEGCMD64_SIZE …
#define MACHO_SECTCMD64_SIZE …
#define MACHO_NLIST64_SIZE …
#define VM_PROT_DEFAULT …
#define VM_PROT_ALL …
enum reltype { … };
#define RL_MAX_32 …
#define RL_MAX_64 …
struct macho_fmt { … };
static struct macho_fmt fmt;
static void fwriteptr(uint64_t data, FILE * fp)
{ … }
struct section { … };
#define S_NASM_TYPE_MASK …
static struct section absolute_sect;
struct reloc { … };
struct symbol { … };
#define DEFAULT_SECTION_ALIGNMENT …
static struct section *sects, **sectstail, **sectstab;
static struct symbol *syms, **symstail;
static uint32_t nsyms;
static uint32_t ilocalsym = …;
static uint32_t iextdefsym = …;
static uint32_t iundefsym = …;
static uint32_t nlocalsym;
static uint32_t nextdefsym;
static uint32_t nundefsym;
static struct symbol **extdefsyms = …;
static struct symbol **undefsyms = …;
static struct RAA *extsyms;
static struct SAA *strs;
static uint32_t strslen;
static uint32_t head_ncmds = …;
static uint32_t head_sizeofcmds = …;
static uint32_t head_flags = …;
static uint64_t seg_filesize = …;
static uint64_t seg_vmsize = …;
static uint32_t seg_nsects = …;
static uint64_t rel_padcnt = …;
static uint32_t build_version_platform = …;
static uint32_t build_version_minos = …;
bool macho_set_min_os(const char *str);
#define xstrncpy(xdst, xsrc) …
#define xstrncmp(xdst, xsrc) …
#define alignint32_t(x) …
#define alignint64_t(x) …
#define alignptr(x) …
static struct hash_table section_by_name;
static struct RAA *section_by_index;
static struct section * never_null
find_or_add_section(const char *segname, const char *sectname)
{ … }
static inline bool is_new_section(const struct section *s)
{ … }
static struct section *get_section_by_name(const char *segname,
const char *sectname)
{ … }
static struct section *get_section_by_index(int32_t index)
{ … }
struct dir_list { … };
struct file_list { … };
struct dw_sect_list { … };
struct section_info { … };
#define DW_LN_BASE …
#define DW_LN_RANGE …
#define DW_OPCODE_BASE …
#define DW_MAX_LN …
#define DW_MAX_SP_OPCODE …
static struct file_list *dw_head_file = …, *dw_cur_file = …, **dw_last_file_next = …;
static struct dir_list *dw_head_dir = …, **dw_last_dir_next = …;
static struct dw_sect_list *dw_head_sect = …, *dw_cur_sect = …, *dw_last_sect = …;
static uint32_t cur_line = …, dw_num_files = …, dw_num_dirs = …, dw_num_sects = …;
static bool dbg_immcall = …;
static const char *module_name = …;
static int32_t macho_tlvp_sect;
static int32_t macho_gotpcrel_sect;
static void macho_init(void)
{ … }
static void sect_write(struct section *sect,
const uint8_t *data, uint32_t len)
{ … }
static struct symbol *macho_find_sym(struct section *s, uint64_t offset,
bool global, bool exact)
{ … }
static int64_t add_reloc(struct section *sect, int32_t section,
int64_t offset,
enum reltype reltype, int bytes)
{ … }
static void macho_output(int32_t secto, const void *data,
enum out_type type, uint64_t size,
int32_t section, int32_t wrt)
{ … }
#define S_CODE …
#define NO_TYPE …
static const struct macho_known_section { … } known_sections[] = …;
static const struct macho_known_section_attr { … } sect_attribs[] = …;
static const struct macho_known_section *
lookup_known_section(const char *name, bool by_sectname)
{ … }
static int32_t macho_section(char *name, int *bits)
{ … }
static int32_t macho_herelabel(const char *name, enum label_type type,
int32_t section, int32_t *subsection,
bool *copyoffset)
{ … }
static void macho_symdef(char *name, int32_t section, int64_t offset,
int is_global, char *special)
{ … }
static void macho_sectalign(int32_t seg, unsigned int value)
{ … }
extern macros_t macho_stdmac[];
static int layout_compare (const struct symbol **s1,
const struct symbol **s2)
{ … }
static void macho_layout_symbols (uint32_t *numsyms,
uint32_t *strtabsize)
{ … }
static void macho_calculate_sizes (void)
{ … }
static void macho_write_header (void)
{ … }
static uint32_t macho_write_segment (uint64_t offset)
{ … }
static void macho_write_relocs (struct reloc *r)
{ … }
static void macho_write_section (void)
{ … }
static void macho_write_symtab (void)
{ … }
static void macho_fixup_relocs (struct reloc *r)
{ … }
static void macho_write (void)
{ … }
static void macho_cleanup(void)
{ … }
static bool macho_set_section_attribute_by_symbol(const char *label, uint32_t flags)
{ … }
static enum directive_result macho_no_dead_strip(const char *labels)
{ … }
static enum directive_result
macho_pragma(const struct pragma *pragma)
{ … }
static const struct pragma_facility macho_pragma_list[] = …;
static void macho_dbg_generate(void)
{ … }
static void new_file_list (const char *file_name, const char *dir_name)
{ … }
static void macho_dbg_init(void)
{ … }
static void macho_dbg_linenum(const char *file_name, int32_t line_num, int32_t segto)
{ … }
static void macho_dbg_output(int type, void *param)
{ … }
static void macho_dbg_cleanup(void)
{ … }
#ifdef OF_MACHO32
static const struct macho_fmt macho32_fmt = …;
static void macho32_init(void)
{ … }
static const struct dfmt macho32_df_dwarf = …;
static const struct dfmt * const macho32_df_arr[2] = …;
const struct ofmt of_macho32 = …;
#endif
#ifdef OF_MACHO64
static const struct macho_fmt macho64_fmt = …;
static void macho64_init(void)
{ … }
static const struct dfmt macho64_df_dwarf = …;
static const struct dfmt * const macho64_df_arr[2] = …;
bool macho_set_min_os(const char *str) { … }
const struct ofmt of_macho64 = …;
#endif
#endif