[compiler-rt] [compiler-rt] Fix interceptors with Solaris as (PR #72973)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 02:17:28 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Marco Elver (melver)

<details>
<summary>Changes</summary>

Jakub Jelínek reports:

  As mentioned in https://gcc.gnu.org/PR112563, the new DECLARE_WRAPPER macro
  added in 37445e9 and ammended in 85d3873 doesn't work on SPARC/Solaris with
  Solaris as.

  While clang and GNU as when used from GCC seems to be forgiving on most
  architectures and allow both %function and @<!-- -->function (with the latter not being
  allowed on ARM/AArch64 I believe because @ is assembler comment start there),
  Solaris as doesn't allow the %function form.

Fix it by using %function only for ARM.

Co-developed-by: Jakub Jelínek <jakub@<!-- -->redhat.com>
Reported-by: Jakub Jelínek <jakub@<!-- -->redhat.com>
Closes: https://github.com/llvm/llvm-project/issues/72970

---
Full diff: https://github.com/llvm/llvm-project/pull/72973.diff


2 Files Affected:

- (modified) compiler-rt/lib/interception/interception.h (+7-1) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_asm.h (+5-1) 


``````````diff
diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 069f73d276f3c40..9d8b60b2eef58c2 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -185,6 +185,11 @@ const interpose_substitution substitution_##func_name[]             \
 #  else
 #   define __ASM_WEAK_WRAPPER(func) ".weak " #func "\n"
 #  endif  // SANITIZER_FREEBSD || SANITIZER_NETBSD
+#  if defined(__arm__) || defined(__aarch64__)
+#   define ASM_TYPE_FUNCTION_STR "%function"
+#  else
+#   define ASM_TYPE_FUNCTION_STR "@function"
+#  endif
 // Keep trampoline implementation in sync with sanitizer_common/sanitizer_asm.h
 #  define DECLARE_WRAPPER(ret_type, func, ...)                                 \
      extern "C" ret_type func(__VA_ARGS__);                                    \
@@ -196,7 +201,8 @@ const interpose_substitution substitution_##func_name[]             \
        __ASM_WEAK_WRAPPER(func)                                                \
        ".set " #func ", " SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n"           \
        ".globl " SANITIZER_STRINGIFY(TRAMPOLINE(func)) "\n"                    \
-       ".type  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", %function\n"         \
+       ".type  " SANITIZER_STRINGIFY(TRAMPOLINE(func)) ", "                    \
+         ASM_TYPE_FUNCTION_STR "\n"                                            \
        SANITIZER_STRINGIFY(TRAMPOLINE(func)) ":\n"                             \
        SANITIZER_STRINGIFY(CFI_STARTPROC) "\n"                                 \
        SANITIZER_STRINGIFY(ASM_TAIL_CALL) " __interceptor_"                    \
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_asm.h b/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
index 3c9bbdc9678b09a..bbb18cfbdf15feb 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_asm.h
@@ -62,7 +62,11 @@
 
 #if !defined(__APPLE__)
 # define ASM_HIDDEN(symbol) .hidden symbol
-# define ASM_TYPE_FUNCTION(symbol) .type symbol, %function
+# if defined(__arm__) || defined(__aarch64__)
+#  define ASM_TYPE_FUNCTION(symbol) .type symbol, %function
+# else
+#  define ASM_TYPE_FUNCTION(symbol) .type symbol, @function
+# endif
 # define ASM_SIZE(symbol) .size symbol, .-symbol
 # define ASM_SYMBOL(symbol) symbol
 # define ASM_SYMBOL_INTERCEPTOR(symbol) symbol

``````````

</details>


https://github.com/llvm/llvm-project/pull/72973


More information about the llvm-commits mailing list