Index: llvm/test/tools/llvm-readobj/elf-section-types.test =================================================================== --- llvm/test/tools/llvm-readobj/elf-section-types.test +++ llvm/test/tools/llvm-readobj/elf-section-types.test @@ -63,14 +63,20 @@ # LLVM: Type: Unknown (0x1000) # LLVM: Name: loos # LLVM: Type: Unknown (0x60000000) +# LLVM: Name: fooos +# LLVM: Type: Unknown (0x60000F00) # LLVM: Name: hios # LLVM: Type: SHT_GNU_versym # LLVM: Name: loproc # LLVM: Type: Unknown (0x70000000) +# LLVM: Name: fooproc +# LLVM: Type: Unknown (0x70000F00) # LLVM: Name: hiproc # LLVM: Type: Unknown (0x7FFFFFFF) # LLVM: Name: louser # LLVM: Type: Unknown (0x80000000) +# LLVM: Name: foouser +# LLVM: Type: Unknown (0x80000F00) # LLVM: Name: hiuser # LLVM: Type: Unknown (0xFFFFFFFF) # LLVM: Name: .symtab @@ -94,10 +100,8 @@ # GNU-NEXT: group GROUP # GNU-NEXT: symtab_shndx SYMTAB SECTION INDICES # GNU-NEXT: relr RELR -## FIXME: These next two lines should print something like ANDROID_REL and ANDROID_RELA. -## See https://bugs.llvm.org/show_bug.cgi?id=40773. -# GNU-NEXT: android_rel 0000000000000000 -# GNU-NEXT: android_rela 0000000000000000 +# GNU-NEXT: android_rel LOOS+0x1 +# GNU-NEXT: android_rela LOOS+0x2 # GNU-NEXT: android_relr RELR # GNU-NEXT: llvm_odrtab LLVM_ODRTAB # GNU-NEXT: linker_options LLVM_LINKER_OPTIONS @@ -107,8 +111,19 @@ # GNU-NEXT: gnu_hash GNU_HASH # GNU-NEXT: gnu_verdef VERDEF # GNU-NEXT: gnu_verneed VERNEED -## TODO: Add testing for unknown section types in GNU output style. -## See https://bugs.llvm.org/show_bug.cgi?id=40773. +# GNU-NEXT: unknown 0x1000: +# GNU_NEXT: loos LOOS+0 +# GNU_NEXT: fooos LOOS+0xF00 +# GNU_NEXT: hios VERSYM +# GNU_NEXT: loproc LOPROC+0 +# GNU_NEXT: fooproc LOPROC+0xF00 +# GNU_NEXT: hiproc LOPROC+0xFFFFFFF +# GNU_NEXT: louser LOUSER+0 +# GNU_NEXT: fooouser LOUSER+0xF00 +# GNU_NEXT: hiuser LOUSER+0x7FFFFFFF +# GNU_NEXT: .symtab SYMTAB +# GNU_NEXT: .strtab STRTAB +# GNU_NEXT: .shstrtab STRTAB --- !ELF FileHeader: @@ -186,15 +201,21 @@ Type: 0x1000 - Name: loos Type: 0x60000000 + - Name: fooos + Type: 0x60000F00 - Name: hios Type: 0x6fffffff Entries: [] - Name: loproc Type: 0x70000000 + - Name: fooproc + Type: 0x70000F00 - Name: hiproc Type: 0x7fffffff - Name: louser Type: 0x80000000 + - Name: foouser + Type: 0x80000F00 - Name: hiuser Type: 0xffffffff Symbols: Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -2829,7 +2829,21 @@ OS << "\nThere are no relocations in this file.\n"; } -std::string getSectionTypeString(unsigned Arch, unsigned Type) { +// Print the offset of a particular section from anyone of the ranges: +// (SHT_LOOS, SHT_HIOS), (SHT_LOPROC, SHT_HIPROC), (SHT_LOUSER, SHT_HIUSER). +// If 'Type' does not fall within any of those ranges, then a string is +// returned as '' followed by the type value. +static std::string getSectionTypeOffsetString(unsigned Type) { + if (Type > SHT_LOOS && Type < SHT_HIOS) + return "LOOS+0x" + to_hexString(Type - SHT_LOOS); + else if (Type > SHT_LOPROC && Type < SHT_HIPROC) + return "LOPROC+0x" + to_hexString(Type - SHT_LOPROC); + else if (Type > SHT_LOUSER && Type < SHT_HIUSER) + return "LOUSER+0x" + to_hexString(Type - SHT_LOUSER); + return "0x" + to_hexString(Type) + ": "; +} + +static std::string getSectionTypeString(unsigned Arch, unsigned Type) { using namespace ELF; switch (Arch) { @@ -2924,8 +2938,18 @@ return "VERNEED"; case SHT_GNU_versym: return "VERSYM"; + case SHT_LOOS: + return "LOOS+0"; + case SHT_LOPROC: + return "LOPROC+0"; + case SHT_HIPROC: + return "LOPROC+0x" + to_hexString(SHT_HIPROC - SHT_LOPROC); + case SHT_LOUSER: + return "LOUSER+0"; + case SHT_HIUSER: + return "LOUSER+0x" + to_hexString(SHT_HIUSER - SHT_LOUSER); default: - return ""; + return getSectionTypeOffsetString(Type); } return ""; }