This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] -p: Dump PE header for PE/COFF
ClosedPublic

Authored by MaskRay on Nov 6 2021, 5:40 PM.

Details

Summary

For a trivial DLL built with clang --target=x86_64-windows -O2 -c a.c; lld-link -subsystem:console -dll a.o -out:a.dll,
objdump -p vs llvm-objdump -p:

-a.dll:     file format pei-x86-64
-
+a.dll: file format coff-x86-64
 Characteristics 0x2022
        executable
        large address aware
@@ -57,4 +56,4 @@
 Entry d 0000000000000000 00000000 Delay Import Directory
 Entry e 0000000000000000 00000000 CLR Runtime Header
 Entry f 0000000000000000 00000000 Reserved
-
+Export Table:

For a Linux image (vmlinuz-5.10.76-gentoo-r1) built with CONFIG_EFI_STUB=y
(https://www.kernel.org/doc/html/latest/admin-guide/efi-stub.html):

-vmlinuz-5.10.76-gentoo-r1:     file format pei-x86-64
-
-Characteristics 0x20e
+vmlinuz-5.10.76-gentoo-r1:     file format coff-x86-64
+Characteristics 0x206
        executable
        line numbers stripped
-       symbols stripped
        debugging information removed

 Time/Date              Wed Dec 31 16:00:00 1969
@@ -55,10 +53,4 @@
 Entry d 0000000000000000 00000000 Delay Import Directory
 Entry e 0000000000000000 00000000 CLR Runtime Header
 Entry f 0000000000000000 00000000 Reserved
-
-
-PE File Base Relocations (interpreted .reloc section contents)
-
-Virtual Address: 000037ca Chunk size 10 (0xa) Number of fixups 1
-       reloc    0 offset    0 [37ca] ABSOLUTE
-
+Export Table:

symbols stripped looks like a GNU objdump problem.

Diff Detail

Event Timeline

MaskRay created this revision.Nov 6 2021, 5:40 PM
MaskRay requested review of this revision.Nov 6 2021, 5:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 6 2021, 5:40 PM
alexander-shaposhnikov added inline comments.
llvm/tools/llvm-objdump/COFFDump.cpp
42

explicit
maybe pass const ref ? (e.g. nullptr is not a valid value for the argument)

51

where is this method used ?

63

this method does not appear to use Obj or Is64, make it static ?

81

static constexpr ?

166

constexpr ?

185

maybe 16 can be replaced with a named constant or some expression ?

MaskRay updated this revision to Diff 385320.Nov 6 2021, 8:03 PM
MaskRay marked 6 inline comments as done.

thanks for the review comments. applied

llvm/tools/llvm-objdump/COFFDump.cpp
42

OK, I switched printCOFFFileHeader as well.

81

constexpr suffices.

A non-template variable of non-volatile const-qualified type having namespace-scope has internal linkage ([basic.link]), so no need for static.

166

constexpr applies to the object declaration (DirName is a constexpr) which has a different meaning: the element type will be char* which will lead to -Wwrite-strings.

static constexpr const char *DirName[16] works but it is just unnecessarily verbose.

llvm/tools/llvm-objdump/COFFDump.cpp
166

Yeah, I meant the latter, perhaps, it doesn't matter much here.

jhenderson added inline comments.Nov 8 2021, 12:32 AM
llvm/test/tools/llvm-objdump/COFF/private-headers.yaml
70

Here and the other zero-valued fields, it might be advisable to use a non-zero value, to avoid any instances of variables not actually being assigned values properly (e.g. they were assigned to the wrong value/the wrong variable was assigned this variable's value etc).

llvm/tools/llvm-objdump/COFFDump.cpp
42

Looks like explicit is still needed?

MaskRay updated this revision to Diff 385550.Nov 8 2021, 10:10 AM
MaskRay marked 3 inline comments as done.

improve tests

MaskRay added inline comments.Nov 8 2021, 10:12 AM
llvm/test/tools/llvm-objdump/COFF/private-headers.yaml
70

I copied the fields from an existing test. Updated.

Nothing to add from me here, the patch looks fine to me (when others are ok with it).

jhenderson accepted this revision.Nov 9 2021, 12:20 AM

LGTM, although best wait for @alexander-shaposhnikov

This revision is now accepted and ready to land.Nov 9 2021, 12:20 AM
MaskRay edited the summary of this revision. (Show Details)Nov 9 2021, 10:08 AM
This revision was automatically updated to reflect the committed changes.
Unknown Object (User) added a subscriber: Unknown Object (User).Oct 19 2022, 6:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 6:51 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
Unknown Object (User) added a comment.Oct 19 2022, 6:52 PM

Thank you for your input! It has been quite beneficial to me!
redactle unlimited