1212#include < mach-o/loader.h>
1313#include < mach-o/nlist.h>
1414#include " symbols.h"
15+ #include " dwarf.h"
1516#include " log.h"
1617
1718UnloadProtection::UnloadProtection (const CodeCache *cc) {
@@ -138,13 +139,15 @@ class MachOParser {
138139 const symtab_command* symtab = NULL ;
139140 const dysymtab_command* dysymtab = NULL ;
140141 const section_64* stubs_section = NULL ;
142+ bool has_eh_frame = false ;
141143
142144 for (uint32_t i = 0 ; i < header->ncmds ; i++) {
143145 if (lc->cmd == LC_SEGMENT_64 ) {
144146 const segment_command_64* sc = (const segment_command_64*)lc;
145147 if (strcmp (sc->segname , " __TEXT" ) == 0 ) {
146148 _cc->updateBounds (_image_base, add (_image_base, sc->vmsize ));
147149 stubs_section = findSection (sc, " __stubs" );
150+ has_eh_frame = findSection (sc, " __eh_frame" ) != NULL ;
148151 } else if (strcmp (sc->segname , " __LINKEDIT" ) == 0 ) {
149152 link_base = _vmaddr_slide + sc->vmaddr - sc->fileoff ;
150153 } else if (strcmp (sc->segname , " __DATA" ) == 0 || strcmp (sc->segname , " __DATA_CONST" ) == 0 ) {
@@ -168,6 +171,12 @@ class MachOParser {
168171 }
169172 }
170173
174+ // GCC emits __eh_frame (DWARF CFI); clang emits __unwind_info (compact unwind).
175+ // On aarch64, GCC and clang use different frame layouts, so detecting the
176+ // compiler matters. On x86_64 both use the same layout (no-op distinction).
177+ const FrameDesc& frame = has_eh_frame ? FrameDesc::default_frame : FrameDesc::fallback_default_frame ();
178+ _cc->setDwarfTable (NULL , 0 , frame);
179+
171180 return true ;
172181 }
173182};
0 commit comments