This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Reorder --dump-section before --remove-section for ELF.
ClosedPublic

Authored by sameerarora101 on Jun 3 2020, 7:50 AM.

Details

Summary

Reorder DumpSection under handleArgs in
file ELFObjcopy.cpp. DumpSection is placed
before replaceAndRemoveSections and is therefore
now the first operation under handleArgs. Thus,
it is now performed before both add and remove
section operations.

Change for the MachO format at D81123. Together fixes https://bugs.llvm.org/show_bug.cgi?id=44283.

Diff Detail

Event Timeline

sameerarora101 created this revision.Jun 3 2020, 7:50 AM
sameerarora101 marked an inline comment as done.Jun 3 2020, 7:51 AM
sameerarora101 added inline comments.
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
275

Added by the linter!

smeenai added inline comments.Jun 3 2020, 10:55 AM
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
275

I'd probably undo this change, given that this part of the code isn't close to the part of the code you're modifying.

This comment was removed by sameerarora101.

Remove linter changes.

sameerarora101 marked an inline comment as done.Jun 3 2020, 11:19 AM
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
623
StringRef SectionName;
StringRef FileName;
std::tie(SectionName, FileName) = Flag.split('=');
sameerarora101 marked 2 inline comments as done.Jun 3 2020, 12:01 PM
sameerarora101 added inline comments.
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
623

Got it, thanks!

sameerarora101 marked an inline comment as done.

Decouple SecPair into SectionName and FileName.

Harbormaster completed remote builds in B58961: Diff 268261.
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
622

nit:

for (StringRef Flag : Config.DumpSection)

StringRef is usually passed by value (it's essentially just a pointer + size)

llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
622

and the same comment applies to https://reviews.llvm.org/D81123

llvm/test/tools/llvm-objcopy/ELF/dump-before-add-remove.test
11 ↗(On Diff #268274)

nit: it looks like it's the only place where these macros (INPUT, SECTION) are used. In this case we don't really need them, simply use the corresponding values directly (on the line 37)

MaskRay added inline comments.Jun 3 2020, 10:44 PM
llvm/test/tools/llvm-objcopy/ELF/dump-before-add-remove.test
1 ↗(On Diff #268274)

Perhaps dump-section-before-add-remove

3 ↗(On Diff #268274)

##

For new tests we use ## to make comments stand out from RUN/CHECK lines.

6 ↗(On Diff #268274)

You can dump the second line of od output (it prints the size) and delete wc -c

8 ↗(On Diff #268274)

the newly added

11 ↗(On Diff #268274)

I think we typically place CHECK lines before the tests. Some earlier tests do not follow the convention, but newer tests can.

18 ↗(On Diff #268274)

Delete excess indentation. Keep one just after Machine: , the longest key.

ditto below

llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
620

Section must be dumped -> Dump sections

Sorry, didn't see this patch when I posted on your Mach-O one! Thanks for it. @MaskRay and @alexshap seem to have been pretty comprehensive, so no more comments from me for now.

sameerarora101 marked 10 inline comments as done.Jun 4 2020, 7:07 AM
sameerarora101 added inline comments.
llvm/test/tools/llvm-objcopy/ELF/dump-before-add-remove.test
11 ↗(On Diff #268274)

I was able to do this for SECTION but it seems I still need to pass in the INPUT macro with FileCheck (it explicitly prints %t otherwise). Is that fine?

sameerarora101 marked an inline comment as done.

Updating source and test file according to the inline commments.

sameerarora101 edited the summary of this revision. (Show Details)Jun 4 2020, 9:19 AM
llvm/test/tools/llvm-objcopy/ELF/dump-before-add-remove.test
11 ↗(On Diff #268274)

I was able to do this for SECTION but it seems I still need to pass in the INPUT macro with FileCheck (it explicitly prints %t otherwise). Is that fine?

I would remove -DSECTION - it would slightly trim down the command line / look simpler

sameerarora101 marked 2 inline comments as done.Jun 4 2020, 11:53 AM
sameerarora101 added inline comments.
llvm/test/tools/llvm-objcopy/ELF/dump-before-add-remove.test
11 ↗(On Diff #268274)

Yup, removed it in the new revision, thanks.

sameerarora101 retitled this revision from [llvm-objcopy] Reorder --dump-section before --remove-section for ELF. Fixes PR44283 to [llvm-objcopy] Reorder --dump-section before --remove-section for ELF..Jun 4 2020, 11:53 AM
sameerarora101 edited the summary of this revision. (Show Details)
llvm/test/tools/llvm-objcopy/ELF/dump-section-before-add-remove.test
10

nit: to me it's somehow easier to read the test when the "check:" lines follow the corresponding invocations:

# RUN: llvm-objcopy ...
# RUN: llvm-objdump %t | FileCheck %s

# CHECK: Expected line 1
# CHECK: Expected line 2

!ELF
FileHeader:
   Class: ...

not sure how it compares with what @MaskRay mentioned above, I do not have a strong opinion regarding this.

Ktwu added inline comments.Jun 4 2020, 1:25 PM
llvm/test/tools/llvm-objcopy/ELF/dump-section-before-add-remove.test
10

I visually prefer CHECKs after RUNs as well, and it's what folks in lld have been doing, too (and it's also consistent with the NODUMP check below -- the FileCheck happens before the NODUMP).

</2cents>

sameerarora101 marked an inline comment as done.
sameerarora101 edited the summary of this revision. (Show Details)

Updating %ts and '='.

jhenderson accepted this revision.Jun 5 2020, 12:09 AM

LGTM, once my two comments have been addressed. Also, please replace the PR reference with a real bug URL.

llvm/test/tools/llvm-objcopy/ELF/dump-section-before-add-remove.test
7

Nit: "before it is removed".

10

+1 - this is also my prefererred style

This revision is now accepted and ready to land.Jun 5 2020, 12:09 AM
sameerarora101 marked 5 inline comments as done.Jun 5 2020, 6:19 AM
sameerarora101 added inline comments.
llvm/test/tools/llvm-objcopy/ELF/dump-section-before-add-remove.test
10

ok, moving it down then.

Putting CHECKs after the RUNs.

sameerarora101 edited the summary of this revision. (Show Details)Jun 5 2020, 6:23 AM

Thanks for the reviews everyone 😊

jhenderson accepted this revision.Jun 5 2020, 7:42 AM
MaskRay accepted this revision.Jun 5 2020, 8:17 AM
MaskRay added inline comments.
llvm/test/tools/llvm-objcopy/ELF/dump-section-before-add-remove.test
9

CHECK-NEXT:

sameerarora101 marked an inline comment as done.Jun 5 2020, 8:51 AM

Updating test: CHECK -> CHECK-NEXT

This revision was automatically updated to reflect the committed changes.