mgorny updated this revision to Diff 187254. mgorny marked an inline comment as done and an inline comment as not done. mgorny retitled this revision from "Correct recognition of NetBSD images" to "[lldb] [ObjectFile/ELF] Correct recognition of NetBSD images". mgorny edited the summary of this revision. mgorny added a comment.
Added tests. I'm using yaml2obj for the regular executable, and binary file for the core dump (I've stripped it to initial 4k since that seems enough for lldb to recognize it). CHANGES SINCE LAST ACTION https://reviews.llvm.org/D42870/new/ https://reviews.llvm.org/D42870 Files: lldb/lit/Modules/ELF/Inputs/netbsd.core lldb/lit/Modules/ELF/netbsd-core.test lldb/lit/Modules/ELF/netbsd-exec.yaml lldb/lit/Modules/lit.local.cfg lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -55,6 +55,7 @@ const char *const LLDB_NT_OWNER_FREEBSD = "FreeBSD"; const char *const LLDB_NT_OWNER_GNU = "GNU"; const char *const LLDB_NT_OWNER_NETBSD = "NetBSD"; +const char *const LLDB_NT_OWNER_NETBSDCORE = "NetBSD-CORE"; const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD"; const char *const LLDB_NT_OWNER_CSR = "csr"; const char *const LLDB_NT_OWNER_ANDROID = "Android"; @@ -70,8 +71,10 @@ const elf_word LLDB_NT_GNU_BUILD_ID_TAG = 0x03; -const elf_word LLDB_NT_NETBSD_ABI_TAG = 0x01; -const elf_word LLDB_NT_NETBSD_ABI_SIZE = 4; +const elf_word LLDB_NT_NETBSD_NT_NETBSD_IDENT_TAG = 1; +const elf_word LLDB_NT_NETBSD_NT_NETBSD_IDENT_DESCSZ = 4; +const elf_word LLDB_NT_NETBSD_NT_NETBSD_IDENT_NAMESZ = 7; +const elf_word LLDB_NT_NETBSD_NT_PROCINFO = 1; // GNU ABI note OS constants const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00; @@ -1294,25 +1297,39 @@ // The note.n_name == LLDB_NT_OWNER_GNU is valid for Linux platform arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux); } - // Process NetBSD ELF notes. + // Process NetBSD ELF executables and shared libraries else if ((note.n_name == LLDB_NT_OWNER_NETBSD) && - (note.n_type == LLDB_NT_NETBSD_ABI_TAG) && - (note.n_descsz == LLDB_NT_NETBSD_ABI_SIZE)) { - // Pull out the min version info. + (note.n_type == LLDB_NT_NETBSD_NT_NETBSD_IDENT_TAG) && + (note.n_descsz == LLDB_NT_NETBSD_NT_NETBSD_IDENT_DESCSZ) && + (note.n_namesz == LLDB_NT_NETBSD_NT_NETBSD_IDENT_NAMESZ)) { + // Pull out the version info. uint32_t version_info; if (data.GetU32(&offset, &version_info, 1) == nullptr) { error.SetErrorString("failed to read NetBSD ABI note payload"); return error; } - + // Convert the version info into a major/minor/patch number. + // #define __NetBSD_Version__ MMmmrrpp00 + // + // M = major version + // m = minor version; a minor number of 99 indicates current. + // r = 0 (since NetBSD 3.0 not used) + // p = patchlevel + const uint32_t version_major = version_info / 100000000; + const uint32_t version_minor = (version_info % 100000000) / 1000000; + const uint32_t version_patch = (version_info % 10000) / 100; + // Set the elf OS version to NetBSD. Also clear the vendor. + arch_spec.GetTriple().setOSName( + llvm::formatv("netbsd{0}.{1}.{2}", version_major, version_minor, + version_patch).str()); + arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor); + } + // Process NetBSD ELF core(5) notes + else if ((note.n_name == LLDB_NT_OWNER_NETBSDCORE) && + (note.n_type == LLDB_NT_NETBSD_NT_PROCINFO)) { // Set the elf OS version to NetBSD. Also clear the vendor. arch_spec.GetTriple().setOS(llvm::Triple::OSType::NetBSD); arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor); - - if (log) - log->Printf( - "ObjectFileELF::%s detected NetBSD, min version constant %" PRIu32, - __FUNCTION__, version_info); } // Process OpenBSD ELF notes. else if (note.n_name == LLDB_NT_OWNER_OPENBSD) { Index: lldb/lit/Modules/lit.local.cfg =================================================================== --- lldb/lit/Modules/lit.local.cfg +++ lldb/lit/Modules/lit.local.cfg @@ -1 +1 @@ -config.suffixes = ['.s', '.yaml'] +config.suffixes = ['.s', '.test', '.yaml'] Index: lldb/lit/Modules/ELF/netbsd-exec.yaml =================================================================== --- /dev/null +++ lldb/lit/Modules/ELF/netbsd-exec.yaml @@ -0,0 +1,335 @@ +# Test whether NetBSD executables are recognized correctly. + +# RUN: yaml2obj %s > %t +# RUN: lldb-test object-file %t | FileCheck %s +# CHECK: Architecture: x86_64--netbsd8.99.30 +# CHECK: Type: executable + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 + Entry: 0x00000000002006F0 +Sections: + - Name: .interp + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x0000000000200200 + AddressAlign: 0x0000000000000001 + Content: 2F7573722F6C6962657865632F6C642E656C665F736F00 + - Name: .gnu.hash + Type: SHT_GNU_HASH + Flags: [ SHF_ALLOC ] + Address: 0x0000000000200368 + Link: .dynsym + AddressAlign: 0x0000000000000008 + Content: 0100000008000000020000000600000004C4000040004019008000000004000008000000B88DF10EA6DDA36BBC50769EEAD3EF0E8E029870BBE3927C + - Name: .hash + Type: SHT_HASH + Flags: [ SHF_ALLOC ] + Address: 0x00000000002003A4 + Link: .dynsym + AddressAlign: 0x0000000000000004 + EntSize: 0x0000000000000004 + Content: 0E0000000E0000000D0000000C0000000900000000000000080000000A00000000000000000000000200000000000000040000000000000000000000050000000000000000000000000000000000000000000000000000000000000000000000030000000100000007000000060000000B00000000000000 + - Name: .note.netbsd.ident + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x00000000002005A8 + AddressAlign: 0x0000000000000004 + Content: 0700000004000000010000004E6574425344000078B29535 + - Name: .note.netbsd.pax + Type: SHT_NOTE + Flags: [ SHF_ALLOC ] + Address: 0x00000000002005C0 + AddressAlign: 0x0000000000000004 + Content: '0400000004000000030000005061580000000000' + - Name: .eh_frame_hdr + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x00000000002005D4 + AddressAlign: 0x0000000000000004 + Content: 011B033B30000000050000002F0100004C0000005A0100007400000094010000A4000000D3020000C40000009C040000EC000000 + - Name: .eh_frame + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x0000000000200608 + AddressAlign: 0x0000000000000008 + Content: 1400000000000000017A5200017810011B0C070890010000240000001C000000DB0000002B00000000410E108602410E188303440E20620E18410E10410E08002C00000044000000DE0000003A00000000420E108C02410E188603410E2083046D0A0E18410E10420E08410B000000001C00000074000000E80000003F010000000316010E10450E08000000000000002400000094000000070200002301000000420E108D02420E188C03410E208604410E288305440E301C000000BC000000A80300001D00000000410E108602430D06580C0708000000CCCCCCCC + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x00000000002006F0 + AddressAlign: 0x0000000000000010 + Content: 4883E4F04883EC084889D74889DEE9A401000055534883EC08488D2DE0FFFFFF488D1DD9FFFFFF4839EB730BFF134883C3084839EB72F54883C4085B5DC341545553488B1D0F1A00004C8B25101A00004C39E37319837B08257518488B2BFF5310488945004883C3184C39E372E75B5D415CC3E8580300004863D24863F6488D443202488D14C78B0285C00F840D010000BEFFFFFFFF31C9EB1C83F8070F84F000000083F8037504488B4A084883C2108B0285C0741383F80575DF0FB772084883C2108B0285C075ED4885C90F84CC0000006683FEFF0F84C20000000FB7D6486BD2384801CA4839CA0F86AF000000BEFFFFFFFF31FFEB1583F80675074889CE482B71104883C1384839CA76138B0183F80275E44889CF4883C1384839CA77ED4885FF7479B8FFFFFFFF4839C6746F4889F248035710488B024885C0746031FF31C9EB164883F8087504488B7A084883C210488B024885C074194883F80775E44889F148034A084883C210488B024885C075E74801CF4839CF76238B41084883F808741B4883F82574234883EC08E83D02000048837A08000F840EFFFFFFC3488B014889F248035110488914304883C1184839CF77C5C34155415455534883EC084889FB4889F58B56188B7608488B7D00E8A2FEFFFF488D053B2700004889284C8D2529270000488B451049890424488B4500488B104885D20F84BB000000488D0D0A070000488911488B000FB6104883C00184D2741380FA2F75F04889010FB6104883C00184D275ED4885DB74084889DFE8A9010000E8B401000048833D24180000000F84860000004C8D2DAFFDFFFF488D1DA8FDFFFF4C39EB730BFF134883C3084C39EB72F5488D3DA4FDFFFFE86C0100004C8D2D85FDFFFF488D1D7EFDFFFF4C39EB730BFF134883C3084C39EB72F5488D3D17010000E842010000E8FD0000008B7D08498B1424488B7500E8CD00000089C7E846010000488D054F060000488D0D58260000488908E95AFFFFFFE869FDFFFFE970FFFFFF803D80060000007401C353C6057506000001488D1D35160000488B034885C07408FFD04883C308EBF048833D6517000000740C488D3D04FCFFFFE8F70000005BC3803D3E060000007401C353C605330600000148833D43170000007413488D35E2050000488D3DD3FBFFFFE8D600000048833D2E170000007412488D3DD515000048833F007405E8CA000000488D1DA3150000488B034883F8FF7408FFD04883EB08EBEF5BC3554889E548C745F800000000488B45F8C70001000000B8000000005DC3 + - Name: .init + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x0000000000200A90 + AddressAlign: 0x0000000000000010 + Content: 4883EC08E872FFFFFF4883C408C3 + - Name: .fini + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x0000000000200AA0 + AddressAlign: 0x0000000000000010 + Content: 4883EC08E821FFFFFF4883C408C3 + - Name: .plt + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x0000000000200AB0 + AddressAlign: 0x0000000000000010 + Content: FF35AA050000FF25AC0500000F1F4000FF25AA0500006800000000E9E0FFFFFFFF25A20500006801000000E9D0FFFFFFFF259A0500006802000000E9C0FFFFFFFF25920500006803000000E9B0FFFFFFFF258A0500006804000000E9A0FFFFFFFF25820500006805000000E990FFFFFFFF257A0500006806000000E980FFFFFF + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000201000 + AddressAlign: 0x0000000000000008 + Content: '10302000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' + - Name: .got.plt + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000201058 + AddressAlign: 0x0000000000000008 + Content: 282020000000000000000000000000000000000000000000C60A200000000000D60A200000000000E60A200000000000F60A200000000000060B200000000000160B200000000000260B200000000000 + - Name: .ctors + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000202000 + AddressAlign: 0x0000000000000008 + Content: FFFFFFFFFFFFFFFF0000000000000000 + - Name: .dtors + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000202010 + AddressAlign: 0x0000000000000008 + Content: FFFFFFFFFFFFFFFF0000000000000000 + - Name: .jcr + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000202020 + AddressAlign: 0x0000000000000008 + Content: '0000000000000000' + - Name: .dynamic + Type: SHT_DYNAMIC + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000202028 + Link: .dynstr + AddressAlign: 0x0000000000000008 + EntSize: 0x0000000000000010 + Entries: + - Tag: DT_NEEDED + Value: 0x0000000000000001 + - Tag: DT_DEBUG + Value: 0x0000000000000000 + - Tag: DT_RELA + Value: 0x00000000002004B8 + - Tag: DT_RELASZ + Value: 0x0000000000000048 + - Tag: DT_RELAENT + Value: 0x0000000000000018 + - Tag: DT_JMPREL + Value: 0x0000000000200500 + - Tag: DT_PLTRELSZ + Value: 0x00000000000000A8 + - Tag: DT_PLTGOT + Value: 0x0000000000201058 + - Tag: DT_PLTREL + Value: 0x0000000000000007 + - Tag: DT_SYMTAB + Value: 0x0000000000200218 + - Tag: DT_SYMENT + Value: 0x0000000000000018 + - Tag: DT_STRTAB + Value: 0x000000000020041C + - Tag: DT_STRSZ + Value: 0x000000000000009C + - Tag: DT_GNU_HASH + Value: 0x0000000000200368 + - Tag: DT_HASH + Value: 0x00000000002003A4 + - Tag: DT_INIT + Value: 0x0000000000200A90 + - Tag: DT_FINI + Value: 0x0000000000200AA0 + - Tag: DT_NULL + Value: 0x0000000000000000 + - Name: .got + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000202148 + AddressAlign: 0x0000000000000008 + Content: '000000000000000000000000000000002820200000000000000000000000000000000000000000000000000000000000' + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Address: 0x0000000000203000 + AddressAlign: 0x0000000000000008 + Size: 0x0000000000000011 + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + EntSize: 0x0000000000000001 + Content: 4C696E6B65723A204C4C4420372E302E31004743433A20284E6574425344206E62342032303138313130392920362E352E30004743433A20286E62342032303138313130392920362E352E300000 + - Name: .ident + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 244E65744253443A20637274302E532C7620312E3420323031382F31312F32362031373A33373A3436206A6F65726720457870202400244E65744253443A20637274302D636F6D6D6F6E2E632C7620312E323320323031382F31322F32382032303A31323A3335206368726973746F7320457870202400244E65744253443A20637274692E532C7620312E3120323031302F30382F30372031383A30313A3335206A6F65726720457870202400244E65744253443A20637274626567696E2E532C7620312E3220323031302F31312F33302031383A33373A3539206A6F65726720457870202400244E65744253443A20637274656E642E532C7620312E3120323031302F30382F30372031383A30313A3334206A6F65726720457870202400244E65744253443A206372746E2E532C7620312E3120323031302F30382F30372031383A30313A3335206A6F65726720457870202400 + - Name: .SUNW_ctf + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000004 + Content: F1CF0200000000000000000000000000080000000800000008000000080000001B0000000100000000000000002A2A2A204E6F204C6162656C2050726F7669646564202A2A2A0000F1CF0200000000000000000000000000080000000800000008000000080000001B0000000100000000000000002A2A2A204E6F204C6162656C2050726F7669646564202A2A2A00 +Symbols: + Local: + - Name: crt0-common.c + Type: STT_FILE + - Name: __rela_iplt_end + Visibility: STV_HIDDEN + - Name: __rela_iplt_start + Visibility: STV_HIDDEN + - Name: ___start + Type: STT_FUNC + Section: .text + Value: 0x00000000002008A7 + Size: 0x0000000000000123 + Visibility: STV_HIDDEN + - Name: hello.c + Type: STT_FILE + - Name: _DYNAMIC + Section: .dynamic + Value: 0x0000000000202028 + Visibility: STV_HIDDEN + - Name: __fini_array_end + Section: .text + Value: 0x00000000002006F0 + Visibility: STV_HIDDEN + - Name: __fini_array_start + Section: .text + Value: 0x00000000002006F0 + Visibility: STV_HIDDEN + - Name: __init_array_end + Section: .text + Value: 0x00000000002006F0 + Visibility: STV_HIDDEN + - Name: __preinit_array_end + Section: .text + Value: 0x00000000002006F0 + Visibility: STV_HIDDEN + - Name: _GLOBAL_OFFSET_TABLE_ + Section: .got.plt + Value: 0x0000000000201058 + Visibility: STV_HIDDEN + - Name: __init_array_start + Section: .text + Value: 0x00000000002006F0 + Visibility: STV_HIDDEN + - Name: __preinit_array_start + Section: .text + Value: 0x00000000002006F0 + Visibility: STV_HIDDEN + - Name: __dso_handle + Type: STT_OBJECT + Section: .data + Value: 0x0000000000201008 + Size: 0x0000000000000008 + Visibility: STV_HIDDEN + - Name: __CTOR_LIST_END__ + Section: .ctors + Value: 0x0000000000202008 + Visibility: STV_HIDDEN + Global: + - Name: abort + Type: STT_FUNC + - Name: _init + Section: .init + Value: 0x0000000000200A90 + - Name: environ + Type: STT_OBJECT + Section: .bss + Value: 0x0000000000203000 + Size: 0x0000000000000008 + - Name: __start + Type: STT_FUNC + Section: .text + Value: 0x00000000002006F0 + - Name: __progname + Type: STT_OBJECT + Section: .data + Value: 0x0000000000201000 + Size: 0x0000000000000008 + - Name: _start + Type: STT_FUNC + Section: .text + Value: 0x00000000002006F0 + - Name: main + Type: STT_FUNC + Section: .text + Value: 0x0000000000200A70 + Size: 0x000000000000001D + - Name: _fini + Section: .fini + Value: 0x0000000000200AA0 + - Name: atexit + Type: STT_FUNC + - Name: __ps_strings + Type: STT_OBJECT + Section: .bss + Value: 0x0000000000203008 + Size: 0x0000000000000008 + - Name: exit + Type: STT_FUNC + - Name: _libc_init + Type: STT_FUNC + - Name: _end + Section: .bss + Value: 0x0000000000203011 + Weak: + - Name: __deregister_frame_info + Type: STT_FUNC + - Name: __register_frame_info + Type: STT_FUNC + - Name: _Jv_RegisterClasses +DynamicSymbols: + Global: + - Name: abort + Type: STT_FUNC + - Name: atexit + Type: STT_FUNC + - Name: exit + Type: STT_FUNC + - Name: _libc_init + Type: STT_FUNC + - Name: _init + Section: .init + Value: 0x0000000000200A90 + - Name: environ + Type: STT_OBJECT + Section: .bss + Value: 0x0000000000203000 + Size: 0x0000000000000008 + - Name: __progname + Type: STT_OBJECT + Section: .data + Value: 0x0000000000201000 + Size: 0x0000000000000008 + - Name: _fini + Section: .fini + Value: 0x0000000000200AA0 + - Name: __ps_strings + Type: STT_OBJECT + Section: .bss + Value: 0x0000000000203008 + Size: 0x0000000000000008 + - Name: _end + Section: .bss + Value: 0x0000000000203011 + Weak: + - Name: __deregister_frame_info + Type: STT_FUNC + - Name: __register_frame_info + Type: STT_FUNC + - Name: _Jv_RegisterClasses +... Index: lldb/lit/Modules/ELF/netbsd-core.test =================================================================== --- /dev/null +++ lldb/lit/Modules/ELF/netbsd-core.test @@ -0,0 +1,5 @@ +# Test whether NetBSD core dumps are recognized correctly. + +# RUN: lldb-test object-file %S/Inputs/netbsd.core | FileCheck %s +# CHECK: Architecture: x86_64-unknown-netbsd +# CHECK: Type: core file
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits