This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][COFF] Implement --update-section
ClosedPublic

Authored by abrachet on Jan 25 2022, 2:03 PM.

Diff Detail

Event Timeline

abrachet requested review of this revision.Jan 25 2022, 2:03 PM
abrachet created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 2:03 PM

This looks sensible to me, thanks!

I think we should let @jhenderson have a look at it still though. I think he's out at the moment, but he's hopefully back soon. (Then again, the 14.x branch is happening soon, and in case he's not back before then, and if you have a need to have this included in the branch, I think it could be ok to go ahead sooner, and deal with other feedback later.)

This looks sensible to me, thanks!

I think we should let @jhenderson have a look at it still though. I think he's out at the moment, but he's hopefully back soon. (Then again, the 14.x branch is happening soon, and in case he's not back before then, and if you have a need to have this included in the branch, I think it could be ok to go ahead sooner, and deal with other feedback later.)

Sounds good.

llvm/test/tools/llvm-objcopy/COFF/update-section.test
11

Use llvm-readobj -S -x .text to test the section header and dump the content.

21

Add a test for an IMAGE_SCN_CNT_UNINITIALIZED_DATA section like .bss. There should be an error similar to ELF SHT_NOBITS

27

Consider adding another section and testing two --update-section

abrachet updated this revision to Diff 403772.Jan 27 2022, 1:10 PM
abrachet added a reviewer: MaskRay.
abrachet marked 2 inline comments as done.
abrachet added inline comments.
llvm/test/tools/llvm-objcopy/COFF/update-section.test
21

This works because the data size is 0. Do you want an explicit check for IMAGE_SCN_CNT_UNINITIALIZED_DATA?

MaskRay added a comment.EditedJan 27 2022, 2:17 PM

ELF has such a diagnostic

% fllvm-objcopy --update-section .bss=xxx a.o b.o
/tmp/RelA/bin/llvm-objcopy: error: 'a.o': section '.bss' can't be updated because it does not have contents

% objcopy --update-section .bss=xxx a.o b.o
objcopy: b.o[.bss]: section has no contents

(I might use cannot instead of "can't" for the ELF diagnostic.)

PE/COFF may need something similar.

abrachet updated this revision to Diff 403865.Jan 27 2022, 7:59 PM
MaskRay added inline comments.Jan 27 2022, 8:07 PM
llvm/test/tools/llvm-objcopy/COFF/update-section.test
17

Align the values, i.e.

# SMALLER:      Section {
# SMALLER-NEXT:   Number: 1
# SMALLER-NEXT:   Name: .text
# SMALLER-NOT:  }
# SMALLER:        RawDataSize: 4

And use NOT: } to ensure RawDataSize is in the same Section.

llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
258
266
269
abrachet updated this revision to Diff 403869.Jan 27 2022, 8:23 PM
MaskRay accepted this revision.Jan 27 2022, 8:40 PM

I agree it'd be great to let @jhenderson have a look at it, but seem fine to catch up the 14.x branch and address other issues.

llvm/test/tools/llvm-objcopy/COFF/update-section.test
38

Hex dump of section '.text': should be aligned, too.

49

This needs a diagnostic.

70

delete unused symbols:

This revision is now accepted and ready to land.Jan 27 2022, 8:40 PM
abrachet updated this revision to Diff 403883.Jan 27 2022, 9:40 PM
abrachet marked 8 inline comments as done.

Thanks for the review @MaskRay

I agree it'd be great to let @jhenderson have a look at it, but seem fine to catch up the 14.x branch and address other issues.

Yes I'll wait for James. Theres no rush on my end to get this in before llvm 14.

llvm/test/tools/llvm-objcopy/COFF/update-section.test
70

Looks like I can't error: missing required key 'symbols'

jhenderson added inline comments.Feb 1 2022, 7:13 AM
llvm/test/tools/llvm-objcopy/COFF/update-section.test
17

Just confirming that it is deliberate to keep the section size the same, padded with 0? For ELF, the section is shrunk, which feels more like what I'd expect.

26–27

I have a minor preference for the suggested edit style for flowing over multiple lines.

50

If this is a system error message, there may be a between different OS versions. I believe lit now has substitutions for common error messages to handle this. Look for "%errc_ENOENT" for example usage.

abrachet updated this revision to Diff 404984.Feb 1 2022, 10:09 AM
abrachet marked an inline comment as done.

Change output section size

abrachet marked 3 inline comments as done.Feb 1 2022, 10:10 AM
abrachet added inline comments.
llvm/test/tools/llvm-objcopy/COFF/update-section.test
17

I've changed the size of the section

jhenderson accepted this revision.Feb 2 2022, 12:11 AM

LGTM, but please wait for @MaskRay.

MaskRay accepted this revision.Feb 2 2022, 3:38 PM

Thanks!

This revision was landed with ongoing or failed builds.Feb 3 2022, 1:31 PM
This revision was automatically updated to reflect the committed changes.
abrachet marked an inline comment as done.