[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 6 00:12:10 PST 2024
https://github.com/SihangZhu created https://github.com/llvm/llvm-project/pull/77185
Fix this issue [#76957](https://github.com/llvm/llvm-project/issues/76957)
Libgcc provides __register_frame to register a dynamic .eh_frame section, while __unw_add_dynamic_eh_frame_section can be used to do the same in libunwind. However, the address after dynamic .eh_frame are padding with 0 value, it will be identified as
legal CIE. And __unw_add_dynamic_eh_frame_section will continue to parse subsequent addresses until illegal memory or other sections are accessed.
This patch adds length formal parameter for dynamic registration.
>From 877f03067280873953d2f38f518301c02b4877e4 Mon Sep 17 00:00:00 2001
From: SihangZhu <zhusihang at huawei.com>
Date: Sat, 6 Jan 2024 15:43:41 +0800
Subject: [PATCH] [libunwind] Add length info for .eh_frame registration
---
libunwind/src/libunwind.cpp | 5 +++--
libunwind/src/libunwind_ext.h | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cd610377b63de8..7d78d167b83434 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -318,13 +318,14 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);
}
-void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, size_t length) {
// The eh_frame section start serves as the mh_group
unw_word_t mh_group = eh_frame_start;
CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
auto p = (LocalAddressSpace::pint_t)eh_frame_start;
- while (true) {
+ auto end = p + length;
+ while (p < end) {
if (CFI_Parser<LocalAddressSpace>::decodeFDE(
LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
true) == NULL) {
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 28db43a4f6eef2..1bfb595c46130f 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -55,7 +55,7 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
extern void __unw_add_dynamic_fde(unw_word_t fde);
extern void __unw_remove_dynamic_fde(unw_word_t fde);
-extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, size_t length);
extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
#ifdef __APPLE__
More information about the cfe-commits
mailing list