more bsd updates

This implements support for FreeBSD on aarch64
This partial implements support on FreeBSD(32). This still needs fixing
i386_gen.c because small structures on this target are passed in registers.

Add aligned 16 to __int128_t for FreeBSD
Support __i386__ on FreeBSD/NetBSD
Fix testcase 115 on FreeBSD/NetBSD
Disable testcase 116 on *BSD* because TLS_FUNC/TLS_VAR not set in bcheck.c
Remove FreeBSD/FreeBSD_kernel code from tccelf.c
This commit is contained in:
herman ten brugge 2020-12-22 07:02:47 +01:00
parent 888f4fd982
commit 8f8abcc756
7 changed files with 19 additions and 31 deletions

View File

@ -890,7 +890,7 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__builtin_nanf(ignored_string)", "(0.0F/0.0F)");
# if defined(__aarch64__)
/* FIXME, __int128_t is used by setjump */
tcc_define_symbol(s, "__int128_t", "struct { unsigned char _dummy[16]; }");
tcc_define_symbol(s, "__int128_t", "struct { unsigned char _dummy[16] __attribute((aligned(16))); }");
# endif
# endif
# if TARGETOS_FreeBSD_kernel
@ -903,7 +903,11 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__GNUC_PATCHLEVEL__", "0");
tcc_define_symbol(s, "_Pragma(x)", "");
tcc_define_symbol(s, "__ELF__", "1");
#if PTR_SIZE == 4
tcc_define_symbol(s, "__i386__", "1");
#else
tcc_define_symbol(s, "__amd64__", "1");
#endif
tcc_define_symbol(s, "__builtin_huge_val()", "1e500");
tcc_define_symbol(s, "__builtin_huge_valf()", "1e50f");
tcc_define_symbol(s, "__builtin_huge_vall()", "1e5000L");
@ -957,7 +961,11 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_define_symbol(s, "__GNUC_MINOR__", "3");
tcc_define_symbol(s, "__GNUC_PATCHLEVEL__", "0");
tcc_define_symbol(s, "__GNUC_STDC_INLINE__", "1");
#if PTR_SIZE == 4
tcc_define_symbol(s, "__i386__", "1");
#else
tcc_define_symbol(s, "__amd64__", "1");
#endif
# endif
# else
tcc_define_symbol(s, "__WINT_TYPE__", "unsigned int");

View File

@ -1826,10 +1826,6 @@ struct dyn_inf {
unsigned long data_offset;
addr_t rel_addr;
addr_t rel_size;
#if PTR_SIZE == 4 && (TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel)
addr_t bss_addr;
addr_t bss_size;
#endif
};
/* Assign sections to segments and decide how are sections laid out when loaded
@ -1886,9 +1882,6 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum,
/* dynamic relocation table information, for .dynamic section */
dyninf->rel_addr = dyninf->rel_size = 0;
#if PTR_SIZE == 4 && (TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel)
dyninf->bss_addr = dyninf->bss_size = 0;
#endif
for(j = 0; j < (phnum == 6 ? 3 : 2); j++) {
Section *relocplt = s1->got ? s1->got->relocplt : NULL;
@ -1961,20 +1954,9 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum,
}
/* update dynamic relocation infos */
if (s->sh_type == SHT_RELX && s != relocplt) {
#if PTR_SIZE == 4 && (TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel)
if (!strcmp(strsec->data + s->sh_name, ".rel.got")) {
dyninf->rel_addr = addr;
dyninf->rel_size += s->sh_size; /* XXX only first rel. */
}
if (!strcmp(strsec->data + s->sh_name, ".rel.bss")) {
dyninf->bss_addr = addr;
dyninf->bss_size = s->sh_size; /* XXX only first rel. */
}
#else
if (dyninf->rel_size == 0)
dyninf->rel_addr = addr;
dyninf->rel_size += s->sh_size;
#endif
}
addr += s->sh_size;
if (s->sh_type != SHT_NOBITS)
@ -2115,15 +2097,6 @@ static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf)
put_dt(dynamic, DT_PLTREL, DT_RELA);
}
put_dt(dynamic, DT_RELACOUNT, 0);
#else
#if PTR_SIZE == 4 && (TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel)
if (s1->got)
put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr);
put_dt(dynamic, DT_PLTRELSZ, dyninf->rel_size);
put_dt(dynamic, DT_JMPREL, dyninf->rel_addr);
put_dt(dynamic, DT_PLTREL, DT_REL);
put_dt(dynamic, DT_REL, dyninf->bss_addr);
put_dt(dynamic, DT_RELSZ, dyninf->bss_size);
#else
put_dt(dynamic, DT_REL, dyninf->rel_addr);
put_dt(dynamic, DT_RELSZ, dyninf->rel_size);
@ -2135,7 +2108,6 @@ static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf)
put_dt(dynamic, DT_PLTREL, DT_REL);
}
put_dt(dynamic, DT_RELCOUNT, 0);
#endif
#endif
if (versym_section && verneed_section) {
/* The dynamic linker can not handle VERSYM without VERNEED */

View File

@ -2008,6 +2008,10 @@ ST_FUNC void gbound_args(int nb_args)
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
if (v == TOK_alloca)
func_bound_add_epilog = 1;
#endif
#if TARGETOS_NetBSD
if (v == TOK_longjmp) /* undo rename to __longjmp14 */
sv->sym->asm_label = TOK___bound_longjmp;
#endif
}
}

View File

@ -309,6 +309,7 @@
DEF(TOK___bound_local_new, "__bound_local_new")
DEF(TOK___bound_local_delete, "__bound_local_delete")
DEF(TOK___bound_setjmp, "__bound_setjmp")
DEF(TOK___bound_longjmp, "__bound_longjmp")
DEF(TOK___bound_new_region, "__bound_new_region")
# ifdef TCC_TARGET_PE
# ifdef TCC_TARGET_X86_64
@ -321,6 +322,7 @@
# endif
DEF(TOK_setjmp, "setjmp")
DEF(TOK__setjmp, "_setjmp")
DEF(TOK_longjmp, "longjmp")
#endif
/* Tiny Assembler */

View File

@ -145,8 +145,10 @@ static void check (void)
}
last_value = value;
switch (value) {
#ifndef __FreeBSD__ /* longjmp(jmp_buf, 0) not supported */
case 0:
jump (0);
#endif
default:
if (value < 10)
jump (value + 1);

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <assert.h>
#ifndef _WIN32
#if !(defined( _WIN32) || (defined(__FreeBSD__) && defined(__i386__)))
#define __fastcall __attribute((fastcall))
#endif

View File

@ -51,10 +51,10 @@ endif
ifneq (,$(filter OpenBSD FreeBSD NetBSD,$(TARGETOS)))
SKIP += 106_versym.test # no pthread_condattr_setpshared
SKIP += 114_bound_signal.test # libc problem signal/fork
SKIP += 116_bound_setjmp2.test # No TLS_FUNC/TLS_VAR in bcheck.c
endif
ifeq ($(TARGETOS),NetBSD)
SKIP += 113_btdll.test # text relocations
SKIP += 115_bound_setjmp.test # longjmp renamed to __longjmp14
endif
# Some tests might need arguments