Commit Graph

3425 Commits

Author SHA1 Message Date
Michael Matz
605538f46d Fix sym_scope of typedefs
Sym.sym_scope and Sym.f (FuncAttr) share space, so blindly setting
one clobbers the other.  Right now this only leads to missing errors
on incompatible typedefs (see testcase), which this commit fixes.

But it points to a larger problem:
Generally we can only manipulate Sym.f for anonymous and field symbols,
not for anything that has a top-level name (basically any proper decl),
because the latter use sym_scope.  Luckily the functions type always
contains an anonymous symbol (in sym->type.ref), so we can use that.
But some of the functions attributes actually _do_ apply to the decl,
not the type (e.g. always_inline), so we still have a problem possibly,
when we update an pre-existing type that may already be shared with
another decl.

Would need untangling and perhaps using accessor functions that check
that Sym.f and Sym.sym_scope aren't used for the same symbol.
2023-02-22 17:59:31 +01:00
Detlef Riekenberg
bdec3c5345 Use unsigned int to count sizes for -bench (YARPgen) (part 2)
I have a testfile created by YARPGen (seed=9), which displayed
a negative bss size without this patch.

* tcc needs also a bigger VSTACK_SIZE (i used 512)

--
bye bye ... Detlef
2023-02-03 18:04:56 +01:00
Detlef Riekenberg
b2485d6cd5 Use unsigned int to count sizes for -bench (YARPgen)
I have a testfile created by YARPGen (seed=9), which displayed
a negative bss size without this patch.

* tcc needs also a bigger VSTACK_SIZE (i used 512)

--
bye bye ... Detlef
2023-02-03 01:04:38 +01:00
herman ten brugge
4dc7662a07 Fix preprocessor line directive update
The last commit was not a problem with macos.
The problem was that dwarf version < 5 uses different indexes for
files and directories.
They start at 1 for dwarf version < 5 and 0 for dwarf version >= 5.
2023-01-17 20:08:14 +01:00
Christian Jullien
7874397373 Don't forget to mention the amazing job made by Herman on native macOS. 2023-01-17 15:29:57 +01:00
noneofyourbusiness
4cccba74d2
update changelog 2023-01-17 13:38:04 +01:00
herman ten brugge
d0efbc5d3a Fix preprocessor line directive for macos
Macos has an offset of 1 for DW_LNS_set_file.

Also rewrite dwarf_file to not scan list twice and
move check for <command line> to this function.
2023-01-16 20:26:44 +01:00
herman ten brugge
ee3fef2ce2 Fix preprocessor line directive
The preprocessor line directive did not result in correct debug info
when -g was used.
Line directives like:
 #line 1 "filename"
