Commit Graph

2335 Commits (meesbs)
 

Author SHA1 Message Date
Larry Doolittle 7443db0d5f Remove some unused-parameter lint
Mark TCCState parameter as unused in tcc_undefine_symbol(), tcc_add_symbol(),
tcc_print_stats(), asm_get_local_label_name(), use_section1(), tccpp_delete(),
tcc_tool_ar(), tcc_tool_impdef(), and tcc_tool_cross().
Also mark it unused in tcc_add_bcheck() unless CONFIG_TCC_BCHECK.
Remove it entirely in ld_next().
2017-05-08 08:30:43 -07:00
Christian Jullien 56df27502c C string litteral is const, fix return type of default_elfinterp. Remove #ifndef TCC_IS_NATIVE in arm-gen.c as suggested by grischka. 2017-05-08 09:18:27 +02:00
Larry Doolittle 19d8b8a173 Spelling fixes in C comments only 2017-05-07 21:38:09 -07:00
Larry Doolittle 1b9935cf36 Add missing const and add warning flags 2017-05-07 21:28:05 -07:00
Michael Matz 524f6dff17 Fix a warning
"missing intitializer for field op_type" with gcc -Wextra.  It's
zero-initialized anyway, and not that much a hassle to explicitely
initialize either, so let's be nice and make it not warn.
2017-05-08 05:29:54 +02:00
grischka 44abffe33a more minor fixes
* tccgen: re-allow long double constants for x87 cross
  sizeof (long double) may be 12 or 16 depending on host platform
  (i386/x86_64 on unix/windows).
  Except that it's 8 if the host is on windows and not gcc
  was used to compile tcc.

* win64: fix builtin_va_start after VT_REF removal
  See also a8b83ce43a

* tcctest.c: remove outdated limitation for ll-bitfield test
  It always worked, there is no reason why it should not work
  in future.

* libtcc1.c: exclude long double conversion on ARM

* Makefile: remove CFLAGS from link recipes

* lib/Makefile: use target DEFINES as passed from main Makefile

* lib/armflush.c lib/va_list.c: factor out from libtcc1.c

* arm-gen.c: disable "depreciated" warnings for now
2017-05-07 12:41:29 +02:00
Michael Matz 94ac9f2b49 Accept extern initialized file-scope variables
'extern int i = 42;' at file scope (but not in function scope!) is
allowed and is a proper definition, even though questionable style;
some compilers warn about this.
2017-05-07 08:10:06 +02:00
Michael Matz 5732a1882e elf: Fix last commit
Forgot to mark tccelf.c as to be committed in last commit :-/
2017-05-07 04:52:21 +02:00
Michael Matz 680e84fe42 elf: Support STB_LOCAL dynamic symbols
local symbols can be resolved statically, they don't have to be
done dynamically, so this is a slight speedup at load time for
produced executables and shared libs.  The musl libc also rejects
any STB_LOCAL symbols for dynamic symbol resolution, so there it
also fixes use of shared libs created by tcc.
2017-05-07 04:41:40 +02:00
Michael Matz 600018ce47 elf: Ignore SHF_COMPRESSED sections
some newer systems have debug sections compressed by default, which
includes those in the crt[1in].o startup files.  These can't simply
be concatenated like all others (which leads to invalid section contents
ultimately making gdb fail) but need special handling.

Instead of that special handling (decompressing, which in turn requires
linking against zlib) let's just ignore such sections, even though that
means to also ignore all other debug sections from that particular input
file.  Our own generated files of course don't have the problem.
2017-05-06 07:30:44 +02:00
Michael Matz ff998900b1 struct-init: Fix zero initialization with multi-level designators
See the added testcase.  When one used designators like .a.x to initialize
sub-members of members, and didn't then initialize all of them the
required zero-initialization of the other sub-members wasn't done.
The fix also enables tiny code cleanups.
2017-05-06 05:28:13 +02:00
Michael Matz 0757234560 Fix unsigned enum bit-fields
See testcase.  If an enum has only positive values, fits N bits,
and is placed in a N-bit bit-field that bit-fields must be treated
as unsigned, not signed.
2017-05-05 23:16:43 +02:00
Michael Matz a7a3627ab2 Fix segfault with invalid function def
This invalid function definition:
  int f()[] {}
