Index: include/llvm/ObjectYAML/COFFYAML.h =================================================================== --- include/llvm/ObjectYAML/COFFYAML.h +++ include/llvm/ObjectYAML/COFFYAML.h @@ -59,6 +59,7 @@ uint32_t VirtualAddress; uint16_t Type; StringRef SymbolName; + Optional SymbolTableIndex; }; struct Section { Index: lib/ObjectYAML/COFFYAML.cpp =================================================================== --- lib/ObjectYAML/COFFYAML.cpp +++ lib/ObjectYAML/COFFYAML.cpp @@ -407,7 +407,8 @@ void MappingTraits::mapping(IO &IO, COFFYAML::Relocation &Rel) { IO.mapRequired("VirtualAddress", Rel.VirtualAddress); - IO.mapRequired("SymbolName", Rel.SymbolName); + IO.mapOptional("SymbolName", Rel.SymbolName, StringRef()); + IO.mapOptional("SymbolTableIndex", Rel.SymbolTableIndex); COFF::header &H = *static_cast(IO.getContext()); if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) { Index: tools/obj2yaml/coff2yaml.cpp =================================================================== --- tools/obj2yaml/coff2yaml.cpp +++ tools/obj2yaml/coff2yaml.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "obj2yaml.h" +#include "llvm/ADT/StringMap.h" #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h" #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" @@ -142,6 +143,14 @@ codeview::StringsAndChecksumsRef SC; initializeFileAndStringTable(Obj, SC); + StringMap SymbolOccurrances; + for (const auto &S : Obj.symbols()) { + object::COFFSymbolRef Symbol = Obj.getCOFFSymbol(S); + StringRef Name; + Obj.getSymbolName(Symbol, Name); + SymbolOccurrances[Name]++; + } + for (const auto &ObjSection : Obj.sections()) { const object::coff_section *COFFSection = Obj.getCOFFSection(ObjSection); COFFYAML::Section NewYAMLSection; @@ -192,7 +201,10 @@ OS.flush(); report_fatal_error(Buf); } - Rel.SymbolName = *SymbolNameOrErr; + if (SymbolOccurrances[*SymbolNameOrErr] == 1) + Rel.SymbolName = *SymbolNameOrErr; + else + Rel.SymbolTableIndex = reloc->SymbolTableIndex; Rel.VirtualAddress = reloc->VirtualAddress; Rel.Type = reloc->Type; Relocations.push_back(Rel); Index: tools/yaml2obj/yaml2coff.cpp =================================================================== --- tools/yaml2obj/yaml2coff.cpp +++ tools/yaml2obj/yaml2coff.cpp @@ -529,6 +529,8 @@ : 0); for (const COFFYAML::Relocation &R : S.Relocations) { uint32_t SymbolTableIndex = SymbolTableIndexMap[R.SymbolName]; + if (R.SymbolTableIndex) + SymbolTableIndex = *R.SymbolTableIndex; OS << binary_le(R.VirtualAddress) << binary_le(SymbolTableIndex) << binary_le(R.Type);