diff options
author | Ed Maste <emaste@freebsd.org> | 2015-06-05 13:03:08 +0000 |
---|---|---|
committer | Ed Maste <emaste@freebsd.org> | 2015-06-05 13:03:08 +0000 |
commit | f6a1312f1b30a335889f74d92e5ce5e5a6970f4a (patch) | |
tree | f9bbf864e03000d59b73a818c765c51ab8b4b59b /lldb/source/Plugins/ObjectFile/ELF | |
parent | acd1cd66c17fed8adeb7108ae8c6ae1f7671bac2 (diff) | |
download | bcm5719-llvm-f6a1312f1b30a335889f74d92e5ce5e5a6970f4a.tar.gz bcm5719-llvm-f6a1312f1b30a335889f74d92e5ce5e5a6970f4a.zip |
Improve OSType initialization in elf object file's arch_spec
Setting the OSType in the ArchSpec triple is needed to correctly setup
up the register context plugin. ArchSpec::SetArchitecture, for Mach-O
only, sets the OSType. For ELF it was left to the ObjectFileELF to fill
in the missing OSType.
This change moves the ObjectFileELF logic into ArchSpec.
A new optional 'os' parameter has been added to SetArchitecture.
For ELF, this value is the from the ELF header.e_ident[EI_OSABI].
The default value is 0 or ELFOSABI_NONE.
The real work of determining the OSType was done by the ObjectFileELF
helper function GetOsFromOSABI. This logic has been moved
SetArchitecture.
GetOsFromOSABI has been commented as being deprectated. It is left in
to support asserts.
For ELF the vendor value returned from SetArchitecture should be
UnknownVendor. An unneeded resetting in ObjectFileELF has been removed
and replaced with an assert.
This fixes a problem reading a core file on FreeBSD/ARM because the spec
triple was arm-unknown-unknown.
Patch by Tom Rix.
Differential Revision: http://reviews.llvm.org/D9292
llvm-svn: 239148
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/ELF')
-rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index d8e35b86a60..29558fb5cf1 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -597,6 +597,12 @@ OSABIAsCString (unsigned char osabi_byte) #undef _MAKE_OSABI_CASE } +// +// WARNING : This function is being deprecated +// It's functionality has moved to ArchSpec::SetArchitecture +// This function is only being kept to validate the move. +// +// TODO : Remove this function static bool GetOsFromOSABI (unsigned char osabi_byte, llvm::Triple::OSType &ostype) { @@ -640,23 +646,28 @@ ObjectFileELF::GetModuleSpecifications (const lldb_private::FileSpec& file, const uint32_t sub_type = subTypeFromElfHeader(header); spec.GetArchitecture().SetArchitecture(eArchTypeELF, header.e_machine, - sub_type); + sub_type, + header.e_ident[EI_OSABI]); if (spec.GetArchitecture().IsValid()) { llvm::Triple::OSType ostype; - // First try to determine the OS type from the OSABI field in the elf header. + llvm::Triple::VendorType vendor; + llvm::Triple::OSType spec_ostype = spec.GetArchitecture ().GetTriple ().getOS (); if (log) log->Printf ("ObjectFileELF::%s file '%s' module OSABI: %s", __FUNCTION__, file.GetPath ().c_str (), OSABIAsCString (header.e_ident[EI_OSABI])); - if (GetOsFromOSABI (header.e_ident[EI_OSABI], ostype) && ostype != llvm::Triple::OSType::UnknownOS) - { - spec.GetArchitecture ().GetTriple ().setOS (ostype); - // Also clear the vendor so we don't end up with situations like - // x86_64-apple-FreeBSD. - spec.GetArchitecture ().GetTriple ().setVendor (llvm::Triple::VendorType::UnknownVendor); + // SetArchitecture should have set the vendor to unknown + vendor = spec.GetArchitecture ().GetTriple ().getVendor (); + assert(vendor == llvm::Triple::UnknownVendor); + // + // Validate it is ok to remove GetOsFromOSABI + GetOsFromOSABI (header.e_ident[EI_OSABI], ostype); + assert(spec_ostype == ostype); + if (spec_ostype != llvm::Triple::OSType::UnknownOS) + { if (log) log->Printf ("ObjectFileELF::%s file '%s' set ELF module OS type from ELF header OSABI.", __FUNCTION__, file.GetPath ().c_str ()); } @@ -1387,8 +1398,15 @@ ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl §ion_headers, // We'll refine this with note data as we parse the notes. if (arch_spec.GetTriple ().getOS () == llvm::Triple::OSType::UnknownOS) { + llvm::Triple::OSType ostype; + llvm::Triple::OSType spec_ostype; const uint32_t sub_type = subTypeFromElfHeader(header); - arch_spec.SetArchitecture (eArchTypeELF, header.e_machine, sub_type); + arch_spec.SetArchitecture (eArchTypeELF, header.e_machine, sub_type, header.e_ident[EI_OSABI]); + // + // Validate if it is ok to remove GetOsFromOSABI + GetOsFromOSABI (header.e_ident[EI_OSABI], ostype); + spec_ostype = arch_spec.GetTriple ().getOS (); + assert(spec_ostype == ostype); } // If there are no section headers we are done. |