Going further,
Using native arm64 mon Big Sur M1, .o generated files are for ARM64 But after quickly patching arm64-link.c for case 9, it looks that binary is for x86_64 see below: jullien@mobley:~/tinycc $ ./tcc -c -B. ../foo.c -o foo.o jullien@mobley:~/tinycc $ file foo.o foo.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped jullien@mobley:~/tinycc $ ./tcc -B. ../foo.c -o foo 270: reloc 283 @ 0x10000103c: val=0x100001050 name=.__stubs IGNORE 9 รง quick and ugly patch to see how it goes jullien@mobley:~/tinycc $ file foo foo: Mach-O 64-bit executable x86_64 From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Christian Jullien Sent: Monday, July 05, 2021 07:12 To: tinycc-devel@nongnu.org Cc: 'Herman ten Brugge' Subject: Re: [Tinycc-devel] Linking system dylibs on macOS 11+ Last but not least, tcc x64 compiled on Catalina and copied to Big Sur M1 allows me to compile at light speed my OpenLisp project (as x64 binary of course) which then fully works when translated by Rosetta. This is a big milestone. C. From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Christian Jullien Sent: Monday, July 05, 2021 06:56 To: tinycc-devel@nongnu.org Cc: 'Herman ten Brugge' Subject: Re: [Tinycc-devel] Linking system dylibs on macOS 11+ Hello Sushant, Good things first, trying your fork, it works on both macOS Catalina and High Sierra x64 (it only reports new warnings, see at the end of this post).. Even better, tcc (compiled natively for x64 on Catalina) and then copied to Big Sur M1 WORKS when translated by Rosetta!!! Your patch is clearly the right direction to support Big Sur M1. Now, bad news. When compiled natively for arm64 I still get for hello world: jullien@mobley:~/tinycc $ ./tcc -B. ../hello.c -o hello FIXME: handle reloc type 9 at 1052 [0x134e06d62] to 1050 A more complex example gives me this other error jullien@mobley:~/tinycc $ ./tcc -B. ../openlisp/etc/cspy.c -o foo tcc: error: R_AARCH64_(JUMP|CALL)26 relocation failed (val=1000027f6, addr=1000010a0) Perhaps Herman can help us with relocation errors. He fixed many of them when porting tcc on different BSD systems. As far I understand they are related to elf sections and/or CPU instructions. See arm64-link.c Here are the new warnings to fix: libtcc.c: In function 'tcc_add_file_internal': libtcc.c:1036:32: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1036 | char* soname = filename; | ^~~~~~~~ libtcc.c:1039:28: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1039 | soname = macho_tbd_soname(filename); | ^ libtcc.c:1041:17: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 1041 | void* dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY); | ^~~~ And tccmacho.c: In function 'macho_tbd_soname': tccmacho.c:872:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 872 | struct stat sb; | ^~~~~~ tccmacho.c:874:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 874 | char* data = load_data(fd, 0, sb.st_size+1); | ^~~~ tccmacho.c:876:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 876 | char* pos = data; | ^~~~ tccmacho.c:884:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 884 | char* ret = tcc_mallocz(strlen(soname)+1); | ^~~~ tccmacho.c: In function 'macho_load_tbd': tccmacho.c:897:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 897 | char* data = load_data(fd, 0, sb.st_size+1); | ^~~~ tccmacho.c:899:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 899 | char* pos = data; | ^~~~ tccmacho.c:913:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] 913 | int cont = 1; | ^~~ In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:194 , from tcc.h:35, from tccmacho.c:18: tccmacho.c: In function 'add_segment': tccmacho.c:265:5: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation] 265 | strncpy(sc->segname, name, 16); | ^~~~~~~ In function 'add_section', inlined from 'collect_sections' at tccmacho.c:649:22, inlined from 'macho_output_file' at tccmacho.c:812:9: tccmacho.c:285:5: warning: '__builtin_strncpy' specified bound 16 equals destination size [-Wstringop-truncation] 285 | strncpy(sec->sectname, name, 16); | ^~~~~~~ From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of Sushant Pandurangi Sent: Sunday, July 04, 2021 22:23 To: tinycc-devel@nongnu.org Subject: Re: [Tinycc-devel] Linking system dylibs on macOS 11+ Hi Christian, Unfortunately I don't see why the patch failed. I've never had the "handle reloc type" error. Let's try another way, here is a link to my fork, the branch is osx11-dyld. You can have a look at the log and clone and test directly. https://github.com/sushpa/tinycc In the meantime it is updated to work with `tcc -run` as well. Still x86-64 only. Thanks a lot for the cfarm link, I might look into M1 later this week or next if I can get an account there. Regards, Sushant
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel