Skip to content

Commit 5f33d31

Browse files
author
grischka
committed
tcc: re-enable correct option -r support
Forgot about it. It allows to compile several sources (and other .o's) to one single .o file; tcc -r -o all.o f1.c f2.c f3.S o4.o ... Also: - option -fold-struct-init-code removed, no effect anymore - (tcc_)set_environment() moved to tcc.c - win32/lib/(win)crt1 minor fix & add dependency - debug line output for asm (tcc -c -g xxx.S) enabled - configure/Makefiles: x86-64 -> x86_64 changes - README: cleanup
1 parent 3992378 commit 5f33d31

18 files changed

+178
-151
lines changed

Diff for: Changelog

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Platforms:
1616
- vastly improved support for ARM hard float calling convention
1717
(Thomas Preud'homme, Daniel Glöckner)
1818
- provide a runtime library for ARM (Thomas Preud'homme)
19-
- many x86-64 ABI fixes incl. XMM register passing and tests (James Lyon)
19+
- many x86_64 ABI fixes incl. XMM register passing and tests (James Lyon)
2020
- ABI tests with native compiler using libtcc (James Lyon)
2121
- UNICODE startup code supports wmain and wWinMain (YX Hao)
2222

2323
Features:
2424
- VLA (variable length array) improved (James Lyon, Pip Cet)
2525
- import functions by ordinal in .def files on windows (YX Hao)
26-
- x86/x86-64 assembler much improved (Michael Matz)
26+
- x86/x86_64 assembler much improved (Michael Matz)
2727
- simple dead code suppression (Edmund Grimley Evans, Michael Matz, grischka)
2828
- implement round/fmin/fmax etc. math on windows (Avi Halachmi)
2929
- #pragma once support (Sergey Korshunoff, Vlad Vissoultchev, ...)

Diff for: Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LDFLAGS_P = $(LDFLAGS)
5656

5757
CONFIG_$(ARCH) = yes
5858
NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
59-
NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
59+
NATIVE_DEFINES_$(CONFIG_x86_64) += -DTCC_TARGET_X86_64
6060
NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE
6161
NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC
6262
NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM
@@ -95,7 +95,7 @@ ARM64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
9595
C67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
9696

9797
ifdef CONFIG_WIN32
98-
ifeq ($(ARCH),x86-64)
98+
ifeq ($(ARCH),x86_64)
9999
NATIVE_FILES=$(WIN64_FILES)
100100
PROGS_CROSS=$(WIN32_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
101101
LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
@@ -110,7 +110,7 @@ NATIVE_FILES=$(I386_FILES)
110110
PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
111111
LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
112112

113-
else ifeq ($(ARCH),x86-64)
113+
else ifeq ($(ARCH),x86_64)
114114
NATIVE_FILES=$(X86_64_FILES)
115115
PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
116116
LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a

Diff for: README

+6-15
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,19 @@ Features:
2828
Documentation:
2929
-------------
3030

31-
1) Installation on a i386/x86_64/arm Linux/OSX/FreeBSD host (for Windows read tcc-win32.txt)
32-
33-
Note: For OSX and FreeBSD, gmake should be used instead of make.
31+
1) Installation on a i386/x86_64/arm Linux/OSX/FreeBSD host
3432

3533
./configure
3634
make
3735
make test
3836
make install
3937

40-
Alternatively, out-of-tree builds are supported: you may use different
41-
directories to hold build objects, kept separate from your source tree:
42-
43-
mkdir _build
44-
cd _build
45-
../configure
46-
make
47-
make test
48-
make install
38+
Notes: For OSX and FreeBSD, gmake should be used instead of make.
39+
For Windows read tcc-win32.txt.
4940

50-
Texi2html must be installed to compile the doc.
51-
By default, tcc is installed in /usr/local/bin.
52-
./configure --help shows configuration options.
41+
makeinfo must be installed to compile the doc. By default, tcc is
42+
installed in /usr/local/bin. ./configure --help shows configuration
43+
options.
5344

5445

5546
2) Introduction

Diff for: configure

+5-5
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ case "$cpu" in
163163
x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
164164
cpu="x86"
165165
;;
166-
x86_64|amd64)
167-
cpu="x86-64"
166+
x86_64|amd64|x86-64)
167+
cpu="x86_64"
168168
;;
169169
arm*)
170170
case "$cpu" in
@@ -332,7 +332,7 @@ if test -z "$cross_prefix" ; then
332332
fi
333333

