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.
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.
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.
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.
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.
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.
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.
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.
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.
- 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)
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.
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).
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
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).
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.
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)
- 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
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