macos: make Mach-O somewhat ELF_OBJ_ONLY

we only emit .o files in ELF format, but do use the .got building
from generic ELF code also on MacOS for -run.
This commit is contained in:
Michael Matz 2020-05-09 01:40:36 +02:00
parent c16f5d2fe6
commit 032664bf7f
4 changed files with 19 additions and 13 deletions

8
tcc.h
View File

@ -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);

View File

@ -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)
{

View File

@ -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

View File

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