Fix crtbegin/crtend Use dlsym on all bsd targets Check .eh_frame on all bsd targets Disable test3 on FreeBSD and NetBSD and use test1 instead because dlsym not working (WIP) Disable dlltest and 113_btdll on NetBSD because text relocations are not allowed Disable 115_bound_setjmp on NetBSD because longjmp is renamed into __longjmp14
Unified · Split
| @@ -1105,23 +1105,25 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 1104 unmodified lines | ||
| 1105 | 1105 | /* add libc crt1/crti objects */ |
| 1106 | 1106 | if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && |
| 1107 | 1107 | !s->nostdlib) { |
| 1108 | +#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 1108 | 1109 | #if TARGETOS_OpenBSD |
| 1109 | 1110 | if (output_type != TCC_OUTPUT_DLL) |
| 1110 | 1111 | tcc_add_crt(s, "crt0.o"); |
| 1111 | − if (output_type == TCC_OUTPUT_DLL) | |
| 1112 | − tcc_add_crt(s, "crtbeginS.o"); | |
| 1113 | − else | |
| 1114 | − tcc_add_crt(s, "crtbegin.o"); | |
| 1115 | 1112 | #elif TARGETOS_FreeBSD |
| 1116 | 1113 | if (output_type != TCC_OUTPUT_DLL) |
| 1117 | 1114 | tcc_add_crt(s, "crt1.o"); |
| 1118 | 1115 | tcc_add_crt(s, "crti.o"); |
| 1119 | − tcc_add_crt(s, "crtbegin.o"); | |
| 1120 | 1116 | #elif TARGETOS_NetBSD |
| 1121 | 1117 | if (output_type != TCC_OUTPUT_DLL) |
| 1122 | 1118 | tcc_add_crt(s, "crt0.o"); |
| 1123 | 1119 | tcc_add_crt(s, "crti.o"); |
| 1124 | − tcc_add_crt(s, "crtbegin.o"); | |
| 1120 | +#endif | |
| 1121 | + if (s->static_link) | |
| 1122 | + tcc_add_crt(s, "crtbeginT.o"); | |
| 1123 | + else if (output_type == TCC_OUTPUT_DLL) | |
| 1124 | + tcc_add_crt(s, "crtbeginS.o"); | |
| 1125 | + else | |
| 1126 | + tcc_add_crt(s, "crtbegin.o"); | |
| 1125 | 1127 | #elif !TCC_TARGET_MACHO |
| 1126 | 1128 | /* Mach-O with LC_MAIN doesn't need any crt startup code. */ |
| 1127 | 1129 | if (output_type != TCC_OUTPUT_DLL) |
| @@ -915,7 +915,7 @@ ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve) · 914 unmodified lines | ||
| 915 | 915 | #if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE |
| 916 | 916 | /* dlsym() needs the undecorated name. */ |
| 917 | 917 | void *addr = dlsym(RTLD_DEFAULT, &name[s1->leading_underscore]); |
| 918 | −#if TARGETOS_OpenBSD | |
| 918 | +#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 919 | 919 | if (addr == NULL) { |
| 920 | 920 | int i; |
| 921 | 921 | for (i = 0; i < s1->nb_loaded_dlls; i++) |
| @@ -1460,10 +1460,11 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) · 538 unmodified lines | ||
| 1460 | 1460 | tcc_add_support(s1, TCC_LIBTCC1); |
| 1461 | 1461 | #if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD |
| 1462 | 1462 | /* add crt end if not memory output */ |
| 1463 | − if (s1->output_type == TCC_OUTPUT_DLL) | |
| 1464 | − tcc_add_crt(s1, "crtendS.o"); | |
| 1465 | − else if (s1->output_type != TCC_OUTPUT_MEMORY) { | |
| 1466 | − tcc_add_crt(s1, "crtend.o"); | |
| 1463 | + if (s1->output_type != TCC_OUTPUT_MEMORY) { | |
| 1464 | + if (s1->output_type == TCC_OUTPUT_DLL) | |
| 1465 | + tcc_add_crt(s1, "crtendS.o"); | |
| 1466 | + else | |
| 1467 | + tcc_add_crt(s1, "crtend.o"); | |
| 1467 | 1468 | #if TARGETOS_FreeBSD || TARGETOS_NetBSD |
| 1468 | 1469 | tcc_add_crt(s1, "crtn.o"); |
| 1469 | 1470 | #endif |
| @@ -2856,8 +2857,8 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 1386 unmodified lines | ||
| 2856 | 2857 | sm_table[i].new_section = 1; |
| 2857 | 2858 | found: |
| 2858 | 2859 | if (sh->sh_type != s->sh_type) { |
| 2859 | −#if TARGETOS_OpenBSD | |
| 2860 | − if (strcmp (s->name, ".eh_frame") || sh->sh_type != SHT_PROGBITS) | |
| 2860 | +#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 2861 | + if (strcmp (s->name, ".eh_frame")) | |
| 2861 | 2862 | #endif |
| 2862 | 2863 | { |
| 2863 | 2864 | tcc_error_noabort("invalid section type"); |
| @@ -64,6 +64,17 @@ endif · 63 unmodified lines | ||
| 64 | 64 | ifeq ($(TARGETOS),OpenBSD) |
| 65 | 65 | dlltest: CFLAGS+=-fno-stack-protector |
| 66 | 66 | endif |
| 67 | +ifeq ($(TARGETOS),FreeBSD) | |
| 68 | + # test3 has dlsym problems | |
| 69 | + TESTS := $(filter-out test3,$(TESTS)) | |
| 70 | + TESTS += test1 | |
| 71 | +endif | |
| 72 | +ifeq ($(TARGETOS),NetBSD) | |
| 73 | + # test3 has dlsym problems | |
| 74 | + # dlltest does not allow text relocations | |
| 75 | + TESTS := $(filter-out test3 dlltest,$(TESTS)) | |
| 76 | + TESTS += test1 | |
| 77 | +endif | |
| 67 | 78 | |
| 68 | 79 | RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) |
| 69 | 80 | DISAS = objdump -d |
| @@ -52,6 +52,10 @@ ifneq (,$(filter OpenBSD FreeBSD NetBSD,$(TARGETOS))) · 51 unmodified lines | ||
| 52 | 52 | SKIP += 106_pthread.test # no pthread_condattr_setpshared |
| 53 | 53 | SKIP += 114_bound_signal.test # libc problem signal/fork |
| 54 | 54 | endif |
| 55 | +ifeq ($(TARGETOS),NetBSD) | |
| 56 | + SKIP += 113_btdll.test # text relocations | |
| 57 | + SKIP += 115_bound_setjmp.test # longjmp renamed to __longjmp14 | |
| 58 | +endif | |
| 55 | 59 | |
| 56 | 60 | # Some tests might need arguments |
| 57 | 61 | ARGS = |