Skip to content

[NFC][hwasan] Remove code duplication in ShadowMapping::init #109618

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

Conversation

vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Sep 23, 2024

The goal to is to reorder this function to make
initialization in following order:

  1. Defaults
  2. Target specific overrides
  3. Explicit copt<> overrides

@llvmbot
Copy link
Member

llvmbot commented Sep 23, 2024

@llvm/pr-subscribers-llvm-transforms

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

Author: Vitaly Buka (vitalybuka)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+6-5)
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 2efb97c8759bc9..b82bb353793e7f 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1925,12 +1925,16 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
 
 void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
                                              bool InstrumentWithCalls) {
+  // Start with defaults.
   Scale = kDefaultShadowScale;
+  Kind = OffsetKind::kTls;
+  WithFrameRecord = true;
+
+  // Tune for the target.
   if (TargetTriple.isOSFuchsia()) {
     // Fuchsia is always PIE, which means that the beginning of the address
     // space is always available.
     SetFixed(0);
-    WithFrameRecord = true;
   } else if (ClMappingOffset.getNumOccurrences() > 0) {
     SetFixed(ClMappingOffset);
     WithFrameRecord = false;
@@ -1940,10 +1944,7 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
   } else if (ClWithIfunc) {
     Kind = OffsetKind::kIfunc;
     WithFrameRecord = false;
-  } else if (ClWithTls) {
-    Kind = OffsetKind::kTls;
-    WithFrameRecord = true;
-  } else {
+  } else if (!ClWithTls) {
     Kind = OffsetKind::kGlobal;
     WithFrameRecord = false;
   }

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.nfchwasan-remove-code-duplication-in-shadowmappinginit to main September 23, 2024 22:55
@vitalybuka vitalybuka requested a review from fmayer September 23, 2024 22:58
@vitalybuka vitalybuka merged commit 083f0fa into main Sep 23, 2024
8 of 10 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/nfchwasan-remove-code-duplication-in-shadowmappinginit branch September 23, 2024 23:55
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