- The compiler should not use these - However tccrun.c & libtcc1.a files should use these Also: - use s1->loaded_dlls for loaded dlls instead of dlopens - alpine musl: fully supported now and tested - ./configure ... --config-backtrace=no : disable backtraces --config-bcheck=no : disable bcheck - tests:dlltest: enable by default - tccrun.c : simplify mmaps - __builtin_alloca : always use asm-alias (instead of #define) - tccpe.c : use write32le
Unified · Split
| @@ -94,7 +94,10 @@ NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI · 93 unmodified lines | ||
| 94 | 94 | NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP |
| 95 | 95 | NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64 |
| 96 | 96 | NATIVE_DEFINES_$(CONFIG_riscv64) += -DTCC_TARGET_RISCV64 |
| 97 | −NATIVE_DEFINES += $(NATIVE_DEFINES_yes) | |
| 97 | +NATIVE_DEFINES_$(CONFIG_BSD) += -DTARGETOS_$(TARGETOS) | |
| 98 | +NATIVE_DEFINES_no_$(CONFIG_bcheck) += -DCONFIG_TCC_BCHECK=0 | |
| 99 | +NATIVE_DEFINES_no_$(CONFIG_backtrace) += -DCONFIG_TCC_BACKTRACE=0 | |
| 100 | +NATIVE_DEFINES += $(NATIVE_DEFINES_yes) $(NATIVE_DEFINES_no_no) | |
| 98 | 101 | |
| 99 | 102 | ifeq ($(INCLUDED),no) |
| 100 | 103 | # -------------------------------------------------------------------------- |
| @@ -55,7 +55,7 @@ ar_set= · 54 unmodified lines | ||
| 55 | 55 | targetos=`uname` |
| 56 | 56 | case $targetos in |
| 57 | 57 | Darwin) |
| 58 | − confvars="$confvars OSX" | |
| 58 | + confvars="$confvars OSX dll=no" | |
| 59 | 59 | cc=`which cc` |
| 60 | 60 | cc=`readlink $cc` |
| 61 | 61 | tcc_usrinclude="`xcrun --show-sdk-path`/usr/include" |
| @@ -63,9 +63,10 @@ case $targetos in · 1 unmodified line | ||
| 63 | 63 | ;; |
| 64 | 64 | Windows_NT|MINGW*|MSYS*|CYGWIN*) |
| 65 | 65 | mingw32=yes |
| 66 | + targetos=WIN32 | |
| 66 | 67 | ;; |
| 67 | 68 | DragonFly|OpenBSD|FreeBSD|NetBSD) |
| 68 | − confvars="$confvars ldl=no" | |
| 69 | + confvars="$confvars BSD ldl=no" | |
| 69 | 70 | ;; |
| 70 | 71 | *) |
| 71 | 72 | ;; |
| @@ -311,6 +312,7 @@ Advanced options (experts only): · 239 unmodified lines | ||
| 311 | 312 | --elfinterp=... specify elf interpreter |
| 312 | 313 | --triplet=... specify system library/include directory triplet |
| 313 | 314 | --config-uClibc,-musl,-mingw32... enable system specific configurations |
| 315 | + --config-bcheck=no/-backtrace=no disable bounds checker/stack backtraces | |
| 314 | 316 | EOF |
| 315 | 317 | #echo "NOTE: The object files are build at the place where configure is launched" |
| 316 | 318 | exit 1 |
| @@ -30,17 +30,17 @@ ifeq "$($(T)-libtcc1-usegcc)" "yes" · 29 unmodified lines | ||
| 30 | 30 | XFLAGS = $(CFLAGS) -fPIC -gstabs -fno-omit-frame-pointer -Wno-unused-function -Wno-unused-variable |
| 31 | 31 | endif |
| 32 | 32 | |
| 33 | +ifneq ($(CONFIG_backtrace),no) | |
| 33 | 34 | # only for native compiler |
| 35 | +ifneq ($(CONFIG_bcheck),no) | |
| 34 | 36 | $(X)BCHECK_O = bcheck.o |
| 37 | +endif | |
| 35 | 38 | $(X)BT_O = bt-exe.o bt-log.o |
| 36 | −$(X)B_O = bcheck.o bt-exe.o bt-log.o bt-dll.o | |
| 37 | − | |
| 38 | −ifeq ($(CONFIG_musl)$(CONFIG_uClibc),yes) | |
| 39 | − BCHECK_O = | |
| 40 | −else | |
| 41 | − DSO_O = dsohandle.o | |
| 39 | +$(X)B_O = $(BCHECK_O) bt-exe.o bt-log.o bt-dll.o | |
| 42 | 40 | endif |
| 43 | 41 | |
| 42 | +DSO_O = dsohandle.o | |
| 43 | + | |
| 44 | 44 | I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BT_O) |
| 45 | 45 | X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BT_O) |
| 46 | 46 | ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o fetch_and_add_arm.o $(BT_O) |
| @@ -82,7 +82,7 @@ $(X)%.o : %.S · 35 unmodified lines | ||
| 82 | 82 | $(TOP)/%.o : %.c |
| 83 | 83 | $S$(XCC) -c $< -o $@ $(XFLAGS) |
| 84 | 84 | |
| 85 | −$(TOP)/bcheck.o : XFLAGS += -g | |
| 85 | +$(TOP)/bcheck.o : XFLAGS += -g $(if (CONFIG_musl),-DTCC_MUSL) | |
| 86 | 86 | $(TOP)/bt-exe.o : $(TOP)/tccrun.c |
| 87 | 87 | |
| 88 | 88 | $(X)crt1w.o : crt1.c |
| @@ -161,6 +161,9 @@ static pthread_spinlock_t bounds_spin; · 160 unmodified lines | ||
| 161 | 161 | #define HAVE_TLS_FUNC (1) |
| 162 | 162 | #define HAVE_TLS_VAR (0) |
| 163 | 163 | #endif |
| 164 | +#ifdef TCC_MUSL | |
| 165 | +# undef HAVE_CTYPE | |
| 166 | +#endif | |
| 164 | 167 | #endif |
| 165 | 168 | |
| 166 | 169 | #if MALLOC_REDIR |
| @@ -1150,7 +1153,7 @@ void __attribute__((destructor)) __bound_exit(void) · 983 unmodified lines | ||
| 1150 | 1153 | dprintf(stderr, "%s, %s():\n", __FILE__, __FUNCTION__); |
| 1151 | 1154 | |
| 1152 | 1155 | if (inited) { |
| 1153 | −#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OpenBSD__) | |
| 1156 | +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OpenBSD__) && !defined TCC_MUSL | |
| 1154 | 1157 | if (print_heap) { |
| 1155 | 1158 | extern void __libc_freeres (void); |
| 1156 | 1159 | __libc_freeres (); |
| @@ -880,7 +880,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 879 unmodified lines | ||
| 880 | 880 | tcc_define_symbol(s, "__linux__", NULL); |
| 881 | 881 | tcc_define_symbol(s, "__linux", NULL); |
| 882 | 882 | # endif |
| 883 | −# if defined(__FreeBSD__) | |
| 883 | +# if TARGETOS_FreeBSD | |
| 884 | 884 | tcc_define_symbol(s, "__FreeBSD__", "12"); |
| 885 | 885 | /* No 'Thread Storage Local' on FreeBSD with tcc */ |
| 886 | 886 | tcc_define_symbol(s, "__NO_TLS", NULL); |
| @@ -889,10 +889,10 @@ LIBTCCAPI TCCState *tcc_new(void) · 2 unmodified lines | ||
| 889 | 889 | tcc_define_symbol(s, "__int128_t", "struct { unsigned char _dummy[16]; }"); |
| 890 | 890 | # endif |
| 891 | 891 | # endif |
| 892 | −# if defined(__FreeBSD_kernel__) | |
| 892 | +# if TARGETOS_FreeBSD_kernel | |
| 893 | 893 | tcc_define_symbol(s, "__FreeBSD_kernel__", NULL); |
| 894 | 894 | # endif |
| 895 | −# if defined(__NetBSD__) | |
| 895 | +# if TARGETOS_NetBSD | |
| 896 | 896 | tcc_define_symbol(s, "__NetBSD__", "1"); |
| 897 | 897 | tcc_define_symbol(s, "__GNUC__", "4"); |
| 898 | 898 | tcc_define_symbol(s, "__GNUC_MINOR__", "0"); |
| @@ -900,11 +900,10 @@ LIBTCCAPI TCCState *tcc_new(void) · 1 unmodified line | ||
| 900 | 900 | tcc_define_symbol(s, "_Pragma(x)", ""); |
| 901 | 901 | tcc_define_symbol(s, "__ELF__", "1"); |
| 902 | 902 | # endif |
| 903 | −# if defined(__OpenBSD__) | |
| 903 | +# if TARGETOS_OpenBSD | |
| 904 | 904 | tcc_define_symbol(s, "__OpenBSD__", "1"); |
| 905 | 905 | tcc_define_symbol(s, "_ANSI_LIBRARY", "1"); |
| 906 | 906 | tcc_define_symbol(s, "__GNUC__", "4"); |
| 907 | − tcc_define_symbol(s, "__builtin_alloca", "alloca"); /* as we claim GNUC */ | |
| 908 | 907 | /* used by math.h */ |
| 909 | 908 | tcc_define_symbol(s, "__builtin_huge_val()", "1e500"); |
| 910 | 909 | tcc_define_symbol(s, "__builtin_huge_valf()", "1e50f"); |
| @@ -940,17 +939,15 @@ LIBTCCAPI TCCState *tcc_new(void) · 29 unmodified lines | ||
| 940 | 939 | /* wint_t is unsigned int by default, but (signed) int on BSDs |
| 941 | 940 | and unsigned short on windows. Other OSes might have still |
| 942 | 941 | other conventions, sigh. */ |
| 943 | −# if defined(__FreeBSD__) || defined (__FreeBSD_kernel__) \ | |
| 944 | − || defined(__NetBSD__) || defined(__OpenBSD__) | |
| 942 | +# if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel || TARGETOS_NetBSD || TARGETOS_OpenBSD | |
| 945 | 943 | tcc_define_symbol(s, "__WINT_TYPE__", "int"); |
| 946 | −# ifdef __FreeBSD__ | |
| 944 | +# if TARGETOS_FreeBSD | |
| 947 | 945 | /* define __GNUC__ to have some useful stuff from sys/cdefs.h |
| 948 | 946 | that are unconditionally used in FreeBSDs other system headers :/ */ |
| 949 | 947 | tcc_define_symbol(s, "__GNUC__", "9"); |
| 950 | 948 | tcc_define_symbol(s, "__GNUC_MINOR__", "3"); |
| 951 | 949 | tcc_define_symbol(s, "__GNUC_PATCHLEVEL__", "0"); |
| 952 | 950 | tcc_define_symbol(s, "__amd64__", "1"); |
| 953 | − tcc_define_symbol(s, "__builtin_alloca", "alloca"); | |
| 954 | 951 | # endif |
| 955 | 952 | # else |
| 956 | 953 | tcc_define_symbol(s, "__WINT_TYPE__", "unsigned int"); |
| @@ -969,7 +966,6 @@ LIBTCCAPI TCCState *tcc_new(void) · 12 unmodified lines | ||
| 969 | 966 | tcc_define_symbol(s, "__GNUC__", "4"); /* darwin emits warning on GCC<4 */ |
| 970 | 967 | tcc_define_symbol(s, "__APPLE_CC__", "1"); /* for <TargetConditionals.h> */ |
| 971 | 968 | tcc_define_symbol(s, "_DONT_USE_CTYPE_INLINE_", "1"); |
| 972 | − tcc_define_symbol(s, "__builtin_alloca", "alloca"); /* as we claim GNUC */ | |
| 973 | 969 | /* used by math.h */ |
| 974 | 970 | tcc_define_symbol(s, "__builtin_huge_val()", "1e500"); |
| 975 | 971 | tcc_define_symbol(s, "__builtin_huge_valf()", "1e50f"); |
| @@ -1028,12 +1024,6 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 52 unmodified lines | ||
| 1028 | 1024 | dynarray_reset(&s1->target_deps, &s1->nb_target_deps); |
| 1029 | 1025 | dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs); |
| 1030 | 1026 | dynarray_reset(&s1->argv, &s1->argc); |
| 1031 | −#ifdef __OpenBSD__ | |
| 1032 | − tcc_free(s1->dlopens); | |
| 1033 | − s1->dlopens = NULL; | |
| 1034 | − s1->nb_dlopens = 0; | |
| 1035 | −#endif | |
| 1036 | − | |
| 1037 | 1027 | cstr_free(&s1->cmdline_defs); |
| 1038 | 1028 | cstr_free(&s1->cmdline_incl); |
| 1039 | 1029 | #ifdef TCC_IS_NATIVE |
| @@ -1115,24 +1105,24 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 75 unmodified lines | ||
| 1115 | 1105 | /* add libc crt1/crti objects */ |
| 1116 | 1106 | if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && |
| 1117 | 1107 | !s->nostdlib) { |
| 1118 | −#if defined(__OpenBSD__) | |
| 1108 | +#if TARGETOS_OpenBSD | |
| 1119 | 1109 | if (output_type != TCC_OUTPUT_DLL) |
| 1120 | 1110 | tcc_add_crt(s, "crt0.o"); |
| 1121 | 1111 | if (output_type == TCC_OUTPUT_DLL) |
| 1122 | 1112 | tcc_add_crt(s, "crtbeginS.o"); |
| 1123 | 1113 | else |
| 1124 | 1114 | tcc_add_crt(s, "crtbegin.o"); |
| 1125 | −#elif defined(__FreeBSD__) | |
| 1115 | +#elif TARGETOS_FreeBSD | |
| 1126 | 1116 | if (output_type != TCC_OUTPUT_DLL) |
| 1127 | 1117 | tcc_add_crt(s, "crt1.o"); |
| 1128 | 1118 | tcc_add_crt(s, "crti.o"); |
| 1129 | 1119 | tcc_add_crt(s, "crtbegin.o"); |
| 1130 | −#elif defined(__NetBSD__) | |
| 1120 | +#elif TARGETOS_NetBSD | |
| 1131 | 1121 | if (output_type != TCC_OUTPUT_DLL) |
| 1132 | 1122 | tcc_add_crt(s, "crt0.o"); |
| 1133 | 1123 | tcc_add_crt(s, "crti.o"); |
| 1134 | 1124 | tcc_add_crt(s, "crtbegin.o"); |
| 1135 | −#elif !defined(TCC_TARGET_MACHO) | |
| 1125 | +#elif !TCC_TARGET_MACHO | |
| 1136 | 1126 | /* Mach-O with LC_MAIN doesn't need any crt startup code. */ |
| 1137 | 1127 | if (output_type != TCC_OUTPUT_DLL) |
| 1138 | 1128 | tcc_add_crt(s, "crt1.o"); |
| @@ -1155,16 +1145,26 @@ LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) · 16 unmodified lines | ||
| 1155 | 1145 | return 0; |
| 1156 | 1146 | } |
| 1157 | 1147 | |
| 1148 | +#if !defined TCC_TARGET_MACHO || defined TCC_IS_NATIVE | |
| 1149 | +ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname) | |
| 1150 | +{ | |
| 1151 | + DLLReference *ref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname)); | |
| 1152 | + strcpy(ref->name, dllname); | |
| 1153 | + dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, ref); | |
| 1154 | + return ref; | |
| 1155 | +} | |
| 1156 | +#endif | |
| 1157 | + | |
| 1158 | 1158 | ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) |
| 1159 | 1159 | { |
| 1160 | − int fd, ret; | |
| 1160 | + int fd, ret = -1; | |
| 1161 | 1161 | |
| 1162 | 1162 | /* open the file */ |
| 1163 | 1163 | fd = _tcc_open(s1, filename); |
| 1164 | 1164 | if (fd < 0) { |
| 1165 | 1165 | if (flags & AFF_PRINT_ERROR) |
| 1166 | 1166 | tcc_error_noabort("file '%s' not found", filename); |
| 1167 | − return -1; | |
| 1167 | + return ret; | |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | s1->current_filename = filename; |
| @@ -1181,55 +1181,53 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 10 unmodified lines | ||
| 1181 | 1181 | #endif |
| 1182 | 1182 | |
| 1183 | 1183 | switch (obj_type) { |
| 1184 | + | |
| 1184 | 1185 | case AFF_BINTYPE_REL: |
| 1185 | 1186 | ret = tcc_load_object_file(s1, fd, 0); |
| 1186 | 1187 | break; |
| 1187 | −#ifndef TCC_TARGET_PE | |
| 1188 | + | |
| 1189 | + case AFF_BINTYPE_AR: | |
| 1190 | + ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE)); | |
| 1191 | + break; | |
| 1192 | + | |
| 1193 | +#ifdef TCC_TARGET_PE | |
| 1194 | + default: | |
| 1195 | + ret = pe_load_file(s1, fd, filename); | |
| 1196 | +#else | |
| 1188 | 1197 | case AFF_BINTYPE_DYN: |
| 1189 | 1198 | if (s1->output_type == TCC_OUTPUT_MEMORY) { |
| 1190 | − ret = 0; | |
| 1191 | 1199 | #ifdef TCC_IS_NATIVE |
| 1192 | − { | |
| 1193 | − void *dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY); | |
| 1194 | − if (NULL == dl) | |
| 1195 | − ret = -1; | |
| 1196 | −#ifdef __OpenBSD__ | |
| 1197 | − else | |
| 1198 | − dynarray_add(&s1->dlopens, &s1->nb_dlopens, dl); | |
| 1199 | −#endif | |
| 1200 | − } | |
| 1200 | + void *dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY); | |
| 1201 | + if (dl) { | |
| 1202 | + tcc_add_dllref(s1, filename)->handle = dl; | |
| 1203 | + ret = 0; | |
| 1204 | + } | |
| 1201 | 1205 | #endif |
| 1202 | − } else { | |
| 1203 | −#ifndef TCC_TARGET_MACHO | |
| 1204 | − ret = tcc_load_dll(s1, fd, filename, | |
| 1205 | − (flags & AFF_REFERENCED_DLL) != 0); | |
| 1206 | + break; | |
| 1207 | + } | |
| 1208 | +#ifdef TCC_TARGET_MACHO | |
| 1209 | + ret = macho_load_dll(s1, fd, filename, | |
| 1210 | + (flags & AFF_REFERENCED_DLL) != 0); | |
| 1206 | 1211 | #else |
| 1207 | − ret = macho_load_dll(s1, fd, filename, | |
| 1208 | − (flags & AFF_REFERENCED_DLL) != 0); | |
| 1212 | + ret = tcc_load_dll(s1, fd, filename, | |
| 1213 | + (flags & AFF_REFERENCED_DLL) != 0); | |
| 1209 | 1214 | #endif |
| 1210 | − } | |
| 1211 | − break; | |
| 1212 | −#endif | |
| 1213 | − case AFF_BINTYPE_AR: | |
| 1214 | − ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE)); | |
| 1215 | 1215 | break; |
| 1216 | + | |
| 1216 | 1217 | #ifdef TCC_TARGET_COFF |
| 1217 | 1218 | case AFF_BINTYPE_C67: |
| 1218 | 1219 | ret = tcc_load_coff(s1, fd); |
| 1219 | 1220 | break; |
| 1220 | 1221 | #endif |
| 1221 | 1222 | default: |
| 1222 | −#ifdef TCC_TARGET_PE | |
| 1223 | − ret = pe_load_file(s1, filename, fd); | |
| 1224 | −#elif defined(TCC_TARGET_MACHO) | |
| 1225 | − ret = -1; | |
| 1226 | −#else | |
| 1223 | +#ifndef TCC_TARGET_MACHO | |
| 1227 | 1224 | /* as GNU ld, consider it is an ld script if not recognized */ |
| 1228 | 1225 | ret = tcc_load_ldscript(s1, fd); |
| 1229 | 1226 | #endif |
| 1227 | + | |
| 1228 | +#endif /* !TCC_TARGET_PE */ | |
| 1230 | 1229 | if (ret < 0) |
| 1231 | − tcc_error_noabort("%s: unrecognized file type %d", filename, | |
| 1232 | − obj_type); | |
| 1230 | + tcc_error_noabort("%s: unrecognized file type", filename); | |
| 1233 | 1231 | break; |
| 1234 | 1232 | } |
| 1235 | 1233 | close(fd); |
| @@ -169,11 +169,11 @@ static const char version[] = · 168 unmodified lines | ||
| 169 | 169 | " Windows" |
| 170 | 170 | #elif defined(TCC_TARGET_MACHO) |
| 171 | 171 | " Darwin" |
| 172 | −#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 172 | +#elif TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel | |
| 173 | 173 | " FreeBSD" |
| 174 | −#elif defined(__OpenBSD__) | |
| 174 | +#elif TARGETOS_OpenBSD | |
| 175 | 175 | " OpenBSD" |
| 176 | −#elif defined(__NetBSD__) | |
| 176 | +#elif TARGETOS_NetBSD | |
| 177 | 177 | " NetBSD" |
| 178 | 178 | #else |
| 179 | 179 | " Linux" |
| @@ -184,13 +184,16 @@ extern long double strtold (const char *__nptr, char **__endptr); · 183 unmodified lines | ||
| 184 | 184 | # endif |
| 185 | 185 | #endif |
| 186 | 186 | |
| 187 | −#if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT | |
| 188 | −# define CONFIG_TCC_BACKTRACE | |
| 189 | −# if (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || \ | |
| 190 | − defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 || \ | |
| 191 | − defined TCC_TARGET_RISCV64) \ | |
| 192 | − && !defined TCC_UCLIBC && !defined TCC_MUSL | |
| 193 | −# define CONFIG_TCC_BCHECK /* enable bound checking code */ | |
| 187 | +#if !defined TCC_IS_NATIVE \ | |
| 188 | + || (defined CONFIG_TCC_BACKTRACE && CONFIG_TCC_BACKTRACE==0) | |
| 189 | +# undef CONFIG_TCC_BACKTRACE | |
| 190 | +# undef CONFIG_TCC_BCHECK | |
| 191 | +#else | |
| 192 | +# define CONFIG_TCC_BACKTRACE 1 | |
| 193 | +# if defined CONFIG_TCC_BCHECK && CONFIG_TCC_BCHECK==0 | |
| 194 | +# undef CONFIG_TCC_BCHECK | |
| 195 | +# else | |
| 196 | +# define CONFIG_TCC_BCHECK 1 /* enable bound checking code */ | |
| 194 | 197 | # endif |
| 195 | 198 | #endif |
| 196 | 199 | |
| @@ -254,9 +257,9 @@ extern long double strtold (const char *__nptr, char **__endptr); · 57 unmodified lines | ||
| 254 | 257 | |
| 255 | 258 | /* name of ELF interpreter */ |
| 256 | 259 | #ifndef CONFIG_TCC_ELFINTERP |
| 257 | −# if defined __FreeBSD__ | |
| 260 | +# if TARGETOS_FreeBSD | |
| 258 | 261 | # define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1" |
| 259 | −# elif defined __FreeBSD_kernel__ | |
| 262 | +# elif TARGETOS_FreeBSD_kernel | |
| 260 | 263 | # if defined(TCC_TARGET_X86_64) |
| 261 | 264 | # define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1" |
| 262 | 265 | # else |
| @@ -264,7 +267,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 1 unmodified line | ||
| 264 | 267 | # endif |
| 265 | 268 | # elif defined __DragonFly__ |
| 266 | 269 | # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2" |
| 267 | −# elif defined __NetBSD__ | |
| 270 | +# elif TARGETOS_NetBSD | |
| 268 | 271 | # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so" |
| 269 | 272 | # elif defined __GNU__ |
| 270 | 273 | # define CONFIG_TCC_ELFINTERP "/lib/ld.so" |
| @@ -282,7 +285,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 11 unmodified lines | ||
| 282 | 285 | # if defined(TCC_MUSL) |
| 283 | 286 | # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1" |
| 284 | 287 | # else |
| 285 | −# if defined(__OpenBSD__) | |
| 288 | +# if TARGETOS_OpenBSD | |
| 286 | 289 | # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.so" |
| 287 | 290 | # else |
| 288 | 291 | # define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2" |
| @@ -793,12 +796,6 @@ struct TCCState { · 504 unmodified lines | ||
| 793 | 796 | char **crt_paths; |
| 794 | 797 | int nb_crt_paths; |
| 795 | 798 | |
| 796 | −#ifdef __OpenBSD__ | |
| 797 | − /* track dlopen */ | |
| 798 | − void **dlopens; | |
| 799 | − int nb_dlopens; | |
| 800 | −#endif | |
| 801 | − | |
| 802 | 799 | /* -D / -U options */ |
| 803 | 800 | CString cmdline_defs; |
| 804 | 801 | /* -include options */ |
| @@ -1309,6 +1306,9 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind); · 504 unmodified lines | ||
| 1309 | 1306 | #ifdef _WIN32 |
| 1310 | 1307 | ST_FUNC char *normalize_slashes(char *path); |
| 1311 | 1308 | #endif |
| 1309 | +#if !defined TCC_TARGET_MACHO || defined TCC_IS_NATIVE | |
| 1310 | +ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname); | |
| 1311 | +#endif | |
| 1312 | 1312 | |
| 1313 | 1313 | /* tcc_parse_args return codes: */ |
| 1314 | 1314 | #define OPT_HELP 1 |
| @@ -1743,7 +1743,7 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str); · 428 unmodified lines | ||
| 1743 | 1743 | |
| 1744 | 1744 | /* ------------ tccpe.c -------------- */ |
| 1745 | 1745 | #ifdef TCC_TARGET_PE |
| 1746 | −ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd); | |
| 1746 | +ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename); | |
| 1747 | 1747 | ST_FUNC int pe_output_file(TCCState * s1, const char *filename); |
| 1748 | 1748 | ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value); |
| 1749 | 1749 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |
| @@ -94,7 +94,7 @@ ST_FUNC void tccelf_stab_new(TCCState *s) · 93 unmodified lines | ||
| 94 | 94 | #ifdef CONFIG_TCC_BACKTRACE |
| 95 | 95 | /* include stab info with standalone backtrace support */ |
| 96 | 96 | if (s->do_backtrace && s->output_type != TCC_OUTPUT_MEMORY) |
| 97 | − shf = SHF_ALLOC; | |
| 97 | + shf = SHF_ALLOC | SHF_WRITE; // SHF_WRITE needed for musl/SELINUX | |
| 98 | 98 | #endif |
| 99 | 99 | stab_section = new_section(s, ".stab", SHT_PROGBITS, shf); |
| 100 | 100 | stab_section->sh_entsize = sizeof(Stab_Sym); |
| @@ -906,20 +906,15 @@ ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve) · 805 unmodified lines | ||
| 906 | 906 | /* Use ld.so to resolve symbol for us (for tcc -run) */ |
| 907 | 907 | if (do_resolve) { |
| 908 | 908 | #if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE |
| 909 | −#ifdef TCC_TARGET_MACHO | |
| 910 | − /* The symbols in the symtables have a prepended '_' | |
| 911 | − but dlsym() needs the undecorated name. */ | |
| 912 | − void *addr = dlsym(RTLD_DEFAULT, name + 1); | |
| 913 | −#else | |
| 914 | − void *addr = dlsym(RTLD_DEFAULT, name); | |
| 915 | −#ifdef __OpenBSD__ | |
| 909 | + /* dlsym() needs the undecorated name. */ | |
| 910 | + void *addr = dlsym(RTLD_DEFAULT, &name[s1->leading_underscore]); | |
| 911 | +#if TARGETOS_OpenBSD | |
| 916 | 912 | if (addr == NULL) { |
| 917 | 913 | int i; |
| 918 | − for (i = 0; i < s1->nb_dlopens; i++) | |
| 919 | − if ((addr = dlsym(s1->dlopens[i], name))) | |
| 914 | + for (i = 0; i < s1->nb_loaded_dlls; i++) | |
| 915 | + if ((addr = dlsym(s1->loaded_dlls[i]->handle, name))) | |
| 920 | 916 | break; |
| 921 | 917 | } |
| 922 | −#endif | |
| 923 | 918 | #endif |
| 924 | 919 | if (addr) { |
| 925 | 920 | sym->st_value = (addr_t) addr; |
| @@ -1421,7 +1416,7 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) · 495 unmodified lines | ||
| 1421 | 1416 | #ifdef CONFIG_TCC_BCHECK |
| 1422 | 1417 | if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) { |
| 1423 | 1418 | tcc_add_library_err(s1, "pthread"); |
| 1424 | −#if !defined(__OpenBSD__) && !defined(__NetBSD__) | |
| 1419 | +#if !TARGETOS_OpenBSD && !TARGETOS_NetBSD | |
| 1425 | 1420 | tcc_add_library_err(s1, "dl"); |
| 1426 | 1421 | #endif |
| 1427 | 1422 | tcc_add_support(s1, "bcheck.o"); |
| @@ -1439,13 +1434,13 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) · 11 unmodified lines | ||
| 1439 | 1434 | #endif |
| 1440 | 1435 | if (strlen(TCC_LIBTCC1) > 0) |
| 1441 | 1436 | tcc_add_support(s1, TCC_LIBTCC1); |
| 1442 | −#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) | |
| 1437 | +#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 1443 | 1438 | /* add crt end if not memory output */ |
| 1444 | 1439 | if (s1->output_type == TCC_OUTPUT_DLL) |
| 1445 | 1440 | tcc_add_crt(s1, "crtendS.o"); |
| 1446 | 1441 | else if (s1->output_type != TCC_OUTPUT_MEMORY) { |
| 1447 | 1442 | tcc_add_crt(s1, "crtend.o"); |
| 1448 | −#if defined(__FreeBSD__) || defined(__NetBSD__) | |
| 1443 | +#if TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 1449 | 1444 | tcc_add_crt(s1, "crtn.o"); |
| 1450 | 1445 | #endif |
| 1451 | 1446 | } |
| @@ -1806,7 +1801,7 @@ struct dyn_inf { · 354 unmodified lines | ||
| 1806 | 1801 | unsigned long data_offset; |
| 1807 | 1802 | addr_t rel_addr; |
| 1808 | 1803 | addr_t rel_size; |
| 1809 | −#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 1804 | +#if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel | |
| 1810 | 1805 | addr_t bss_addr; |
| 1811 | 1806 | addr_t bss_size; |
| 1812 | 1807 | #endif |
| @@ -1818,23 +1813,26 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 5 unmodified lines | ||
| 1818 | 1813 | Section *interp, Section* strsec, |
| 1819 | 1814 | struct dyn_inf *dyninf, int *sec_order) |
| 1820 | 1815 | { |
| 1821 | − int i, j, k, file_type, sh_order_index, file_offset; | |
| 1822 | − unsigned long s_align; | |
| 1823 | − long long tmp; | |
| 1824 | − addr_t addr; | |
| 1825 | − ElfW(Phdr) *ph; | |
| 1816 | + int i, sh_order_index, file_offset; | |
| 1826 | 1817 | Section *s; |
| 1827 | 1818 | |
| 1828 | − file_type = s1->output_type; | |
| 1829 | 1819 | sh_order_index = 1; |
| 1830 | 1820 | file_offset = 0; |
| 1831 | 1821 | if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) |
| 1832 | 1822 | file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr)); |
| 1833 | − s_align = ELF_PAGE_SIZE; | |
| 1834 | − if (s1->section_align) | |
| 1835 | − s_align = s1->section_align; | |
| 1836 | 1823 | |
| 1837 | − if (phnum > 0) { | |
| 1824 | +#ifndef ELF_OBJ_ONLY | |
| 1825 | + if (phnum > 0) { /* phnum is 0 for TCC_OUTPUT_OBJ */ | |
| 1826 | + unsigned long s_align; | |
| 1827 | + long long tmp; | |
| 1828 | + addr_t addr; | |
| 1829 | + ElfW(Phdr) *ph; | |
| 1830 | + int j, k, file_type = s1->output_type; | |
| 1831 | + | |
| 1832 | + s_align = ELF_PAGE_SIZE; | |
| 1833 | + if (s1->section_align) | |
| 1834 | + s_align = s1->section_align; | |
| 1835 | + | |
| 1838 | 1836 | if (s1->has_text_addr) { |
| 1839 | 1837 | int a_offset, p_offset; |
| 1840 | 1838 | addr = s1->text_addr; |
| @@ -1863,7 +1861,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 22 unmodified lines | ||
| 1863 | 1861 | |
| 1864 | 1862 | /* dynamic relocation table information, for .dynamic section */ |
| 1865 | 1863 | dyninf->rel_addr = dyninf->rel_size = 0; |
| 1866 | −#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 1864 | +#if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel | |
| 1867 | 1865 | dyninf->bss_addr = dyninf->bss_size = 0; |
| 1868 | 1866 | #endif |
| 1869 | 1867 | |
| @@ -1934,7 +1932,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 64 unmodified lines | ||
| 1934 | 1932 | } |
| 1935 | 1933 | /* update dynamic relocation infos */ |
| 1936 | 1934 | if (s->sh_type == SHT_RELX) { |
| 1937 | −#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 1935 | +#if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel | |
| 1938 | 1936 | if (!strcmp(strsec->data + s->sh_name, ".rel.got")) { |
| 1939 | 1937 | dyninf->rel_addr = addr; |
| 1940 | 1938 | dyninf->rel_size += s->sh_size; /* XXX only first rel. */ |
| @@ -1979,6 +1977,7 @@ static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr, int phnum, · 38 unmodified lines | ||
| 1979 | 1977 | } |
| 1980 | 1978 | } |
| 1981 | 1979 | } |
| 1980 | +#endif /* ELF_OBJ_ONLY */ | |
| 1982 | 1981 | |
| 1983 | 1982 | /* all other sections come after */ |
| 1984 | 1983 | for(i = 1; i < s1->nb_sections; i++) { |
| @@ -2080,7 +2079,7 @@ static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf) · 95 unmodified lines | ||
| 2080 | 2079 | put_dt(dynamic, DT_RELA, dyninf->rel_addr); |
| 2081 | 2080 | put_dt(dynamic, DT_RELASZ, dyninf->rel_size); |
| 2082 | 2081 | put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel)); |
| 2083 | −#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) | |
| 2082 | +#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 2084 | 2083 | put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr); |
| 2085 | 2084 | put_dt(dynamic, DT_PLTRELSZ, dyninf->rel_size); |
| 2086 | 2085 | put_dt(dynamic, DT_JMPREL, dyninf->rel_addr); |
| @@ -2088,7 +2087,7 @@ static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf) · 1 unmodified line | ||
| 2088 | 2087 | put_dt(dynamic, DT_BIND_NOW, 1); /* Dirty hack */ |
| 2089 | 2088 | #endif |
| 2090 | 2089 | #else |
| 2091 | −#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
| 2090 | +#if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel | |
| 2092 | 2091 | put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr); |
| 2093 | 2092 | put_dt(dynamic, DT_PLTRELSZ, dyninf->rel_size); |
| 2094 | 2093 | put_dt(dynamic, DT_JMPREL, dyninf->rel_addr); |
| @@ -2200,8 +2199,7 @@ static void tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr, · 105 unmodified lines | ||
| 2200 | 2199 | ehdr.e_ident[4] = ELFCLASSW; |
| 2201 | 2200 | ehdr.e_ident[5] = ELFDATA2LSB; |
| 2202 | 2201 | ehdr.e_ident[6] = EV_CURRENT; |
| 2203 | −#if !defined(TCC_TARGET_PE) && (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) | |
| 2204 | − /* FIXME: should set only for freebsd _target_, but we exclude only PE target */ | |
| 2202 | +#if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel | |
| 2205 | 2203 | ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; |
| 2206 | 2204 | #endif |
| 2207 | 2205 | #ifdef TCC_TARGET_ARM |
| @@ -2408,7 +2406,7 @@ static void create_arm_attribute_section(TCCState *s1) · 200 unmodified lines | ||
| 2408 | 2406 | } |
| 2409 | 2407 | #endif |
| 2410 | 2408 | |
| 2411 | −#if defined(__OpenBSD__) | |
| 2409 | +#if TARGETOS_OpenBSD | |
| 2412 | 2410 | static Section *create_openbsd_note_section(TCCState *s1) |
| 2413 | 2411 | { |
| 2414 | 2412 | Section *s = find_section (s1, ".note.openbsd.ident"); |
| @@ -2441,7 +2439,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 26 unmodified lines | ||
| 2441 | 2439 | #ifdef TCC_TARGET_ARM |
| 2442 | 2440 | create_arm_attribute_section (s1); |
| 2443 | 2441 | #endif |
| 2444 | −#ifdef __OpenBSD__ | |
| 2442 | +#if TARGETOS_OpenBSD | |
| 2445 | 2443 | if (file_type != TCC_OUTPUT_OBJ) |
| 2446 | 2444 | note = create_openbsd_note_section (s1); |
| 2447 | 2445 | #endif |
| @@ -2766,7 +2764,7 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, · 318 unmodified lines | ||
| 2766 | 2764 | #ifdef TCC_ARM_EABI |
| 2767 | 2765 | sh->sh_type != SHT_ARM_EXIDX && |
| 2768 | 2766 | #endif |
| 2769 | −#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) | |
| 2767 | +#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 2770 | 2768 | sh->sh_type != SHT_X86_64_UNWIND && |
| 2771 | 2769 | sh->sh_type != SHT_NOTE && |
| 2772 | 2770 | #endif |
| @@ -3321,10 +3319,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 548 unmodified lines | ||
| 3321 | 3319 | store_version(s1, &v, dynstr); |
| 3322 | 3320 | |
| 3323 | 3321 | /* add the dll and its level */ |
| 3324 | − dllref = tcc_mallocz(sizeof(DLLReference) + strlen(soname)); | |
| 3325 | − dllref->level = level; | |
| 3326 | − strcpy(dllref->name, soname); | |
| 3327 | − dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref); | |
| 3322 | + tcc_add_dllref(s1, soname)->level = level; | |
| 3328 | 3323 | |
| 3329 | 3324 | /* add dynamic symbols in dynsym_section */ |
| 3330 | 3325 | for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) { |
| @@ -1277,24 +1277,10 @@ static int pe_check_symbols(struct pe_info *pe) · 1276 unmodified lines | ||
| 1277 | 1277 | unsigned long offset = is->thk_offset; |
| 1278 | 1278 | if (offset) { |
| 1279 | 1279 | /* got aliased symbol, like stricmp and _stricmp */ |
| 1280 | − | |
| 1281 | 1280 | } else { |
| 1282 | 1281 | char buffer[100]; |
| 1283 | − WORD *p; | |
| 1282 | + unsigned char *p; | |
| 1284 | 1283 | |
| 1285 | − offset = text_section->data_offset; | |
| 1286 | − /* add the 'jmp IAT[x]' instruction */ | |
| 1287 | −#ifdef TCC_TARGET_ARM | |
| 1288 | − p = section_ptr_add(text_section, 8+4); // room for code and address | |
| 1289 | − (*(DWORD*)(p)) = 0xE59FC000; // arm code ldr ip, [pc] ; PC+8+0 = 0001xxxx | |
| 1290 | − (*(DWORD*)(p+2)) = 0xE59CF000; // arm code ldr pc, [ip] | |
| 1291 | −#else | |
| 1292 | − p = section_ptr_add(text_section, 8); | |
| 1293 | − *p = 0x25FF; | |
| 1294 | −#ifdef TCC_TARGET_X86_64 | |
| 1295 | − *(DWORD*)(p+1) = (DWORD)-4; | |
| 1296 | −#endif | |
| 1297 | −#endif | |
| 1298 | 1284 | /* add a helper symbol, will be patched later in |
| 1299 | 1285 | pe_build_imports */ |
| 1300 | 1286 | sprintf(buffer, "IAT.%s", name); |
| @@ -1302,16 +1288,27 @@ static int pe_check_symbols(struct pe_info *pe) · 1 unmodified line | ||
| 1302 | 1288 | symtab_section, 0, sizeof(DWORD), |
| 1303 | 1289 | ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), |
| 1304 | 1290 | 0, SHN_UNDEF, buffer); |
| 1291 | + | |
| 1292 | + offset = text_section->data_offset; | |
| 1293 | + is->thk_offset = offset; | |
| 1294 | + | |
| 1295 | + /* add the 'jmp IAT[x]' instruction */ | |
| 1305 | 1296 | #ifdef TCC_TARGET_ARM |
| 1297 | + p = section_ptr_add(text_section, 8+4); // room for code and address | |
| 1298 | + write32le(p + 0, 0xE59FC000); // arm code ldr ip, [pc] ; PC+8+0 = 0001xxxx | |
| 1299 | + write32le(p + 4, 0xE59CF000); // arm code ldr pc, [ip] | |
| 1306 | 1300 | put_elf_reloc(symtab_section, text_section, |
| 1307 | 1301 | offset + 8, R_XXX_THUNKFIX, is->iat_index); // offset to IAT position |
| 1308 | 1302 | #else |
| 1303 | + p = section_ptr_add(text_section, 8); | |
| 1304 | + write16le(p, 0x25FF); | |
| 1305 | +#ifdef TCC_TARGET_X86_64 | |
| 1306 | + write32le(p + 2, (DWORD)-4); | |
| 1307 | +#endif | |
| 1309 | 1308 | put_elf_reloc(symtab_section, text_section, |
| 1310 | 1309 | offset + 2, R_XXX_THUNKFIX, is->iat_index); |
| 1311 | 1310 | #endif |
| 1312 | − is->thk_offset = offset; | |
| 1313 | 1311 | } |
| 1314 | − | |
| 1315 | 1312 | /* tcc_realloc might have altered sym's address */ |
| 1316 | 1313 | sym = (ElfW(Sym) *)symtab_section->data + sym_index; |
| 1317 | 1314 | |
| @@ -1531,16 +1528,13 @@ ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t va · 213 unmodified lines | ||
| 1531 | 1528 | ); |
| 1532 | 1529 | } |
| 1533 | 1530 | |
| 1534 | −static int add_dllref(TCCState *s1, const char *dllname) | |
| 1531 | +static int pe_add_dllref(TCCState *s1, const char *dllname) | |
| 1535 | 1532 | { |
| 1536 | − DLLReference *dllref; | |
| 1537 | 1533 | int i; |
| 1538 | 1534 | for (i = 0; i < s1->nb_loaded_dlls; ++i) |
| 1539 | 1535 | if (0 == strcmp(s1->loaded_dlls[i]->name, dllname)) |
| 1540 | 1536 | return i + 1; |
| 1541 | − dllref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname)); | |
| 1542 | − strcpy(dllref->name, dllname); | |
| 1543 | − dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref); | |
| 1537 | + tcc_add_dllref(s1, dllname); | |
| 1544 | 1538 | return s1->nb_loaded_dlls; |
| 1545 | 1539 | } |
| 1546 | 1540 | |
| @@ -1737,7 +1731,7 @@ static int pe_load_def(TCCState *s1, int fd) · 190 unmodified lines | ||
| 1737 | 1731 | continue; |
| 1738 | 1732 | |
| 1739 | 1733 | case 2: |
| 1740 | − dllindex = add_dllref(s1, dllname); | |
| 1734 | + dllindex = pe_add_dllref(s1, dllname); | |
| 1741 | 1735 | ++state; |
| 1742 | 1736 | /* fall through */ |
| 1743 | 1737 | default: |
| @@ -1773,7 +1767,7 @@ static int pe_load_dll(TCCState *s1, const char *filename) · 29 unmodified lines | ||
| 1773 | 1767 | if (ret) { |
| 1774 | 1768 | return -1; |
| 1775 | 1769 | } else if (p) { |
| 1776 | − index = add_dllref(s1, filename); | |
| 1770 | + index = pe_add_dllref(s1, filename); | |
| 1777 | 1771 | for (q = p; *q; q += 1 + strlen(q)) |
| 1778 | 1772 | pe_putimport(s1, index, q, 0); |
| 1779 | 1773 | tcc_free(p); |
| @@ -1782,7 +1776,7 @@ static int pe_load_dll(TCCState *s1, const char *filename) · 2 unmodified lines | ||
| 1782 | 1776 | } |
| 1783 | 1777 | |
| 1784 | 1778 | /* ------------------------------------------------------------- */ |
| 1785 | −ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd) | |
| 1779 | +ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename) | |
| 1786 | 1780 | { |
| 1787 | 1781 | int ret = -1; |
| 1788 | 1782 | char buf[10]; |
| @@ -3700,8 +3700,7 @@ static void tcc_predefs(CString *cstr) · 3699 unmodified lines | ||
| 3700 | 3700 | "__BOTH(char*,strcat,(char*,const char*))\n" |
| 3701 | 3701 | "__BOTH(char*,strchr,(const char*,int))\n" |
| 3702 | 3702 | "__BOTH(char*,strdup,(const char*))\n" |
| 3703 | −#if defined(TCC_TARGET_PE) || defined(__OpenBSD__) || \ | |
| 3704 | − defined(__FreeBSD__) || defined(__NetBSD__) | |
| 3703 | +#if TCC_TARGET_PE || TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD | |
| 3705 | 3704 | "#define __MAYBE_REDIR __BOTH\n" |
| 3706 | 3705 | #else // HAVE MALLOC_REDIR |
| 3707 | 3706 | "#define __MAYBE_REDIR __BUILTIN\n" |
| @@ -3713,6 +3712,8 @@ static void tcc_predefs(CString *cstr) · 5 unmodified lines | ||
| 3713 | 3712 | "__MAYBE_REDIR(void,free,(void*))\n" |
| 3714 | 3713 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |
| 3715 | 3714 | "__BOTH(void*,alloca,(__SIZE_TYPE__))\n" |
| 3715 | +#else | |
| 3716 | + "__BUILTIN(void*,alloca,(__SIZE_TYPE__))\n" | |
| 3716 | 3717 | #endif |
| 3717 | 3718 | #if defined(TCC_TARGET_ARM) && defined(TCC_ARM_EABI) |
| 3718 | 3719 | "__BOUND(void*,__aeabi_memcpy,(void*,const void*,__SIZE_TYPE__))\n" |
| @@ -91,27 +91,14 @@ LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr) · 90 unmodified lines | ||
| 91 | 91 | int fd = mkstemp(tmpfname); |
| 92 | 92 | unlink(tmpfname); |
| 93 | 93 | ftruncate(fd, size); |
| 94 | −#ifdef __OpenBSD__ | |
| 95 | −{ | |
| 96 | − int offs; | |
| 94 | + | |
| 97 | 95 | size = (size + (PAGESIZE-1)) & ~(PAGESIZE-1); |
| 98 | − offs = (size + (0x100000-1)) & ~(0x100000-1); | |
| 99 | − prx = NULL; | |
| 100 | − ptr = mmap(NULL, size + offs, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); | |
| 101 | − if (ptr != MAP_FAILED) { | |
| 102 | − /* mmap RX memory at a fixed distance */ | |
| 103 | − munmap((char*)ptr + size, offs); | |
| 104 | − prx = mmap((char*)ptr + offs, size, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, fd, 0); | |
| 105 | − } | |
| 106 | −} | |
| 107 | −#else | |
| 108 | − ptr = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); | |
| 109 | − prx = mmap (NULL, size, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0); | |
| 110 | −#endif | |
| 96 | + ptr = mmap(NULL, size * 2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); | |
| 97 | + /* mmap RX memory at a fixed distance */ | |
| 98 | + prx = mmap((char*)ptr + size, size, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, fd, 0); | |
| 111 | 99 | if (ptr == MAP_FAILED || prx == MAP_FAILED) |
| 112 | 100 | tcc_error("tccrun: could not map memory"); |
| 113 | − dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size); | |
| 114 | − dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, prx); | |
| 101 | + dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)(size*2)); | |
| 115 | 102 | ptr_diff = (char*)prx - (char*)ptr; |
| 116 | 103 | close(fd); |
| 117 | 104 | //printf("map %p %p %p\n", ptr, prx, (void*)ptr_diff); |
| @@ -131,7 +118,6 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 13 unmodified lines | ||
| 131 | 118 | for (i = 0; i < s1->nb_runtime_mem; ++i) { |
| 132 | 119 | #ifdef HAVE_SELINUX |
| 133 | 120 | unsigned size = (unsigned)(addr_t)s1->runtime_mem[i++]; |
| 134 | − munmap(s1->runtime_mem[i++], size); | |
| 135 | 121 | munmap(s1->runtime_mem[i], size); |
| 136 | 122 | #else |
| 137 | 123 | #ifdef _WIN64 |
| @@ -23,29 +23,13 @@ TESTS = \ · 22 unmodified lines | ||
| 23 | 23 | tests2-dir \ |
| 24 | 24 | pp-dir |
| 25 | 25 | |
| 26 | −BTESTS = btest test1b | |
| 27 | 26 | # test4_static -- Not all relocation types are implemented yet. |
| 28 | 27 | # asmtest / asmtest2 -- minor differences with gcc |
| 29 | 28 | |
| 30 | −# bounds-checking is supported on i386 and x86_64 on linux and windows | |
| 31 | −ifeq (-$(CONFIG_musl)-, --) | |
| 32 | −ifeq ($(ARCH),i386) | |
| 33 | − TESTS += $(BTESTS) | |
| 34 | −endif | |
| 35 | −ifeq ($(ARCH),x86_64) | |
| 36 | − TESTS += $(BTESTS) | |
| 37 | −endif | |
| 38 | −ifeq ($(ARCH),arm) | |
| 39 | − TESTS += $(BTESTS) | |
| 40 | −endif | |
| 41 | −ifeq ($(ARCH),arm64) | |
| 42 | − TESTS += $(BTESTS) | |
| 43 | −endif | |
| 44 | −ifeq ($(ARCH),riscv64) | |
| 45 | − TESTS += $(BTESTS) | |
| 29 | +ifneq ($(CONFIG_bcheck),no) | |
| 30 | + TESTS += btest test1b | |
| 46 | 31 | endif |
| 47 | −endif | |
| 48 | −ifdef CONFIG_OSX # some don't work yet | |
| 32 | +ifeq ($(CONFIG_dll),no) | |
| 49 | 33 | TESTS := $(filter-out dlltest, $(TESTS)) |
| 50 | 34 | endif |
| 51 | 35 | ifeq (,$(filter arm64 i386 x86_64,$(ARCH))) |
| @@ -55,18 +39,14 @@ ifeq ($(CONFIG_arm_eabi),yes) · 3 unmodified lines | ||
| 55 | 39 | TESTS := $(filter-out test3,$(TESTS)) |
| 56 | 40 | endif |
| 57 | 41 | ifeq (,$(filter i386 x86_64,$(ARCH))) |
| 58 | − TESTS := $(filter-out dlltest asm-c-connect-test,$(TESTS)) | |
| 42 | + TESTS := $(filter-out asm-c-connect-test,$(TESTS)) | |
| 59 | 43 | endif |
| 60 | − | |
| 61 | 44 | ifeq ($(OS),Windows_NT) # for libtcc_test to find libtcc.dll |
| 62 | 45 | PATH := $(CURDIR)/$(TOP)$(if $(findstring ;,$(PATH)),;,:)$(PATH) |
| 63 | 46 | endif |
| 64 | − | |
| 65 | 47 | ifdef CONFIG_OSX |
| 66 | 48 | LIBS += $(LINK_LIBTCC) |
| 67 | 49 | endif |
| 68 | − | |
| 69 | − | |
| 70 | 50 | ifeq ($(ARCH),arm) |
| 71 | 51 | # tcctest refers to the alignment of functions, and with thumb mode |
| 72 | 52 | # the low bit of code addresses selects the mode, so the "alignment" |
| @@ -14,7 +14,6 @@ ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float · 13 unmodified lines | ||
| 14 | 14 | endif |
| 15 | 15 | ifdef CONFIG_OSX |
| 16 | 16 | SKIP += 40_stdio.test 42_function_pointer.test |
| 17 | − SKIP += 113_btdll.test # no shared lib support yet | |
| 18 | 17 | endif |
| 19 | 18 | ifeq ($(ARCH),x86_64) |
| 20 | 19 | SKIP += 73_arm64.test |
| @@ -24,16 +23,20 @@ ifeq (,$(filter i386,$(ARCH))) · 3 unmodified lines | ||
| 24 | 23 | endif |
| 25 | 24 | ifeq (,$(filter i386 x86_64,$(ARCH))) |
| 26 | 25 | SKIP += 85_asm-outside-function.test # x86 asm |
| 27 | − SKIP += 113_btdll.test # dll support needed | |
| 28 | 26 | endif |
| 29 | −ifeq (,$(filter i386 x86_64 arm arm64 riscv64,$(ARCH))) | |
| 27 | +ifeq ($(CONFIG_backtrace),no) | |
| 30 | 28 | SKIP += 112_backtrace.test |
| 29 | + SKIP += 113_btdll.test | |
| 30 | + CONFIG_bcheck = no # no bcheck without backtrace | |
| 31 | +endif | |
| 32 | +ifeq ($(CONFIG_bcheck),no) | |
| 31 | 33 | SKIP += 114_bound_signal.test |
| 32 | 34 | SKIP += 115_bound_setjmp.test |
| 33 | 35 | SKIP += 116_bound_setjmp2.test |
| 36 | + SKIP += 117_builtins.test | |
| 34 | 37 | endif |
| 35 | −ifeq (-$(CONFIG_musl)-,-yes-) | |
| 36 | − SKIP += 112_backtrace.test | |
| 38 | +ifeq ($(CONFIG_dll),no) | |
| 39 | + SKIP += 113_btdll.test # no shared lib support yet | |
| 37 | 40 | endif |
| 38 | 41 | ifeq (-$(findstring gcc,$(CC))-,--) |
| 39 | 42 | SKIP += $(patsubst %.expect,%.test,$(GEN-ALWAYS)) |
| @@ -45,12 +48,6 @@ ifeq (-$(CONFIG_WIN32)-,-yes-) · 5 unmodified lines | ||
| 45 | 48 | SKIP += 106_pthread.test # No pthread support |
| 46 | 49 | SKIP += 114_bound_signal.test # No pthread support |
| 47 | 50 | endif |
| 48 | −ifeq ($(TARGETOS),OpenBSD) | |
| 49 | − SKIP += 106_pthread.test | |
| 50 | − SKIP += 113_btdll.test | |
| 51 | − SKIP += 114_bound_signal.test | |
| 52 | − SKIP += 116_bound_setjmp2.test | |
| 53 | −endif | |
| 54 | 51 | |
| 55 | 52 | # Some tests might need arguments |
| 56 | 53 | ARGS = |
| @@ -109,8 +106,10 @@ GEN-ALWAYS = · 52 unmodified lines | ||
| 109 | 106 | 115_bound_setjmp.test: FLAGS += -b |
| 110 | 107 | 116_bound_setjmp2.test: FLAGS += -b |
| 111 | 108 | 117_builtins.test: T1 = ( $(TCC) -run $1 && $(TCC) -b -run $1 ) |
| 109 | +ifneq ($(CONFIG_bcheck),no) | |
| 112 | 110 | 121_struct_return.test: FLAGS += -b |
| 113 | 111 | 122_vla_reuse.test: FLAGS += -b |
| 112 | +endif | |
| 114 | 113 | |
| 115 | 114 | # Filter source directory in warnings/errors (out-of-tree builds) |
| 116 | 115 | FILTER = 2>&1 | sed -e 's,$(SRC)/,,g' |