diff --git a/lib/bcheck.c b/lib/bcheck.c index 2008a262..a72efc1d 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -223,7 +223,7 @@ typedef struct alloca_list_struct { #elif defined(__OpenBSD__) #define BOUND_TID_TYPE pid_t #define BOUND_GET_TID syscall (SYS_getthrid) -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) #define BOUND_TID_TYPE pid_t #define BOUND_GET_TID 0 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__riscv) diff --git a/libtcc.c b/libtcc.c index 82217f60..4cedf71e 100644 --- a/libtcc.c +++ b/libtcc.c @@ -889,7 +889,11 @@ LIBTCCAPI TCCState *tcc_new(void) tcc_define_symbol(s, "__FreeBSD_kernel__", NULL); # endif # if defined(__NetBSD__) - tcc_define_symbol(s, "__NetBSD__", "__NetBSD__"); + tcc_define_symbol(s, "__NetBSD__", "1"); + tcc_define_symbol(s, "__GNUC__", "4"); + tcc_define_symbol(s, "__GNUC_MINOR__", "0"); + tcc_define_symbol(s, "__GNUC_PATCHLEVEL__", "0"); + tcc_define_symbol(s, "_Pragma(x)", ""); # endif # if defined(__OpenBSD__) tcc_define_symbol(s, "__OpenBSD__", "1"); @@ -1110,6 +1114,11 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) tcc_add_crt(s, "crt1.o"); tcc_add_crt(s, "crti.o"); tcc_add_crt(s, "crtbegin.o"); +#elif defined(__NetBSD__) + if (output_type != TCC_OUTPUT_DLL) + tcc_add_crt(s, "crt0.o"); + tcc_add_crt(s, "crti.o"); + tcc_add_crt(s, "crtbegin.o"); #elif !defined(TCC_TARGET_MACHO) /* Mach-O with LC_MAIN doesn't need any crt startup code. */ if (output_type != TCC_OUTPUT_DLL) diff --git a/tcc.c b/tcc.c index c2bb0dd0..b574f932 100644 --- a/tcc.c +++ b/tcc.c @@ -173,6 +173,8 @@ static const char version[] = " FreeBSD" #elif defined(__OpenBSD__) " OpenBSD" +#elif defined(__NetBSD__) + " NetBSD" #else " Linux" #endif diff --git a/tccelf.c b/tccelf.c index 69519939..0a569da8 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1431,11 +1431,11 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) #endif if (strlen(TCC_LIBTCC1) > 0) tcc_add_support(s1, TCC_LIBTCC1); -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) /* add crt end if not memory output */ if (s1->output_type != TCC_OUTPUT_MEMORY) { tcc_add_crt(s1, "crtend.o"); -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) tcc_add_crt(s1, "crtn.o"); #endif } @@ -2070,7 +2070,7 @@ static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf) put_dt(dynamic, DT_RELA, dyninf->rel_addr); put_dt(dynamic, DT_RELASZ, dyninf->rel_size); put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel)); -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) 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); @@ -2756,7 +2756,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, #ifdef TCC_ARM_EABI sh->sh_type != SHT_ARM_EXIDX && #endif -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) sh->sh_type != SHT_X86_64_UNWIND && sh->sh_type != SHT_NOTE && #endif diff --git a/tccrun.c b/tccrun.c index 3f61ef31..c965e4e3 100644 --- a/tccrun.c +++ b/tccrun.c @@ -162,7 +162,7 @@ LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv) #if defined(__APPLE__) || defined(__FreeBSD__) char **envp = NULL; -#elif defined(__OpenBSD__) +#elif defined(__OpenBSD__) || defined(__NetBSD__) extern char **environ; char **envp = environ; #else