luvit / luvi

A project in-between luv and luvit.
Apache License 2.0
308 stars 63 forks source link

Build failure on Apple Silicon #243

Closed carlocab closed 2 years ago

carlocab commented 3 years ago

As I mentioned in #242, I'm trying to build luvi on Apple Silicon. However, this fails with a linker error:

ld: missing LC_SEGMENT file 'jitted_tmp/src/lua/init.lua_luvi_generated.o' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [luvi] Error 1
make[1]: *** [CMakeFiles/luvi.dir/all] Error 2
make: *** [all] Error 2

CI logs available at https://github.com/Homebrew/homebrew-core/pull/69036/checks?check_run_id=1739201673.

The error starts here and the CMake invocation is here.

This compiles successfully on the Intel CI nodes. As previously mentioned, I'm building with a custom libuv (v1.40), a custom LuaJIT (OpenResty v2.1-20201229), and a shared libluv (v1.36.0, built with the aforementioned libuv and LuaJIT).

carlocab commented 3 years ago

There's mention of setting TARGET_ARCH in https://github.com/luvit/luvi/commit/a9dc8dae2eb69d4a754a0cf5c08622d70f6b7067, but that seems to be only useful for cross-compiling. Still, I thought it might be worth a try [1], but it doesn't help. I still get the exact same error. [2]

[1] https://github.com/Homebrew/homebrew-core/pull/69036/commits/fa3d9876d6137f31e7913f1b3972ff781311b917 [2] https://github.com/Homebrew/homebrew-core/runs/1739322226#step:7:338

drveoj commented 3 years ago

I think this is basically a duplicate of #230 because the apple silicon is basically ARM (aarch64) under the hood. Same error, same place.

carlocab commented 3 years ago

Yes, it does look like the same error. Apple ARM isn't exactly the same as aarch64, however. There are still a lot of things that work fine on aarch64 but don't run on Apple Silicon.

carlocab commented 3 years ago

Actually, I'm not sure. Is missing LC_SEGMENT file the same as a segfault?

reasonMix commented 3 years ago

modify the luajit source code.bcsave_machobj function in the bcsave.lua. delete the fat mode, only use the thin mode for apple m1

carlocab commented 2 years ago

modify the luajit source code.bcsave_machobj function in the bcsave.lua. delete the fat mode, only use the thin mode for apple m1

This seems like a likely fix. See LuaJIT/LuaJIT#649.

carlocab commented 2 years ago

This is fixed by LuaJIT/LuaJIT#863 and the following patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index abb2f15..f27858f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -170,10 +170,6 @@ lua_add_executable(luvi
   ${lpeg_re_lua}
 )

-if(APPLE)
-  set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000 ${CMAKE_EXE_LINKER_FLAGS}")
-endif()
-
 if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
   set(CMAKE_EXE_LINKER_FLAGS "-Wl,-E")
 endif()
carlocab commented 2 years ago

Not quite fixed yet, as this still needs https://github.com/LuaJIT/LuaJIT/pull/863. But I suppose that's not really actionable here, so I'm ok to leave this closed.