History

replace native platform macros in the compiler

- 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

grischka committed 5 years ago

Commit e2e62fc1 parent 02f61d513 files · +163 −202Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t