334334
if test -z "$triplet"; then
335-
if test $cpu = "x86-64" -o $cpu = "aarch64" ; then
335+
if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
336336
if test -f "/usr/lib64/crti.o" ; then
337337
tcc_lddir="lib64"
338338
fi
@@ -453,8 +453,8 @@ echo "#define GCC_MINOR $gcc_minor" >> $TMPH
453453

454454
if test "$cpu" = "x86" ; then
455455
echo "ARCH=i386" >> config.mak
456-
elif test "$cpu" = "x86-64" ; then
457-
echo "ARCH=x86-64" >> config.mak
456+
elif test "$cpu" = "x86_64" ; then
457+
echo "ARCH=x86_64" >> config.mak
458458
elif test "$cpu" = "armv4l" ; then
459459
echo "ARCH=arm" >> config.mak
460460
echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH

Diff for: lib/Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
99
ifndef TARGET
1010
# we're building the native libtcc1.a
1111
ifdef CONFIG_WIN32
12-
ifeq ($(ARCH),x86-64)
12+
ifeq ($(ARCH),x86_64)
1313
TARGET = x86_64-win32
1414
else
1515
TARGET = i386-win32
1616
endif
1717
else ifeq ($(ARCH),i386)
1818
TARGET = i386
19-
else ifeq ($(ARCH),x86-64)
19+
else ifeq ($(ARCH),x86_64)
2020
TARGET = x86_64
2121
else ifeq ($(ARCH),arm)
2222
TARGET = arm
@@ -83,6 +83,9 @@ $(DIR)/%.o : %.c
8383
$(DIR)/%.o : %.S
8484
$(XCC) -c $< -o $@ $(TGT) $(XFLAGS)
8585

86+
$(DIR)/crt1w.o : crt1.c
87+
$(DIR)/wincrt1w.o : wincrt1.c
88+
8689
$(OBJ) : $(DIR)/exists
8790

8891
%/exists :

Diff for: libtcc.c

-19
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,6 @@ static const FlagDef options_f[] = {
15721572
{ offsetof(TCCState, nocommon), FD_INVERT, "common" },
15731573
{ offsetof(TCCState, leading_underscore), 0, "leading-underscore" },
15741574
{ offsetof(TCCState, ms_extensions), 0, "ms-extensions" },
1575-
{ offsetof(TCCState, old_struct_init_code), 0, "old-struct-init-code" },
15761575
{ offsetof(TCCState, dollars_in_identifiers), 0, "dollars-in-identifiers" },
15771576
{ 0, 0, NULL }
15781577
};
@@ -1984,21 +1983,3 @@ PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time)
19841983
fprintf(stderr, "* %d bytes memory used\n", mem_max_size);
19851984
#endif
19861985
}
1987-
1988-
PUB_FUNC void tcc_set_environment(TCCState *s)
1989-
{
1990-
char * path;
1991-
1992-
path = getenv("C_INCLUDE_PATH");
1993-
if(path != NULL) {
1994-
tcc_add_include_path(s, path);
1995-
}
1996-
path = getenv("CPATH");
1997-
if(path != NULL) {
1998-
tcc_add_include_path(s, path);
1999-
}
2000-
path = getenv("LIBRARY_PATH");
2001-
if(path != NULL) {
2002-
tcc_add_library_path(s, path);
2003-
}
2004-
}

Diff for: tcc-doc.texi

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ gcc's algorithm.
387387
Select the float ABI. Possible values: @code{softfp} and @code{hard}
388388