should now work.
2023-01-16 08:39:34 +01:00
herman ten brugge
79d439ee4f Allow const expr in builtin_frame_address/builtin_return_address 2023-01-16 08:37:47 +01:00
noneofyourbusiness
560526a49d
Changelog: get started with the changelog since 0.9.27 2023-01-01 16:39:14 +01:00
noneofyourbusiness
fa0fa62b0c
Makefile: remove unportable -v flag from distclean target 2023-01-01 16:30:57 +01:00
herman ten brugge
20a22cf3d6 Fix tcc -ar c symbol header size
tcc -ar t failed sometimes because the header size was not correct.
2022-12-28 07:38:39 +01:00
noneofyourbusiness
d15dec711d
tcc -ar: change mode to 644, use ARMAG 2022-12-28 03:08:02 +01:00
Per Nordlöw
9957c686a4 Remove _Static_assert verifying the size of CString because it breaks C99 builds with gcc-5 2022-12-28 00:31:14 +01:00
Per Nordlöw
78c3ea30a6 Reduce CString memory usage from 3 to two 2 words 2022-12-27 21:50:39 +01:00
herman ten brugge
7ed9c95ae7 Allow parallel build testsuite 2022-12-27 14:11:18 +01:00
herman ten brugge
d1fa89a11f Fix problem with large section size.
In tcc_load_object_file use unsigned long for size/offset.
This avoids strange sizes of sections in case of overflow.
The sections that are now larger then 4G may not work.
This avoids a hang on macos in realloc.
2022-12-27 07:45:38 +01:00
noneofyourbusiness
676755f6ee
help: also update main help with tcc -ar options and sort them 2022-12-26 01:48:54 +01:00
Christian Jullien
95e39517ef Add -Wl,-install_name macOS clang compatible flag as clang refuses -Wl,-soname. This helps configure scripts using both clang and tcc. 2022-12-24 09:30:00 +01:00
herman ten brugge
3fd6a05fff Fix multiple rpath tccmacho
If multiple rpaths are specified then output multiple LC_RPATH load
commands instead of one with : seperator.
2022-12-23 19:48:39 +01:00
herman ten brugge
03841b6f16 Update bind problem macho
Changed -1 into -2 for plt_offset,
2022-12-23 12:17:55 +01:00
herman ten brugge
da0cc61794 Fix bind problem macho
The problem occurs when a shared library creates a pointer to
a function and then the application also uses this function.
2022-12-22 20:50:37 +01:00
grischka
62d857a6f9 tccgen: better find_field() not found error messages
Also: return all of 'cumofs' (no extra '+' required at caller)
2022-12-22 16:17:39 +01:00
herman ten brugge
909d58dd5e Add tcc -ar x and t options
On macos we cannot use the ar because is does not support elf files
and then does not generate a symbol table.
The solution is to use 'tcc -ar'. The problem now is that some
pacages first built an archive with 'tcc -ar c' and later extracts
the archive with 'tcc -ar x' and built with this a dylib file.
The 'tcc -ar x' failed. So I implemented it. I also added the t
option because it was simple to do,
2022-12-20 07:34:41 +01:00
herman ten brugge
d5f25d19b3 Add macos clang/ld compiler options
With these option I can now built several packages without problem.
There are a lot of options we can add so I tried to implement the
minumum.

Add the following options:
dynamiclib		same as -shared
flat_namespace		default/ignored
two_levelnamespace	ignored
undefined		default/ignored
install_name		name of dynmic lib
compatibility_version	version dynamic lib
current_version	version version dynamic lib

-Wl options:
all_load		same as whole-archive
force_load		same as whole-archive with lib
single_module		ignored
2022-12-20 07:24:48 +01:00
herman ten brugge
f6f3d646fb Fix dll support for macho
Export now all global symbols in export trie instead of only text
symbols.

I wrote too much data into dylib file because I did not check
for sk_unknown/sk_discard/sk_uw_info.

Simplified code in tccrun.c
2022-12-18 14:07:19 +01:00
herman ten brugge
04810db83a Allow building lib with gcc/clang
Needed when using ...libtcc1-usegcc=yes in lib/Makefile.

lib/bcheck.c: Add __clang__ for pragma diagnostic
lib/bt-log.c: Add pragma diagnostic as in lib/bcheck.c
lib/builtin.c: Add a lot of alias code to allow building with gcc/clang
lib/stdatomic.c: Same as lib/builtin.c
lib/tcov.c: Avoid clang compiler warning
2022-12-17 09:37:37 +01:00
herman ten brugge
d66a62fa6b Fix dll support macho for x86_64
Macho uses bind/rebase instead of dynsym so disable them for relocate_sections.
2022-12-17 07:43:01 +01:00
herman ten brugge
8d3930bdb6 Add dll support for macho
Update configure and remove dll=no for Darwin.
Also removed dwarf=$dwarf because this is not a config option.

In tccelf.c only add __PAGEZERO if stabs and executable.

In tccrun.c correct rt_printline_dwarf code for dll.

In tests/Makefile disable dlltest with PIC for Darwin because object
format of .o file is still in elf.

