@@ -205,7 +205,36 @@ class ReflectionContext
205
205
return false ;
206
206
207
207
auto Slide = ImageStart.getAddressData () - Command->vmaddr ;
208
+ std::string Prefix = " __swift5" ;
209
+ uint64_t RangeStart = UINT64_MAX;
210
+ uint64_t RangeEnd = UINT64_MAX;
208
211
auto SectionsBuf = reinterpret_cast <const char *>(Sections.get ());
212
+ for (unsigned I = 0 ; I < NumSect; ++I) {
213
+ auto S = reinterpret_cast <typename T::Section *>(
214
+ SectionsBuf + (I * sizeof (typename T::Section)));
215
+ if (strncmp (S->sectname , Prefix.c_str (), strlen (Prefix.c_str ())) != 0 )
216
+ continue ;
217
+ if (RangeStart == UINT64_MAX && RangeEnd == UINT64_MAX) {
218
+ RangeStart = S->addr + Slide;
219
+ RangeEnd = S->addr + S->size + Slide;
220
+ continue ;
221
+ }
222
+ RangeStart = std::min (RangeStart, (uint64_t )S->addr + Slide);
223
+ RangeEnd = std::max (RangeEnd, (uint64_t )(S->addr + S->size + Slide));
224
+ // Keep the range rounded to 8 byte alignment on both ends so we don't
225
+ // introduce misaligned pointers mapping between local and remote
226
+ // address space.
227
+ RangeStart = RangeStart & ~7 ;
228
+ RangeEnd = RangeEnd + 7 & ~7 ;
229
+ }
230
+
231
+ if (RangeStart == UINT64_MAX && RangeEnd == UINT64_MAX)
232
+ return false ;
233
+
234
+ auto SectBuf = this ->getReader ().readBytes (RemoteAddress (RangeStart),
235
+ RangeEnd - RangeStart);
236
+ if (!SectBuf)
237
+ return false ;
209
238
210
239
auto findMachOSectionByName = [&](llvm::StringRef Name)
211
240
-> std::pair<RemoteRef<void >, uint64_t > {
@@ -215,13 +244,11 @@ class ReflectionContext
215
244
if (strncmp (S->sectname , Name.data (), strlen (Name.data ())) != 0 )
216
245
continue ;
217
246
auto RemoteSecStart = S->addr + Slide;
218
- auto LocalSectBuf =
219
- this ->getReader ().readBytes (RemoteAddress (RemoteSecStart), S->size );
220
- if (!LocalSectBuf)
221
- return {nullptr , 0 };
222
-
223
- auto StartRef = RemoteRef<void >(RemoteSecStart, LocalSectBuf.get ());
224
- savedBuffers.push_back (std::move (LocalSectBuf));
247
+ auto SectBufData = reinterpret_cast <const char *>(SectBuf.get ());
248
+ auto LocalSectStart =
249
+ reinterpret_cast <const char *>(SectBufData + RemoteSecStart - RangeStart);
250
+
251
+ auto StartRef = RemoteRef<void >(RemoteSecStart, LocalSectStart);
225
252
return {StartRef, S->size };
226
253
}
227
254
return {nullptr , 0 };
@@ -280,6 +307,7 @@ class ReflectionContext
280
307
}
281
308
282
309
savedBuffers.push_back (std::move (Buf));
310
+ savedBuffers.push_back (std::move (SectBuf));
283
311
savedBuffers.push_back (std::move (Sections));
284
312
return true ;
285
313
}
0 commit comments