@@ -409,24 +409,6 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
409
409
// that don't help at all.
410
410
#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
411
411
412
- struct _LIBUNWIND_HIDDEN dl_iterate_cb_data {
413
- LocalAddressSpace *addressSpace;
414
- UnwindInfoSections *sects;
415
- uintptr_t targetAddr;
416
- };
417
-
418
- int findUnwindSectionsByPhdr (struct dl_phdr_info *pinfo, size_t , void *data) {
419
- auto cbdata = static_cast <dl_iterate_cb_data *>(data);
420
- bool found_obj = false ;
421
- bool found_hdr = false ;
422
-
423
- assert (cbdata);
424
- assert (cbdata->sects );
425
-
426
- if (cbdata->targetAddr < pinfo->dlpi_addr ) {
427
- return false ;
428
- }
429
-
430
412
#if !defined(Elf_Half)
431
413
typedef ElfW (Half) Elf_Half;
432
414
#endif
@@ -437,8 +419,8 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
437
419
typedef ElfW (Addr) Elf_Addr;
438
420
#endif
439
421
422
+ static Elf_Addr calculateImageBase (struct dl_phdr_info *pinfo) {
440
423
Elf_Addr image_base = pinfo->dlpi_addr ;
441
-
442
424
#if defined(__ANDROID__) && __ANDROID_API__ < 18
443
425
if (image_base == 0 ) {
444
426
// Normally, an image base of 0 indicates a non-PIE executable. On
@@ -456,11 +438,32 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
456
438
}
457
439
}
458
440
#endif
441
+ return image_base;
442
+ }
459
443
460
- #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
444
+ struct _LIBUNWIND_HIDDEN dl_iterate_cb_data {
445
+ LocalAddressSpace *addressSpace;
446
+ UnwindInfoSections *sects;
447
+ uintptr_t targetAddr;
448
+ };
449
+
450
+ #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
461
451
#if !defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
462
- #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
452
+ #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
463
453
#endif
454
+
455
+ int findUnwindSectionsByPhdr (struct dl_phdr_info *pinfo, size_t , void *data) {
456
+ auto *cbdata = static_cast <dl_iterate_cb_data *>(data);
457
+ bool found_obj = false ;
458
+ bool found_hdr = false ;
459
+
460
+ assert (cbdata);
461
+ assert (cbdata->sects );
462
+
463
+ if (cbdata->targetAddr < pinfo->dlpi_addr )
464
+ return 0 ;
465
+
466
+ Elf_Addr image_base = calculateImageBase (pinfo);
464
467
size_t object_length;
465
468
466
469
for (Elf_Half i = 0 ; i < pinfo->dlpi_phnum ; i++) {
@@ -492,7 +495,25 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
492
495
} else {
493
496
return false ;
494
497
}
495
- #else // defined(_LIBUNWIND_ARM_EHABI)
498
+ }
499
+
500
+ #else // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND)
501
+ // Given all the #ifdef's above, the code here is for
502
+ // defined(LIBUNWIND_ARM_EHABI)
503
+
504
+ int findUnwindSectionsByPhdr (struct dl_phdr_info *pinfo, size_t , void *data) {
505
+ auto *cbdata = static_cast <dl_iterate_cb_data *>(data);
506
+ bool found_obj = false ;
507
+ bool found_hdr = false ;
508
+
509
+ assert (cbdata);
510
+ assert (cbdata->sects );
511
+
512
+ if (cbdata->targetAddr < pinfo->dlpi_addr )
513
+ return 0 ;
514
+
515
+ Elf_Addr image_base = calculateImageBase (pinfo);
516
+
496
517
for (Elf_Half i = 0 ; i < pinfo->dlpi_phnum ; i++) {
497
518
const Elf_Phdr *phdr = &pinfo->dlpi_phdr [i];
498
519
if (phdr->p_type == PT_LOAD) {
@@ -508,8 +529,8 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
508
529
}
509
530
}
510
531
return found_obj && found_hdr;
511
- #endif
512
532
}
533
+ #endif // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND)
513
534
#endif // defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
514
535
515
536
0 commit comments