[Bug 17209] New: ObjectFileELF::GetModuleSpecifications overrides OS and Vendor name with those from host

Bug ID 17209
Summary ObjectFileELF::GetModuleSpecifications overrides OS and Vendor name with those from host
Product lldb
Version unspecified
Hardware PC
OS FreeBSD
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@cs.uiuc.edu
Reporter emaste@freebsd.org
Classification Unclassified

spec.GetArchitecture().GetTriple().setOSName
(Host::GetOSString().GetCString());
spec.GetArchitecture().GetTriple().setVendorName(Host::GetVendorString().GetCString());

We would like to be able to open Linux and FreeBSD core files on any of Linux,
FreeBSD, and OS X.

Michael provided a reference for the GNU ABI tag already:
[http://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/noteabitag.html](http://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/noteabitag.html)

Note that the build ID page reports that "the name is not normative, and the
section can be merged with other SHT_NOTE sections."
[http://fedoraproject.org/wiki/Releases/FeatureBuildId](http://fedoraproject.org/wiki/Releases/FeatureBuildId)
We should apply the same logic for ABI tag parsing, using the note name and not
relying on the section name.

We can fall back to using the Host's OS/Vendor if the note is not found.

A handy reference:

** Linux **
Name: GNU
Type: NT_GNU_ABI_TAG (1)
Desc: Four 4-byte words, as follows
 OS (0=linux)
 major version (minimum compatible kernel version)
 minor version
 dot version

** FreeBSD **
Name: FreeBSD
Type: NT_FREEBSD_ABI_TAG (1)
Desc: One 4-byte word

** NetBSD **
Name: NetBSD
Type: NT_NETBSD_IDENT(?) (1)
Desc: One 4-byte word containing the version constant

[http://www.netbsd.org/docs/kernel/elf-notes.html](http://www.netbsd.org/docs/kernel/elf-notes.html)

** OpenBSD **
Name: OpenBSD
Type: NT_OPENBSD_IDENT (1)

emaste@freebsd.org changed bug 17209

What Removed Added
Status NEW RESOLVED
Resolution FIXED

Comment # 3 on bug 17209 from emaste@freebsd.org

Fixed by Todd Fiala in r211907:

    Fix ObjectFileELF to determine architectures independent of host.           

    Previously ObjectFileELF was simplifying and assuming the object file it
was
    looking at was the same as the host architecture/triple.  This would break  
    attempts to run, say, lldb on MacOSX against lldb-gdbserver on Linux since  
    the MacOSX lldb would say that the linux elf file was really an Apple
MacOSX
    architecture.  Chaos would ensue.                                           

    This change allows the elf file to parse ELF notes for Linux, FreeBSD and   
    NetBSD, and determine the OS appropriately from them.  It also initializes  
    the OS type from the ELF header OSABI if it is set (which it is for FreeBSD 
    but not for Linux).                                                         

    Added a test with freebsd and linux images that verify that                 
    '(lldb) image list -t -A' prints out the expected architecture for each.