[compiler-rt] fix the module map of main executable on darwin platforms (PR #107227)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 05:12:49 PDT 2024


https://github.com/pudge62 created https://github.com/llvm/llvm-project/pull/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`.

>From 0152595d59f91bcb84a8bb7b2b885af0fe44cbf7 Mon Sep 17 00:00:00 2001
From: pudge62 <70063806+pudge62 at users.noreply.github.com>
Date: Wed, 4 Sep 2024 20:05:57 +0800
Subject: [PATCH] fix the module map of main executable on darwin platforms

skip the __PAGEZERO segment when calculate image range
---
 compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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())) {



More information about the llvm-commits mailing list