diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -235,6 +235,9 @@ return 4; } + std::vector> + getOtherFlagsFromSymbol(const Elf_Ehdr &Header, const Elf_Sym &Symbol) const; + Elf_Dyn_Range dynamic_table() const { // A valid .dynamic section contains an array of entries terminated // with a DT_NULL entry. However, sometimes the section content may @@ -3276,6 +3279,35 @@ printRelRelaReloc(R, *Target); } +template +std::vector> +ELFDumper::getOtherFlagsFromSymbol(const Elf_Ehdr &Header, + const Elf_Sym &Symbol) const { + std::vector> SymOtherFlags(std::begin(ElfSymOtherFlags), + std::end(ElfSymOtherFlags)); + if (Header.e_machine == EM_MIPS) { + // Someone in their infinite wisdom decided to make STO_MIPS_MIPS16 + // flag overlap with other ST_MIPS_xxx flags. So consider both + // cases separately. + if ((Symbol.st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16) + SymOtherFlags.insert(SymOtherFlags.end(), + std::begin(ElfMips16SymOtherFlags), + std::end(ElfMips16SymOtherFlags)); + else + SymOtherFlags.insert(SymOtherFlags.end(), + std::begin(ElfMipsSymOtherFlags), + std::end(ElfMipsSymOtherFlags)); + } else if (Header.e_machine == EM_AARCH64) { + SymOtherFlags.insert(SymOtherFlags.end(), + std::begin(ElfAArch64SymOtherFlags), + std::end(ElfAArch64SymOtherFlags)); + } else if (Header.e_machine == EM_RISCV) { + SymOtherFlags.insert(SymOtherFlags.end(), std::begin(ElfRISCVSymOtherFlags), + std::end(ElfRISCVSymOtherFlags)); + } + return SymOtherFlags; +} + static inline void printFields(formatted_raw_ostream &OS, StringRef Str1, StringRef Str2) { OS.PadToColumn(2u); @@ -6894,29 +6926,8 @@ // by flags enumeration in that case. W.printNumber("Other", 0); else { - std::vector> SymOtherFlags(std::begin(ElfSymOtherFlags), - std::end(ElfSymOtherFlags)); - if (this->Obj.getHeader().e_machine == EM_MIPS) { - // Someones in their infinite wisdom decided to make STO_MIPS_MIPS16 - // flag overlapped with other ST_MIPS_xxx flags. So consider both - // cases separately. - if ((Symbol.st_other & STO_MIPS_MIPS16) == STO_MIPS_MIPS16) - SymOtherFlags.insert(SymOtherFlags.end(), - std::begin(ElfMips16SymOtherFlags), - std::end(ElfMips16SymOtherFlags)); - else - SymOtherFlags.insert(SymOtherFlags.end(), - std::begin(ElfMipsSymOtherFlags), - std::end(ElfMipsSymOtherFlags)); - } else if (this->Obj.getHeader().e_machine == EM_AARCH64) { - SymOtherFlags.insert(SymOtherFlags.end(), - std::begin(ElfAArch64SymOtherFlags), - std::end(ElfAArch64SymOtherFlags)); - } else if (this->Obj.getHeader().e_machine == EM_RISCV) { - SymOtherFlags.insert(SymOtherFlags.end(), - std::begin(ElfRISCVSymOtherFlags), - std::end(ElfRISCVSymOtherFlags)); - } + std::vector> SymOtherFlags = + this->getOtherFlagsFromSymbol(this->Obj.getHeader(), Symbol); W.printFlags("Other", Symbol.st_other, ArrayRef(SymOtherFlags), 0x3u); } printSymbolSection(Symbol, SymIndex, ShndxTable);