Commit Graph

3219 Commits

Author SHA1 Message Date
Michael Matz
1da92cdd93 Accept attributes after labels
newer GCC can associate attributes with statements and labels,
this implements only the latter (and ignores the attributes).
2022-08-16 15:59:41 +02:00
Michael Matz
b077bc8ff7 x86asm: Add vm* and iret[wlq] insns
The no-operand vm* instructions can be interpreted as having a
funny modrm byte, but unlike no-operand OPC_MODRM it's also the
r/m field which selects the insn, not (only) the reg field (aka group),
so we need another insn type.
2022-08-16 15:59:41 +02:00
Michael Matz
2309517066 x86asm: Add popcnt
as this is the first opcode TCC supports that has a 0xf3 prefix
and uses integer registers (not SSE ones) this also needs some shuffling
of the prefix code to not generate invalid instructions (the REX prefix
_must_ come directly before the main opcode (including 0f prefix), and
hence needs to come after the 0xf3 prefix).  Also disable some mnemonics
in asmtest.S that new GAS doesn't support anymore.  The only difference
to GAS (in asmtest.S) is now the 'lock negl' instruction which TCC
emits as 'lock; negl'.  That's fine.
2022-08-16 15:59:41 +02:00
Michael Matz
98bab41cba Support asm goto
this adds generic support for asm goto, but I've tested only
on x86.
2022-08-16 15:59:41 +02:00
Michael Matz
154c3e7450 Fix unnamed bitfield struct members
they look similar to labels 'foobar : 32' (when foobar is a typedef),
but cannot be handled as such in parse_btype, the context is important
(labels can only happen when called from within 'block', aka decl0 in
VT_LOCAL context).  This got broken back in 2019 (1b57560).
2022-08-16 15:59:41 +02:00
herman ten brugge
47dc6e6d7b Add __has_include and __has_include_next support
tcctok.h:
- Add __has_include_next

tccpp.c:
- New functions parse_include and get_include_file
- Changed expr_preprocess and preprocess
2022-08-14 12:17:31 +02:00
herman ten brugge
1de025c13a Check dState instead of do_debug in tccdbg.c
This fixes:
  tcc -g -E

and programs like:
  #pragma comment (option,"-g")
  int main(void) {return 0;}
2022-08-11 09:03:13 +02:00
herman ten brugge
b7733aeef1 Fix wchar_t strings with 'x', 'u' and 'U' 2022-08-11 08:37:00 +02:00
Detlef Riekenberg
8b906427e3 tccgen: cleanup _Alignas implementation
Remove the unneeded compare, introduced in the recent _Alignas update.
sorry for that

--
bye bye Detlef
2022-08-04 12:02:52 +02:00
Vincent Lefevre
ef19711ba5 Use && rather than & for a Boolean operation. 2022-07-29 12:43:44 +02:00
Detlef Riekenberg
746560dc45 Do not fail with _Alignas(0) and _Alignas(1), used by autotools
Used by configure scripts, generated by newer GNU autotools
Autotools now checks for C11 and C99 compatibbility

--
bye bye Detlef
2022-07-28 18:30:54 +02:00
Detlef Riekenberg
bc12ab02c0 Accept -Wl,Map=filename.map
The parameter is stored in tccstate, but nothing more.

Used by multiple software packages.
Current tested example is OpenWatcom-v2

--
bye bye ... Detlef
2022-07-28 17:33:51 +02:00
herman ten brugge
2647dc063d Change plt_name size from 100 to 200.
I have jni code with very large symbol names (150 chars max).
This change avoids having names classes.
2022-07-25 13:00:15 +02:00
herman ten brugge
4589fdfad4 Fix netbsd elf problem
The dynamic linker on netbsd can only handle 2 PT_LOAD sections.
2022-07-25 12:55:26 +02:00
grischka
09808f327f tcc android-enabled (armeabi-v7a)
On an armeabi-v7a device (phone) in the termux app with
clang & make installed this passes all the tests.

