Skip to content

Fixing UB on Windows for trampoline allocations #85639

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 2 commits into from
Mar 19, 2024
Merged

Conversation

zacklj89
Copy link
Contributor

@zacklj89 zacklj89 commented Mar 18, 2024

Fixing the type of the constant to avoid undefined behavior with respect to overflow.

@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2024

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

Author: Zack Johnson (zacklj89)

Changes

This is actually used on Windows, so removing UNUSED as well as fixing the type of the constant to avoid undefined behavior with respect to overflow.


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

1 Files Affected:

  • (modified) compiler-rt/lib/interception/interception_win.cpp (+1-1)
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 1829358705fe82..3602b24401a3a1 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -339,7 +339,7 @@ struct TrampolineMemoryRegion {
   uptr max_size;
 };
 
-UNUSED static const uptr kTrampolineScanLimitRange = 1 << 31;  // 2 gig
+static const uptr kTrampolineScanLimitRange = 1ull << 31;  // 2 gig
 static const int kMaxTrampolineRegion = 1024;
 static TrampolineMemoryRegion TrampolineRegions[kMaxTrampolineRegion];
 

@mstorsjo
Copy link
Member

This is actually used on Windows, so removing UNUSED

No, it's not used in i386 mode. It's used in some modes, but not all - therefore it is marked as unused to silence warnings in those build configuration. See 979c38c which introduced the attribute here.

@zacklj89
Copy link
Contributor Author

This is actually used on Windows, so removing UNUSED

No, it's not used in i386 mode. It's used in some modes, but not all - therefore it is marked as unused to silence warnings in those build configuration. See 979c38c which introduced the attribute here.

Then shouldn't it be guarded by #if SANITIZER_WINDOWS64 rather than UNUSED? When I was debugging I was confused by the presence of UNUSED.

@mstorsjo
Copy link
Member

This is actually used on Windows, so removing UNUSED

No, it's not used in i386 mode. It's used in some modes, but not all - therefore it is marked as unused to silence warnings in those build configuration. See 979c38c which introduced the attribute here.

Then shouldn't it be guarded by #if SANITIZER_WINDOWS64 rather than UNUSED? When I was debugging I was confused by the presence of UNUSED.

That's certainly an option too. IIRC I proposed that originally, but avoiding ifdefs and marking it unused was suggested here: https://reviews.llvm.org/D91852#inline-861716

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

(At this point, it'd be good to update the commit description, which ends up as the commit message, to not refer to removing UNUSED any longer. Or whoever does the merge can do that fixup of the commit message before finishing the merge.)

@mstorsjo mstorsjo merged commit 4b10d1f into main Mar 19, 2024
@mstorsjo mstorsjo deleted the users/zacklj89/2gig-ub branch March 19, 2024 13:16
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…5639)

Fixing the type of the constant to avoid undefined behavior with respect
to overflow.
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.

5 participants