diff --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h --- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h +++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h @@ -28,6 +28,11 @@ : StorageMappingClass(Smc), Index(Idx), IsLabel(Label) {} }; +namespace objdump { +bool compareXCOFFSymbolInfo(const XCOFFSymbolInfo &SymInfo1, + const XCOFFSymbolInfo &SymInfo2); +} + struct SymbolInfoTy { uint64_t Addr; StringRef Name; @@ -52,9 +57,12 @@ friend bool operator<(const SymbolInfoTy &P1, const SymbolInfoTy &P2) { assert(P1.IsXCOFF == P2.IsXCOFF && "P1.IsXCOFF should be equal to P2.IsXCOFF."); - if (P1.IsXCOFF) - return std::tie(P1.Addr, P1.Name) < std::tie(P2.Addr, P2.Name); - else + if (P1.IsXCOFF) { + if (P1.Addr == P2.Addr) + return objdump::compareXCOFFSymbolInfo(P1.XCOFFSymInfo, + P2.XCOFFSymInfo); + return P1.Addr < P2.Addr; + } else return std::tie(P1.Addr, P1.Name, P1.Type) < std::tie(P2.Addr, P2.Name, P2.Type); } diff --git a/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test b/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test --- a/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test +++ b/llvm/test/tools/llvm-objdump/XCOFF/disassemble-symbol-description.test @@ -22,7 +22,7 @@ COMMON: Inputs/xcoff-section-headers.o: file format aixcoff-rs6000 COMMON: Disassembly of section .text: PLAIN: 00000000 <.text>: -DESC: 00000000 (idx: 4) .text: +DESC: 00000000 (idx: 16) .func: COMMON-NEXT: 0: 80 62 00 04 lwz 3, 4(2) COMMON-NEXT: 4: 80 63 00 00 lwz 3, 0(3) COMMON-NEXT: 8: 4e 80 00 20 blr diff --git a/llvm/tools/llvm-objdump/XCOFFDump.cpp b/llvm/tools/llvm-objdump/XCOFFDump.cpp --- a/llvm/tools/llvm-objdump/XCOFFDump.cpp +++ b/llvm/tools/llvm-objdump/XCOFFDump.cpp @@ -72,3 +72,27 @@ outs() << "[" << XCOFF::getMappingClassString(Smc) << "]"; } } + +bool objdump::compareXCOFFSymbolInfo(const XCOFFSymbolInfo &SymInfo1, + const XCOFFSymbolInfo &SymInfo2) { + // Compare Label first. If the symbol is Label, it is in high priority. + if (SymInfo1.IsLabel != SymInfo2.IsLabel) + return SymInfo1.IsLabel < SymInfo2.IsLabel; + + // If symbol have not StorageMappingClass, it is in low proirity. + if (!SymInfo1.StorageMappingClass) + return true; + + if (!SymInfo2.StorageMappingClass) + return false; + + // TC0 symbol is low prority than other SMC. + if (SymInfo1.StorageMappingClass.getValue() == XCOFF::XMC_TC0) + return true; + + if (SymInfo2.StorageMappingClass.getValue() == XCOFF::XMC_TC0) + return false; + + return SymInfo1.StorageMappingClass.getValue() <= + SymInfo1.StorageMappingClass.getValue(); +}