Can be used as a cross compiler to create "native apps" as well.
Example 'config-extra.mak' for the cross arm-eabi-tcc:

  SYSROOT = <path_to_android_ndk...>/sysroot/usr
  TRIPLET = arm-linux-androideabi
  ANDRVER = 32

  ROOT-arm-eabi = $(SYSROOT)

  CRT-arm-eabi = {R}/lib/$(TRIPLET)/$(ANDRVER)
  LIB-arm-eabi = {B};{R}/lib/$(TRIPLET)/$(ANDRVER);{R}/lib/$(TRIPLET)
  INC-arm-eabi = {B}/lib/include;{R}/include/$(TRIPLET);{R}/include

  DEF-arm-eabi = -DTCC_TARGET_ARM -DTCC_ARM_VFP -DTCC_ARM_EABI
  DEF-arm-eabi += -DTARGETOS_ANDROID -DCONFIG_TCC_PIE -DCONFIG_NEW_DTAGS
  DEF-arm-eabi += -DCONFIG_TCC_ELFINTERP=\"/system/bin/linker\"

  # on unix replace ';' by ':'.
  $ ./configure && make cross-arm-eabi && make install
2022-07-24 09:51:32 +02:00
grischka
8e860702e4 tccelf: sort_sections()
Sort sections in separate function to allow variable
calculatiion of needed program headers.  Such execinstr
and relro cah have their own PT_LOAD header.

315 insertions(+), 370 deletions(-)
2022-07-24 09:45:48 +02:00
grischka
ebaa5c81f4 dynamic executables (PIE)
Allows to create dynamic executables, using the code path
for TCC_OUTPUT_DLL but add an .interp header (plus a FLAGS_1
entry in the dynamic section to make 'readelf' say "PIE")

Introduces TCC_OUTPUT_DYN as alias for TCC_OUTPUT_DLL.
There is no runtime option,  only one to configure:

    ./configure --config-pie

