Skip to content

[libc] [riscv] support build with scudo on riscv64 #74951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

SchrodingerZhu
Copy link
Contributor

This patch fixes cmake configuration when building with LLVM_LIBC_INCLUDE_SCUDO. In libc, LIBC_TARGET_ARCHITECTURE is renamed from riscv64 to riscv. However, compiler-rt, hence scudo, distinguishes riscv32 and riscv64 in the support list. As a result, we need to translate the architecture name accordingly.

This patch fixes cmake configuration when building with LLVM_LIBC_INCLUDE_SCUDO.
In libc, LIBC_TARGET_ARCHITECTURE is renamed from `riscv64` to `riscv`. However,
`compiler-rt`, hence `scudo`, distinguishes `riscv32` and `riscv64` in the
support list. As a result, we need to translate the architecture name accordingly.
@SchrodingerZhu
Copy link
Contributor Author

All tests passed on my riscv64 machine after this patch.

@SchrodingerZhu SchrodingerZhu marked this pull request as ready for review December 9, 2023 23:22
@llvmbot llvmbot added the libc label Dec 9, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2023

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

This patch fixes cmake configuration when building with LLVM_LIBC_INCLUDE_SCUDO. In libc, LIBC_TARGET_ARCHITECTURE is renamed from riscv64 to riscv. However, compiler-rt, hence scudo, distinguishes riscv32 and riscv64 in the support list. As a result, we need to translate the architecture name accordingly.


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

1 Files Affected:

  • (modified) libc/src/stdlib/CMakeLists.txt (+16-7)
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index c54d32eb7afdb1..a4d51fb9a11eef 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -268,18 +268,27 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
   set(SCUDO_DEPS "")
 
   include(${LIBC_SOURCE_DIR}/../compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake)
-  if(NOT (LIBC_TARGET_ARCHITECTURE IN_LIST ALL_SCUDO_STANDALONE_SUPPORTED_ARCH))
-    message(FATAL_ERROR "Architecture ${LIBC_TARGET_ARCHITECTURE} is not supported by SCUDO. 
+  
+  # scudo distinguishes riscv32 and riscv64, so we need to translate the architecture
+  set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO ${LIBC_TARGET_ARCHITECTURE})
+  if(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
+    set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO riscv64)
+  elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV32)
+    set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO riscv32)
+  endif()
+
+  if(NOT (LIBC_TARGET_ARCHITECTURE_FOR_SCUDO IN_LIST ALL_SCUDO_STANDALONE_SUPPORTED_ARCH))
+    message(FATAL_ERROR "Architecture ${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} is not supported by SCUDO. 
       Either disable LLVM_LIBC_INCLUDE_SCUDO or change your target architecture.")
   endif()
 
-  list(APPEND SCUDO_DEPS RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE}
-      RTScudoStandaloneCWrappers.${LIBC_TARGET_ARCHITECTURE})
+  list(APPEND SCUDO_DEPS RTScudoStandalone.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
+      RTScudoStandaloneCWrappers.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO})
 
   list(APPEND SCUDO_DEPS
-    RTGwpAsan.${LIBC_TARGET_ARCHITECTURE}
-    RTGwpAsanBacktraceLibc.${LIBC_TARGET_ARCHITECTURE}
-    RTGwpAsanSegvHandler.${LIBC_TARGET_ARCHITECTURE}
+    RTGwpAsan.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
+    RTGwpAsanBacktraceLibc.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
+    RTGwpAsanSegvHandler.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
     )
   
   add_entrypoint_external(

@SchrodingerZhu
Copy link
Contributor Author

@michaelrj-google PTAL

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@inclyc inclyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge according to previous approval

@inclyc inclyc merged commit 2c0abdf into llvm:main Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants