[lldb] [ObjectFile/ELF] Fix recognizing NetBSD images

Split the recognition into NetBSD executables & shared libraries
and core(5) files.

Introduce new owner type: "NetBSD-CORE", as core(5) files are not tagged
in the same way as regular NetBSD executables.

Stop using incorrectly ABI_TAG and ABI_SIZE.  Introduce IDENT_TAG,
IDENT_DECSZ, IDENT_NAMESZ and PROCINFO.

The new values detect correctly the NetBSD images.

The patch has been originally written by Kamil Rytarowski.  I've added
tests and applied minor code changes per review.  The work has been
sponsored by the NetBSD Foundation.

Differential Revision: https://reviews.llvm.org/D42870

llvm-svn: 354466
This commit is contained in:
Michal Gorny 2019-02-20 14:31:06 +00:00
parent dac37fb38d
commit 4f134fb660
5 changed files with 64 additions and 13 deletions

Binary file not shown.

View File

@ -0,0 +1,12 @@
# Test whether NetBSD core dumps are recognized correctly.
# Core dump generated by the following program:
# int main() {
# void* v = 0;
# *v = 1;
# return 0;
# }
# RUN: lldb-test object-file %S/Inputs/netbsd-amd64.core | FileCheck %s
# CHECK: Architecture: x86_64-unknown-netbsd
# CHECK: Type: core file

View File

@ -0,0 +1,22 @@
# 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: .note.netbsd.ident
Type: SHT_NOTE
Flags: [ SHF_ALLOC ]
Address: 0x00000000002005A8
AddressAlign: 0x0000000000000004
Content: 0700000004000000010000004E6574425344000078B29535
...

View File

@ -1 +1 @@
config.suffixes = ['.s', '.yaml']
config.suffixes = ['.s', '.test', '.yaml']

View File

@ -55,6 +55,7 @@ namespace {
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_ABI_SIZE = 16;
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_IDENT_TAG = 1;
const elf_word LLDB_NT_NETBSD_IDENT_DESCSZ = 4;
const elf_word LLDB_NT_NETBSD_IDENT_NAMESZ = 7;
const elf_word LLDB_NT_NETBSD_PROCINFO = 1;
// GNU ABI note OS constants
const elf_word LLDB_NT_GNU_ABI_OS_LINUX = 0x00;
@ -1294,25 +1297,39 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
// 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_IDENT_TAG) &&
(note.n_descsz == LLDB_NT_NETBSD_IDENT_DESCSZ) &&
(note.n_namesz == LLDB_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_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) {