100 insertions(+), 76 deletions(-)
2022-07-24 09:44:50 +02:00
grischka
e460f7dbb2 tccelf: load libtcc1.a from library path
... rather than from tccdir.  Also allows to load cross
versions of bcheck.o etc. (if we would build them which
we currently don't).

18 insertions(+), 24 deletions(-)
2022-07-24 09:44:34 +02:00
grischka
d653cf01f3 tccelf: load objects first
It seems to make sense to load any helper objects (such as
bcheck.o) first, and then load standard libraries.

29 insertions(+), 29 deletions(-)
2022-07-24 09:42:28 +02:00
grischka
7d6979d452 tccelf: avoid lookup of _GLOBAL_OFFSET_TABLE_
Instead, return its symbol index from build_got_entries()
Also, copy dynamic symbols later when size of _GLOBAL_OFFSET_TABLE_
was already set and handle -rdynamic there too.
See commit 4c82b00342

5 insertions(+), 5 deletions(-)
2022-07-24 09:42:04 +02:00
grischka
c81519e1c4 tccgen: don't generate elf-symbols under nocode/NODATA
seems that symbols under nocode/NODATA should not produce
elf symbols at all, not just elf symbols with no size.
See commit 4c82b00342

5 insertions(+), 5 deletions(-)
2022-07-24 09:41:57 +02:00
grischka
e8adc64203 libtcc: extend tcc_add_dllref()
libtcc.c:
- integrate find_dllref loop into tcc_add_dllref()
tccelf.c:
- make sure a DT_NEEDED tag is put for versions even
  when the dll was not previously loaded.
Related commit 4c82b00342

48 insertions(+), 77 deletions(-)
2022-07-24 09:30:41 +02:00
grischka
7d31904247 tccelf: fix version patch for defined symbols
previous patch seems to work only for bcheck.o and only because
it's loaded after libraries (which is maybe wrong too).
See commit 4c82b00342

section_ptr_add() already clears area to zeros

4 insertions(+), 11 deletions(-)
2022-07-24 09:30:41 +02:00
Arthur Williams
8482682061 Define __TCC_BACKTRACE_ENABLED__ if backtrace is enabled
If the `-btN` was specified, then the __TCC_BACKTRACE_ENABLED__
macro will be defined. This provides a way for user code
to tell if tcc_backtrace is defined or not.
2022-07-23 15:12:15 -07:00
grischka
af1abf1f45 Revert "Fix wrong handling of strings..." (almost)
See commit e588b65390.
Was not "wrong" really, just different. But appears to be outdated.
Now disabled by default (top of tccpp.c: ACCEPT_LF_IN_STRINGS)
Also, in skipped code, just warn.

Also: cleanup "Optimize small structure copying on x86_64"
(commit 3715f1d7ee)
- remove some copy&paste coding (tccgen.c)
- RSI/RDI need to be preserved on windows
- simply don't use under bcheck (this is tinycc)
2022-07-16 00:41:37 +02:00
Ziyao
e588b65390
Fix wrong handling of strings which do not end properly at the end of line 2022-07-13 15:43:26 +08:00
herman ten brugge
a83b285685 Add extra locking in bound checking code 2022-07-09 12:10:08 +02:00
herman ten brugge
2c70652e04 Enabled test 112_backtrace
Changed script in Makefile for testcase 112
Used bound_struct_copy_count in lib/bcheck.c
2022-07-09 11:51:13 +02:00
Ziyao
2d210fef49
Skip test 112_backtrace on x86_64,because commit 3715f1d breaks
it.Commit 3715f1d makes the error message of bound check on x86_64
different from other platforms,which breaks the test process.But that
commit exactly works well.
2022-07-09 12:56:07 +08:00
Ziyao
3715f1d7ee
Optimize small structure copying on x86_64 2022-07-09 12:53:29 +08:00
Detlef Riekenberg
fe7ee1105c libtcc: Let "-Wl,*" also accept "--entry=xxx" as alias for "--e=xxx" 2022-07-08 00:18:14 +02:00
Michael Matz
73c22f831f Fix fallthrough of non-entered stmt expressions
commit ec5d94291 made is to that the nocode_wanted state from
inside a statement expression is retained after it.  That is wrong
if the statement expression can't be entered to start with.  In the
latter case the state from before the stmt-expr is the one we need.
2022-07-01 17:20:37 +02:00
Michael Matz
ebb4e71236 flexarray: Accept empty ones
See testcase, it's a GNU extension, but widely accepted (the
linux kernel uses it).  This got broken with 72b520e709.
2022-07-01 15:37:23 +02:00
Reinhard Urban
9712541156 Add missing ELFOSABI constants
from my github rurban/brandelf
2022-06-13 15:10:15 +02:00
herman ten brugge
cd627c6c40 Fix riscv assembler
riscv64-asm.c:
	asm_opcode: add return
	asm_parse_regvar: add abi register names

riscv64-tok.h:
	add abi register names
2022-06-07 20:53:14 +02:00
herman ten brugge
afc136262e Fix core dump in case -static is used 2022-05-26 15:41:52 +02:00
herman ten brugge
a4e0f7ef05 Fix bitfield long types for stabs/dwarf
Also made dwarf *leb128 fuctions a litlle bit faster.
2022-05-25 17:04:37 +02:00
herman ten brugge
e301a0ba8d Removed __bound_exit_dll from lib/bt-dll.c 2022-05-19 09:42:41 +02:00
herman ten brugge
aaec564a82 Fix bound checking dlcose problem
The main problem is that an application called dlclose and then
had a bound checking problem. The list of dll's in tccrun was
not updated an caused a crash.
Also fixed some minor other things.

tccdbg.c:
- Allow filenames like ../file.c
- Rewrite DWARF_ABBREV_MEMBER_BF/DWARF_ABBREV_MEMBER a bit

tccelf.c:
- Add call to __bt_exit. This solves problem when dlclose is called

tccrun.c:
- Rewrite rt_printline_dwarf a litlle to use opcode_length correctly
- Do not stop at DW_LNE_end_sequence
- Fix DW_LNE_set_address again. Works now in *bsd.

lib/bt-exe.c lib/bt-dll.c:
- Add __bt_exit/__bound_exit_dll

lib/bcheck.c:
- Add __bound_exit_dll
2022-05-19 07:40:14 +02:00
herman ten brugge
4c82b00342 Update for elflint problems
tccgen.c:
- When __FUNCTION__ is used and no code is generated use symbol len = 0.

tccelf.c:
- If library is present in verneed it should be in DT_NEEDED.
- @plt symbols should have size 0
- set _GLOBAL_OFFSET_TABLE_ st_size correct
- Remove version symbol if new value present

reported by elflint:

__FUNCTION__ problem:
  section [19] '.symtab': symbol 2134 (L.195) does not fit completely in referenced section [14] '.data.ro'
DT_NEEDED problem:
  section [26] '.gnu.version_r': entry 2 references unknown dependency
@plt symbols should have size 0:
  section [22] '.symtab': symbol 36557 (r_core_config_init@plt) does not fit completely in referenced section [14] '.plt'
_GLOBAL_OFFSET_TABLE_ size:
  section [44] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol size 4 does not match .got section size 736
Remove version symbol:
  section [25] '.gnu.version': symbol 86: version index 3 is for requested version
  This happened for example with bounds checking symbol malloc
2022-05-17 07:34:10 +02:00
Detlef Riekenberg
a4f9e3cf4c configure: Use the environment variable CC when compiling tcc (resend)
Using the environment CC is a common used feature to
select a compiler to build any software,
so it should be supported when building tcc.

The old way using the parameter --cc still works.

(resend)

Signed-off-by: Detlef Riekenberg <wine.dev@web.de>
2022-05-15 23:18:41 +02:00
herman ten brugge
0e47167cbe New dwarf update
tccdbg.c
- Fix typo in dwarf_file. This resulted in not finding correct include
  files.

tccrun.c:
- Change FILE_TABLE_SIZE to 512. Some files use very large includes.
- When a dll containted more then 1 file the pc was not calculated
  correctly.
2022-05-14 15:58:40 +02:00
herman ten brugge
53dd065daf Fix unicode compiler warning again 2022-05-14 15:55:27 +02:00
herman ten brugge
19cc80788d Fix unicode compiler warning
The compiler warned about the unicode_to_utf8 code.
I fixed it by giving an error. This is the same as gcc does.
2022-05-12 11:18:37 +02:00
herman ten brugge
e7396c99b0 Dwarf update
Some small updates in tccdbg.c found by checking readelf output from
gcc/clang.

- Change encoding type bool type
- Fix enum signed/unsigned
- Do not hash anon symbol
- Use correct filename/line_number for global variables
- Fix compiler warning in tcc_get_dwarf_info
- Use unsigned long long for array indexes
- Display correct first line of function in gdb
2022-05-12 08:15:28 +02:00
herman ten brugge
748e38ad99 Fix stupid typo. 2022-05-10 07:21:49 +02:00
herman ten brugge
9a81e6366b Fix vla type bug for stabs/dwarf
The wrong vla stabs code was accepted by gdb.
The dwarf vla code was fatal.
2022-05-10 07:16:38 +02:00
grischka
2caaff20fb tccdbg.c: new file
Better avoid global variables, at least in new code.

tccdbg.c hopefully should be logically identical to the
former parts in tccgen/elf.c (s1 tccstate added in some
places)

tccelf.c: dwarf linkage seems special per dwarf rather
than special per target.
2022-05-09 22:37:25 +02:00
grischka
56481d554f bored...
/* Use "-g" as alias for "-g1". Use "-g0" to disable debug */

So not using -g is now the alias for -g0 ?!?

This reverts commit 8759b2581d.
This reverts commit 3ce7bc6efc.
This reverts commit 5fb582ab7f.
This reverts commit aea68dbb40.
This reverts commit fa9c31c3db.
This reverts commit b3bebdb20a.
This reverts commit ecf8e5a00e.
This reverts commit fe6b5c08dc.
This reverts commit e2e5377e7b.
This reverts commit 1cd7998905.
2022-05-09 22:19:15 +02:00
Detlef Riekenberg
1cd7998905 tccmacho: avoid warnings with strncpy and always terminate the target string 2022-05-09 12:49:48 +02:00