Skip to content

Conversation

@anoopkg6
Copy link
Contributor

Fix getShadowAddress computation by adding ShadowBase if it is not zero.

@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

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

@llvm/pr-subscribers-llvm-transforms

Author: None (anoopkg6)

Changes

Fix getShadowAddress computation by adding ShadowBase if it is not zero.


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

2 Files Affected:

  • (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+1-1)
  • (modified) llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (+6-2)
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index ca45d7bd2af7f..05aa7e153f362 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -36,7 +36,7 @@ set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
     ${LOONGARCH64})
 set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
-set(ALL_RTSAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
+set(ALL_RTSAN_SUPPORTED_ARCH ${X86_64} ${ARM64}  ${S390X})
 
 if(ANDROID)
   set(OS_NAME "Android")
diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 5ba2167859490..cc53ec2c0f2f3 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1957,8 +1957,12 @@ Value *DataFlowSanitizer::getShadowAddress(Value *Addr,
 Value *DataFlowSanitizer::getShadowAddress(Value *Addr,
                                            BasicBlock::iterator Pos) {
   IRBuilder<> IRB(Pos->getParent(), Pos);
-  Value *ShadowOffset = getShadowOffset(Addr, IRB);
-  return getShadowAddress(Addr, Pos, ShadowOffset);
+  Value *ShadowAddr = getShadowOffset(Addr, IRB);
+  uint64_t ShadowBase = MapParams->ShadowBase;
+  if (ShadowBase != 0)
+    ShadowAddr =
+        IRB.CreateAdd(ShadowAddr, ConstantInt::get(IntptrTy, ShadowBase));
+  return getShadowAddress(Addr, Pos, ShadowAddr);
 }
 
 Value *DFSanFunction::combineShadowsThenConvert(Type *T, Value *V1, Value *V2,

set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
set(ALL_RTSAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
set(ALL_RTSAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${S390X})
Copy link
Contributor

Choose a reason for hiding this comment

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

This change would belong better in the S390X-specific pull request.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Also, it's for RTSan, not DFSan?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, some unrelated changes got pull into this pr. Updated push should have only one file changes.

@thurstond thurstond requested a review from browneee October 10, 2025 15:55
@thurstond
Copy link
Contributor

Please add "[dfsan]" to the title

@anoopkg6 anoopkg6 changed the title Fix getShadowAddress computation [dfsan] Fix getShadowAddress computation Oct 28, 2025
@anoopkg6
Copy link
Contributor Author

[dfsan] has been added to the tile. This pr has changes related to getShadowAddress in DFSan only. RTSAN change has been removed.
All test using memory-transfer instructions involving memcpy and memmove fail on SystemZ. e.g. origin_memcpy.c, origin_memmove.c, etc in existing dfsan tests.

Copy link
Contributor

@thurstond thurstond left a comment

Choose a reason for hiding this comment

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

Thanks! Is it ready to merge?

@anoopkg6
Copy link
Contributor Author

anoopkg6 commented Oct 29, 2025 via email

@thurstond thurstond merged commit 71be1c1 into llvm:main Oct 29, 2025
10 checks passed
@anoopkg6
Copy link
Contributor Author

anoopkg6 commented Oct 29, 2025 via email

aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
Fix getShadowAddress computation by adding ShadowBase if it is not zero.

Co-authored-by: anoopkg6 <[email protected]>
DEBADRIBASAK pushed a commit to DEBADRIBASAK/llvm-project that referenced this pull request Nov 3, 2025
Fix getShadowAddress computation by adding ShadowBase if it is not zero.

Co-authored-by: anoopkg6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants