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 @@ -234,6 +234,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 @@ -6806,29 +6809,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, makeArrayRef(SymOtherFlags), 0x3u); } printSymbolSection(Symbol, SymIndex, ShndxTable); @@ -7577,29 +7559,8 @@ // by flags enumeration in that case. W.printString("Other", "{}"); 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, makeArrayRef(SymOtherFlags), 0x3u); } this->printSymbolSection(Symbol, SymIndex, ShndxTable); @@ -7620,3 +7581,32 @@ if (R.Addend) W.printHex("Addend", (uintX_t)*R.Addend); } + +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) { + // 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 (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; +}