Skip to content

Commit 3f242f2

Browse files
SeanMcGcopybara-github
authored andcommitted
PR abseil#1874: Simplify detection of the powerpc64 ELFv1 ABI
Imported from GitHub PR abseil#1874 Compilers for 32-bit powerpc may not define `_CALL_ELF`. Squelches an undefined warning from GCC. Fix the pre-processor check, and in turn fix the `symbolize_test` on 32-bit powerpc. Merge cffd4a4 into daa0bfb Merging this change closes abseil#1874 COPYBARA_INTEGRATE_REVIEW=abseil#1874 from SeanMcG:ppc64_elfv2_detect_fix cffd4a4 PiperOrigin-RevId: 748379689 Change-Id: Id0c9e28a6c45482ff9262c2e5b16d2810ada1c4b
1 parent 6e7a7bf commit 3f242f2

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

absl/debugging/symbolize_elf.inc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,20 @@ namespace {
125125
// Some platforms use a special .opd section to store function pointers.
126126
const char kOpdSectionName[] = ".opd";
127127

128-
#if (defined(__powerpc__) && !(_CALL_ELF > 1)) || defined(__ia64)
128+
#if defined(__powerpc64__) && defined(_CALL_ELF)
129+
#if _CALL_ELF <= 1
130+
#define ABSL_INTERNAL_HAVE_PPC64_ELFV1_ABI 1
131+
#endif
132+
#endif
133+
#if defined(ABSL_INTERNAL_HAVE_PPC64_ELFV1_ABI) || defined(__ia64)
129134
// Use opd section for function descriptors on these platforms, the function
130135
// address is the first word of the descriptor.
131-
enum { kPlatformUsesOPDSections = 1 };
132-
#else // not PPC or IA64
133-
enum { kPlatformUsesOPDSections = 0 };
136+
//
137+
// https://maskray.me/blog/2023-02-26-linker-notes-on-power-isa notes that
138+
// opd sections are used on 64-bit PowerPC with the ELFv1 ABI.
139+
inline constexpr bool kPlatformUsesOPDSections = true;
140+
#else
141+
inline constexpr bool kPlatformUsesOPDSections = false;
134142
#endif
135143

136144
// This works for PowerPC & IA64 only. A function descriptor consist of two
@@ -1451,11 +1459,11 @@ static bool MaybeInitializeObjFile(ObjFile *obj) {
14511459
}
14521460
phoff += phentsize;
14531461

1454-
#if defined(__powerpc__) && !(_CALL_ELF > 1)
1455-
// On the PowerPC ELF v1 ABI, function pointers actually point to function
1456-
// descriptors. These descriptors are stored in an .opd section, which is
1457-
// mapped read-only. We thus need to look at all readable segments, not
1458-
// just the executable ones.
1462+
#ifdef ABSL_INTERNAL_HAVE_PPC64_ELFV1_ABI
1463+
// On the PowerPC 64-bit ELFv1 ABI, function pointers actually point to
1464+
// function descriptors. These descriptors are stored in an .opd section,
1465+
// which is mapped read-only. We thus need to look at all readable
1466+
// segments, not just the executable ones.
14591467
constexpr int interesting = PF_R;
14601468
#else
14611469
constexpr int interesting = PF_X | PF_R;
@@ -1762,3 +1770,5 @@ extern "C" bool AbslInternalGetFileMappingHint(const void **start,
17621770
return absl::debugging_internal::GetFileMappingHint(start, end, offset,
17631771
filename);
17641772
}
1773+
1774+
#undef ABSL_INTERNAL_HAVE_PPC64_ELFV1_ABI

0 commit comments

Comments
 (0)