[libunwind] r285636 - fix _dyld_find_unwind_sections() for pre-10.7. Patch by Jeremy Sequoia

Nick Kledzik via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 14:04:18 PDT 2016


Author: kledzik
Date: Mon Oct 31 16:04:17 2016
New Revision: 285636

URL: http://llvm.org/viewvc/llvm-project?rev=285636&view=rev
Log:
fix _dyld_find_unwind_sections() for pre-10.7.  Patch by Jeremy Sequoia

Modified:
    libunwind/trunk/src/AddressSpace.hpp

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=285636&r1=285635&r2=285636&view=diff
==============================================================================
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Mon Oct 31 16:04:17 2016
@@ -321,28 +321,34 @@ LocalAddressSpace::getEncodedP(pint_t &a
     // In 10.7.0 or later, libSystem.dylib implements this function.
     extern "C" bool _dyld_find_unwind_sections(void *, dyld_unwind_sections *);
   #else
-    // In 10.6.x and earlier, we need to implement this functionality.
+    // In 10.6.x and earlier, we need to implement this functionality. Note
+    // that this requires a newer version of libmacho (from cctools) than is
+    // present in libSystem on 10.6.x (for getsectiondata).
     static inline bool _dyld_find_unwind_sections(void* addr, 
                                                     dyld_unwind_sections* info) {
       // Find mach-o image containing address.
       Dl_info dlinfo;
       if (!dladdr(addr, &dlinfo))
         return false;
-      const mach_header *mh = (const mach_header *)dlinfo.dli_saddr;
-      
-      // Find DWARF unwind section in that image.
-      unsigned long size;
-      const uint8_t *p = getsectiondata(mh, "__TEXT", "__eh_frame", &size);
-      if (!p)
-        return false;
-      
-      // Fill in return struct.
-      info->mh = mh;
-      info->dwarf_section = p;
-      info->dwarf_section_length = size;
-      info->compact_unwind_section = 0;
-      info->compact_unwind_section_length = 0;
-     
+#if __LP64__
+      const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase;
+#else
+      const struct mach_header *mh = (const struct mach_header *)dlinfo.dli_fbase;
+#endif
+
+      // Initialize the return struct
+      info->mh = (const struct mach_header *)mh;
+      info->dwarf_section = getsectiondata(mh, "__TEXT", "__eh_frame", &info->dwarf_section_length);
+      info->compact_unwind_section = getsectiondata(mh, "__TEXT", "__unwind_info", &info->compact_unwind_section_length);
+
+      if (!info->dwarf_section) {
+        info->dwarf_section_length = 0;
+      }
+
+      if (!info->compact_unwind_section) {
+        info->compact_unwind_section_length = 0;
+      }
+
       return true;
     }
   #endif




More information about the cfe-commits mailing list