History

tcc.h: define TCC_IS_NATIVE

- disable tccrun feature for non-native (cross-) compilers - define uplong for target adress size - fix using -Wl,-Ttext=... for Win64 (tccpe: ADDR3264 imagebase)

grischka committed 14 years ago

Commit a35b3051 parent a0db7164 files · +34 −20Browse files

Unified · Split

4 files
  1. tcc.c +4 −0
  2. tcc.h +22 −12
  3. tccpe.c +3 −8
  4. tccrun.c +5 −0
tcc.c+4−0
@@ -578,7 +578,11 @@ int main(int argc, char **argv) · 577 unmodified lines
578578 tcc_print_stats(s, getclock_us() - start_time);
579579
580580 if (s->output_type == TCC_OUTPUT_MEMORY) {
581+#ifdef TCC_IS_NATIVE
581582 ret = tcc_run(s, argc - optind, argv + optind);
583+#else
584+ tcc_error_noabort("-run is not available in a cross compiler");
585+#endif
582586 } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
583587 if (s->outfile)
584588 fclose(s->outfile);
tcc.h+22−12
@@ -49,9 +49,6 @@ · 48 unmodified lines
4949 #include <direct.h> /* getcwd */
5050 #define inline __inline
5151 #define inp next_inp
52−#ifdef _WIN64
53−# define uplong unsigned long long
54−#endif
5552 #ifdef LIBTCC_AS_DLL
5653 # define LIBTCCAPI __declspec(dllexport)
5754 #endif
@@ -67,17 +64,10 @@ · 9 unmodified lines
6764
6865 #endif /* !CONFIG_TCCBOOT */
6966
70−#ifndef uplong
71−#define uplong unsigned long
72−#endif
73−
7467 #ifndef PAGESIZE
7568 #define PAGESIZE 4096
7669 #endif
7770
78−#include "elf.h"
79−#include "stab.h"
80−
8171 #ifndef O_BINARY
8272 #define O_BINARY 0
8373 #endif
@@ -86,6 +76,8 @@ · 2 unmodified lines
8676 #define SA_SIGINFO 0x00000004u
8777 #endif
8878
79+#include "elf.h"
80+#include "stab.h"
8981 #include "libtcc.h"
9082
9183 /* parser debug */
@@ -131,8 +123,26 @@ · 39 unmodified lines
131123 #define TCC_TARGET_COFF
132124 #endif
133125
134−#if !defined(CONFIG_TCCBOOT)
135−#define CONFIG_TCC_BACKTRACE
126+/* only native compiler supports -run */
127+#if defined _WIN32 == defined TCC_TARGET_PE
128+# if (defined __i386__ || defined _X86_) && defined TCC_TARGET_I386
129+# define TCC_IS_NATIVE
130+# elif (defined __x86_64__ || defined _AMD64_) && defined TCC_TARGET_X86_64
131+# define TCC_IS_NATIVE
132+# elif defined __arm__ && defined TCC_TARGET_ARM
133+# define TCC_IS_NATIVE
134+# endif
135+#endif
136+
137+#if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT
138+# define CONFIG_TCC_BACKTRACE
139+#endif
140+
141+/* target address type */
142+#if defined TCC_TARGET_X86_64 && (!defined __x86_64__ || defined _WIN32)
143+# define uplong unsigned long long
144+#else
145+# define uplong unsigned long
136146 #endif
137147
138148 /* ------------ path configuration ------------ */
tccpe.c+3−8
@@ -38,10 +38,6 @@ · 37 unmodified lines
3838 # define ADDR3264 DWORD
3939 #endif
4040
41−#if defined _WIN32 && (defined _WIN64) == (defined TCC_TARGET_X86_64)
42−#define TCC_IS_NATIVE
43−#endif
44−
4541 #ifdef _WIN32
4642 void dbg_printf (const char *fmt, ...)
4743 {
@@ -339,7 +335,7 @@ struct pe_info { · 291 unmodified lines
339335 const char *filename;
340336 int type;
341337 DWORD sizeofheaders;
342− DWORD imagebase;
338+ ADDR3264 imagebase;
343339 DWORD start_addr;
344340 DWORD imp_offs;
345341 DWORD imp_size;
@@ -1870,11 +1866,10 @@ ST_FUNC int pe_output_file(TCCState * s1, const char *filename) · 1524 unmodified lines
18701866 ret = pe_write(&pe);
18711867 tcc_free(pe.sec_info);
18721868 } else {
1873−#ifndef TCC_IS_NATIVE
1874− tcc_error_noabort("-run supported only on native platform");
1875−#endif
1869+#ifdef TCC_IS_NATIVE
18761870 pe.thunk = data_section;
18771871 pe_build_imports(&pe);
1872+#endif
18781873 }
18791874
18801875 #ifdef PE_PRINT_SECTIONS
tccrun.c+5−0
@@ -20,6 +20,9 @@ · 19 unmodified lines
2020
2121 #include "tcc.h"
2222
23+/* only native compiler supports -run */
24+#ifdef TCC_IS_NATIVE
25+
2326 #ifdef CONFIG_TCC_BACKTRACE
2427 ST_DATA int rt_num_callers = 6;
2528 ST_DATA const char **rt_bound_error_msg;
@@ -217,6 +220,8 @@ static void set_pages_executable(void *ptr, unsigned long length) · 191 unmodified lines
217220 }
218221
219222 /* ------------------------------------------------------------- */
223+#endif /* TCC_IS_NATIVE */
224+
220225 #ifdef CONFIG_TCC_BACKTRACE
221226
222227 PUB_FUNC void tcc_set_num_callers(int n)

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