This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Use the win32 OS when determining the architecture of a PECOFF obj file
ClosedPublic

Authored by wallace on Sep 13 2016, 4:21 PM.

Details

Summary

When creating the ArchSpec of a PECOFF file, if the subsystem field in the header indicates a windows subsystem, we use Win32 as the OS.

Diff Detail

Event Timeline

wallace updated this revision to Diff 71257.Sep 13 2016, 4:21 PM
wallace retitled this revision from to [lldb] Use the correct OS when determining the architecture of a PECOFF obj file.
wallace updated this object.
wallace added reviewers: zturner, sas.

This doesn't seem right. PowerPC and Thumb on Windows? Greg, does OSX use any of this PECOFF code?

clayborg edited edge metadata.Sep 16 2016, 10:15 AM

I know we have uses of PECOFF for EFI, but our EFI guys actually run a converter to convert their PECOFF file over into mach-o and they use those when debugging in LLDB. So I don' think this change will affect anything on our end. But just to be safe, is there anything else that you can look at inside the PECOFF file to make sure the OS should be set to windows? Any hints in the imports/exports? I can ask our EFI guys for one of their PECOFF files if needed.

Well, I just need to set the correct OS when creating the ArchSpec so that it works well in conjunction with https://reviews.llvm.org/D24283. If I get it somehow from Target, would that be good enough?

I was assuming that PECOFF was win-only and I have no idea of what else to look for in the PECOFF file to determine the OS.

coff contains a subsystem field. Take a look at llvm/Support/COFF.h then search, for example, for IMAGE_SUBSYSTEM_EFI_APPLICATION. This is part of an enum called WindowsSubsystem. This field should exist in all PE/COFF files. I don't know if LLDB parses it. If it does you can just it. If not you might have to add some logic to extract this field out yourself. I agree it probably won't affect anything since this code isn't used by much outside of Windows, but I would rather the code be correct.

omg, i feel ashamed for not noticing that when i was reading the documentation, I'll do as you say, thanks!

clayborg accepted this revision.Sep 16 2016, 10:26 AM
clayborg edited edge metadata.

Go ahead and changes this for now, we'll see if we run into problems. I believe PECOFF is really only used on Windows right now, so we can worry about this when and if we run into problem.

This revision is now accepted and ready to land.Sep 16 2016, 10:26 AM

Sorry, I missed Zach's comment. If we can set this correctly then lets try.

wallace updated this revision to Diff 71875.Sep 19 2016, 1:51 PM
wallace edited edge metadata.

using the subsystem field

wallace updated this revision to Diff 71877.Sep 19 2016, 1:55 PM

clang-format

wallace retitled this revision from [lldb] Use the correct OS when determining the architecture of a PECOFF obj file to [lldb] Use the win32 OS when determining the architecture of a PECOFF obj file.Sep 19 2016, 1:56 PM
wallace updated this object.
wallace added a project: Restricted Project.

I was able to use that field and saw the field IMAGE_SUBSYSTEM_WINDOWS_GUI in the libraries I was loading

zturner accepted this revision.Sep 19 2016, 1:57 PM
zturner edited edge metadata.

I would pass llvm::Triple::UnknownOS instead of the constant 0, but otherwise this looks fine. I'll commit this later today.

Looks good.

source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
973

Use llvm::Triple::UnknownOS instead of 0 here and this will be good to go.

wallace updated this revision to Diff 71880.Sep 19 2016, 2:10 PM
wallace edited edge metadata.

use llvm::Triple::UnknownOS

wallace updated this revision to Diff 71882.Sep 19 2016, 2:18 PM

fix typo

ok let me try that patch first.

wallace closed this revision.Sep 20 2016, 6:39 PM

this was commited by zturner