diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp --- a/llvm/lib/ObjectYAML/DWARFYAML.cpp +++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp @@ -54,10 +54,19 @@ IO.mapOptional("debug_aranges", DWARF.ARanges); if (!DWARF.DebugRanges.empty() || !IO.outputting()) IO.mapOptional("debug_ranges", DWARF.DebugRanges); - IO.mapOptional("debug_pubnames", DWARF.PubNames); - IO.mapOptional("debug_pubtypes", DWARF.PubTypes); - IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames); - IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes); + if (DWARF.PubNames || DWARF.PubTypes || DWARF.GNUPubNames || + DWARF.GNUPubTypes || !IO.outputting()) { + auto *OldContext = IO.getContext(); + bool IsGNUStyle = false; + IO.setContext(&IsGNUStyle); + IO.mapOptional("debug_pubnames", DWARF.PubNames); + IO.mapOptional("debug_pubtypes", DWARF.PubTypes); + + IsGNUStyle = true; + IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames); + IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes); + IO.setContext(OldContext); + } IO.mapOptional("debug_info", DWARF.CompileUnits); IO.mapOptional("debug_line", DWARF.DebugLines); IO.mapOptional("debug_addr", DWARF.DebugAddr); @@ -112,14 +121,15 @@ void MappingTraits::mapping(IO &IO, DWARFYAML::PubEntry &Entry) { IO.mapRequired("DieOffset", Entry.DieOffset); - if (reinterpret_cast(IO.getContext())->IsGNUStyle) + if (static_cast(IO.getContext())->IsGNUStyle) IO.mapRequired("Descriptor", Entry.Descriptor); IO.mapRequired("Name", Entry.Name); } void MappingTraits::mapping( IO &IO, DWARFYAML::PubSection &Section) { - auto OldContext = IO.getContext(); + bool *IsGNUStyle = static_cast(IO.getContext()); + Section.IsGNUStyle = *IsGNUStyle; IO.setContext(&Section); IO.mapRequired("Length", Section.Length); @@ -127,8 +137,7 @@ IO.mapRequired("UnitOffset", Section.UnitOffset); IO.mapRequired("UnitSize", Section.UnitSize); IO.mapRequired("Entries", Section.Entries); - - IO.setContext(OldContext); + IO.setContext(IsGNUStyle); } void MappingTraits::mapping(IO &IO, DWARFYAML::Unit &Unit) {