389389
@item -mno-sse
390-
Do not use sse registers on x86-64
390+
Do not use sse registers on x86_64
391391

392392
@item -m32, -m64
393-
Pass command line to the i386/x86-64 cross compiler.
393+
Pass command line to the i386/x86_64 cross compiler.
394394

395395
@end table
396396

Diff for: tcc.c

+27-25
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ static const char help2[] =
104104
" signed-char default char is signed\n"
105105
" common use common section instead of bss\n"
106106
" leading-underscore decorate extern symbols\n"
107-
" ms-extensions allow struct w/o identifier\n"
107+
" ms-extensions allow anonymous struct in struct\n"
108108
" dollars-in-identifiers allow '$' in C symbols\n"
109-
" old-struct-init-code some hack for parsing initializers\n"
110109
"-m... target specific options:\n"
111110
" ms-bitfields use MSVC bitfield layout\n"
112111
#ifdef TCC_TARGET_ARM
@@ -151,32 +150,18 @@ static const char version[] =
151150
"C67"
152151
#elif defined TCC_TARGET_ARM
153152
"ARM"
154-
# ifdef TCC_ARM_HARDFLOAT
155-
" Hard Float"
156-
# endif
157153
#elif defined TCC_TARGET_ARM64
158154
"AArch64"
159-
# ifdef TCC_ARM_HARDFLOAT
155+
#endif
156+
#ifdef TCC_ARM_HARDFLOAT
160157
" Hard Float"
161-
# endif
162158
#endif
163159
#ifdef TCC_TARGET_PE
164160
" Windows"
165-
#elif defined(__APPLE__)
166-
/* Current Apple OS name as of 2016 */
167-
" macOS"
168161
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
169162
" FreeBSD"
170-
#elif defined(__DragonFly__)
171-
" DragonFly BSD"
172-
#elif defined(__NetBSD__)
173-
" NetBSD"
174-
#elif defined(__OpenBSD__)
175-
" OpenBSD"
176-
#elif defined(__linux__)
177-
" Linux"
178163
#else
179-
" Unidentified system"
164+
" Linux"
180165
#endif
181166
")\n"
182167
;
@@ -201,6 +186,24 @@ static void print_search_dirs(TCCState *s)
201186
#endif
202187
}
203188

189+
static void set_environment(TCCState *s)
190+
{
191+
char * path;
192+
193+
path = getenv("C_INCLUDE_PATH");
194+
if(path != NULL) {
195+
tcc_add_include_path(s, path);
196+
}
197+
path = getenv("CPATH");
198+
if(path != NULL) {
199+
tcc_add_include_path(s, path);
200+
}
201+
path = getenv("LIBRARY_PATH");
202+
if(path != NULL) {
203+
tcc_add_library_path(s, path);
204+
}
205+
}
206+
204207
static char *default_outputfile(TCCState *s, const char *first_file)
205208
{
206209
char buf[1024];
@@ -265,9 +268,6 @@ int main(int argc, char **argv)
265268
#endif
266269
if (opt == OPT_V)
267270
return 0;
268-
269-
tcc_set_environment(s);
270-
271271
if (opt == OPT_PRINT_DIRS) {
272272
/* initialize search dirs */
273273
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
@@ -287,8 +287,8 @@ int main(int argc, char **argv)
287287
if (!s->ppfp)
288288
tcc_error("could not write '%s'", s->outfile);
289289
}
290-
} else if (s->output_type == TCC_OUTPUT_OBJ) {
291-
if (s->nb_libraries != 0 && !s->option_r)
290+
} else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
291+
if (s->nb_libraries)
292292
tcc_error("cannot specify libraries with -c");
293293
if (n > 1 && s->outfile)
294294
tcc_error("cannot specify output file with -c many files");
@@ -301,6 +301,7 @@ int main(int argc, char **argv)
301301
start_time = getclock_ms();
302302
}
303303

