0005-Enhance-setting-write-gs-base-with-cmake-variable-30.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 7eacb2ab839e74cb07038398def5e3cc198448d4 Mon Sep 17 00:00:00 2001
  2. From: Wenyong Huang <wenyong.huang@intel.com>
  3. Date: Tue, 23 Jan 2024 12:21:20 +0800
  4. Subject: [PATCH] Enhance setting write gs base with cmake variable (#3066)
  5. In linux x86-64, developer can use cmake variable to configure whether
  6. to enable writing linear memory base address to x86 GS register or not:
  7. - `cmake -DWAMR_DISABLE_WRITE_GS_BASE=1`: disabled it
  8. - `cmake -DWAMR_DISABLE_WRITE_GS_BASE=0`: enabled it
  9. - `cmake` without `-DWAMR_DISABLE_WRITE_GS_BASE=1/0`:
  10. auto-detected by the compiler
  11. Upstream: https://github.com/bytecodealliance/wasm-micro-runtime/pull/3066
  12. Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
  13. ---
  14. .../build-scripts/config_common.cmake | 65 ++++++++++++-------
  15. 1 file changed, 41 insertions(+), 24 deletions(-)
  16. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake
  17. index e73ebc85f..a61a522f3 100644
  18. --- a/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake
  19. +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake
  20. @@ -408,32 +408,49 @@ if (WAMR_BUILD_STATIC_PGO EQUAL 1)
  21. add_definitions (-DWASM_ENABLE_STATIC_PGO=1)
  22. message (" AOT static PGO enabled")
  23. endif ()
  24. -if (WAMR_DISABLE_WRITE_GS_BASE EQUAL 1)
  25. - add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1)
  26. - message (" Write linear memory base addr to x86 GS register disabled")
  27. -elseif (WAMR_BUILD_TARGET STREQUAL "X86_64"
  28. - AND WAMR_BUILD_PLATFORM STREQUAL "linux")
  29. - set (TEST_WRGSBASE_SOURCE "${CMAKE_BINARY_DIR}/test_wrgsbase.c")
  30. - file (WRITE "${TEST_WRGSBASE_SOURCE}" "
  31. - #include <stdio.h>
  32. - #include <stdint.h>
  33. - int main() {
  34. - uint64_t value;
  35. - asm volatile (\"wrgsbase %0\" : : \"r\"(value));
  36. - printf(\"WRGSBASE instruction is available.\\n\");
  37. - return 0;
  38. - }")
  39. - # Try to compile and run the test program
  40. - try_run (TEST_WRGSBASE_RESULT
  41. - TEST_WRGSBASE_COMPILED
  42. - ${CMAKE_BINARY_DIR}/test_wrgsbase
  43. - SOURCES ${TEST_WRGSBASE_SOURCE}
  44. - CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  45. - )
  46. - #message("${TEST_WRGSBASE_COMPILED}, ${TEST_WRGSBASE_RESULT}")
  47. - if (NOT TEST_WRGSBASE_RESULT EQUAL 0)
  48. +if (WAMR_BUILD_TARGET STREQUAL "X86_64"
  49. + AND WAMR_BUILD_PLATFORM STREQUAL "linux")
  50. + if (WAMR_DISABLE_WRITE_GS_BASE EQUAL 1)
  51. + # disabled by user
  52. + set (DISABLE_WRITE_GS_BASE 1)
  53. + elseif (WAMR_DISABLE_WRITE_GS_BASE EQUAL 0)
  54. + # enabled by user
  55. + set (DISABLE_WRITE_GS_BASE 0)
  56. + elseif (CMAKE_CROSSCOMPILING)
  57. + # disabled in cross compilation environment
  58. + set (DISABLE_WRITE_GS_BASE 1)
  59. + else ()
  60. + # auto-detected by the compiler
  61. + set (TEST_WRGSBASE_SOURCE "${CMAKE_BINARY_DIR}/test_wrgsbase.c")
  62. + file (WRITE "${TEST_WRGSBASE_SOURCE}" "
  63. + #include <stdio.h>
  64. + #include <stdint.h>
  65. + int main() {
  66. + uint64_t value;
  67. + asm volatile (\"wrgsbase %0\" : : \"r\"(value));
  68. + printf(\"WRGSBASE instruction is available.\\n\");
  69. + return 0;
  70. + }")
  71. + # Try to compile and run the test program
  72. + try_run (TEST_WRGSBASE_RESULT
  73. + TEST_WRGSBASE_COMPILED
  74. + ${CMAKE_BINARY_DIR}/test_wrgsbase
  75. + SOURCES ${TEST_WRGSBASE_SOURCE}
  76. + CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  77. + )
  78. + #message("${TEST_WRGSBASE_COMPILED}, ${TEST_WRGSBASE_RESULT}")
  79. + if (TEST_WRGSBASE_RESULT EQUAL 0)
  80. + set (DISABLE_WRITE_GS_BASE 0)
  81. + else ()
  82. + set (DISABLE_WRITE_GS_BASE 1)
  83. + endif ()
  84. + endif ()
  85. + if (DISABLE_WRITE_GS_BASE EQUAL 1)
  86. add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1)
  87. message (" Write linear memory base addr to x86 GS register disabled")
  88. + else ()
  89. + add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=0)
  90. + message (" Write linear memory base addr to x86 GS register enabled")
  91. endif ()
  92. endif ()
  93. if (WAMR_CONFIGUABLE_BOUNDS_CHECKS EQUAL 1)
  94. --
  95. 2.34.1