This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] [COFF] Implement --add-gnu-debuglink
ClosedPublic

Authored by mstorsjo on Jan 21 2019, 2:05 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Jan 21 2019, 2:05 AM
jhenderson added inline comments.Jan 21 2019, 6:49 AM
test/tools/llvm-objcopy/COFF/add-gnu-debuglink.test
3–4 ↗(On Diff #182759)

I know it's not strictly necessary, but it would be nice if comments like this had some sort of leading character, e.g. '#' to make them stand out better.

23 ↗(On Diff #182759)

Just to confirm, this new section is supposed to have a virtual address, i.e. it is loaded at runtime?

tools/llvm-objcopy/COFF/COFFObjcopy.cpp
38 ↗(On Diff #182759)

Are sections required to be in address order?

52 ↗(On Diff #182759)

Rather than modifying in place via a reference, I think it would be better if this returned the section data.

54 ↗(On Diff #182759)

This is probably an instance of too much auto.

169 ↗(On Diff #182759)

I just want to confirm that GNU objcopy doesn't add a gnu debug link section if it is not PE?

tools/llvm-objcopy/COFF/Object.h
46 ↗(On Diff #182759)

I'd probably rename this to ModifiedContents or similar. It isn't clear to me what "Local" means in this context.

mstorsjo marked 2 inline comments as done.Jan 21 2019, 8:27 AM
mstorsjo added inline comments.
tools/llvm-objcopy/COFF/COFFObjcopy.cpp
169 ↗(On Diff #182759)

I'll have a look.

tools/llvm-objcopy/COFF/Object.h
46 ↗(On Diff #182759)

Ok - or maybe rename the old one OrigContents instead?

jhenderson added inline comments.Jan 21 2019, 8:40 AM
tools/llvm-objcopy/COFF/Object.h
46 ↗(On Diff #182759)

Either works for me.

mstorsjo marked 13 inline comments as done.Jan 21 2019, 1:47 PM
mstorsjo added inline comments.
test/tools/llvm-objcopy/COFF/add-gnu-debuglink.test
3–4 ↗(On Diff #182759)

Ok, will add. (The same goes for a lot of the other tests I've added here as well.)

23 ↗(On Diff #182759)

This is at least how GNU objcopy does it. It's not loaded at runtime (it's got the IMAGE_SCN_MEM_DISCARDABLE flag set which means not loaded), but despite this all sections get a virtual address allocated. IIRC windows is pretty picky with this - all sections need to be consecutive without holes, even the ones that aren't loaded.

tools/llvm-objcopy/COFF/COFFObjcopy.cpp
38 ↗(On Diff #182759)

I believe so, yes: https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#section-table-section-headers

In an image file, the VAs for sections must be assigned by the linker so that they are in ascending order and adjacent, and they must be a multiple of the SectionAlignment value in the optional header.

52 ↗(On Diff #182759)

Sure

54 ↗(On Diff #182759)

Ok, will write out the types. (The ELF dir uses auto similarly though.)

169 ↗(On Diff #182759)

GNU objcopy doesn't make a difference, so I'll remove that condition.

mstorsjo updated this revision to Diff 182825.Jan 21 2019, 1:55 PM
mstorsjo marked 5 inline comments as done.

Addressed the review comments.

jhenderson added inline comments.Jan 22 2019, 2:16 AM
tools/llvm-objcopy/COFF/COFFObjcopy.cpp
57 ↗(On Diff #182825)

This one CAN be auto, because its type is clear from the type of LinkTargetOrErr.

54 ↗(On Diff #182759)

I know, and I've disagreed with it there in some places too!

tools/llvm-objcopy/COFF/Object.h
46 ↗(On Diff #182825)

Thinking about this a bit more, I wonder if it would be a good idea for there to be a getContents function that decides which to fetch. This feels like a potential risk point for bugs, if people try to get Contents when it is owned by OrigContents. You'd want to make them both private as a result, and therefore add some setters too.

mstorsjo marked 4 inline comments as done.Jan 22 2019, 2:38 AM
mstorsjo added inline comments.
tools/llvm-objcopy/COFF/Object.h
46 ↗(On Diff #182825)

Right, that makes the code much clearer.

mstorsjo updated this revision to Diff 182869.Jan 22 2019, 2:39 AM
mstorsjo marked an inline comment as done.

Addressed review comments.

This revision is now accepted and ready to land.Jan 22 2019, 2:45 AM
This revision was automatically updated to reflect the committed changes.
jhenderson added inline comments.Jan 22 2019, 3:20 AM
llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
292–293

I didn't spot this earlier, but why are you padding assuming it is x86?

mstorsjo marked an inline comment as done.Jan 22 2019, 8:57 AM
mstorsjo added inline comments.
llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
292–293

Yeah, ideally we'd use a different padding pattern for other arches. So far, LLD/COFF always uses this padding pattern regardless of architecture (while LLD/ELF uses arch specific paddings), and I'm matching that behaviour for now here. I'd like to bring it up for discussion in LLD first, and once some other paddings are settled on there, I'd implement the same over here.