Commit Graph

3287 Commits

Author SHA1 Message Date
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
herman ten brugge
fef701b57f Allow on_exit to be used with -run
Added on_exit support for tcc -run.
Also fixed the last atexit code.
Updated testcase 128
Fixed test/test2/Mafile for testcase 126
2022-12-02 07:11:55 +01:00
herman ten brugge
60d52f0d68 Fix add debug support to macos 2022-12-02 07:05:12 +01:00
noneofyourbusiness
702b802316
TODO: add releases - it's been a while since the last release 2022-12-01 10:03:56 +01:00
noneofyourbusiness
4cb99787a7
make tcc -v more informative (also add commit date/time)
patch from 'Christian Jullien' <eligis@orange.fr>
2022-12-01 06:33:51 +01:00
herman ten brugge
62096265ed Add debug support to macos
lldb now works with this push.

In tccmacho.c add S_ATTR_DEBUG to all debug sections.
Add __DWARF section and rearange struct skinfo.

In tccdbg.c The first filename in dwarf_line can not be used.
Also had to fix structure/union/lexical_block/subroutine to
allow empty childs.
dwarfdump --verify complained about this.
2022-11-30 21:49:07 +01:00
herman ten brugge
ac0604a4d4 Allow atexit to be used with -run
Add atexit code to tccrun.c and added testcase 128
2022-11-29 21:13:20 +01:00
herman ten brugge
065b401c6e Fix static assert with empty string 2022-11-29 19:45:05 +01:00
herman ten brugge
a722a124f3 Allow %n in *printf functions on macos
The problem is that %n in *printf functions require a format string
that is in a read only section. See man page.

So added __DATA_CONST segment and mapped rodata_section into this segment.
Also added __got to this segment.

Change maxprot of segments to the same values used by clang.
2022-11-29 11:15:21 -06:00
herman ten brugge
afcdaf121a Fix __builtin_constant_p with comma expression
See: https://savannah.nongnu.org/bugs/?58606
and: mpfr-4.1.1/tests/tcmp_ui.c

The code '__builtin_constant_p ((i++, 7))' was not working.
I Fixed it in tccgen.c

I added a testcase in tests/tcctest.c. I also wanted to add a test like
'__builtin_constant_p ((10, 7))' but gcc needs -O1 for that to work.
clang (and now tcc) work as expected.
2022-11-29 00:56:26 -06:00
herman ten brugge
747ad409ac New update tccmacho.c
Fix for external functions as pointers in data section.
See testcase 119 and tccmacho.c in check_relocs.

Make bind/rebase code faster in bind_rebase_import.
- Move reloc check out of loop
- Because relocs are sorted we can do bind/rebase by page.

Change name head into seq in trie code.

Remove unused code in bind_rebase.
2022-11-28 11:19:33 -06:00
herman ten brugge
6b9fb93cd1 Fixed trie code generation for apple
I removed the FIXME for generating trie code with working code.

I also fixed a problem where:
cc -g -c a.c; cc -o a a.o
created a bind/rebase error because the second cc did not use -g
and .debug sections where not checked correctly.

I also removed the elfinterp printout in tcc.c when
TCC_TARGET_MACHO is set.
2022-11-27 07:28:40 -06:00
Christian Jullien
d8329c2d19 __nan() is not available on Apple M1, replaced by (0.0F/0.0F) 2022-11-25 17:08:58 +01:00
grischka
312d28b0a8 tccelf: avoid find_section() for known section
- remove calls to "find_..." for stuff that we know to exist and where.
- rename find_section_create(s1,name,0) -> have_section(s1,name)

Also:
- call update_gnu_hash() from elf_output_file()

gnu_hasn() functions could be moved down into an already existing
!ELF_OBJ_ONLY clause, but in order to avoid too many diff lines
I didn't.

- avoid 'long' (elf_hash). sizeof (long) is host-dependent (4 or 8)
- remove unnecessary checks (for dynsym, versym).

Someone reading "if (dynsym == NULL) ..." must conclude that it
actually can happen under certain circumstances, or otherwise,
might conclude that the person who wrote that felt unsure what's
going on exactly.

