This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Add option to add a progbits section from a file
ClosedPublic

Authored by jakehehrlich on Dec 13 2017, 4:59 PM.

Details

Diff Detail

Repository
rL LLVM

Event Timeline

jakehehrlich created this revision.Dec 13 2017, 4:59 PM

Test case?

tools/llvm-objcopy/Object.h
129 ↗(On Diff #126874)

I'm not convinced about the name of the class - how is it different from a Section? It's primarily because the data is owned, isn't it?

Perhaps OwnedDataSection? What do you think?

tools/llvm-objcopy/llvm-objcopy.cpp
116 ↗(On Diff #126874)

Has this line been clang-formatted? It looks quite long.

jakehehrlich added inline comments.Dec 14 2017, 3:53 PM
tools/llvm-objcopy/Object.h
129 ↗(On Diff #126874)

Yep the point is that it owns the data. That seems like a better name. I'll switch it to that.

  1. Added test. I think I just didn't run git add -A before I ran git diff last time
  2. Changed names
  3. Fixed formatting issues.
jhenderson added inline comments.Dec 15 2017, 1:25 AM
tools/llvm-objcopy/llvm-objcopy.cpp
183–196 ↗(On Diff #127046)

It looks like GNU objcopy does add-section after removal of sections. I think we should do the same, so this block of code should move after the removeSections call, but before finalize.

Also, a test demonstrating this point would be good.

This behaviour makes sense, because it allows you to replace the section contents of an existing section.

By the way, I also discovered that for some reason, GNU objcopy won't let you add another instance of a section that already exists. I don't think we need to match this behaviour - it's perfectly valid to add such a section.

I agree on the points about replacement and about not following what GNU objcopy does on duplicate sections.

  1. Added test to show that you can replace a section using --remove-section and --add-section
  2. Moved the AddSection code to after section removal.
This revision is now accepted and ready to land.Dec 18 2017, 1:36 AM
This revision was automatically updated to reflect the committed changes.