In tccmacho.c add dll support and and rpath support.
Corrected trie code. For some reason symbol 'xx' should be after 'xx1'.
Corrected weak symbol support for old macho code.
Used R_JMP_SLOT instead of R_DATA_PTR in check_relocs.
2022-12-16 20:57:45 +01:00
Mathias Krause
9cfc8f60ce x86asm: Add lzcnt/tzcnt support
We already support popcnt, add lzcnt and tzcnt as well.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
2022-12-13 11:34:54 +01:00
herman ten brugge
079692016d Fix stab debug problem with common section 2022-12-11 15:36:37 +01:00
herman ten brugge
dd69143ae6 Add builtins ffs, clz, ctz, clrsb, popcount, parity
Add new file lib/builtin.c
Modify include/tccdefs.h, lib/Makefile to compile it.
Update tests/tcctest.c to test it.
2022-12-11 08:23:22 +01:00
Petr Skocik
ea0c57e90a Allow _Static_assert declarations in structs
This usage has been part of the C grammar since C11
(http://port70.net/~nsz/c/c11/n1570.html#6.7.2.1) and is
also supported by gcc and clang.
2022-12-10 01:12:44 +01:00
herman ten brugge
ac9eeea1d5 Enable vla_test-run on all targets
Fix gen_vla_sp_save/gen_vla_sp_restore in riscv64-gen.c
2022-12-06 11:21:50 +01:00
herman ten brugge
657262c7e5 Enable testcases on apple and x86_64 2022-12-06 08:09:16 +01:00
Christian Jullien
d0c26ba4e5 OSX is used and can't be replaced by macOS yet, revert previous change 2022-12-05 16:28:54 +01:00
Christian Jullien
d1f5d132c6 cosmetic: OSX is a deprecated name, macOS is the official system name for Apple Operating System since 2016. 2022-12-05 15:42:38 +01:00
Christian Jullien
a0f88dca75 on macOS, configure displays the dwarf version used, currently dwarf=4 2022-12-05 15:22:46 +01:00
herman ten brugge
6b9c0024ac Default is now config-new_macho and dwarf=4 for apple
I tested on macos 10, 11, 12 and 13 that old and new macho code work.
I do not know when this new format is introduced but it is now
available on a lot of versions. So make it the default.

Also default to dwarf=4 because stabs and dwarf=5 is not supported.
2022-12-05 11:10:03 +01:00
herman ten brugge
85b27432bb Fix libtcc_test_mt
The test failed because atexit/on_exit code was not correct.
Make it look more like the g_exit_context.
Added a sleep to libtcc_test_mt to allow overlap of threads to
detect this problem.
2022-12-04 11:55:06 +01:00
herman ten brugge
e2db3a5e57 Update load segment code for macho
Add an array with segement to load instead of code.
Dynamically check if segment is used or not.
This fixes the strange __DWARF code segment handling.
2022-12-04 07:27:10 +01:00
herman ten brugge
7cc1cc3881 Fix for lldb usage
lldb does not like function end and next function start at same pc
2022-12-04 07:19:48 +01:00
noneofyourbusiness
ab39d34dde
produce a more informative error message when _Thread_local is used 2022-12-03 20:09:11 +01:00
herman ten brugge
894e166ecf Better fix for old macho format
The last commit only worked on arm64.

The problem was that the new __DWARF segment was empty.
I now remove the __DWARF segment if it is not needed.
This resolves the rebase problem on x86_64.
2022-12-02 22:57:49 +01:00
herman ten brugge
14e78d7cc2 Old macho format does not work with previous push 2022-12-02 20:25:27 +01:00
herman ten brugge
b7356bb638 Reduce memory size macho executables
Do not align vmsize/filesize to SEG_PAGE_SIZE every time.
Move rel_offset check down due to this change.
2022-12-02 13:53:37 +01:00
herman ten brugge
6b398686d6 Fix bounds checking without -run on macos
Update tccrun.c to detect rebase for dwarf debug info.
Enabled testcase 126 on macos.
Add prologue_end/epilogue_begin supoort in tcc.h, tccdbg.c, tccgen.c.
2022-12-02 13:09:47 +01:00
Christian Jullien
ffbf6c26b2 Test was inverted for locally modified version 2022-12-02 08:40:12 +01:00
Christian Jullien
bdaccc2898 Minor -v improvement: remove extra space 2022-12-02 08:28:14 +01:00
Christian Jullien
7015838f51 Use my latest proposed patch for improved -v message. It is simpler and gives a better message, especially when repository has been locally modified: 'tcc version 0.9.27 mob:fef701b 2022-12-02T07:11:55+01:00 locally modified (ARM eabihf Linux)'. Hope it's Ok for maintainers 2022-12-02 08:05:01 +01:00