Commit Graph

61 Commits

Author SHA1 Message Date
grischka
7916cf71cc tcc_error_noabort(): always use this unless compiling
This avoids 'exit(1)' with errors outside of compilation
(nasty in particular with libtcc usage)

As a sideeffect multiple errors can be seen for linker
errors (such as undefined symbols, relocation errors, ...)
2023-04-25 15:22:03 +02: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
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
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
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
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
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
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
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
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
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
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
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
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
Steffen Nurpmeso
917aad3bcf Add some missing fdopen(3) checks (Domingo Alvarez Duarte) 2022-02-28 21:19:41 +01:00
mingodad
1645616843 Revert "Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64"
This reverts commit af686a796b.
2021-10-22 07:39:54 +02:00
mingodad
2ce2dbcb09 Revert "Fix some errors on arm64-asm.c, rename some variables, fix several code style declarations"
This reverts commit 61537d899a.
2021-10-22 07:39:26 +02:00
mingodad
61537d899a Fix some errors on arm64-asm.c, rename some variables, fix several code style declarations 2021-10-22 07:20:00 +02:00
mingodad
af686a796b Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64 2021-10-21 20:09:42 +02:00
grischka
dda95e9b0b WAIT/POST_SEM(): generalize interface (and more)
Currently used only with 'tcc_compile_sem' to protect
tcc_compile(),  but can be used with other semaphores

Also fix deadlock when tcc_enter_state() is called
recursively for the same state, for example with
tcc_warning() from #pragma comment(option,"...")

Also:
- libtcc.c: error1(): use cstr_[v]printf()
- tcc.h: set TCC_USING_DOUBLE_FOR_LDOUBLE for macho-arm64
  (rather than for macho-X86_64)
- tcc.h: define TCC_TARGET_MACHO on __APPLE__ by default
- tcc.h: cleanup TCCState, move DEFASM token stuff to tcctok.h
- tccgen.c: more static
- Makefile/tcc.c: review githash
- tccpe/tcctools: use read() instead of fgets() in pe_load_def()
  (all files opened by tcc for reading are now read via 'int fd')
- configure/win32: don't preset CONFIG_TCCDIR (to allow to override it)
- tcc.c -bench: do not include output/run-time
2021-08-01 20:33:31 +02:00
Christian Jullien
b1d9de6794 [macOS] fix format warning 2021-07-27 07:54:46 +02:00
grischka
eadcee6501 macos: yet another tbd adjustment
configure:
- re-enable apple M1-arm64
- however, with --cpu=x86_64,  set -arch in CFLAGS/LDFLAGS too
  (assume rosetta)

Makefile:
- re-enable osx cross-test (Please do not disable tests)

tcc.h
- set TCC_IS_NATIVE for TCC_TARGET_MACHO on __APPLE__
- apply TCC_USING_DOUBLE_FOR_LDOUBLE for x86_64-osx

libtcc.c:
- cleanup tcc_add_file_internal()
- new function char *tcc_load_text(int fd); and use it for tbd files
2021-07-25 20:55:05 +02:00
Sushant Pandurangi
d5e4b258e1 Minor fixes for gnu90 compatibility 2021-07-06 15:59:12 +02:00
Sushant Pandurangi
33fa3a4d41 macOS 11: tcc -run using dyld shared cache 2021-07-04 11:07:48 +02:00
Sushant Pandurangi
f6fb4d0cf1 macOS 11: link using dyld shared cache
Supports linking using .tbd definitions found in the default installed
command-line tools SDK or Xcode.app SDK. Only for creating executables
(not yet for `tcc -run`).
2021-07-04 11:06:55 +02:00
grischka
72f1dea537 tccelf: use rodata_section, use more rodata in tcc itself
libtcc.c: add -Wwrite-strings to -Wall
tccgen.c: ro float-consts, string-consts, ro arrays if base type is
tccpe.c: merge IAT with rodata
tccrun.c: mprotect rodata accordingly. free section data after copy
x86_64.c: do not use got for static data.
tcc -bench: show data.rw/ro

Probably STB_LOCAL should never get to put_got_entry(), and currently
it doesn't seem to happen (See "Hack Alarm" there)

Other files: use more ro-data in tinycc
2021-02-18 14:43:34 +01:00
grischka
02795106e1 tccelf: use plt-reloc instead of relocplt 2021-02-18 14:42:59 +01:00
herman ten brugge
28646b559d fix cross compiling on openbsd 2021-01-12 09:59:52 +01:00
grischka
cf8d9cf072 win64: fix pe_isafunc()
- tccpe.c: commit "tidy support for helper function" created
  STT_NOTYPE symbols and hence relied on ad-hoc detection which
  didn't work for x86_64 (as reported by Christian Jullien)

- tccgen.c: However to be more safe the helper symbols are
  now made STT_FUNC anyway (via new VT_ASM_FUNC).

Also:
- tcc.h: minor reorder
- riscv64-*, arm64-*, tccmacho.c: avoid some gcc format-warnings
  (mingw-gcc complains about "%llx" being "unknown conversion",
  although it does work since Vista or so)
2020-11-26 16:11:17 +01:00
Christian Jullien
60c1f70bb9 Revert commit 55f8963dfa from wanjochan until better tested on all platforms 2020-09-10 05:49:15 +02:00
wanjochan
55f8963dfa ignore symbol main for .dylib; skip libtcc1 for tccrun mode; 2020-09-08 22:05:00 +08:00
Christian Jullien
49e2d06921 macos: initialize macho struct with memset which removes a clang warning on macOS. 2020-07-07 07:47:48 +02:00
grischka
6a4f3cf127 rework leading underscores
tested on win32/64 to pass the tests when enabled

- libtcc.c :
  let tcc define __leading_underscore if enabled
  tcc_add_symbol() : add _ automatically
- tccelf.c : remove tcc_get_symbol_err(), find_c_sym()
  currently symbol length is limited to 256 in several
  places, so we can use a fixed local buffer for now as well.