304+
set_environment(s);
304305
if (s->output_type == 0)
305306
s->output_type = TCC_OUTPUT_EXE;
306307
tcc_set_output_type(s, s->output_type);
@@ -323,7 +324,8 @@ int main(int argc, char **argv)
323324
}
324325
s->filetype = 0;
325326
s->alacarte_link = 1;
326-
if (ret || --n == 0 || s->output_type == TCC_OUTPUT_OBJ)
327+
if (ret || --n == 0
328+
|| (s->output_type == TCC_OUTPUT_OBJ && !s->option_r))
327329
break;
328330
}
329331

Diff for: tcc.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,7 @@ struct TCCState {
615615
/* C language options */
616616
int char_is_unsigned;
617617
int leading_underscore;
618-
int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
619-
int old_struct_init_code; /* use old algorithm to init array in struct when there is no '{' used.
620-
Liuux 2.4.26 can't find initrd when compiled with a new algorithm */
618+
int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
621619
int dollars_in_identifiers; /* allows '$' char in indentifiers */
622620
int ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
623621

@@ -1147,10 +1145,8 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
11471145

11481146
ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
11491147
PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
1150-
11511148
PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
11521149
PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
1153-
PUB_FUNC void tcc_set_environment(TCCState *s);
11541150
#ifdef _WIN32
11551151
ST_FUNC char *normalize_slashes(char *path);
11561152
#endif
@@ -1276,8 +1272,15 @@ ST_DATA int func_vc;
12761272
ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
12771273
ST_DATA const char *funcname;
12781274

1275+
ST_FUNC void tcc_debug_start(TCCState *s1);
1276+
ST_FUNC void tcc_debug_end(TCCState *s1);
1277+
ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
1278+
ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);
1279+
ST_FUNC void tcc_debug_line(TCCState *s1);
1280+
12791281
ST_FUNC void tccgen_start(TCCState *s1);
12801282
ST_FUNC void tccgen_end(TCCState *s1);
1283+
12811284
ST_FUNC void free_inline_functions(TCCState *s);
12821285
ST_FUNC void check_vstack(void);
12831286

Diff for: tccasm.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,13 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
926926
set_idnum('.', IS_ID);
927927
if (do_preprocess)
928928
parse_flags |= PARSE_FLAG_PREPROCESS;
929-
next();
930929
for(;;) {
930+
next();
931931
if (tok == TOK_EOF)
932932
break;
933+
/* generate line number info */
934+
if (global && s1->do_debug)
935+
tcc_debug_line(s1);
933936
parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
934937
redo:
935938
if (tok == '#') {
@@ -981,15 +984,12 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
981984
}
982985
}
983986
/* end of line */
984-
if (tok != ';' && tok != TOK_LINEFEED){
987+
if (tok != ';' && tok != TOK_LINEFEED)
985988
expect("end of line");
986-
}
987989
parse_flags &= ~PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
988-
next();
989990
}
990991

991992
asm_free_labels(s1);
992-
993993
return 0;
994994
}
995995

@@ -1001,24 +1001,19 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
10011001

10021002
define_start = define_stack;
10031003
preprocess_start(s1);
1004+
tcc_debug_start(s1);
10041005

10051006
/* default section is text */
10061007
cur_text_section = text_section;
10071008
ind = cur_text_section->data_offset;
10081009
nocode_wanted = 0;
10091010

1010-
/* an elf symbol of type STT_FILE must be put so that STB_LOCAL
1011-
symbols can be safely used */
1012-
put_elf_sym(symtab_section, 0, 0,
1013-
ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
1014-
SHN_ABS, file->filename);
1015-
10161011
ret = tcc_assemble_internal(s1, do_preprocess, 1);
10171012

10181013
cur_text_section->data_offset = ind;
10191014

1015+
tcc_debug_end(s1);
10201016
free_defines(define_start);
1021-
10221017
return ret;
10231018
}
10241019

0 commit comments

Comments
 (0)