aboutsummaryrefslogtreecommitdiff
path: root/libunwind/src
diff options
context:
space:
mode:
authorJessica Clarke <jrtc27@jrtc27.com>2022-01-18 23:50:05 +0000
committerJessica Clarke <jrtc27@jrtc27.com>2022-01-19 00:05:30 +0000
commitb6a93967d9c11e79802b5e75cec1584d6c8aa472 (patch)
tree8fb8b8f75404b4ca326ed1293c7eaeb05f340a8d /libunwind/src
parente3dd47f987e71568e3dab0a779c0520388eb6cd9 (diff)
downloadllvm-b6a93967d9c11e79802b5e75cec1584d6c8aa472.zip
llvm-b6a93967d9c11e79802b5e75cec1584d6c8aa472.tar.gz
llvm-b6a93967d9c11e79802b5e75cec1584d6c8aa472.tar.bz2
[NFC][libunwind] Fix uintptr_t vs size_t confusion for lengths
These two are not conceptually the same; the former is a pointer shoved in an integer, the latter is an offset or length. On the architectures supported by libunwind, these two have the same underlying type, namely unsigned int on ILP32, unsigned long on LP64 and unsigned long long on LLP64. However, on CHERI, and thus Arm's Morello, they are not the same, as pointers are hardware capabilities that carry additional metadata including bounds and permissions, which is preserved in uintptr_t but not in size_t. Thus, fix all length variables to be of type size_t not uintptr_t, as we have done downstream for a while in CHERI LLVM but did not get round to upstreaming. Note that dyld_unwind_sections is currently defined in Apple's headers as genuinely using uintptr_t to represent lengths. This is a bad API and should be fixed, which would be totally API and ABI compatible due to size_t and uintptr_t being the same type on all supported Apple systems, but our definition is left matching theirs until such a time as they fix their bogus types. This is intended to be an NFC change on all architectures supported by LLVM upstream, only being a functional change for CHERI downstream in CHERI LLVM.
Diffstat (limited to 'libunwind/src')
-rw-r--r--libunwind/src/AddressSpace.hpp24
-rw-r--r--libunwind/src/DwarfParser.hpp6
2 files changed, 15 insertions, 15 deletions
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index cfceac2..0c4dfeb 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -121,23 +121,23 @@ struct UnwindInfoSections {
uintptr_t dso_base;
#endif
#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
- uintptr_t text_segment_length;
+ size_t text_segment_length;
#endif
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
uintptr_t dwarf_section;
- uintptr_t dwarf_section_length;
+ size_t dwarf_section_length;
#endif
#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
uintptr_t dwarf_index_section;
- uintptr_t dwarf_index_section_length;
+ size_t dwarf_index_section_length;
#endif
#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
uintptr_t compact_unwind_section;
- uintptr_t compact_unwind_section_length;
+ size_t compact_unwind_section_length;
#endif
#if defined(_LIBUNWIND_ARM_EHABI)
uintptr_t arm_section;
- uintptr_t arm_section_length;
+ size_t arm_section_length;
#endif
};
@@ -430,7 +430,7 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base,
// .eh_frame_hdr records the start of .eh_frame, but not its size.
// Rely on a zero terminator to find the end of the section.
cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
- cbdata->sects->dwarf_section_length = UINTPTR_MAX;
+ cbdata->sects->dwarf_section_length = SIZE_MAX;
return true;
}
}
@@ -506,22 +506,22 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
info.dso_base = (uintptr_t)dyldInfo.mh;
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section;
- info.dwarf_section_length = dyldInfo.dwarf_section_length;
+ info.dwarf_section_length = (size_t)dyldInfo.dwarf_section_length;
#endif
info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section;
- info.compact_unwind_section_length = dyldInfo.compact_unwind_section_length;
+ info.compact_unwind_section_length = (size_t)dyldInfo.compact_unwind_section_length;
return true;
}
#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
info.dso_base = 0;
// Bare metal is statically linked, so no need to ask the dynamic loader
- info.dwarf_section_length = (uintptr_t)(&__eh_frame_end - &__eh_frame_start);
+ info.dwarf_section_length = (size_t)(&__eh_frame_end - &__eh_frame_start);
info.dwarf_section = (uintptr_t)(&__eh_frame_start);
_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",
(void *)info.dwarf_section, (void *)info.dwarf_section_length);
#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
info.dwarf_index_section = (uintptr_t)(&__eh_frame_hdr_start);
- info.dwarf_index_section_length = (uintptr_t)(&__eh_frame_hdr_end - &__eh_frame_hdr_start);
+ info.dwarf_index_section_length = (size_t)(&__eh_frame_hdr_end - &__eh_frame_hdr_start);
_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: index section %p length %p",
(void *)info.dwarf_index_section, (void *)info.dwarf_index_section_length);
#endif
@@ -530,7 +530,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
// Bare metal is statically linked, so no need to ask the dynamic loader
info.arm_section = (uintptr_t)(&__exidx_start);
- info.arm_section_length = (uintptr_t)(&__exidx_end - &__exidx_start);
+ info.arm_section_length = (size_t)(&__exidx_end - &__exidx_start);
_LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",
(void *)info.arm_section, (void *)info.arm_section_length);
if (info.arm_section && info.arm_section_length)
@@ -584,7 +584,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
int length = 0;
info.arm_section =
(uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length);
- info.arm_section_length = (uintptr_t)length * sizeof(EHABIIndexEntry);
+ info.arm_section_length = (size_t)length * sizeof(EHABIIndexEntry);
if (info.arm_section && info.arm_section_length)
return true;
#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 2153a71..8630178 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -151,7 +151,7 @@ public:
};
static bool findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
- uintptr_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo,
+ size_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo,
CIE_Info *cieInfo);
static const char *decodeFDE(A &addressSpace, pint_t fdeStart,
FDE_Info *fdeInfo, CIE_Info *cieInfo,
@@ -230,11 +230,11 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,
/// Scan an eh_frame section to find an FDE for a pc
template <typename A>
bool CFI_Parser<A>::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
- uintptr_t sectionLength, pint_t fdeHint,
+ size_t sectionLength, pint_t fdeHint,
FDE_Info *fdeInfo, CIE_Info *cieInfo) {
//fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc);
pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart;
- const pint_t ehSectionEnd = (sectionLength == UINTPTR_MAX)
+ const pint_t ehSectionEnd = (sectionLength == SIZE_MAX)
? static_cast<pint_t>(-1)
: (ehSectionStart + sectionLength);
while (p < ehSectionEnd) {