Skip to content

[TSan] fix the module map of main executable on darwin platforms #107227

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
Sep 26, 2024

Conversation

pudge62
Copy link
Contributor

@pudge62 pudge62 commented Sep 4, 2024

In the executable image on Darwin platforms, there is a __PAGEZERO segment with a size of 0. When calculating the module map, this segment must be skipped to avoid errors. The previous implementation inaccurately calculated the executable image's range, starting the address at 0 + slide.

@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2024

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

Author: None (pudge62)

Changes

In the executable image on Darwin platforms, there is a __PAGEZERO segment with a size of 0. When calculating the module map, this segment must be skipped to avoid errors. The previous implementation inaccurately calculated the executable image's range, starting the address at 0 + slide.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp (+2-1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
index b44e016a0e5bc6..d13bc8e6ea261c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
@@ -433,7 +433,8 @@ void MemoryMappingLayout::DumpListOfModules(
   MemoryMappedSegmentData data;
   segment.data_ = &data;
   while (Next(&segment)) {
-    if (segment.filename[0] == '\0') continue;
+    // skip the __PAGEZERO segment, its vmsize is 0
+    if (segment.filename[0] == '\0' || (segment.start == segment.end)) continue;
     LoadedModule *cur_module = nullptr;
     if (!modules->empty() &&
         0 == internal_strcmp(segment.filename, modules->back().full_name())) {

@pudge62 pudge62 changed the title fix the module map of main executable on darwin platforms [TSan] fix the module map of main executable on darwin platforms Sep 4, 2024
Copy link

github-actions bot commented Sep 4, 2024

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

@pudge62
Copy link
Contributor Author

pudge62 commented Sep 4, 2024

cc @kcc @dvyukov @vitalybuka for review

Copy link

github-actions bot commented Sep 4, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

skip the __PAGEZERO segment when calculate image range
@pudge62
Copy link
Contributor Author

pudge62 commented Sep 15, 2024

Ping

@vitalybuka vitalybuka merged commit 781cb10 into llvm:main Sep 26, 2024
7 checks passed
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Sep 27, 2024
…m#107227)

In the executable image on Darwin platforms, there is a `__PAGEZERO`
segment with a size of 0. When calculating the module map, this segment
must be skipped to avoid errors. The previous implementation
inaccurately calculated the executable image's range, starting the
address at `0 + slide`.
@pudge62 pudge62 deleted the fix_module_map branch October 28, 2024 04:37
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