terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.72k stars 201 forks source link

Malformed mach-o on macOS 12.5 (M1) #588

Closed shoe42 closed 2 years ago

shoe42 commented 2 years ago

Building using the default -pagezero_size and -image_base arguments results in an executable that cannot be executed (M1, macOS 12.5, LLVM 13, using LuaJIT commit https://github.com/LuaJIT/LuaJIT/commit/3065c910ad6027031aabe2dfd3c26a3d0f014b4f):

$ lldb ./bin/terra               
(lldb) target create "./bin/terra"
Current executable set to '.../terra/build/bin/terra' (arm64).
(lldb) r
error: Malformed Mach-o file

As per https://github.com/LuaJIT/LuaJIT/issues/649#issuecomment-751341864, are the flags still necessary with LuaJIT 2.1? Perhaps this isn't being caught in the tests due to the binary not actually being executed?

https://github.com/terralang/terra/blob/4e58e686aea7ffb513818c918a955a0ad023f64c/travis.sh#L248-L253

elliottslaughter commented 2 years ago

We test on x86 Mac all the time (both in CI and locally). So I guess this is an ARM64 issue.

The lines you linked to are for the "plain" tests, but we always run in CMake (except on Windows).

https://github.com/terralang/terra/blob/4e58e686aea7ffb513818c918a955a0ad023f64c/travis.sh#L242-L245

If you'd like to send a PR to delete these lines, I'd be happy to take it if it passes:

https://github.com/terralang/terra/blob/8bf225f3d9cacfdf4fb1b7393e6baf2deb4b0d15/src/CMakeLists.txt#L330-L336

https://github.com/terralang/terra/blob/8bf225f3d9cacfdf4fb1b7393e6baf2deb4b0d15/GNUmakefile#L176-L179

elliottslaughter commented 2 years ago

If it would help to pin https://github.com/LuaJIT/LuaJIT/commit/3065c910ad6027031aabe2dfd3c26a3d0f014b4f, I'd be happy to take a PR for that too.

shoe42 commented 2 years ago

Looks like the LuaJIT version doesn't affect this specific issue. PR: https://github.com/terralang/terra/pull/589.

shoe42 commented 2 years ago

One other thing I forgot to mention is that "stock" clang (from clitools) had some issues finding header files (unrelated to this) - I'll open a separate issue for that.

shoe42 commented 2 years ago

Fixed by https://github.com/terralang/terra/pull/589.