- win32/lib/crtinit.c : new file for init/fini
- lib/*.S, tests7* : use __leading_underscore
- bt-log.c: this file wont work relibaly if compiled with gcc
2020-07-06 13:00:47 +02:00
grischka
72277967ff some cleanups related to recent commits
- configure/Makefile : cleanup, really use CC_NAME
- tccasm.c : remove C99 construct that MSVC doesn't compile
- arm-gen.c, x86_64-gen.c, riscv64-gen.c, tccmacho.c : ditto
- arm64-gen.c: commit 383acf8eff wrote:
  "Instead of a cast, it would be better to pass the exact type."
  It is true that there are better solutions but it is not
  passing the exact type (I think).
- tcctest.c: revert "fix cast test for clang" 03646ad46f
  this obviously wants to test non-portable conversions
- 114_bound_signal.test: clock_nanosleep is too new for older
  linuxes, just use sleep() instead
2020-07-06 13:00:47 +02:00
herman ten brugge
9712aff9c0 Fix gcc testsuite problems
arm-gen.c:
- is_hgen_float_aggr/gfunc_sret: Fix for zero sized structs

arm64-gen.c:
- arm64_ldrs: Fix for zero sized structs
- arm64_sym: Use R_AARCH64_ABS64 instead of R_AARCH64_MOVW_UABS_G*
             This has same speed. See 117_gcc_test.c(tst_adr)
- load: Fix for zero sized structs and add VT_CONST | VT_LVAL support
- store: add VT_CONST | VT_LVAL support
- arm64_gen_bl_or_b: Allow branch. See 117_gcc_test.c(tst_branch)
- gen_bounds_prolog: Use R_AARCH64_ABS64 for bound checking
- gen_bounds_epilog: Use R_AARCH64_ABS64 for bound checking
- gfunc_call: Allow large stack
- arm64_gen_opic: Do not crash on large shift

riscv64-gen.c:
- load: Move type_size call. (move_reg set sv.type.ref NULL for VT_STRUCT)
- gfunc_call: Allow large stack
- gen_opil: Fix word mode calls

x86_64-gen.c:
- load: Fix for zero sized structs

libtcc.c:
- Add some defines for gcc testsuite (only most common)

tccgen.c:
- parse_builtin_params: Add types for builtins
- unary: Add builtins: __builtin_abort __builtin_memcpy __builtin_memcmp
                       __builtin_memmove __builtin_memset __builtin_strlen
                       __builtin_strcpy __builtin_strncpy __builtin_strcmp
                       __builtin_strncmp __builtin_strcat __builtin_strchr
                       __builtin_strdup __builtin_malloc __builtin_realloc
                       __builtin_calloc __builtin_free __builtin_alloca
- decl_initializer: Fix crash. See 60_errors_and_warnings(test_var_array)

tccmacho.c:
- Remove 'ret = 0'

tcctok.h:
- Add builtin/bound checking tokens

tests/gcctestsuite.sh:
- Add more counters and run execute tests

tests/bug.c
- Some remaining bugs in tcc (not complete)

tests/tests2/60_errors_and_warnings:
- Add test_var_array test

tests/tests2/117_gcc_test:
- New test

Results of gcctestsuite.sh for all targets:

linux:
x86_64: 3036 test(s) ok.  328 test(s) failed.  24 test(s) exe failed.
i386:   3037 test(s) ok.  327 test(s) failed.  24 test(s) exe failed.
arm:    2986 test(s) ok.  362 test(s) failed.  40 test(s) exe failed.
arm64:  2996 test(s) ok.  367 test(s) failed.  25 test(s) exe failed.
macos:  3031 test(s) ok.  332 test(s) failed.  25 test(s) exe failed.
riscv:  2948 test(s) ok.  401 test(s) failed.  39 test(s) exe failed.

windows:
x86_64: 3027 test(s) ok.  333 test(s) failed.  28 test(s) exe failed.
i386:   3029 test(s) ok.  331 test(s) failed.  28 test(s) exe failed.

linux with bounds checking:
x86_64: 3030 test(s) ok.  328 test(s) failed.  30 test(s) exe failed.
i386:   3028 test(s) ok.  327 test(s) failed.  33 test(s) exe failed.
arm:    2997 test(s) ok.  362 test(s) failed.  29 test(s) exe failed.
arm64:  2986 test(s) ok.  367 test(s) failed.  35 test(s) exe failed.
macos:  3026 test(s) ok.  332 test(s) failed.  30 test(s) exe failed.
riscv:  2936 test(s) ok.  409 test(s) failed.  43 test(s) exe failed.

windows with bounds checking:
x86_64: 3029 test(s) ok.  332 test(s) failed.  27 test(s) exe failed.
i386:   3027 test(s) ok.  331 test(s) failed.  30 test(s) exe failed.

all: fail for complex and vector types, nested functions
     and a lot of gcc defines/buitins.
arm/arm64/riscv: fail for asm and alloca.
riscv: fail with 'error: unimp: store(struct)'
2020-07-05 14:01:50 +02:00
Michael Matz
1711eb2ef3 macos: add overview comment 2020-06-20 22:25:08 +02:00
Michael Matz
d174af08f9 macos: Fix memtest
* free allocated memory
* fix weak symbols related to -run
* remove memtest from ignored tests for OSX
2020-06-20 22:17:08 +02:00
Michael Matz
ac86fb50cd macos: Tidy code 2020-06-20 22:17:08 +02:00
Michael Matz
c86760c1e9 macos: Read exported symbols from dylibs
up to now we simply assumed that any undefined symbols will be
provided by some shared libs on the cmdline.  Now we check this.
2020-06-20 22:17:08 +02:00
Michael Matz
f2e154e1e5 macos: Disable verbose linking output 2020-06-20 22:17:08 +02:00