arm64-gen.c:
 TCC_TARGET_MACHO instead of __APPLE__ (to support cross-compilers
 for the apple/M1 target)
2022-11-25 12:13:47 +01:00
herman ten brugge
28fa4d3db6 Add strncat and strrchr to bounds checking 2022-11-25 00:31:32 -06:00
herman ten brugge
f48efeef8c Update to run on apple 13.0 (Ventura)
Add --config-codesign option to run codesign on apple to sign executables.
See configure and Makefile

In tccmacho.c use codesign option to call codesign application.
Add build_version/source_version
Sort sections in __LINKEDIT the same way as llvm does.
Add simple support for trie code. Need some more attention.
Fix rebase/bind error.
2022-11-25 00:19:45 -06:00
herman ten brugge
b86d82c8b3 Add new macho object format to tccmacho
Apple has a new object format that uses chained fixups.
I have implemented this with a configure option '--config-new_macho'
See configure and Makefile

tccmacho.c contains the biggest change.
I split the lazy_bind_rebase structure into lazy_bind and rebase for the
old format.
Under the macro CONFIG_NEW_MACHO there is the new macho format code.

In arm64-gen.c we do not need to push all registers on stack for
variadic functions. variadic parameters are pushed on stack for apple.

There is still one open isue. The export trie is empty.
This only effects dlsym when a local symbol is used.

tested on apple x86_64(10.5) and arm64(12.3).
2022-11-22 23:58:40 -06:00
herman ten brugge
d605d75ba8 Fix stab support for apple 2022-11-18 01:56:46 -06:00
herman ten brugge
d578151f8c Fix weak support apple 2022-11-18 01:51:36 -06:00
herman ten brugge
e99cf72784 Add weak support apple
Update tccmacho.c for weak symbols.
Undo tests/tcctest.c disable weak symbols test.
2022-11-17 14:03:00 -06:00
Christian Jullien
233d5d5f6f Fix old_style_f call when compiled by clang. 2022-11-17 14:35:31 +01:00
herman ten brugge
f89a6f12a7 Fix atomic test_and_set and clear
The __atomic_test_and_set and __atomic_clear code was correct.
They needed locking.
Replaced to code with assembly code.
The changes are in include/stdatomic.h, lib/stdatomic.c, lib/atomic.S
Enabled tests/tests2/124_atomic_counter.c for apple again.

Also moved lib/fetch_and_add.S code to lib/atomic.S.
Removed lib/fetch_and_add.S
Adjusted lib/Makefile
2022-11-17 05:57:21 -06:00
herman ten brugge
c8ef84c854 Add support for apple m1
The apple m1 uses position independent executables (pie).
I have implemented this in tccmacho.c

Apple also uses the stack different for var_args.
Also characters are signed instead of unsigned.
This is implemented in arm64-gen.c/tccdefs.h

Add bounds checking lib to lib/Makefile.

Add underscore support in lib/atomic.S and lib/fetch_and_add.S

Disable __clear_cache in lib/lib-arm64.c (Use system version).
I will try to fix this in future push.

Disable test_asm_call in tests/tcctest.c. Clang does not support @plt.
Also disable weak symbols test.
I will try to fix weak support in future push.

Disable tests/tests2/124_atomic_counter.c for 64BITS.
This is a bug in the atomic code and will be fixed in future push.

You have to use --dwarf configure option. stabs only works with -run.

tested on apple x86_64(10.5) and arm64(12.3).
2022-11-16 12:52:51 -06:00
Vlad Vissoultchev
c6b722f3f8
github: use macOS 11.7 and silence 96_nodata_wanted on Windows 2022-11-12 15:21:17 +02:00
Christian Jullien
8eabf67e1e Fix typo in tst_strtoll_strtoull. The wrong function was called for unsigned long long type. 2022-11-12 06:55:39 +01:00
Christian Jullien
6219b2de00 Add tests on Windows for strtoll and strtoull. Tests can probably be used on all systems. 2022-11-11 07:12:49 +01:00
Christian Jullien
40f01478d8 Add support for missing strtoll and strtoull on Windows 32/64 2022-11-11 06:23:26 +01:00
noneofyourbusiness
aea2b53123
update TODO: static linking sort of works 2022-10-30 13:05:26 +01:00
Bernhard Reutner-Fischer
df6fd04aaf github: commentary typo fix
and remove a trailing space

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2022-10-23 08:52:06 +02:00
noneofyourbusiness
7d76420857
produce a more informative error message when parsing _Complex 2022-10-19 14:06:04 +02:00
herman ten brugge
878fcccdb2 Small preprocessor fix
Set BOL flag for code like:
  #define tcc_test()
  #if 1
  tcc_test
  #endif
2022-10-17 07:49:47 +02:00
herman ten brugge
79a8229fb5 Add atomic functions for arm/arm64/riscv
Make code more compatible with gcc. Change
__atomic_store
__atomic_load
__atomic_exchange
__atomic_compare_exchange

Also add (include/stdatomic.h, lib/stdatomic.c):
atomic_thread_fence
atomic_signal_fence
atomic_is_lock_free

And gcc extensions (tcctok.h, tccgen.c, lib/stdatomic.c):
__atomic_fetch_nand
__atomic_and_fetch
__atomic_sub_fetch
__atomic_or_fetch
__atomic_xor_fetch
__atomic_and_fetch
__atomic_nand_fetch

Add new file lib/atomic.S with assembly code for __atomic_compare_exchange_n
for arm/arm64/riscv. Also update lib/Makefile.

Update testcode in 124_atomic_counter and 125_atomic_misc to test new functions.
Also update tests/tests2/Makefile to run tests on arm/arm64/riscv.
2022-10-16 18:51:56 +02:00
grischka
bb80cbe0d9 tcctest.c: sizeof (long) != 8
Bad assumption make bad things happen:

    long d3;
    asm(..."1:\tdec %3\n\t" : ... "=&c" (d3)

Which wants 'dec RDI' but did 'dec EDI' on _WIN64.

Also:
- tcctest.c: enable more asm tests for win64
- configure: show errors if any with 'gcc conftest.c'
- tccgen.c: remove decl0(x, y, z)
2022-10-14 21:56:16 +02:00
mingodad
c60f1d953c Update tests on Ubuntu from 18.04 to 20.04 because github is deprecating 18.04 2022-10-14 15:01:54 +02:00
mingodad
d27ca0e0c0 Add a github action to build/test tinycc on github mirror 2022-10-14 12:31:26 +02:00
grischka
d76e03232b win64: hi-mem adjustments
- x86_64-link.c:
  ignore relocation overflow to undefined (weak) symbols
- 104_inline.test:
  test lower 32 bits only
- tccpe.c:
  support -Wl,--image-base=... above the 32bit range
2022-10-13 20:32:47 +02:00
herman ten brugge
c03d59eae0 Fix macos warning for create_gnu_hash
Also add new function modify_reloctions_old_to_new for common code in
sort_syms and update_gnu_hash.
2022-10-12 07:24:34 +02:00
Detlef Riekenberg
b9aeb21f3f gcctestsuite: Make the script usable on more systems, skip some tests
The script was expecting gcc-3.2 in a specific directory,
works only, when building tcc in the source directory
and creates >3200 files in /tmp (probably a SSD).

Now gcctestsuite.sh works much better.
* use TESTSUITE_PATH, to tell the script the location, where the actual
  gcc.c-torture directory is
* work also, when tcc was build in a separate build directory.
  use TCC_SOURCE_PATH, when guessing the tcc source directory does not work
* use RUNTIME_DIR to redirect compiler output
  (default: XDG_RUNTIME_DIR, then /tmp)
* skip tests for features not implemented in tcc ( *_builtin_*, _Complex )

--
Regards, Detlef
2022-10-12 00:59:02 +02:00
grischka
aef64762c1 tccpp: #define max(a,b) && max /= 8;
This fixes 20a1ebf854
where the '/' above was lost when max() was defined

Also: ignore binary files with -E (for example 'tcc -lxxx -E ...')
2022-10-09 20:30:15 +02:00