diff --git a/riscv64-link.c b/riscv64-link.c index 7051cfe8..02c5718a 100644 --- a/riscv64-link.c +++ b/riscv64-link.c @@ -155,11 +155,6 @@ ST_FUNC void relocate_plt(TCCState *s1) } } -struct pcrel_hi { - addr_t addr, val; -}; -static struct pcrel_hi last_hi; - void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) { diff --git a/tcc.h b/tcc.h index 837cbdd8..34ce5cd4 100644 --- a/tcc.h +++ b/tcc.h @@ -45,9 +45,6 @@ /* XXX: need to define this to use them in non ISOC99 context */ extern float strtof (const char *__nptr, char **__endptr); extern long double strtold (const char *__nptr, char **__endptr); -# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) -extern char **environ; -# endif #endif #ifdef _WIN32 @@ -436,7 +433,6 @@ typedef struct TokenSym { struct Sym *sym_struct; /* direct pointer to structure */ struct Sym *sym_identifier; /* direct pointer to identifier */ int tok; /* token number */ - int cnt; int len; char str[1]; } TokenSym; @@ -886,6 +882,11 @@ struct TCCState { ElfW_Rel *qrel; # define qrel s1->qrel +#ifdef TCC_TARGET_RISCV64 + struct pcrel_hi { addr_t addr, val; } last_hi; +# define last_hi s1->last_hi +#endif + #ifdef TCC_TARGET_PE /* PE info */ int pe_subsystem; diff --git a/tccelf.c b/tccelf.c index 2442a3bb..69519939 100644 --- a/tccelf.c +++ b/tccelf.c @@ -2137,9 +2137,6 @@ static int final_sections_reloc(TCCState *s1) if (s1->nb_errors != 0) return -1; - /* Some targets use static data between relocations (riscv64) */ - tcc_enter_state (s1); - /* relocate sections */ /* XXX: ignore sections with allocated relocations ? */ for(i = 1; i < s1->nb_sections; i++) { @@ -2148,8 +2145,6 @@ static int final_sections_reloc(TCCState *s1) relocate_section(s1, s); } - tcc_exit_state(); - /* relocate relocation entries if the relocation tables are allocated in the executable */ for(i = 1; i < s1->nb_sections; i++) { diff --git a/tccgen.c b/tccgen.c index 566d5281..aa57a5fd 100644 --- a/tccgen.c +++ b/tccgen.c @@ -4321,38 +4321,19 @@ static Sym * find_field (CType *type, int v, int *cumofs) return s; } -/* - * c = 0: reset symbol counter - * c = 1: increment symbol counter - * c = 2: check symbol counter - */ - -static void check_fields (CType *type, int c) +static void check_fields (CType *type, int check) { Sym *s = type->ref; - int v; while ((s = s->next) != NULL) { - if ((s->v & SYM_FIELD) && - (s->type.t & VT_BTYPE) == VT_STRUCT && - (s->v & ~SYM_FIELD) >= SYM_FIRST_ANOM) { - check_fields (&s->type, c); - } - v = s->v & ~SYM_FIELD; - if (v < tok_ident) - switch (c) { - case 0: - table_ident[v - TOK_IDENT]->cnt = 0; - break; - case 1: - table_ident[v - TOK_IDENT]->cnt++; - break; - case 2: - if (table_ident[v - TOK_IDENT]->cnt != 1) - tcc_error("duplicate member '%s'", - get_tok_str(v, NULL)); - break; - } + int v = s->v & ~SYM_FIELD; + if (v < SYM_FIRST_ANOM) { + TokenSym *ts = table_ident[v - TOK_IDENT]; + if (check && (ts->tok & SYM_FIELD)) + tcc_error("duplicate member '%s'", get_tok_str(v, NULL)); + ts->tok ^= SYM_FIELD; + } else if ((s->type.t & VT_BTYPE) == VT_STRUCT) + check_fields (&s->type, check); } } @@ -4809,9 +4790,8 @@ do_decl: if (ad.cleanup_func) { tcc_warning("attribute '__cleanup__' ignored on type"); } - check_fields(type, 0); check_fields(type, 1); - check_fields(type, 2); + check_fields(type, 0); struct_layout(type, &ad); } } diff --git a/tccrun.c b/tccrun.c index a603946a..3f61ef31 100644 --- a/tccrun.c +++ b/tccrun.c @@ -63,6 +63,10 @@ static void *win64_add_function_table(TCCState *s1); static void win64_del_function_table(void *); #endif +#ifndef PAGESIZE +# define PAGESIZE 4096 +#endif + /* ------------------------------------------------------------- */ /* Do all relocations (needed before using tcc_get_symbol()) Returns -1 on error. */ @@ -87,20 +91,19 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) int fd = mkstemp(tmpfname); unlink(tmpfname); ftruncate(fd, size); - #ifdef __OpenBSD__ - { /* OpenBSD uses random 64 addresses that are far apart. This does not - work for the x86_64 target. - This might be a problem in the future for other targets. */ - static char *prw = (char *) 0x100000000; - char *pex = prw + 0x40000000; - - ptr = mmap (prw, size, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); - prx = mmap (pex, size, PROT_READ|PROT_EXEC, MAP_SHARED | MAP_FIXED, fd, 0); - tcc_enter_state (s1); - prw += 0x100000000; - tcc_exit_state(); +{ + int offs; + size = (size + (PAGESIZE-1)) & ~(PAGESIZE-1); + offs = (size + (0x100000-1)) & ~(0x100000-1); + prx = NULL; + ptr = mmap(NULL, size + offs, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (ptr != MAP_FAILED) { + /* mmap RX memory at a fixed distance */ + munmap((char*)ptr + size, offs); + prx = mmap((char*)ptr + offs, size, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, fd, 0); } +} #else ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0); @@ -111,6 +114,7 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, prx); ptr_diff = (char*)prx - (char*)ptr; close(fd); + //printf("map %p %p %p\n", ptr, prx, (void*)ptr_diff); } #else ptr = tcc_malloc(size); @@ -155,8 +159,12 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) #ifdef CONFIG_TCC_BACKTRACE rt_context *rc = &g_rtctxt; #endif -# if defined(__APPLE__) || defined(__FreeBSD__) + +#if defined(__APPLE__) || defined(__FreeBSD__) char **envp = NULL; +#elif defined(__OpenBSD__) + extern char **environ; + char **envp = environ; #else char **envp = environ; #endif @@ -333,9 +341,6 @@ static void set_pages_executable(TCCState *s1, void *ptr, unsigned long length) void __clear_cache(void *beginning, void *end); # ifndef HAVE_SELINUX addr_t start, end; -# ifndef PAGESIZE -# define PAGESIZE 4096 -# endif start = (addr_t)ptr & ~(PAGESIZE - 1); end = (addr_t)ptr + length; end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1); diff --git a/tests/Makefile b/tests/Makefile index 68a5ce4e..0b74fbc9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -57,9 +57,6 @@ endif ifeq (,$(filter i386 x86_64,$(ARCH))) TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS)) endif -ifeq ($(TARGETOS),OpenBSD) - TESTS := $(filter-out libtest_mt test3 dlltest asm-c-connect-test pp-dir btest test1b,$(TESTS)) -endif ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll PATH := $(CURDIR)/$(TOP)$(if $(findstring ;,$(PATH)),;,:)$(PATH)