Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells
@ 2022-12-21 14:33 Maxim Kokryashkin via Tarantool-patches
  2023-01-09 15:28 ` [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper Igor Munkin via Tarantool-patches
  2023-01-09 15:32 ` [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells Igor Munkin via Tarantool-patches
  0 siblings, 2 replies; 8+ messages in thread
From: Maxim Kokryashkin via Tarantool-patches @ 2022-12-21 14:33 UTC (permalink / raw)
  To: tarantool-patches, imun

Before the patch, the external unwinding probe command could
fail on systems that don't have Bash installed. This patch
changes the command invocation, so it now uses the `sh` symlink.
---
Branch: https://github.com/tarantool/luajit/tree/fckxorg/gh-noticket-fix-build-for-non-bash
PR: https://github.com/tarantool/tarantool/pull/8087

First noticed on Alpine. Here is the build log after the patch:

/luajit/build # cat /etc/issue
Welcome to Alpine Linux 3.15
Kernel \r on an \m (\l)

/luajit/build # cmake .. -DCMAKE_BUILD_TYPE=Debug -DLUAJIT_DISABLE_SYSPROF=ON
-- The C compiler identification is GNU 10.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- [SetVersion] Reading version from VCS: v2.1.0-beta3-272-g9c4048dc
-- [SetBuildParallelLevel] CMAKE_BUILD_PARALLEL_LEVEL is 12
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- LuaJIT system profiler support is disabled
CMake Warning at test/lua-Harness-tests/CMakeLists.txt:9 (message):
  `prove' is not found, so lua-Harness-tests target is not generated


CMake Warning at test/tarantool-tests/CMakeLists.txt:9 (message):
  `prove' is not found, so tarantool-tests target is not generated


-- Configuring done
-- Generating done
-- Build files have been written to: /luajit/build
/luajit/build # make -j
[  1%] Building C object src/host/CMakeFiles/minilua.dir/minilua.c.o
[  1%] Linking C executable minilua
[  1%] Built target minilua
[  2%] Generating buildvm_arch.h
[  3%] Building C object src/host/CMakeFiles/buildvm.dir/buildvm_fold.c.o
[  3%] Building C object src/host/CMakeFiles/buildvm.dir/buildvm.c.o
[  3%] Building C object src/host/CMakeFiles/buildvm.dir/buildvm_asm.c.o
[  4%] Building C object src/host/CMakeFiles/buildvm.dir/buildvm_lib.c.o
[  5%] Building C object src/host/CMakeFiles/buildvm.dir/buildvm_peobj.c.o
[  5%] Linking C executable buildvm
[  5%] Built target buildvm
[  6%] Generating lj_vm.S
[  7%] Generating lj_vm.S
[  7%] Generating lj_bcdef.h
[  8%] Generating lj_recdef.h
[  9%] Generating lj_ffdef.h
[ 10%] Generating lj_libdef.h
[ 11%] Generating jit/vmdef.lua
[ 11%] Generating lj_folddef.h
Scanning dependencies of target vm_shared
Scanning dependencies of target vm_static
[ 11%] Building ASM object src/CMakeFiles/vm_shared.dir/lj_vm.S.o
[ 12%] Building ASM object src/CMakeFiles/vm_static.dir/lj_vm.S.o
[ 12%] Built target vm_shared
[ 12%] Built target vm_static
[ 12%] Built target buildvm_output
[ 12%] Building C object src/CMakeFiles/core_static.dir/lj_buf.c.o
[ 13%] Building C object src/CMakeFiles/core_static.dir/lj_bc.c.o
[ 13%] Building C object src/CMakeFiles/core_shared.dir/lj_api.c.o
[ 14%] Building C object src/CMakeFiles/core_static.dir/lj_api.c.o
[ 15%] Building C object src/CMakeFiles/core_static.dir/lj_debug.c.o
[ 16%] Building C object src/CMakeFiles/core_shared.dir/lj_debug.c.o
[ 17%] Building C object src/CMakeFiles/core_shared.dir/lj_bc.c.o
[ 17%] Building C object src/CMakeFiles/core_shared.dir/lj_dispatch.c.o
[ 18%] Building C object src/CMakeFiles/core_static.dir/lj_err.c.o
[ 18%] Building C object src/CMakeFiles/core_static.dir/lj_dispatch.c.o
[ 18%] Building C object src/CMakeFiles/core_static.dir/lj_func.c.o
[ 20%] Building C object src/CMakeFiles/core_shared.dir/lj_err.c.o
[ 20%] Building C object src/CMakeFiles/core_shared.dir/lj_buf.c.o
[ 21%] Building C object src/CMakeFiles/core_shared.dir/lj_func.c.o
[ 22%] Building C object src/CMakeFiles/core_static.dir/lj_gc.c.o
[ 22%] Building C object src/CMakeFiles/core_shared.dir/lj_gc.c.o
[ 23%] Building C object src/CMakeFiles/core_shared.dir/lj_lib.c.o
[ 23%] Building C object src/CMakeFiles/core_shared.dir/lj_load.c.o
[ 24%] Building C object src/CMakeFiles/core_static.dir/lj_lib.c.o
[ 25%] Building C object src/CMakeFiles/core_shared.dir/lj_mapi.c.o
[ 25%] Building C object src/CMakeFiles/core_shared.dir/lj_meta.c.o
[ 25%] Building C object src/CMakeFiles/core_static.dir/lj_load.c.o
[ 26%] Building C object src/CMakeFiles/core_shared.dir/lj_obj.c.o
[ 27%] Building C object src/CMakeFiles/core_static.dir/lj_mapi.c.o
[ 27%] Building C object src/CMakeFiles/core_static.dir/lj_meta.c.o
[ 28%] Building C object src/CMakeFiles/core_static.dir/lj_obj.c.o
[ 29%] Building C object src/CMakeFiles/core_shared.dir/lj_state.c.o
[ 29%] Building C object src/CMakeFiles/core_static.dir/lj_state.c.o
[ 29%] Building C object src/CMakeFiles/core_shared.dir/lj_str.c.o
[ 30%] Building C object src/CMakeFiles/core_shared.dir/lj_strfmt.c.o
[ 31%] Building C object src/CMakeFiles/core_static.dir/lj_str.c.o
[ 31%] Building C object src/CMakeFiles/core_static.dir/lj_strfmt_num.c.o
[ 31%] Building C object src/CMakeFiles/core_shared.dir/lj_strfmt_num.c.o
[ 32%] Building C object src/CMakeFiles/core_static.dir/lj_strfmt.c.o
[ 33%] Building C object src/CMakeFiles/core_static.dir/lj_strscan.c.o
[ 34%] Building C object src/CMakeFiles/core_shared.dir/lj_strscan.c.o
[ 34%] Building C object src/CMakeFiles/core_shared.dir/lj_tab.c.o
[ 36%] Building C object src/CMakeFiles/core_static.dir/lj_udata.c.o
[ 36%] Building C object src/CMakeFiles/core_shared.dir/lj_udata.c.o
[ 36%] Building C object src/CMakeFiles/core_static.dir/lj_vmevent.c.o
[ 36%] Building C object src/CMakeFiles/core_static.dir/lj_tab.c.o
[ 37%] Building C object src/CMakeFiles/core_static.dir/lib_aux.c.o
[ 38%] Building C object src/CMakeFiles/core_shared.dir/lj_vmevent.c.o
[ 40%] Building C object src/CMakeFiles/core_static.dir/lib_init.c.o
[ 40%] Building C object src/CMakeFiles/core_static.dir/lib_base.c.o
[ 41%] Building C object src/CMakeFiles/core_static.dir/lib_math.c.o
[ 41%] Building C object src/CMakeFiles/core_shared.dir/lib_aux.c.o
[ 42%] Building C object src/CMakeFiles/core_shared.dir/lib_init.c.o
[ 42%] Building C object src/CMakeFiles/core_shared.dir/lib_base.c.o
[ 43%] Building C object src/CMakeFiles/core_shared.dir/lib_math.c.o
[ 43%] Building C object src/CMakeFiles/core_static.dir/lib_bit.c.o
[ 43%] Building C object src/CMakeFiles/core_shared.dir/lib_bit.c.o
[ 44%] Building C object src/CMakeFiles/core_static.dir/lib_string.c.o
[ 44%] Building C object src/CMakeFiles/core_static.dir/lib_table.c.o
[ 45%] Building C object src/CMakeFiles/core_static.dir/lib_io.c.o
[ 46%] Building C object src/CMakeFiles/core_shared.dir/lib_string.c.o
[ 47%] Building C object src/CMakeFiles/core_shared.dir/lib_table.c.o
[ 47%] Building C object src/CMakeFiles/core_shared.dir/lib_io.c.o
[ 48%] Building C object src/CMakeFiles/core_static.dir/lib_os.c.o
[ 48%] Building C object src/CMakeFiles/core_static.dir/lib_jit.c.o
[ 49%] Building C object src/CMakeFiles/core_static.dir/lib_debug.c.o
[ 49%] Building C object src/CMakeFiles/core_static.dir/lib_package.c.o
[ 49%] Building C object src/CMakeFiles/core_static.dir/lib_misc.c.o
[ 50%] Building C object src/CMakeFiles/core_static.dir/lib_ffi.c.o
[ 51%] Building C object src/CMakeFiles/core_shared.dir/lib_os.c.o
[ 52%] Building C object src/CMakeFiles/core_static.dir/lj_bcread.c.o
[ 52%] Building C object src/CMakeFiles/core_shared.dir/lib_package.c.o
[ 53%] Building C object src/CMakeFiles/core_shared.dir/lib_debug.c.o
[ 54%] Building C object src/CMakeFiles/core_static.dir/lj_bcwrite.c.o
[ 54%] Building C object src/CMakeFiles/core_static.dir/lj_lex.c.o
[ 55%] Building C object src/CMakeFiles/core_shared.dir/lib_jit.c.o
[ 55%] Building C object src/CMakeFiles/core_shared.dir/lib_ffi.c.o
[ 55%] Building C object src/CMakeFiles/core_shared.dir/lj_bcread.c.o
[ 56%] Building C object src/CMakeFiles/core_static.dir/lj_parse.c.o
[ 57%] Building C object src/CMakeFiles/core_shared.dir/lj_bcwrite.c.o
[ 57%] Building C object src/CMakeFiles/core_static.dir/lj_memprof.c.o
[ 58%] Building C object src/CMakeFiles/core_shared.dir/lib_misc.c.o
[ 60%] Building C object src/CMakeFiles/core_static.dir/lj_profile.c.o
[ 60%] Building C object src/CMakeFiles/core_shared.dir/lj_lex.c.o
[ 61%] Building C object src/CMakeFiles/core_shared.dir/lj_parse.c.o
[ 62%] Building C object src/CMakeFiles/core_static.dir/lj_sysprof.c.o
[ 61%] Building C object src/CMakeFiles/core_static.dir/lj_profile_timer.c.o
[ 63%] Building C object src/CMakeFiles/core_static.dir/lj_symtab.c.o
[ 63%] Building C object src/CMakeFiles/core_static.dir/lj_alloc.c.o
[ 64%] Building C object src/CMakeFiles/core_shared.dir/lj_memprof.c.o
[ 64%] Building C object src/CMakeFiles/core_shared.dir/lj_profile.c.o
[ 65%] Building C object src/CMakeFiles/core_static.dir/lj_char.c.o
[ 65%] Building C object src/CMakeFiles/core_static.dir/lj_utils_leb128.c.o
[ 66%] Building C object src/CMakeFiles/core_shared.dir/lj_profile_timer.c.o
[ 66%] Building C object src/CMakeFiles/core_shared.dir/lj_symtab.c.o
[ 67%] Building C object src/CMakeFiles/core_static.dir/lj_vmmath.c.o
[ 68%] Building C object src/CMakeFiles/core_static.dir/lj_wbuf.c.o
[ 69%] Building C object src/CMakeFiles/core_shared.dir/lj_sysprof.c.o
[ 69%] Building C object src/CMakeFiles/core_static.dir/lj_asm.c.o
[ 69%] Building C object src/CMakeFiles/core_static.dir/lj_ir.c.o
[ 69%] Building C object src/CMakeFiles/core_shared.dir/lj_alloc.c.o
[ 70%] Building C object src/CMakeFiles/core_shared.dir/lj_utils_leb128.c.o
[ 71%] Building C object src/CMakeFiles/core_shared.dir/lj_char.c.o
[ 72%] Building C object src/CMakeFiles/core_static.dir/lj_ffrecord.c.o
[ 73%] Building C object src/CMakeFiles/core_static.dir/lj_mcode.c.o
[ 73%] Building C object src/CMakeFiles/core_shared.dir/lj_vmmath.c.o
[ 73%] Building C object src/CMakeFiles/core_static.dir/lj_record.c.o
[ 74%] Building C object src/CMakeFiles/core_shared.dir/lj_wbuf.c.o
[ 75%] Building C object src/CMakeFiles/core_static.dir/lj_snap.c.o
[ 75%] Building C object src/CMakeFiles/core_shared.dir/lj_asm.c.o
[ 76%] Building C object src/CMakeFiles/core_static.dir/lj_trace.c.o
[ 77%] Building C object src/CMakeFiles/core_shared.dir/lj_ffrecord.c.o
[ 78%] Building C object src/CMakeFiles/core_static.dir/lj_opt_fold.c.o
[ 78%] Building C object src/CMakeFiles/core_static.dir/lj_opt_loop.c.o
[ 78%] Building C object src/CMakeFiles/core_static.dir/lj_opt_dce.c.o
[ 78%] Building C object src/CMakeFiles/core_shared.dir/lj_ir.c.o
[ 80%] Building C object src/CMakeFiles/core_static.dir/lj_opt_mem.c.o
[ 81%] Building C object src/CMakeFiles/core_shared.dir/lj_mcode.c.o
[ 82%] Building C object src/CMakeFiles/core_static.dir/lj_carith.c.o
[ 82%] Building C object src/CMakeFiles/core_static.dir/lj_opt_narrow.c.o
[ 82%] Building C object src/CMakeFiles/core_shared.dir/lj_snap.c.o
[ 83%] Building C object src/CMakeFiles/core_static.dir/lj_opt_sink.c.o
[ 85%] Building C object src/CMakeFiles/core_shared.dir/lj_record.c.o
[ 85%] Building C object src/CMakeFiles/core_static.dir/lj_ccallback.c.o
[ 84%] Building C object src/CMakeFiles/core_static.dir/lj_ccall.c.o
[ 85%] Building C object src/CMakeFiles/core_shared.dir/lj_opt_dce.c.o
[ 86%] Building C object src/CMakeFiles/core_shared.dir/lj_opt_fold.c.o
[ 88%] Building C object src/CMakeFiles/core_static.dir/lj_cconv.c.o
[ 87%] Building C object src/CMakeFiles/core_shared.dir/lj_trace.c.o
[ 88%] Building C object src/CMakeFiles/core_shared.dir/lj_opt_mem.c.o
[ 88%] Building C object src/CMakeFiles/core_shared.dir/lj_opt_loop.c.o
[ 89%] Building C object src/CMakeFiles/core_static.dir/lj_cdata.c.o
[ 89%] Building C object src/CMakeFiles/core_static.dir/lj_clib.c.o
[ 90%] Building C object src/CMakeFiles/core_static.dir/lj_cparse.c.o
[ 91%] Building C object src/CMakeFiles/core_static.dir/lj_crecord.c.o
[ 91%] Building C object src/CMakeFiles/core_static.dir/lj_ctype.c.o
[ 92%] Building C object src/CMakeFiles/core_shared.dir/lj_opt_narrow.c.o
[ 92%] Building C object src/CMakeFiles/core_shared.dir/lj_opt_sink.c.o
[ 93%] Building C object src/CMakeFiles/core_shared.dir/lj_carith.c.o
[ 93%] Building C object src/CMakeFiles/core_shared.dir/lj_ccallback.c.o
[ 94%] Building C object src/CMakeFiles/core_shared.dir/lj_ccall.c.o
[ 94%] Building C object src/CMakeFiles/core_shared.dir/lj_cconv.c.o
[ 95%] Building C object src/CMakeFiles/core_shared.dir/lj_cdata.c.o
[ 95%] Building C object src/CMakeFiles/core_shared.dir/lj_cparse.c.o
[ 96%] Building C object src/CMakeFiles/core_shared.dir/lj_clib.c.o
[ 97%] Building C object src/CMakeFiles/core_shared.dir/lj_crecord.c.o
[ 97%] Building C object src/CMakeFiles/core_shared.dir/lj_ctype.c.o
[ 97%] Built target core_shared
[ 97%] Linking C shared library libluajit.so
[ 97%] Built target core_static
[ 98%] Linking C static library libluajit.a
[ 98%] Built target libluajit_shared
[ 98%] Built target libluajit_static
[ 98%] Built target libluajit
[ 98%] Building C object src/CMakeFiles/luajit_static.dir/luajit.c.o
[100%] Linking C executable luajit
[100%] Built target luajit_static
[100%] Built target luajit-main

 cmake/SetTargetFlags.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
index 1ca438f1..0303a2c6 100644
--- a/cmake/SetTargetFlags.cmake
+++ b/cmake/SetTargetFlags.cmake
@@ -23,7 +23,7 @@ else()
     # Find out whether the target toolchain always generates
     # unwindtables.
     execute_process(
-      COMMAND bash -c "exec 2>/dev/null; echo 'extern void b(void);int a(void){b();return 0;}' | ${CMAKE_C_COMPILER} -c -x c - -o tmpunwind.o && { grep -qa -e eh_frame -e __unwind_info tmpunwind.o || grep -qU -e eh_frame -e __unwind_info tmpunwind.o; } && echo E; rm -f tmpunwind.o"
+      COMMAND sh -c "exec 2>/dev/null; echo 'extern void b(void);int a(void){b();return 0;}' | ${CMAKE_C_COMPILER} -c -x c - -o tmpunwind.o && { grep -qa -e eh_frame -e __unwind_info tmpunwind.o || grep -qU -e eh_frame -e __unwind_info tmpunwind.o; } && echo E; rm -f tmpunwind.o"
       WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
       OUTPUT_VARIABLE TESTUNWIND
       RESULT_VARIABLE TESTUNWIND_RC
-- 
2.38.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper
  2022-12-21 14:33 [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells Maxim Kokryashkin via Tarantool-patches
@ 2023-01-09 15:28 ` Igor Munkin via Tarantool-patches
  2023-01-10 10:05   ` Sergey Kaplun via Tarantool-patches
  2023-01-12 14:55   ` Igor Munkin via Tarantool-patches
  2023-01-09 15:32 ` [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells Igor Munkin via Tarantool-patches
  1 sibling, 2 replies; 8+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-01-09 15:28 UTC (permalink / raw)
  To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches

After struggling with black voodoo magic oneliner provided by Mike Pall
in scope of e131936133c58de4426c595db2341caf5a1665b5 ("Cleanup and
enable external unwinding for more platforms.") to check whether the
target toolchain always generates unwind tables, it was decided to
implement it as a CMake function to encapsulate and comment this damn
"grep" spell.

Signed-off-by: Igor Munkin <imun@tarantool.org>
---

Branch: https://github.com/tarantool/luajit/compare/imun/fix-build-for-non-bash
CI is green(*): https://github.com/tarantool/luajit/commit/e717eaa

(*) Max, could you please check this patch on the Alpine?

 cmake/CheckUnwindTables.cmake | 114 ++++++++++++++++++++++++++++++++++
 cmake/SetTargetFlags.cmake    |  18 ++----
 2 files changed, 120 insertions(+), 12 deletions(-)
 create mode 100644 cmake/CheckUnwindTables.cmake

diff --git a/cmake/CheckUnwindTables.cmake b/cmake/CheckUnwindTables.cmake
new file mode 100644
index 00000000..903977ad
--- /dev/null
+++ b/cmake/CheckUnwindTables.cmake
@@ -0,0 +1,114 @@
+# CheckUnwindTables provides a convenient way to define whether
+# the target toolchain generates unwind tables.
+#
+# This function implements black voodoo magic provided by Mike
+# Pall in scope of e131936133c58de4426c595db2341caf5a1665b5
+# ("Cleanup and enable external unwinding for more platforms.")
+# via CMake.
+#
+# Example usage:
+#
+#   # Find out whether the target toolchain always generates
+#   # unwind tables.
+#   CheckUnwindTables(HAVE_UNWIND_TABLES)
+#   if(HAVE_UNWIND_TABLES)
+#     AppendFlags(TARGET_C_FLAGS -DLUAJIT_UNWIND_EXTERNAL)
+#   endif()
+
+function(CheckUnwindTables status)
+  set(_CHECK_UNWIND_TABLES_RESULT FALSE)
+
+  # 1. Build the command compiling the simple object file using
+  #    the target toolchain.
+  # XXX: CMake helper <try_compile> can't be used, since there is
+  # no executable file as a result, but only an object file (in
+  # other words, there is no <main> function in C source file).
+  set(_TEST_UNWIND_OBJECT "${CMAKE_BINARY_DIR}/test-unwind-tables.o")
+  string(CONCAT _TEST_UNWIND_SOURCE
+    "extern void b(void);"
+    "int a(void) {"
+      "b();"
+      "return 0;"
+    "}"
+  )
+  string(CONCAT _TEST_UNWIND_COMPILE
+    "echo '${_TEST_UNWIND_SOURCE}'"
+    "|"
+    "${CMAKE_C_COMPILER} -c -x c - -o ${_TEST_UNWIND_OBJECT}"
+  )
+
+  # 2. Use <grep> to find either .eh_frame (for ELF) or
+  #    __unwind_info (for Mach-O) entries in the compiled object
+  #    file. After the several attempts in scope of the following
+  #    commits:
+  #    * e131936133c58de4426c595db2341caf5a1665b5 ("Cleanup and
+  #      enable external unwinding for more platforms.")
+  #    * d4a554d6ee1507f7313641b26ed09bf1b518fa1f ("OSX: Fix build
+  #      by hardcoding external frame unwinding.")
+  #    * b9d523965b3f55b19345a1ed1ebc92e431747ce1 ("BSD: Fix build
+  #      with BSD grep.")
+  #    * 66563bdab0c7acf3cd61dc6cfcca36275951d084 ("Fix build with
+  #      busybox grep.")
+  #    Mike came up with the solution to use both alternatives:
+  #    `grep -qa' as the major one and `grep -qU' as a fallback for
+  #    BSD platforms.
+  set(_TEST_GREP_GNU "grep -qa")
+  set(_TEST_GREP_BSD "grep -qU")
+  set(_TEST_GREP_PATTERN "-e eh_frame -e __unwind_info")
+  string(CONCAT _TEST_UNWIND_CHECK
+    # XXX: Mind the space after the opening brace. The space is
+    # vital since { is a *reserved word* (i.e. the command built
+    # into the shell). For more info see the following link:
+    # https://www.gnu.org/software/bash/manual/html_node/Reserved-Words.html.
+    "{ "
+    "${_TEST_GREP_GNU} ${_TEST_GREP_PATTERN} ${_TEST_UNWIND_OBJECT}"
+    "||"
+    "${_TEST_GREP_BSD} ${_TEST_GREP_PATTERN} ${_TEST_UNWIND_OBJECT}"
+    # XXX: Mind the semicolon prior to the closing brace. The
+    # semicolon is vital due to we are executing the list of shell
+    # commands that has to be terminated by one of ';', '&', or a
+    # newline. Considering it will be executed synchronously via
+    # <execute_process>, only the first option fits here. For more
+    # info see the following link:
+    # https://www.gnu.org/software/bash/manual/html_node/Lists.html
+    # XXX: Considering the preceding semicolon, there is no need to
+    # separate } command with the additional whitespace.
+    ";}"
+  )
+
+  # 3. Use step 1 and step 2 to check whether target toolchain
+  #    always generates unwind tables.
+  # XXX: There is no need in "echo E" command at the end, since
+  # we can check $? of the command by <RESULT_VARIABLE> value.
+  # Fun fact: there is $(.SHELLSTATUS) variable in GNU Make, but
+  # it can't be used in <ifeq>/<ifneq> conditions, so we can't get
+  # rid of "echo E" in the original Makefile machinery.
+  execute_process(
+    COMMAND /bin/sh -c "${_TEST_UNWIND_COMPILE} && ${_TEST_UNWIND_CHECK}"
+    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+    RESULT_VARIABLE _TEST_UNWIND_RC
+    ERROR_QUIET
+    OUTPUT_QUIET
+  )
+
+  if(_TEST_UNWIND_RC EQUAL 0)
+    set(_CHECK_UNWIND_TABLES_RESULT TRUE)
+  endif()
+
+  # Remove generated object file.
+  file(REMOVE ${_TEST_UNWIND_OBJECT})
+
+  set(${status} ${_CHECK_UNWIND_TABLES_RESULT} PARENT_SCOPE)
+  # XXX: Unset the internal variable to not spoil CMake cache.
+  # Study the case in CheckIPOSupported.cmake, that affected this
+  # module: https://gitlab.kitware.com/cmake/cmake/-/commit/4b82977
+  unset(_CHECK_UNWIND_TABLES_RESULT)
+  unset(_TEST_UNWIND_RC)
+  unset(_TEST_UNWIND_CHECK)
+  unset(_TEST_GREP_PATTERN)
+  unset(_TEST_GREP_BSD)
+  unset(_TEST_GREP_GNU)
+  unset(_TEST_UNWIND_COMPILE)
+  unset(_TEST_UNWIND_SOURCE)
+  unset(_TEST_UNWIND_OBJECT)
+endfunction()
diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
index 1ca438f1..3b9e481d 100644
--- a/cmake/SetTargetFlags.cmake
+++ b/cmake/SetTargetFlags.cmake
@@ -6,6 +6,8 @@
 # * TARGET_SHARED_FLAGS
 # * TARGET_LIBS
 
+include(CheckUnwindTables)
+
 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   set(BUILDVM_MODE machasm)
 else() # Linux and FreeBSD.
@@ -21,18 +23,10 @@ else()
   string(FIND ${TARGET_C_FLAGS} "LJ_NO_UNWIND 1" UNWIND_POS)
   if(UNWIND_POS EQUAL -1)
     # Find out whether the target toolchain always generates
-    # unwindtables.
-    execute_process(
-      COMMAND bash -c "exec 2>/dev/null; echo 'extern void b(void);int a(void){b();return 0;}' | ${CMAKE_C_COMPILER} -c -x c - -o tmpunwind.o && { grep -qa -e eh_frame -e __unwind_info tmpunwind.o || grep -qU -e eh_frame -e __unwind_info tmpunwind.o; } && echo E; rm -f tmpunwind.o"
-      WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
-      OUTPUT_VARIABLE TESTUNWIND
-      RESULT_VARIABLE TESTUNWIND_RC
-    )
-    if(TESTUNWIND_RC EQUAL 0)
-      string(FIND "${TESTUNWIND}" "E" UNW_TEST_POS)
-      if(NOT UNW_TEST_POS EQUAL -1)
-        AppendFlags(TARGET_C_FLAGS -DLUAJIT_UNWIND_EXTERNAL)
-      endif()
+    # unwind tables.
+    CheckUnwindTables(HAVE_UNWIND_TABLES)
+    if(HAVE_UNWIND_TABLES)
+      AppendFlags(TARGET_C_FLAGS -DLUAJIT_UNWIND_EXTERNAL)
     endif()
   endif()
 endif()
-- 
2.34.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells
  2022-12-21 14:33 [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells Maxim Kokryashkin via Tarantool-patches
  2023-01-09 15:28 ` [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper Igor Munkin via Tarantool-patches
@ 2023-01-09 15:32 ` Igor Munkin via Tarantool-patches
  1 sibling, 0 replies; 8+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-01-09 15:32 UTC (permalink / raw)
  To: Maxim Kokryashkin; +Cc: tarantool-patches

Max,

Thanks for your patch!

After several Mike's fixups, a couple of yours, I've finally decided to
implement this oneliner via CMake (already discussed the subj offline).

Hence, I propose to supersed this fix by my patch sent as a reply to
your message. I also add Sergey Kaplun as a reviewer, since I consider
my patch much more complex than yours and ask you to review it too.

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper
  2023-01-09 15:28 ` [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper Igor Munkin via Tarantool-patches
@ 2023-01-10 10:05   ` Sergey Kaplun via Tarantool-patches
  2023-01-10 11:12     ` Igor Munkin via Tarantool-patches
  2023-01-12 14:55   ` Igor Munkin via Tarantool-patches
  1 sibling, 1 reply; 8+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2023-01-10 10:05 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

Hi, Igor!

Thanks for the patch!
LGTM!

On 09.01.23, Igor Munkin wrote:
> After struggling with black voodoo magic oneliner provided by Mike Pall
> in scope of e131936133c58de4426c595db2341caf5a1665b5 ("Cleanup and
> enable external unwinding for more platforms.") to check whether the
> target toolchain always generates unwind tables, it was decided to
> implement it as a CMake function to encapsulate and comment this damn
> "grep" spell.
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---
> 
> Branch: https://github.com/tarantool/luajit/compare/imun/fix-build-for-non-bash
> CI is green(*): https://github.com/tarantool/luajit/commit/e717eaa
> 
> (*) Max, could you please check this patch on the Alpine?

Should we add the Alpine build and test in our CI in the scope of this
commit or with separate one?

> 
>  cmake/CheckUnwindTables.cmake | 114 ++++++++++++++++++++++++++++++++++
>  cmake/SetTargetFlags.cmake    |  18 ++----
>  2 files changed, 120 insertions(+), 12 deletions(-)
>  create mode 100644 cmake/CheckUnwindTables.cmake
> 
> diff --git a/cmake/CheckUnwindTables.cmake b/cmake/CheckUnwindTables.cmake
> new file mode 100644
> index 00000000..903977ad
> --- /dev/null
> +++ b/cmake/CheckUnwindTables.cmake

<snipped>

> diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake
> index 1ca438f1..3b9e481d 100644
> --- a/cmake/SetTargetFlags.cmake
> +++ b/cmake/SetTargetFlags.cmake

<snipped>

> -- 
> 2.34.0
> 

-- 
Best regards,
Sergey Kaplun

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper
  2023-01-10 10:05   ` Sergey Kaplun via Tarantool-patches
@ 2023-01-10 11:12     ` Igor Munkin via Tarantool-patches
  2023-01-10 17:36       ` Maxim Kokryashkin via Tarantool-patches
  0 siblings, 1 reply; 8+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-01-10 11:12 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for your review!

On 10.01.23, Sergey Kaplun wrote:
> Hi, Igor!
> 
> Thanks for the patch!
> LGTM!

Added your tag:
| Reviewed-by: Sergey Kaplun <skaplun@tarantool.org>

> 

<snipped>

> > (*) Max, could you please check this patch on the Alpine?
> 
> Should we add the Alpine build and test in our CI in the scope of this
> commit or with separate one?

Honestly, I don't want to make LuaJIT CI similar to Tarantool one in
this context: if you commit to support the Linux-based distro zoo in our
CI, feel free to extend it by yourself. I'd rather introduce FreeBSD (or
another BSD distro) instead of another fancy Linux with little tweaks
that differ it from the popular ones.

> 

<snipped>

> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Tarantool-patches]  [PATCH] cmake: introduce CheckUnwindTables helper
  2023-01-10 11:12     ` Igor Munkin via Tarantool-patches
@ 2023-01-10 17:36       ` Maxim Kokryashkin via Tarantool-patches
  2023-01-10 19:18         ` Igor Munkin via Tarantool-patches
  0 siblings, 1 reply; 8+ messages in thread
From: Maxim Kokryashkin via Tarantool-patches @ 2023-01-10 17:36 UTC (permalink / raw)
  To: Igor Munkin; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 989 bytes --]


Hi, Igor!
Thanks for the patch!
LGTM.
 
--
Best regards,
Maxim Kokryashkin
 
  
>Вторник, 10 января 2023, 14:27 +03:00 от Igor Munkin <imun@tarantool.org>:
> 
>Sergey,
>
>Thanks for your review!
>
>On 10.01.23, Sergey Kaplun wrote:
>> Hi, Igor!
>>
>> Thanks for the patch!
>> LGTM!
>
>Added your tag:
>| Reviewed-by: Sergey Kaplun < skaplun@tarantool.org >
>
>>
>
><snipped>
>
>> > (*) Max, could you please check this patch on the Alpine?
>>
>> Should we add the Alpine build and test in our CI in the scope of this
>> commit or with separate one?
>
>Honestly, I don't want to make LuaJIT CI similar to Tarantool one in
>this context: if you commit to support the Linux-based distro zoo in our
>CI, feel free to extend it by yourself. I'd rather introduce FreeBSD (or
>another BSD distro) instead of another fancy Linux with little tweaks
>that differ it from the popular ones.
>
>>
>
><snipped>
>
>>
>> --
>> Best regards,
>> Sergey Kaplun
>
>--
>Best regards,
>IM
 

[-- Attachment #2: Type: text/html, Size: 1625 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper
  2023-01-10 17:36       ` Maxim Kokryashkin via Tarantool-patches
@ 2023-01-10 19:18         ` Igor Munkin via Tarantool-patches
  0 siblings, 0 replies; 8+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-01-10 19:18 UTC (permalink / raw)
  To: Maxim Kokryashkin; +Cc: tarantool-patches

Max,

Thanks for your review!

On 10.01.23, Maxim Kokryashkin wrote:
> 
> Hi, Igor!
> Thanks for the patch!
> LGTM.

Added your tag:
| Reviewed-by: Maxim Kokryashkin <m.kokryashkin@tarantool.org>

>  
> --
> Best regards,
> Maxim Kokryashkin
>  

<snipped>

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper
  2023-01-09 15:28 ` [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper Igor Munkin via Tarantool-patches
  2023-01-10 10:05   ` Sergey Kaplun via Tarantool-patches
@ 2023-01-12 14:55   ` Igor Munkin via Tarantool-patches
  1 sibling, 0 replies; 8+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-01-12 14:55 UTC (permalink / raw)
  To: Sergey Kaplun, Maxim Kokryashkin; +Cc: tarantool-patches

I've checked the patches into all corresponding long-term branches in
tarantool/luajit and bumped a new version in master, 2.10.

On 09.01.23, Igor Munkin wrote:
> After struggling with black voodoo magic oneliner provided by Mike Pall
> in scope of e131936133c58de4426c595db2341caf5a1665b5 ("Cleanup and
> enable external unwinding for more platforms.") to check whether the
> target toolchain always generates unwind tables, it was decided to
> implement it as a CMake function to encapsulate and comment this damn
> "grep" spell.
> 
> Signed-off-by: Igor Munkin <imun@tarantool.org>
> ---
> 
> Branch: https://github.com/tarantool/luajit/compare/imun/fix-build-for-non-bash
> CI is green(*): https://github.com/tarantool/luajit/commit/e717eaa
> 
> (*) Max, could you please check this patch on the Alpine?
> 
>  cmake/CheckUnwindTables.cmake | 114 ++++++++++++++++++++++++++++++++++
>  cmake/SetTargetFlags.cmake    |  18 ++----
>  2 files changed, 120 insertions(+), 12 deletions(-)
>  create mode 100644 cmake/CheckUnwindTables.cmake
> 

<snipped>

> -- 
> 2.34.0
> 

-- 
Best regards,
IM

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-12 15:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 14:33 [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells Maxim Kokryashkin via Tarantool-patches
2023-01-09 15:28 ` [Tarantool-patches] [PATCH] cmake: introduce CheckUnwindTables helper Igor Munkin via Tarantool-patches
2023-01-10 10:05   ` Sergey Kaplun via Tarantool-patches
2023-01-10 11:12     ` Igor Munkin via Tarantool-patches
2023-01-10 17:36       ` Maxim Kokryashkin via Tarantool-patches
2023-01-10 19:18         ` Igor Munkin via Tarantool-patches
2023-01-12 14:55   ` Igor Munkin via Tarantool-patches
2023-01-09 15:32 ` [Tarantool-patches] [PATCH luajit] cmake: fix build for non-bash shells Igor Munkin via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox