This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][COFF] Add support for --set-section-flags
ClosedPublic

Authored by sdmitriev on Jan 21 2020, 7:20 AM.

Diff Detail

Event Timeline

sdmitriev created this revision.Jan 21 2020, 7:20 AM
MaskRay added inline comments.
llvm/test/tools/llvm-objcopy/COFF/set-section-flags.test
2

-o

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
95

How do you get this list?

Have you verified that other flags will be dropped?

sdmitriev added inline comments.Jan 21 2020, 6:16 PM
llvm/test/tools/llvm-objcopy/COFF/set-section-flags.test
2

Ok.

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
95

Well, just by thinking what should be preserved:) I am not completely sure about the IMAGE_SCN_LNK_INFO, but the other flags from this list I think should be there.

sdmitriev updated this revision to Diff 239473.Jan 21 2020, 6:19 PM
sdmitriev marked 2 inline comments as done.

Addressed review comments.

Can you check (or did you already?) whether this matches how GNU objcopy behaves (for the cases in GNU objcopy that seem intentional/sensible at least)?

Can you check (or did you already?) whether this matches how GNU objcopy behaves (for the cases in GNU objcopy that seem intentional/sensible at least)?

Yes, I verified that mingw objcopy produces the same results for all tests from llvm/test/tools/llvm-objcopy/COFF/set-section-flags.test except tests error messages and new "exclude" flag. But I did not check what flags it preserves .

Can you check (or did you already?) whether this matches how GNU objcopy behaves (for the cases in GNU objcopy that seem intentional/sensible at least)?

Yes, I verified that mingw objcopy produces the same results for all tests from llvm/test/tools/llvm-objcopy/COFF/set-section-flags.test except tests error messages and new "exclude" flag. But I did not check what flags it preserves .

Ok - as @MaskRay asked about that, can you test which flags are preserved and which dropped implicitly as well?

Can you check (or did you already?) whether this matches how GNU objcopy behaves (for the cases in GNU objcopy that seem intentional/sensible at least)?

Yes, I verified that mingw objcopy produces the same results for all tests from llvm/test/tools/llvm-objcopy/COFF/set-section-flags.test except tests error messages and new "exclude" flag. But I did not check what flags it preserves .

Ok - as @MaskRay asked about that, can you test which flags are preserved and which dropped implicitly as well?

As far as I see it does not preserve any flags at all (except alignment flags). Do you suggest to do the same in llvm-objcopy?

sdmitriev updated this revision to Diff 239768.Jan 22 2020, 8:04 PM

Updated patch to match GNU binutils behavior.

The new exclude flag is pretty ELF-centric as things stand. I don't know if there's an equivalent COFF section characteristic that really maps to it. If not, we should either a) reject it, or b) accept it and do nothing with it except perhaps clear the flags. I tentatively prefer b) for simplicity, but regardless it should at least be tested. What do others think?

Documentation should be updated so that --set-section-flags is no longer listed as ELF-specific.

llvm/test/tools/llvm-objcopy/COFF/set-section-flags.test
4

Use '##' for comments to make them stand out better from lit/FileCheck directives. This is what we've tended to do in other new tests for readability.

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
220

Any particular reason you're making this const?

The new exclude flag is pretty ELF-centric as things stand. I don't know if there's an equivalent COFF section characteristic that really maps to it. If not, we should either a) reject it, or b) accept it and do nothing with it except perhaps clear the flags. I tentatively prefer b) for simplicity, but regardless it should at least be tested. What do others think?

I believe exclude flag which maps to SHF_EXCLUDE for ELF objects maps well to the COFF's IMAGE_SCN_LNK_REMOVE flag.

Documentation should be updated so that --set-section-flags is no longer listed as ELF-specific.

I agree. If documentation says that --set-section-flags is ELF specific it should definitely be updated.

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
220

Nothing specific, but I do not see any reasons why it cannot be const especially if we do not plan to modify pointee . Do you see any reasons why it cannot have const qualifier?

sdmitriev updated this revision to Diff 240088.Jan 23 2020, 8:20 PM

Addressed review comments.

sdmitriev marked 3 inline comments as done.Jan 23 2020, 8:21 PM
sdmitriev updated this revision to Diff 240090.Jan 23 2020, 8:51 PM

Updated documentation change.

jhenderson added inline comments.Jan 24 2020, 1:52 AM
llvm/docs/CommandGuide/llvm-objcopy.rst
440–441

These two lines need reflowing. We tend to try to keep lines within 80 characters in this document.

440–441

This is still under the "ELF-specific Options" section...

444

I feel like we should also document the effects on COFF objects. Otherwise, people aren't going to know what each setting does.

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
220

No specific reason, except that we don't often make local variables const from my experience.

sdmitriev updated this revision to Diff 240145.Jan 24 2020, 3:29 AM

Addressed review comments.

sdmitriev marked 7 inline comments as done.Jan 24 2020, 3:32 AM
sdmitriev added inline comments.
llvm/docs/CommandGuide/llvm-objcopy.rst
440–441

Right. I did not realize that there is a dedicated ELF-specific section. I have added --set-section-flags option description to the COFF-specific section.

jhenderson added inline comments.Jan 24 2020, 3:56 AM
llvm/docs/CommandGuide/llvm-objcopy.rst
440–441

I've actually just removed the COFF-specific section (see rG0298a8751152). The normal approach would be to put the whole lot in the generic section (since the switch applies to multiple formats), and put the individual ELF and COFF bits one below the other in the description. See --strip-all for a sort-of example (it explains ELF and then COFF/Mach-O).

sdmitriev updated this revision to Diff 240160.Jan 24 2020, 4:34 AM
sdmitriev marked an inline comment as done.

Updated documentation change.

jhenderson added inline comments.Jan 24 2020, 5:39 AM
llvm/docs/CommandGuide/llvm-objcopy.rst
143

I'd probably rephrase this as follows:

"For ELF objects, the flags have the following effects:"

I'd also rephrase the COFF one similarly.

158

add -> add the

Here and on each subsequent line starting with "add".

159

unless -> unless the

sdmitriev updated this revision to Diff 240169.Jan 24 2020, 5:54 AM
sdmitriev marked 3 inline comments as done.

Addressed comments.

jhenderson accepted this revision.Jan 24 2020, 6:04 AM

Okay, LGTM, but I'd like somebody with more COFF familiarity to confirm they're happy.

This revision is now accepted and ready to land.Jan 24 2020, 6:04 AM

LGTM from a COFF perspective

This revision was automatically updated to reflect the committed changes.