This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][MachO] Fix adding multiple sections
ClosedPublic

Authored by eqv on Nov 3 2020, 8:46 AM.

Details

Summary

Added a test for the broken behavior and fixed size field in newly added sections.

Test Plan:

in
cd ~/local/toolchain_dev/build/Release/Linux-x86_64/toolchain # run:
ninja check-llvm-tools-llvm-objcopy # run all tests for objcopy
ninja check-llvm # run all LLVM tests ... it's good practice

Diff Detail

Event Timeline

eqv created this revision.Nov 3 2020, 8:46 AM
eqv requested review of this revision.Nov 3 2020, 8:46 AM
eqv added a reviewer: smeenai.Nov 3 2020, 8:49 AM

Mechanical note: we try to keep the first line of the commit message concise (preferably under 72 characters; some people try to keep it under 50). We also usually add tags in square brackets to indicate the areas the patch touches. A conventional subject line for this commit would be something like:

[llvm-objcopy][MachO] Fix adding multiple sections
llvm/test/tools/llvm-objcopy/MachO/add-multiple-sections.test
1

I'd also add a test for adding two new sections into two different segments.

There's a couple of more tests for --add-section that would be good to have, but fall outside the scope of this diff (they're better suited for add-section-error.test). I'm also note sure what the desired behavior for them is (maybe @alexshap would know):

  • Issuing multiple --add-section commands with the same section name.
  • Attempting to add a section with the same name and segment as an existing section.
MaskRay added inline comments.Nov 3 2020, 1:29 PM
llvm/test/tools/llvm-objcopy/MachO/add-multiple-sections.test
3

Drive-by: I think the test should be folded into add-section-64.test

eqv retitled this revision from added test & fixed broken "add more than one section" workflow in objcopy on MachO Binaries. to [llvm-objcopy][MachO] Fix adding multiple sections.Nov 3 2020, 1:30 PM

Any ideas why seemingly unrelated tests are failing? Is this something I should worry about?

In D90690#2372192, @eqv wrote:

Any ideas why seemingly unrelated tests are failing? Is this something I should worry about?

I wouldn't worry about it. The symtab-sh-info.s failure is a known issue, and D88348 should fix that. Dunno about the other one, but it's pretty clearly unrelated.

llvm/test/tools/llvm-objcopy/MachO/add-multiple-sections.test
1

I'd also add a test for adding two new sections into two different segments.

+1

Issuing multiple --add-section commands with the same section name.

I'm not sure either, e.g. I've done a quick experiment on OSX - created a binary with multiple sections having the same name (and belonging to the same segment) and it appears to work fine (in particular, the dynamic loader doesn't complain). There are other potential issues here which would be good to detect (e.g. adding sections into an existing binary can actually break it (e.g. segments might start to overlap), but I think this is out of scope for the current diff, the proposed fix (in MachOObject.cpp) is actually very useful.

7

nit: Add a new section twice ...

13

nit: Add two new sections ...

55
  1. nit: the lines 55-57 are not particularly useful / relevant for this test, I'd start with Sections [ ...
  1. CHECK: CHECK-NEXT: ...
llvm/test/tools/llvm-objcopy/MachO/add-multiple-sections.test
1

(i meant adding sections into an existing segment ...)

llvm/test/tools/llvm-objcopy/MachO/add-multiple-sections.test
3

I was thinking about it too and but now it seems to me that it would be better to keep this test separate.
That test (as well as add-section-32.test) verifies a number of things related to adding sections and I would prefer not to overload it further with extra logic. It makes things a bit easier to maintain.

eqv updated this revision to Diff 302699.Nov 3 2020, 3:05 PM

fixed nitpicks

eqv updated this revision to Diff 302989.Nov 4 2020, 4:17 PM
eqv marked 3 inline comments as done.

added test for two different segments

besides a small nit this looks reasonable to me, I'd wait for @smeenai to take a look as well

llvm/test/tools/llvm-objcopy/MachO/add-multiple-sections.test
12

nit: i'd probably rename CHECK-A -> CASE1, CHECK-B -> CASE3

This revision is now accepted and ready to land.Nov 5 2020, 1:03 PM
smeenai accepted this revision.Nov 6 2020, 12:17 PM

LGTM

eqv updated this revision to Diff 303538.Nov 6 2020, 1:40 PM
eqv marked 4 inline comments as done.

fixed CHECK-A => CHECK-1

This revision was landed with ongoing or failed builds.Nov 7 2020, 6:19 PM
This revision was automatically updated to reflect the committed changes.