diff -X excl.tinycc -rduNp tinycc.oorig/Changelog tinycc/Changelog --- tinycc.oorig/Changelog 2005-09-05 23:04:10.000000000 +0200 +++ tinycc/Changelog 2005-10-01 15:55:25.000000000 +0200 @@ -1,3 +1,5 @@ +- make test uses tcc -run which requires libtcc1.a + version 0.9.24: - ignore AS_NEEDED ld command diff -X excl.tinycc -rduNp tinycc.oorig/configure tinycc/configure --- tinycc.oorig/configure 2005-04-15 18:03:23.000000000 +0200 +++ tinycc/configure 2005-10-01 15:56:29.000000000 +0200 @@ -19,8 +19,6 @@ TMPH="${TMPDIR1}/tcc-conf-${RANDOM}-$$-$ # default parameters build_cross="no" -prefix="" -execprefix="" bindir="" libdir="" tccdir="" @@ -57,10 +55,10 @@ case "$cpu" in ;; esac gprof="no" +bcheck="no" bigendian="no" mingw32="no" -LIBSUF=".a" -EXESUF="" + # OS specific targetos=`uname -s` @@ -110,14 +108,18 @@ for opt do ;; --extra-libs=*) extralibs=${opt#--extra-libs=} ;; - --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` + --cpu=*) cpu="${opt#--cpu=}" ;; --enable-gprof) gprof="yes" ;; + --enable-bcheck) bcheck="yes" + ;; --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-" ;; --enable-cross) build_cross="yes" ;; + --help) usage="yes" + ;; esac done @@ -130,11 +132,55 @@ cc="${cross_prefix}${cc}" ar="${cross_prefix}${ar}" strip="${cross_prefix}${strip}" +# flag to pass to the compiler and linker to generate profiling data +if test -z "$CC_GPROF_FLAG" +then + CC_GPROF_FLAGS="-pg" +fi + if test "$mingw32" = "yes" ; then LIBSUF=".lib" EXESUF=".exe" + tcc_path_sep="'\\\\'" + if test -z "$prefix" ; then + prefix="/c/Program Files/tcc" + fi + execprefix="$prefix" + bindir="$prefix" + tccdir="$prefix" + docdir="$prefix/doc" +else + LIBSUF=".a" + EXESUF="" + tcc_path_sep="'/'" + if test -z "$prefix" ; then + prefix="/usr/local" + fi + if test x"$execprefix" = x""; then + execprefix="${prefix}" + fi + if test x"$bindir" = x""; then + bindir="${execprefix}/bin" + fi + if test x"$docdir" = x""; then + docdir="$prefix/share/doc/tcc" + fi +fi # mingw32 + +if test x"$libdir" = x""; then +libdir="${execprefix}/lib" +fi +if test x"$tccdir" = x""; then +tccdir="${execprefix}/lib/tcc" +fi +if test x"$mandir" = x""; then +mandir="${prefix}/man" +fi +if test x"$includedir" = x""; then +includedir="${prefix}/include" fi + if test -z "$cross_prefix" ; then # --- @@ -178,7 +224,7 @@ if $cc -o $TMPO $TMPC 2> /dev/null ; the gcc_major="3" fi -if test x"$1" = x"-h" -o x"$1" = x"--help" ; then +if test x"$1" = x"-h" -o x"$1" = x"--help" -o "x$usage" = "xyes" ; then cat << EOF Usage: configure [options] @@ -194,54 +240,20 @@ echo " --bindir=DIR user ex echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]" echo " --includedir=DIR C header files in DIR [PREFIX/include]" echo " --mandir=DIR man documentation in DIR [PREFIX/man]" -echo " --build-cross build cross compilers" +echo " --enable-cross build cross compilers" echo "" echo "Advanced options (experts only):" echo " --source-path=PATH path of source code [$source_path]" -echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" +echo " --cross-prefix=PREFIX use PREFIX for cross compile tools [$cross_prefix]" echo " --cc=CC use C compiler CC [$cc]" echo " --make=MAKE use specified make [$make]" +#echo " --enable-gprof enable call graph profile support [$gprof]" +echo " --enable-bcheck enable bounds checking support [$bcheck]" echo "" #echo "NOTE: The object files are build at the place where configure is launched" exit 1 fi -if test "$mingw32" = "yes" ; then - if test -z "$prefix" ; then - prefix="/c/Program Files/tcc" - fi - execprefix="$prefix" - bindir="$prefix" - tccdir="$prefix" - docdir="$prefix/doc" -else - if test -z "$prefix" ; then - prefix="/usr/local" - fi - if test x"$execprefix" = x""; then - execprefix="${prefix}" - fi - if test x"$bindir" = x""; then - bindir="${execprefix}/bin" - fi - if test x"$docdir" = x""; then - docdir="$prefix/share/doc/tcc" - fi -fi # mingw32 - -if test x"$libdir" = x""; then -libdir="${execprefix}/lib" -fi -if test x"$tccdir" = x""; then -tccdir="${execprefix}/lib/tcc" -fi -if test x"$mandir" = x""; then -mandir="${prefix}/man" -fi -if test x"$includedir" = x""; then -includedir="${prefix}/include" -fi - echo "Binary directory $bindir" echo "TinyCC directory $tccdir" echo "Library directory $libdir" @@ -254,6 +266,7 @@ echo "make $make" echo "CPU $cpu" echo "Big Endian $bigendian" echo "gprof enabled $gprof" +echo "bcheck enabled $bcheck" echo "cross compilers $build_cross" echo "Creating config.mak and config.h" @@ -280,6 +293,8 @@ echo "CFLAGS=$CFLAGS" >> config.mak echo "LDFLAGS=$LDFLAGS" >> config.mak echo "LIBSUF=$LIBSUF" >> config.mak echo "EXESUF=$EXESUF" >> config.mak +echo "#define TCC_PATH_SEP $tcc_path_sep" >> $TMPH + if test "$cpu" = "x86" ; then echo "ARCH=i386" >> config.mak echo "#define HOST_I386 1" >> $TMPH @@ -312,8 +327,14 @@ if test "$bigendian" = "yes" ; then fi if test "$gprof" = "yes" ; then echo "TARGET_GPROF=yes" >> config.mak + echo "CFLAGS+=$CC_GPROF_FLAGS" >> config.mak + echo "LDFLAGS+=$CC_GPROF_FLAGS" >> config.mak echo "#define HAVE_GPROF 1" >> $TMPH fi +if test "$bcheck" = "yes" ; then + echo "TARGET_BCHECK=yes" >> config.mak + echo "#define CONFIG_TCC_BCHECK 1" >> $TMPH +fi if test "$build_cross" = "yes" ; then echo "CONFIG_CROSS=yes" >> config.mak fi diff -X excl.tinycc -rduNp tinycc.oorig/elf.h tinycc/elf.h --- tinycc.oorig/elf.h 2005-04-24 21:45:59.000000000 +0200 +++ tinycc/elf.h 2005-10-01 15:55:25.000000000 +0200 @@ -378,8 +378,10 @@ typedef struct #define STB_NUM 3 /* Number of defined types. */ #define STB_LOOS 10 /* Start of OS-specific */ #define STB_HIOS 12 /* End of OS-specific */ +#if 0 /* processor specific is not used in tcc */ #define STB_LOPROC 13 /* Start of processor-specific */ #define STB_HIPROC 15 /* End of processor-specific */ +#endif /* Legal values for ST_TYPE subfield of st_info (symbol type). */ @@ -391,9 +393,10 @@ typedef struct #define STT_NUM 5 /* Number of defined types. */ #define STT_LOOS 11 /* Start of OS-specific */ #define STT_HIOS 12 /* End of OS-specific */ +#if 0 /* processor specific is not used in tcc */ #define STT_LOPROC 13 /* Start of processor-specific */ #define STT_HIPROC 15 /* End of processor-specific */ - +#endif /* Symbol table indices are found in the hash buckets and chain table of a symbol hash table section. This special index value indicates diff -X excl.tinycc -rduNp tinycc.oorig/libtcc.h tinycc/libtcc.h --- tinycc.oorig/libtcc.h 2004-10-24 00:49:08.000000000 +0200 +++ tinycc/libtcc.h 2005-10-01 15:55:25.000000000 +0200 @@ -22,9 +22,6 @@ void tcc_enable_debug(TCCState *s); void tcc_set_error_func(TCCState *s, void *error_opaque, void (*error_func)(void *opaque, const char *msg)); -/* set/reset a warning */ -int tcc_set_warning(TCCState *s, const char *warning_name, int value); - /*****************************/ /* preprocessor */ @@ -60,6 +57,7 @@ int tcc_compile_string(TCCState *s, cons #define TCC_OUTPUT_EXE 1 /* executable file */ #define TCC_OUTPUT_DLL 2 /* dynamic library */ #define TCC_OUTPUT_OBJ 3 /* object file */ +#define TCC_OUTPUT_PP 4 /* output preprocessed source */ int tcc_set_output_type(TCCState *s, int output_type); #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */ diff -X excl.tinycc -rduNp tinycc.oorig/Makefile tinycc/Makefile --- tinycc.oorig/Makefile 2005-09-05 23:04:10.000000000 +0200 +++ tinycc/Makefile 2005-10-01 15:55:25.000000000 +0200 @@ -6,16 +6,19 @@ include config.mak CFLAGS+=-g -Wall ifndef CONFIG_WIN32 LIBS=-ldl +ifdef TARGET_BCHECK BCHECK_O=bcheck.o +BCHECK_TEST=btest +endif endif CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC LIBS_P= -CFLAGS+=-mpreferred-stack-boundary=2 +#CFLAGS+=-mpreferred-stack-boundary=2 ifeq ($(GCC_MAJOR),2) CFLAGS+=-m386 -malign-functions=0 else -CFLAGS+=-march=i386 -falign-functions=0 -fno-strict-aliasing +#CFLAGS+=-march=i386 -falign-functions=0 -fno-strict-aliasing endif DISAS=objdump -d @@ -46,7 +49,7 @@ endif endif # run local version of tcc with local libraries and includes -TCC=./tcc -B. -I. +TCC=./tcc$(EXESUF) -B. -I. all: $(PROGS) \ libtcc1.a $(BCHECK_O) tcc-doc.html tcc.1 libtcc.a \ @@ -65,24 +68,24 @@ tcctest.ref: tcctest.c test.ref: tcctest.ref ./tcctest.ref > $@ -test.out: tcc tcctest.c +test.out: tcc$(EXESUF) libtcc1.a tcctest.c $(TCC) -run tcctest.c > $@ -run: tcc tcctest.c +run: tcc$(EXESUF) libtcc1.a tcctest.c $(TCC) -run tcctest.c # iterated test2 (compile tcc then compile tcctest.c !) -test2: tcc tcc.c tcctest.c test.ref +test2: tcc$(EXESUF) libtcc1.a tcc.c tcctest.c test.ref $(TCC) -run tcc.c -B. -I. -run tcctest.c > test.out2 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi # iterated test3 (compile tcc then compile tcc then compile tcctest.c !) -test3: tcc tcc.c tcctest.c test.ref +test3: tcc$(EXESUF) libtcc1.a tcc.c tcctest.c test.ref $(TCC) -run tcc.c -B. -I. -run tcc.c -B. -I. -run tcctest.c > test.out3 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi # binary output test -test4: tcc test.ref +test4: tcc$(EXESUF) libtcc1.a test.ref # dynamic output $(TCC) -o tcctest1 tcctest.c ./tcctest1 > test1.out @@ -105,7 +108,7 @@ test4: tcc test.ref BOUNDS_OK = 1 4 8 10 BOUNDS_FAIL= 2 5 7 9 11 12 13 -btest: boundtest.c tcc +btest: boundtest.c tcc$(EXESUF) $(BCHECK_O) libtcc1.a @for i in $(BOUNDS_OK); do \ if $(TCC) -b -run boundtest.c $$i ; then \ /bin/true ; \ @@ -123,11 +126,11 @@ btest: boundtest.c tcc echo Bound test OK # speed test -speed: tcc ex2 ex3 +speed: tcc$(EXESUF) ex2 ex3 time ./ex2 1238 2 3 4 10 13 4 - time ./tcc -I. ./ex2.c 1238 2 3 4 10 13 4 + time ./tcc$(EXESUF) -I. ./ex2.c 1238 2 3 4 10 13 4 time ./ex3 35 - time ./tcc -I. ./ex3.c 35 + time ./tcc$(EXESUF) -I. ./ex3.c 35 ex2: ex2.c $(CC) $(CFLAGS) -o $@ $< @@ -171,10 +174,11 @@ tiny_impdef$(EXESUF): tiny_impdef.c ifdef CONFIG_WIN32 # for windows, we must use TCC because we generate ELF objects LIBTCC1_OBJS=$(addprefix win32/lib/, crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o) libtcc1.o -LIBTCC1_CC=./tcc.exe -Bwin32 +LIBTCC1_CC=./tcc$(EXESUF) -Bwin32 +CFLAGS:= else LIBTCC1_OBJS=libtcc1.o -LIBTCC1_CC=$(CC) +LIBTCC1_CC=$(CC) $(CFLAGS) endif %.o: %.c @@ -187,7 +191,7 @@ libtcc1.a: $(LIBTCC1_OBJS) $(AR) rcs $@ $^ bcheck.o: bcheck.c - $(CC) -O2 -Wall -c -o $@ $< + $(CC) -O2 $(CFLAGS) -Wall -c -o $@ $< install: tcc_install libinstall @@ -217,16 +221,17 @@ ifdef CONFIG_WIN32 endif clean: - rm -f *~ *.o *.a tcc tcc1 tcct tcc_g tcctest.ref *.bin *.i ex2 \ - core gmon.out test.out test.ref a.out tcc_p \ - *.exe *.lib tcc.pod libtcc_test \ + rm -f *~ *.o *.a tcc$(EXESUF) tcc1 tcct tcc_g$(EXESUF) tcctest.ref \ + *.bin *.i ex2 core gmon.out test.out test.ref a.out tcc_p \ + *.exe *.lib tcc.pod libtcc_test asmtest.ref asmtest.out \ + test.out2 test.out3 \ tcctest[1234] test[1234].out $(PROGS) win32/lib/*.o distclean: clean rm -f config.h config.mak config.texi # profiling version -tcc_p: tcc.c Makefile +tcc_p$(EXESUF): tcc.c Makefile $(CC) $(CFLAGS_P) -o $@ $< $(LIBS_P) # libtcc generation and example @@ -245,12 +250,12 @@ libtcc.a: libtcc.o libtcc_test$(EXESUF): libtcc_test.c libtcc.a $(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS) -libtest: libtcc_test - ./libtcc_test +libtest: libtcc_test$(EXESUF) + ./libtcc_test$(EXESUF) # targets for development -%.bin: %.c tcc +%.bin: %.c tcc$(EXESUF) $(TCC) -g -o $@ $< $(DISAS) $@ @@ -260,7 +265,7 @@ instr: instr.o # tiny assembler testing asmtest.ref: asmtest.S - $(CC) -c -o asmtest.ref.o asmtest.S + $(CC) $(CFLAGS) -c -o asmtest.ref.o asmtest.S objdump -D asmtest.ref.o > $@ # XXX: we compute tcc.c to go faster during development ! @@ -274,20 +279,22 @@ asmtest: asmtest.out asmtest.ref @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi instr.o: instr.S - $(CC) -O2 -Wall -g -c -o $@ $< + $(CC) -O2 -Wall -g $(CFLAGS) -c -o $@ $< -cache: tcc_g +cache: tcc_g$(EXESUF) cachegrind ./tcc_g -o /tmp/linpack -lm bench/linpack.c vg_annotate tcc.c > /tmp/linpack.cache.log # documentation and man page tcc-doc.html: tcc-doc.texi - texi2html -monolithic -number $< + texi2html -monolithic -number $< || > $(@) tcc.1: tcc-doc.texi ./texi2pod.pl $< tcc.pod pod2man --section=1 --center=" " --release=" " tcc.pod > $@ +check: test $(BCHECK_TEST) test2 test4 asmtest libtest$(EXESUF) + FILE=tcc-$(shell cat VERSION) # tar release (use 'make -k tar' on a checkouted tree) diff -X excl.tinycc -rduNp tinycc.oorig/tcc.c tinycc/tcc.c --- tinycc.oorig/tcc.c 2005-09-05 23:04:12.000000000 +0200 +++ tinycc/tcc.c 2005-10-01 15:55:25.000000000 +0200 @@ -86,9 +86,9 @@ #define TCC_TARGET_I386 #endif -#if !defined(WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \ - !defined(TCC_TARGET_C67) -#define CONFIG_TCC_BCHECK /* enable bound checking code */ +#if defined(WIN32) || defined(__UCLIBC__) || defined(TCC_TARGET_ARM) || \ + defined(TCC_TARGET_C67) +#undef CONFIG_TCC_BCHECK /* disable bound checking code on unsupported setups */ #endif #if defined(WIN32) && !defined(TCC_TARGET_PE) @@ -271,6 +271,7 @@ typedef struct BufferedFile { uint8_t *buf_end; int fd; int line_num; /* current line number - here to simplify code */ + int line_pos; /* current position in line - here to simplify code */ int ifndef_macro; /* #ifndef macro / #endif search */ int ifndef_macro_saved; /* saved ifndef_macro */ int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ @@ -280,6 +281,11 @@ typedef struct BufferedFile { unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */ } BufferedFile; +static void next_line(BufferedFile *bfile) { + bfile->line_num++; + bfile->line_pos = 0; +} + #define CH_EOB '\\' /* end of buffer or '\0' char in file */ #define CH_EOF (-1) /* end of file */ @@ -730,7 +736,7 @@ int __stdcall FreeConsole(void); #define strtof (float)strtod #define strtoll (long long)strtol #endif -#elif defined(TCC_UCLIBC) || defined(__FreeBSD__) +#elif defined(__UCLIBC__) || defined(__FreeBSD__) /* currently incorrect */ long double strtold(const char *nptr, char **endptr) { @@ -768,7 +774,7 @@ static void decl_initializer_alloc(CType int has_init, int v, int scope); int gv(int rc); void gv2(int rc1, int rc2); -void move_reg(int r, int s); +static void move_reg(int r, int s); void save_regs(int n); void save_reg(int r); void vpop(void); @@ -784,8 +790,8 @@ struct macro_level { static void macro_subst(TokenString *tok_str, Sym **nested_list, const int *macro_str, struct macro_level **can_read_stream); -void gen_op(int op); -void force_charshort_cast(int t); +static void gen_op(int op); +static void force_charshort_cast(int t); static void gen_cast(CType *type); void vstore(void); static Sym *sym_find(int v); @@ -1367,11 +1373,12 @@ void error1(TCCState *s1, int is_warning buf[0] = '\0'; if (file) { for(f = s1->include_stack; f < s1->include_stack_ptr; f++) - strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n", - (*f)->filename, (*f)->line_num); + strcat_printf(buf, sizeof(buf), "In file included from %s:%d:%d\n", + (*f)->filename, (*f)->line_num, (*f)->line_pos); if (file->line_num > 0) { strcat_printf(buf, sizeof(buf), - "%s:%d: ", file->filename, file->line_num); + "%s:%d:%d: ", file->filename, file->line_num, + file->line_pos); } else { strcat_printf(buf, sizeof(buf), "%s: ", file->filename); @@ -1382,6 +1389,8 @@ void error1(TCCState *s1, int is_warning } if (is_warning) strcat_printf(buf, sizeof(buf), "warning: "); + else + strcat_printf(buf, sizeof(buf), "error: "); strcat_vprintf(buf, sizeof(buf), fmt, ap); if (!s1->error_func) { @@ -1452,7 +1461,8 @@ void warning(const char *fmt, ...) void skip(int c) { if (tok != c) - error("'%c' expected", c); + error("syntax error before %c token. '%c' expected but saw \"%s\"", + tok, c, tokcstr.data); next(); } @@ -1637,7 +1647,7 @@ char *get_tok_str(int v, CValue *cv) case TOK_CLLONG: case TOK_CULLONG: /* XXX: not quite exact, but only useful for testing */ - sprintf(p, "%Lu", cv->ull); + sprintf(p, "%llu", cv->ull); break; case TOK_CCHAR: case TOK_LCHAR: @@ -1853,6 +1863,7 @@ BufferedFile *tcc_open(TCCState *s1, con if (bf->filename[i] == '\\') bf->filename[i] = '/'; bf->line_num = 1; + bf->line_pos = 0; bf->ifndef_macro = 0; bf->ifdef_stack_ptr = s1->ifdef_stack_ptr; // printf("opening '%s'\n", filename); @@ -1908,6 +1919,7 @@ static int handle_eob(void) static inline void inp(void) { ch = *(++(file->buf_ptr)); + file->line_pos++; /* end of buffer/file handling */ if (ch == CH_EOB) ch = handle_eob(); @@ -1919,13 +1931,13 @@ static void handle_stray(void) while (ch == '\\') { inp(); if (ch == '\n') { - file->line_num++; + next_line(file); inp(); } else if (ch == '\r') { inp(); if (ch != '\n') goto fail; - file->line_num++; + next_line(file); inp(); } else { fail: @@ -1961,6 +1973,7 @@ static int handle_stray1(uint8_t *p) #define PEEKC_EOB(c, p)\ {\ p++;\ + file->line_pos++;\ c = *p;\ if (c == '\\') {\ file->buf_ptr = p;\ @@ -2009,12 +2022,12 @@ static uint8_t *parse_line_comment(uint8 if (c == '\\') { PEEKC_EOB(c, p); if (c == '\n') { - file->line_num++; + next_line(file); PEEKC_EOB(c, p); } else if (c == '\r') { PEEKC_EOB(c, p); if (c == '\n') { - file->line_num++; + next_line(file); PEEKC_EOB(c, p); } } @@ -2032,7 +2045,7 @@ static uint8_t *parse_line_comment(uint8 static uint8_t *parse_comment(uint8_t *p) { int c; - + p++; for(;;) { /* fast skip loop */ @@ -2048,7 +2061,7 @@ static uint8_t *parse_comment(uint8_t *p } /* now we can handle all the cases */ if (c == '\n') { - file->line_num++; + next_line(file); p++; } else if (c == '*') { p++; @@ -2067,12 +2080,12 @@ static uint8_t *parse_comment(uint8_t *p while (c == '\\') { PEEKC_EOB(c, p); if (c == '\n') { - file->line_num++; + next_line(file); PEEKC_EOB(c, p); } else if (c == '\r') { PEEKC_EOB(c, p); if (c == '\n') { - file->line_num++; + next_line(file); PEEKC_EOB(c, p); } } else { @@ -2138,13 +2151,13 @@ static uint8_t *parse_pp_string(uint8_t /* escape : just skip \[\r]\n */ PEEKC_EOB(c, p); if (c == '\n') { - file->line_num++; + next_line(file); p++; } else if (c == '\r') { PEEKC_EOB(c, p); if (c != '\n') expect("'\n' after '\r'"); - file->line_num++; + next_line(file); p++; } else if (c == CH_EOF) { goto unterminated_string; @@ -2157,7 +2170,7 @@ static uint8_t *parse_pp_string(uint8_t } } } else if (c == '\n') { - file->line_num++; + next_line(file); goto add_char; } else if (c == '\r') { PEEKC_EOB(c, p); @@ -2165,7 +2178,7 @@ static uint8_t *parse_pp_string(uint8_t if (str) cstr_ccat(str, '\r'); } else { - file->line_num++; + next_line(file); goto add_char; } } else { @@ -2202,7 +2215,7 @@ void preprocess_skip(void) goto redo_no_start; case '\n': start_of_line = 1; - file->line_num++; + next_line(file); p++; goto redo_no_start; case '\\': @@ -3505,6 +3518,7 @@ static inline void next_nomacro1(void) case '\v': case '\r': p++; + file->line_pos++; goto redo_no_start; case '\\': @@ -3564,8 +3578,9 @@ static inline void next_nomacro1(void) if (parse_flags & PARSE_FLAG_LINEFEED) { tok = TOK_LINEFEED; } else { - file->line_num++; tok_flags |= TOK_FLAG_BOL; + next_line(file); + file->line_pos++; p++; goto redo_no_start; } @@ -3582,6 +3597,7 @@ static inline void next_nomacro1(void) goto redo_no_start; } else { if (c == '#') { + file->line_pos++; p++; tok = TOK_TWOSHARPS; } else { @@ -3614,12 +3630,14 @@ static inline void next_nomacro1(void) p1 = p; h = TOK_HASH_INIT; h = TOK_HASH_FUNC(h, c); + file->line_pos++; p++; for(;;) { c = *p; if (!isidnum_table[c]) break; h = TOK_HASH_FUNC(h, c); + file->line_pos++; p++; } if (c != '\\') { @@ -3639,7 +3657,7 @@ static inline void next_nomacro1(void) goto token_found; pts = &(ts->hash_next); } - ts = tok_alloc_new(pts, p1, len); + ts = tok_alloc_new(pts, (const char*)p1, len); token_found: ; } else { /* slower case */ @@ -3647,8 +3665,10 @@ static inline void next_nomacro1(void) while (p1 < p) { cstr_ccat(&tokcstr, *p1); + file->line_pos++; p1++; } + file->line_pos--; p--; PEEKC(c, p); parse_ident_slow: @@ -3676,7 +3696,7 @@ static inline void next_nomacro1(void) goto parse_ident_slow; } } - break; + break; /* never get here */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -3767,11 +3787,13 @@ static inline void next_nomacro1(void) case '<': PEEKC(c, p); if (c == '=') { + file->line_pos++; p++; tok = TOK_LE; } else if (c == '<') { PEEKC(c, p); if (c == '=') { + file->line_pos++; p++; tok = TOK_A_SHL; } else { @@ -3785,11 +3807,13 @@ static inline void next_nomacro1(void) case '>': PEEKC(c, p); if (c == '=') { + file->line_pos++; p++; tok = TOK_GE; } else if (c == '>') { PEEKC(c, p); if (c == '=') { + file->line_pos++; p++; tok = TOK_A_SAR; } else { @@ -3803,9 +3827,11 @@ static inline void next_nomacro1(void) case '&': PEEKC(c, p); if (c == '&') { + file->line_pos++; p++; tok = TOK_LAND; } else if (c == '=') { + file->line_pos++; p++; tok = TOK_A_AND; } else { @@ -3816,9 +3842,11 @@ static inline void next_nomacro1(void) case '|': PEEKC(c, p); if (c == '|') { + file->line_pos++; p++; tok = TOK_LOR; } else if (c == '=') { + file->line_pos++; p++; tok = TOK_A_OR; } else { @@ -3829,9 +3857,11 @@ static inline void next_nomacro1(void) case '+': PEEKC(c, p); if (c == '+') { + file->line_pos++; p++; tok = TOK_INC; } else if (c == '=') { + file->line_pos++; p++; tok = TOK_A_ADD; } else { @@ -3842,12 +3872,15 @@ static inline void next_nomacro1(void) case '-': PEEKC(c, p); if (c == '-') { + file->line_pos++; p++; tok = TOK_DEC; } else if (c == '=') { + file->line_pos++; p++; tok = TOK_A_SUB; } else if (c == '>') { + file->line_pos++; p++; tok = TOK_ARROW; } else { @@ -3871,6 +3904,7 @@ static inline void next_nomacro1(void) p = parse_line_comment(p); goto redo_no_start; } else if (c == '=') { + file->line_pos++; p++; tok = TOK_A_DIV; } else { @@ -3893,6 +3927,7 @@ static inline void next_nomacro1(void) case '$': /* only used in assembler */ case '@': /* dito */ tok = c; + file->line_pos++; p++; break; default: @@ -4707,7 +4742,7 @@ void save_regs(int n) /* move register 's' to 'r', and flush previous value of r to memory if needed */ -void move_reg(int r, int s) +static void move_reg(int r, int s) { SValue sv; @@ -4720,8 +4755,9 @@ void move_reg(int r, int s) } } + /* get address of vtop (vtop MUST BE an lvalue) */ -void gaddrof(void) +static void gaddrof(void) { vtop->r &= ~VT_LVAL; /* tricky: if saved lvalue, then we can go back to lvalue */ @@ -4731,7 +4767,7 @@ void gaddrof(void) #ifdef CONFIG_TCC_BCHECK /* generate lvalue bound code */ -void gbound(void) +static void gbound(void) { int lval_type; CType type1; @@ -5555,7 +5591,7 @@ static void check_comparison_pointer_typ } /* generic gen_op: handles types problems */ -void gen_op(int op) +static void gen_op(int op) { int u, t1, t2, bt1, bt2, t; CType type1; @@ -5692,7 +5728,7 @@ void gen_op(int op) } /* generic itof for unsigned long long case */ -void gen_cvt_itof1(int t) +static void gen_cvt_itof1(int t) { if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) == (VT_LLONG | VT_UNSIGNED)) { @@ -5713,7 +5749,7 @@ void gen_cvt_itof1(int t) } /* generic ftoi for unsigned long long case */ -void gen_cvt_ftoi1(int t) +static void gen_cvt_ftoi1(int t) { int st; @@ -5737,7 +5773,7 @@ void gen_cvt_ftoi1(int t) } /* force char or short cast */ -void force_charshort_cast(int t) +static void force_charshort_cast(int t) { int bits, dbt; dbt = t & VT_BTYPE; @@ -9299,6 +9335,7 @@ int tcc_compile_string(TCCState *s, cons bf->buf_end = buf + len; pstrcpy(bf->filename, sizeof(bf->filename), ""); bf->line_num = 1; + bf->line_pos = 0; file = bf; ret = tcc_compile(s); @@ -9329,6 +9366,7 @@ void tcc_define_symbol(TCCState *s1, con *bf->buf_end = CH_EOB; bf->filename[0] = '\0'; bf->line_num = 1; + bf->line_pos = 0; file = bf; s1->include_stack_ptr = s1->include_stack; @@ -9979,6 +10017,7 @@ static int tcc_add_file_internal(TCCStat ehdr.e_ident[2] == ELFMAG2 && ehdr.e_ident[3] == ELFMAG3) { file->line_num = 0; /* do not display line number if error */ + file->line_pos = 0; if (ehdr.e_type == ET_REL) { ret = tcc_load_object_file(s1, fd, 0); } else if (ehdr.e_type == ET_DYN) { @@ -10200,7 +10239,7 @@ static int set_flag(TCCState *s, const F /* set/reset a warning */ -int tcc_set_warning(TCCState *s, const char *warning_name, int value) +static int tcc_set_warning(TCCState *s, const char *warning_name, int value) { int i; const FlagDef *p; @@ -10283,6 +10322,7 @@ void help(void) " -Idir add include path 'dir'\n" " -Dsym[=val] define 'sym' with value 'val'\n" " -Usym undefine 'sym'\n" + " -E preprocess to stdout\n" "Linker options:\n" " -Ldir add library path 'dir'\n" " -llib link with dynamic or static library 'lib'\n" @@ -10319,6 +10359,7 @@ enum { TCC_OPTION_bench, TCC_OPTION_bt, TCC_OPTION_b, + TCC_OPTION_E, TCC_OPTION_g, TCC_OPTION_c, TCC_OPTION_static, @@ -10354,6 +10395,7 @@ static const TCCOption tcc_options[] = { #ifdef CONFIG_TCC_BCHECK { "b", TCC_OPTION_b, 0 }, #endif + { "E", TCC_OPTION_E, 0 }, { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, { "c", TCC_OPTION_c, 0 }, { "static", TCC_OPTION_static, 0 }, @@ -10515,6 +10557,9 @@ int parse_args(TCCState *s, int argc, ch do_debug = 1; break; #endif + case TCC_OPTION_E: + output_type |= TCC_OUTPUT_PP; + break; case TCC_OPTION_g: do_debug = 1; break; diff -X excl.tinycc -rduNp tinycc.oorig/tccelf.c tinycc/tccelf.c --- tinycc.oorig/tccelf.c 2005-09-05 23:04:12.000000000 +0200 +++ tinycc/tccelf.c 2005-10-01 15:55:25.000000000 +0200 @@ -204,8 +204,8 @@ static int add_elf_sym(Section *s, unsig /* weak is ignored if already global */ } else { #if 0 - printf("new_bind=%d new_shndx=%d last_bind=%d old_shndx=%d\n", - sym_bind, sh_num, esym_bind, esym->st_shndx); + printf("%12d new_bind=%d new_shndx=%d last_bind=%d old_shndx=%d\n", + sym_index, sym_bind, sh_num, esym_bind, esym->st_shndx); #endif /* NOTE: we accept that two DLL define the same symbol */ if (s != tcc_state->dynsymtab_section) @@ -1823,6 +1823,7 @@ static int tcc_load_object_file(TCCState /* find corresponding section, if any */ for(j = 1; j < s1->nb_sections;j++) { s = s1->sections[j]; +//fprintf(stderr,"[%2d] s->name='%s', sh_name='%s'\n", i,s->name,sh_name); if (!strcmp(s->name, sh_name)) { if (!strncmp(sh_name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1)) { @@ -1831,6 +1832,7 @@ static int tcc_load_object_file(TCCState symbols can still be defined in it. */ sm_table[i].link_once = 1; +//fprintf(stderr,"sm[%d].l_o=true\n", i); goto next; } else { goto found; @@ -1874,7 +1876,6 @@ static int tcc_load_object_file(TCCState /* second short pass to update sh_link and sh_info fields of new sections */ - sm = sm_table; for(i = 1; i < ehdr.e_shnum; i++) { s = sm_table[i].s; if (!s || !sm_table[i].new_section) @@ -1888,6 +1889,7 @@ static int tcc_load_object_file(TCCState s1->sections[s->sh_info]->reloc = s; } } + sm = sm_table; /* resolve symbols */ old_to_new_syms = tcc_mallocz(nb_syms * sizeof(int)); @@ -1949,9 +1951,14 @@ static int tcc_load_object_file(TCCState if (sym_index >= nb_syms) goto invalid_reloc; sym_index = old_to_new_syms[sym_index]; - if (!sym_index) { +//fprintf(stderr,"[%2d] sym_index=%d sm.l_o='%s'\n",i, sym_index,sm->link_once?"true":"false"); + /* ignore link_once in rel section. */ + if (!sym_index && !sm->link_once) { +//fprintf(stderr,"sm.l_o='%s'\n", sm->link_once?"true":"false"); invalid_reloc: error_noabort("Invalid relocation entry"); + error_noabort(" [%2d] '%s' @%.8x", i, + strsec + sh->sh_name, rel->r_offset); goto fail; } rel->r_info = ELF32_R_INFO(sym_index, type); @@ -2066,7 +2073,7 @@ static int tcc_load_archive(TCCState *s1 break; } ar_name[i + 1] = '\0'; - // printf("name='%s' size=%d %s\n", ar_name, size, ar_size); +/* printf("name='%s' size=%d %s\n", ar_name, size, ar_size);*/ file_offset = lseek(fd, 0, SEEK_CUR); /* align to even */ size = (size + 1) & ~1; diff -X excl.tinycc -rduNp tinycc.oorig/tcclib.h tinycc/tcclib.h --- tinycc.oorig/tcclib.h 2002-08-18 15:25:12.000000000 +0200 +++ tinycc/tcclib.h 2005-10-01 15:55:25.000000000 +0200 @@ -35,6 +35,7 @@ int fgetc(FILE *stream); char *fgets(char *s, int size, FILE *stream); int getc(FILE *stream); int getchar(void); +int putchar(int); char *gets(char *s); int ungetc(int c, FILE *stream); int fflush(FILE *stream); diff -X excl.tinycc -rduNp tinycc.oorig/tcctest.c tinycc/tcctest.c --- tinycc.oorig/tcctest.c 2005-09-05 23:04:12.000000000 +0200 +++ tinycc/tcctest.c 2005-10-01 15:55:25.000000000 +0200 @@ -223,7 +223,7 @@ void macro_test(void) #line 203 "test" printf("__LINE__=%d __FILE__=%s\n", __LINE__, __FILE__); -#line 220 "tcctest.c" +#line 226 "tcctest.c" /* not strictly preprocessor, but we test it there */ #ifdef C99_MACROS @@ -915,9 +915,11 @@ void bool_test() } } +static int tab_init[0]; + /* GCC accepts that */ -static int tab_reinit[]; static int tab_reinit[10]; +static int tab_reinit[]; //int cinit1; /* a global variable can be defined several times without error ! */ int cinit1; diff -X excl.tinycc -rduNp tinycc.oorig/TODO tinycc/TODO --- tinycc.oorig/TODO 2004-11-07 16:51:57.000000000 +0100 +++ tinycc/TODO 2005-10-01 15:55:25.000000000 +0200 @@ -22,8 +22,6 @@ TODO list: - see -lxxx bug (Michael Charity). - see transparent union pb in /urs/include/sys/socket.h - precise behaviour of typeof with arrays ? (__put_user macro) -- #include_next support for /usr/include/limits ? - but should suffice for most cases) - handle '? x, y : z' in unsized variable initialization (',' is considered incorrectly as separator in preparser) - function pointers/lvalues in ? : (linux kernel net/core/dev.c)