chromium/third_party/nasm/output/outmacho.c

/* ----------------------------------------------------------------------- *
 *
 *   Copyright 1996-2018 The NASM Authors - All Rights Reserved
 *   See the file AUTHORS included with the NASM distribution for
 *   the specific copyright holders.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following
 *   conditions are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *
 *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 *     CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 *     INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 *     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 *     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 *     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ----------------------------------------------------------------------- */

/*
 * outmacho.c	output routines for the Netwide Assembler to produce
 *		NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X object files
 */

#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)

/* Mach-O in-file header structure sizes */
#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

/* Mach-O relocations numbers */

#define VM_PROT_DEFAULT
#define VM_PROT_ALL

/* Our internal relocation types */
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

/* fake section for absolute symbols, *not* part of the section linked list */
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;

/* These variables are set by macho_layout_symbols() to organize
   the symbol table and string table in order the dynamic linker
   expects.  They are then used in macho_write() to put out the
   symbols and strings in that order.

   The order of the symbol table is:
     local symbols
     defined external symbols (sorted by name)
     undefined external symbols (sorted by name)

   The order of the string table is:
     strings for external symbols
     strings for local symbols
 */
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;

/* Global file information. This should be cleaned up into either
   a structure or as function arguments.  */
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 =;

/* build_version_platform information
   PLATFORM_INVALID implies that build_version_platform won't emitted. */
static uint32_t build_version_platform =;
/* X.Y.Z is encoded in nibbles xxxx.yy.zz */
static uint32_t build_version_minos =;

/* used in nasm.c */
bool macho_set_min_os(const char *str);

/*
 * Functions for handling fixed-length zero-padded string
 * fields, that may or may not be null-terminated.
 */

/* Copy a string into a zero-padded fixed-length field */
#define xstrncpy(xdst, xsrc)

/* Compare a fixed-length field with a string */
#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 =;

/*
 * Special section numbers which are used to define Mach-O special
 * symbols, which can be used with WRT to provide PIC relocation
 * types.
 */
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)
{}

/*
 * Find a suitable global symbol for a ..gotpcrel or ..tlvp reference
 */
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

/* Translation table from traditional Unix section names to Mach-O */
static const struct macho_known_section {} known_sections[] =;

/* Section type or attribute directives */
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[];

/* Comparison function for qsort symbol layout.  */
static int layout_compare (const struct symbol **s1,
			   const struct symbol **s2)
{}

/* The native assembler does a few things in a similar function

	* Remove temporary labels
	* Sort symbols according to local, external, undefined (by name)
	* Order the string table

   We do not remove temporary labels right now.

   numsyms is the total number of symbols we have. strtabsize is the
   number entries in the string table.  */

static void macho_layout_symbols (uint32_t *numsyms,
				  uint32_t *strtabsize)
{}

/* Calculate some values we'll need for writing later.  */

static void macho_calculate_sizes (void)
{}

/* Write out the header information for the file.  */

static void macho_write_header (void)
{}

/* Write out the segment load command at offset.  */

static uint32_t macho_write_segment (uint64_t offset)
{}

/* For a given chain of relocs r, write out the entire relocation
   chain to the object file.  */

static void macho_write_relocs (struct reloc *r)
{}

/* Write out the section data.  */
static void macho_write_section (void)
{}

/* Write out the symbol table. We should already have sorted this
   before now.  */
static void macho_write_symtab (void)
{}

/* Fixup the snum in the relocation entries, we should be
   doing this only for externally referenced symbols. */
static void macho_fixup_relocs (struct reloc *r)
{}

/* Write out the object file.  */

static void macho_write (void)
{}
/* We do quite a bit here, starting with finalizing all of the data
   for the object file, writing, and then freeing all of the data from
   the file.  */

static void macho_cleanup(void)
{}

static bool macho_set_section_attribute_by_symbol(const char *label, uint32_t flags)
{}

/*
 * Mark a symbol for no dead stripping
 */
static enum directive_result macho_no_dead_strip(const char *labels)
{}

/*
 * Mach-O pragmas
 */
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

/*
 * Local Variables:
 * mode:c
 * c-basic-offset:4
 * End:
 *
 * end of file */