Skip to content

Commit

Permalink
Yet another luajit.cmake unwind detection fix
Browse files Browse the repository at this point in the history
Previously, CMake would only read up to the first NUL or control character (for me that meant it would only read "ELF" from tmpunwind.o).
This was making CMake think there was no `eh_frame`/`__unwind_info` string in the file even if there actually was.

Now, CMake skips binary data in tmpunwind.o and just reads all the ASCII strings from the file, which is fine for what we need to do with it.

This fixes:

    In file included from luv/deps/luajit/src/ljamalg.c:23:
    luv/deps/luajit/src/lj_err.c: In function ‘lj_err_unwind_dwarf’:
    luv/deps/luajit/src/lj_err.c:469:2: error: #error "Broken build system -- only use the provided Makefiles!"
      469 | #error "Broken build system -- only use the provided Makefiles!"
          |  ^~~~~

for me on Linux x86_64 when trying to build Luv
  • Loading branch information
squeek502 authored and zhaozg committed Sep 8, 2022
1 parent d53bd3f commit ebc79ee
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion deps/luajit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ ELSEIF(NOT WIN32)
execute_process(COMMAND "${CMAKE_C_COMPILER}" -c -x c "${TMPUNWIND_DIR}/tmpunwind.c" -o "${TMPUNWIND_DIR}/tmpunwind.o"
RESULT_VARIABLE UNWIND_TEST_ERRORED)
IF(UNWIND_TEST_ERRORED EQUAL 0)
file(READ "${TMPUNWIND_DIR}/tmpunwind.o" TMPUNWIND_O)
# Use STRINGS here so that CMake doesn't stop reading the file once it hits a NUL character.
# Note: STRINGS skips all non-ASCII/binary bytes, but that's okay since we're only checking
# for the presence of some ASCII strings.
file(STRINGS "${TMPUNWIND_DIR}/tmpunwind.o" TMPUNWIND_O)
string(FIND "${TMPUNWIND_O}" "eh_frame" EH_FRAME_FOUND)
string(FIND "${TMPUNWIND_O}" "__unwind_info" UNWIND_INFO_FOUND)
IF(EH_FRAME_FOUND GREATER -1 OR UNWIND_INFO_FOUND GREATER -1)
Expand Down

0 comments on commit ebc79ee

Please sign in to comment.