diff --git a/tcc.h b/tcc.h index 82d8d977..50205a59 100644 --- a/tcc.h +++ b/tcc.h @@ -882,6 +882,10 @@ struct TCCState { # define ELF_OBJ_ONLY #endif +#ifdef TCC_TARGET_MACHO +# define ELF_OBJ_ONLY +#endif + #ifndef ELF_OBJ_ONLY int nb_sym_versions; struct sym_version *sym_versions; @@ -1524,7 +1528,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte); ST_FUNC void add_array(TCCState *s1, const char *sec, int c); -#ifndef ELF_OBJ_ONLY +#if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO) ST_FUNC void build_got_entries(TCCState *s1); #endif ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc); @@ -1556,7 +1560,7 @@ enum gotplt_entry { ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */ }; -#ifndef ELF_OBJ_ONLY +#if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO) ST_FUNC int code_reloc (int reloc_type); ST_FUNC int gotplt_entry_type (int reloc_type); ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr); diff --git a/tccelf.c b/tccelf.c index 558846c1..0c6087f1 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1065,7 +1065,9 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) #endif return count; } +#endif +#if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO) static void build_got(TCCState *s1) { /* if no got, then create it */ @@ -1270,15 +1272,6 @@ ST_FUNC void build_got_entries(TCCState *s1) } } } - -/* put dynamic tag */ -static void put_dt(Section *dynamic, int dt, addr_t val) -{ - ElfW(Dyn) *dyn; - dyn = section_ptr_add(dynamic, sizeof(ElfW(Dyn))); - dyn->d_tag = dt; - dyn->d_un.d_val = val; -} #endif ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, long offs) @@ -1978,6 +1971,15 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, } #ifndef ELF_OBJ_ONLY +/* put dynamic tag */ +static void put_dt(Section *dynamic, int dt, addr_t val) +{ + ElfW(Dyn) *dyn; + dyn = section_ptr_add(dynamic, sizeof(ElfW(Dyn))); + dyn->d_tag = dt; + dyn->d_un.d_val = val; +} + static void fill_unloadable_phdr(ElfW(Phdr) *phdr, int phnum, Section *interp, Section *dynamic) { diff --git a/tccrun.c b/tccrun.c index 183df102..8b7c9e44 100644 --- a/tccrun.c +++ b/tccrun.c @@ -271,7 +271,7 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff) if (s->reloc) relocate_section(s1, s); } -#ifndef TCC_TARGET_PE +#if !defined(TCC_TARGET_PE) || defined(TCC_TARGET_MACHO) relocate_plt(s1); #endif diff --git a/x86_64-link.c b/x86_64-link.c index 2dd4a50f..ceec8d0d 100644 --- a/x86_64-link.c +++ b/x86_64-link.c @@ -22,7 +22,7 @@ #include "tcc.h" -#ifndef ELF_OBJ_ONLY +#if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO) /* Returns 1 for a code relocation, 0 for a data relocation. For unknown relocations, returns -1. */ int code_reloc (int reloc_type)