was tried to be handled but there was no testcase if it actually worked.
This fixes it and adds a TCC only testcase.
2017-05-05 22:01:02 +02:00
Michael Matz d4878985e8 Rebuild cross compilers when sources change
ONE_SOURCE=yes cross-compilers currently only depend on tcc.c, which
itself has no further deps.  So e.g. changing tccgen.c or tcctok.h
don't automatically rebuild cross compilers.  Let's go over
the intermediate $(X)tcc.o file which automatically depends on
LIBTCC_INC, which are all relevant source files.
2017-05-02 03:14:05 +02:00
Michael Matz 149678e888 Tidy decl_designator
Removing the need for the notfirst local variable, and tidy loop structure
and error messaging a bit.
2017-05-02 03:14:05 +02:00
Michael Matz 9839b60177 Remove label_or_decl
The only use of this function can be rewritten in terms of
is_label (if one other use of that one are a bit amended).
2017-05-02 03:14:05 +02:00
Michael Matz c7dbc900c8 Cleanups (float consts, sections, symbols)
introduce common_section (SHN_COMMON), factorize some handling
in decl_initializer_alloc, add section_add and use it to factorize
some code that allocates stuff in sections (at the same time also fixing
harmless bugs re section alignment), use init_putv to emit float consts
into .data from gv() (fixing an XXX).
2017-05-02 03:13:55 +02:00
Michael Matz 25522e4799 Merge func_decl_list into decl0
Removes some code duplication and also implements one feature:
checking for duplicate decls for old style parameters.
2017-05-02 03:07:37 +02:00
Michael Matz 7aef0522b0 Tidy decl_designator
The fixme therein is long solved.
2017-05-02 03:07:37 +02:00
Michael Matz 8ca98e23c4 Tidy unary() a bit
factor code a bit for transforming tokens into SValues.  This revealed
a bug in TOK_GET (see testcase), which happened to be harmless before.
So fix that as well.
2017-05-02 03:07:37 +02:00
Michael Matz 21b12ea10d Factor some code
Three places that skip (and store) tokens in some fashion can
be factored a bit.
2017-05-02 03:07:37 +02:00
Michael Matz 328b06a3fc Extend type_to_str
to also print storage-class specifiers.
2017-05-02 03:07:36 +02:00
Michael Matz 182367e232 Reorganize type parsing
Various corner cases for declarator parsing were incorrect.  This
reorganizes and fixes it, and somewhat simplifies it as well.
2017-05-02 03:07:36 +02:00
Michael Matz 5891fbc0c8 Tidy typename parsing a bit 2017-05-02 03:07:36 +02:00
Michael Matz 51314932e3 Tidy arg parsing for builtins
Saves some lines of code.
2017-05-02 03:07:36 +02:00
Michael Matz 10551d6961 Clarify that the CIL target code is dead
This backend doesn't work anymore since a long time.
Don't remove it yet, it might be an inspiration.
2017-05-02 03:07:36 +02:00
Michael Matz a8b83ce43a Remove VT_REF
The canonical way to describe a local variable that actually holds
the address of an lvalue is VT_LLOCAL.  Remove the last user of VT_REF,
and handling of it, thereby freeing a flag for SValue.r.
2017-05-02 03:07:36 +02:00
Michael Matz 8b9697ca6b Fix bogus check for VT_LLOCAL types
VT_LLOCAL is a flag on .r, not on type.t.  Fixing this requires
minor surgery for compound literals which accidentally happened
to be subsumed by the bogus test.
2017-05-02 03:07:36 +02:00
Michael Matz 24420bb5c0 elf: Tidy section headers
Don't emit useless section headers and also sort them in allocated
order.  Doesn't change behaviour except makes the resulting files
a tiny bit smaller (though at the expense of some very tiny compile
time and code size increase of tcc itself; not 100% it's worth it).
2017-05-02 03:07:36 +02:00
Michael Matz 3c39cb5cd8 fix __builtin_expect
the second argument can be an arbitrary expression (including
side-effects), not just a constant.  This removes the last user
of expr_lor_const and hence also that function (and expr_land_const).
Also the argument to __builtin_constant_p can be only a non-comma
expression (like all functions arguments).
2017-05-02 03:07:36 +02:00
Michael Matz 8d9dd3c008 Fix more bitfield corner cases
Our code generation assumes that it can load/store with the
bit-fields base type, so bit_pos/bit_size must be in range for this.
We could change the fields type or adjust offset/bit_pos; we do the
latter.
2017-05-01 06:18:48 +02:00
Michael Matz 4ce73354fc Fix last change
Skipping anonymous bit-fields is correct, but not other
anonymous ones like unions or structs.
2017-05-01 06:04:19 +02:00
Michael Matz f775d68725 Remove a bit-field TODO
Checked the lcc testsuite for bitfield stuff (in cq.c and fields.c),
fixed one more error in initializing unnamed members (which have
to be skipped), removed the TODO.
2017-04-29 22:09:10 +02:00
Michael Matz 28084420fe Fix char bitfields corner case
See testcase.
2017-04-29 21:25:31 +02:00
Thomas Stalder 76e16465bf arm: Fix build_got_entries 2017-04-27 14:16:49 +02:00
Christian Jullien f12851e388 Add -static to be in sync with Windows bat. 2017-04-27 07:01:46 +02:00
grischka a35752d233 configure: fix permissions
There must be something with git on windows that it
messes up x permissions sometimes.
2017-04-26 00:01:23 +02:00
Larry Doolittle 37999a4fbf Simple-minded fix for bug #50847
bug #50847: #line directive corrupts #include search path
Keep a second copy of the filename, that isn't changed by the #line directive,
and use that on the initial search path for #include files.
2017-04-25 12:32:41 -07:00
grischka 7acf9aa862 final adjustments for release
- configure/Makefiles: minor adjustments

- build-tcc.bat: add -static to gcc options
  (avoids libgcc_s*.dll dependency with some mingw versions)

- tccpe.c/tcctools.c: eliminate MAX_PATH
  (not available for cross compilers)

- tccasm.c: use uint64_t/strtoull in unary()
  (unsigned long sometimes is only uint32_t, as always on windows)

- tccgen.c: Revert (f077d16c) "tccgen: gen_cast: cast FLOAT to DOUBLE"
  Was a rather experimental, tentative commit, not really necessary
  and somewhat ugly too.

- cleanup recent osx support:
  - Makefile/libtcc.c: cleanup copy&paste code
  - tccpp.c: restore deleted function
2017-04-25 21:01:54 +02:00
Andrei Warkentin fb4f57666c tcc: report Darwin when building for Mach-O binaries.
Somewhat revert c4c3f50, but key off the config, not
host system.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
2017-04-25 13:57:33 +03:00
Andrei Warkentin 63b2f907bd tcc: fixup clang warnings
The O(xxx) stuff in i386-asm.c had me scratching my head. Extracting
the macro and trying it out in a separate program doesn't give
me any warnings, so I'm confused about what could be going on there.
Any cast will make things happy. I used a uint64_t to catch actual
cases of overflow, which will still cause a -Wconstant-conversion
warning.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
2017-04-25 13:55:18 +03:00
Andrei Warkentin 91cd148a05 tcc: early OSX native support
- build scripts
- working '-run' mode, e.g.:

./tcc -B. -I./include -I. -I.. -D_ANSI_SOURCE -run examples/ex1.c

Note: we don't bother parsing Mach-O/Fat images yet. We blindly
dlopen the image.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
2017-04-25 13:55:18 +03:00
Marc Vertes 0ac29b53dc Add support of musl-libc
The port is functional. Bound checking is not supported yet.
2017-04-20 22:01:50 +02:00
Michael Matz 328b826e8a tccpp: Fix corner case of fnlike macro invocation
Arg substitution leaves placeholder marker in the stream for
empty arguments.  Those need to be skipped when searching for
a fnlike macro invocation in the replacement list itself.  See
testcase.
2017-04-15 19:34:55 +02:00
grischka 536ed76d5a tccgen/win32: let __declspec(dllimport) imply extern
Also, retain storage qualifiers in type_decl, in particular
also for function pointers.  This allows to get rid of this
very early hack in decl()
    type.t |= (btype.t & VT_STATIC); /* Retain "static". */
which was to fix the case of
    int main() { static int (*foo)(); ...

Also:
- missing __declspec(dllimport) is an error now
- except if the symbol is "_imp__symbol"
- demonstrate export/import of data in the dll example (while
  'extern' isn't strictly required with dllimport anymore)
- new function 'patch_storage()' replaces 'weaken_symbol()'
  and 'apply_visibility()'
- new function 'update_storage()' applies storage attributes
  to Elf symbols.
- put_extern_sym/2 accepts new pseudo section SECTION_COMMON
- add -Wl,-export-all-symbols as alias for -rdynamic
- add -Wl,-subsystem=windows for mingw compatibility
- redefinition of 'sym' error for initialized global data
2017-04-04 08:34:52 +02:00
Christian Jullien c4c3f5009e Even on Darwin, tcc should display Linux 2017-02-26 16:28:52 +01:00
Avi Halachmi (:avih) 2da36731da win: tests Makefile: fix global path
Commit bb93064 changed the path seperator from ':' to ';', which was
likely accidental. While path seperator on Windows is generally ';', the
Makefile clearly expects a posix-y shell, and in such environments the
separator is ':'.

This fixes the test run in MSYS2 and MSYS(1) environments, which got
broken on bb93064 .
2017-02-26 15:41:26 +02:00
Christian Jullien 206829415a Linux was incorrectly identified in banner when compiled on macOS Darwin 2017-02-26 08:02:53 +01:00
grischka bb93064d78 makefile: unify cross with native builds
supports building cross compilers on the fly without need
for configure --enable-cross

   $ make cross          # all compilers
   $ make cross-TARGET   # only TARGET-compiler & its libtcc1.a

with TARGET one from
   i386 x86_64 i386-win32 x86_64-win32 arm arm64 arm-wince c67

Type 'make help' for more information
2017-02-25 12:51:04 +01:00
Christian Jullien 669f61117d Cygwin Makefile was to aggresive to remove entire lib/ 2017-02-24 22:51:10 +01:00