macos: First cut at generating Mach-O executables
commit94066765ed761a4916713c6ad5375c48b76c4330
authorMichael Matz <matz@suse.de>
Fri, 15 May 2020 01:46:55 +0000 (15 03:46 +0200)
committerMichael Matz <matz@suse.de>
Sat, 20 Jun 2020 20:09:21 +0000 (20 22:09 +0200)
tree7e42804334ba5f69555e7f9626f1398196ded52a
parentb882cad67e16d5b81ddc96510c14ea543b473aa4
macos: First cut at generating Mach-O executables

this does generate a working executable for a very simple
example input, e.g. this:

% cat simple.c
int main(void)
{
  return 0;
}
% ./tcc -B. -c simple.c
% ./tcc -nostdlib -B. simple.o -lc
% ./a.out && echo okay
okay

(the -lc is actually not necessary right now, see below).  This
has many limitations:

* no symbol table, hence no calls to external functions from
  e.g. libc, aka libSystemB
* no proper entry point (should be main, but is hardcoded to first
  real .text address)
* libSystemB is hardcoded, no other libs are supported (but again
  no external calls anyway)
* generated Mach-O executable is in old format: neither LC_DYLD_INFO
  no export tries for symbols are created (no symbol table at all!)
* the __LINKEDIT segment is faked and empty, as dyld doesn't like
  it empty even if no symbols point into it
* same with __DATA, dyld wants a non-empty writable segment which
  we enforce with useless data
* no relocations, hence no function call stubs (lazy or not) are
  generated
* hardcodes some other constants as well
Makefile
tcc.h
tccelf.c
tccgen.c
tccmacho.c [new file with mode: 0644]