This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] Refactor llvm-objcopy to allow llvm-strip to differ
AbandonedPublic

Authored by jakehehrlich on Dec 11 2017, 4:45 PM.

Details

Summary

Being a drop in replacement for GNU objcopy has been a desire of the project as it has been devolved but we'd also like to replace GNU strip as well. Unfortunately they sport different interfaces and in one cases their interfaces contradict each other. This change adds a means of allowing for different behavior between objcopy and strip.

  1. The options have been moved down further into the code and put into a namespace so that they're relatively hidden
  2. InvokeMain now calls the appropriate function either Strip or Objcopy
  3. The CopyConfig struct was added (and CopyBinary made a method of it) in order to drive CopyBinary instead of the options directly
  4. The only difference added between llvm-objcopy and llvm-strip right now is that llvm-strip defaults to --strip-all

Diff Detail

Repository
rL LLVM

Event Timeline

jakehehrlich created this revision.Dec 11 2017, 4:45 PM

Added test for the "-S" option's behavior in both cases. Everything else should be common behavior.

It looks to me like you should split this change down into multiple parts, in no particular order:

  1. Create a symlink for llvm-strip, and show that you can test it for a basic case.
  2. Refactor the command-line options.
  3. Add explicit -o option.
  4. Add -S option.
  5. Add support for explicit -O elf (by the way, you need a test for this, probably a simple copy, and binary diff against it not being specified).

What do you think?

tools/llvm-objcopy/llvm-objcopy.cpp
165

Why this change?

235

Again why this change?

259

Ditto

That order of changes sounds pretty reasonable to me. I'll work on breaking it up.

tools/llvm-objcopy/llvm-objcopy.cpp
165

ToRemove (and Keep and OnlyKeep) are members of this. This function became a method so that I could change all the variables in it via CopyConfig's members. Adding "this" to the capture list lets me use ToRemove in this function.

jakehehrlich retitled this revision from [llvm-objcopy] Add alias and "driver" for llvm-strip to [llvm-objcopy] Refactor llvm-objcopy to allow llvm-strip to differ.
jakehehrlich edited the summary of this revision. (Show Details)

Split this diff up. This part of the split is most closely related to the original so I put it here.

jhenderson added inline comments.Dec 13 2017, 3:29 AM
test/tools/llvm-objcopy/basic-strip.test
1

I think you accidentally made this a diff against your previous version, although it's a new file!

tools/llvm-objcopy/llvm-objcopy.cpp
165

At least in this particular case, you are already capturing everything by reference anyway, so ToRemove seems to be available (at least in my MSVC build). The other two cases are fine. I'd also support here replacing the general & capture with an explicit this capture, since only ToRemove is used.

326

It feels to me like this should be a member of the CopyConfig class. Maybe even part of the constructor. Is there ever a case you can imagine when you would NOT want to call CommonConfig?

Oh, you also seem to have lost the changes that llvm-strip as an alias.

Oh, you also seem to have lost the changes that llvm-strip as an alias.

That's in another change that I added you as a reviewer on. This diff (the one that mentions adding a symlink) is relative to that one.

jakehehrlich added inline comments.Dec 13 2017, 2:17 PM
tools/llvm-objcopy/llvm-objcopy.cpp
326

Nope, I think it will always be called. Also I'm currently working on splitting this up into two separate binaries instead of using this symlink hack. This is going to go in a common .o file that both will use. Good idea.

This change as-is looks fine to me, except for the previously highlighted issue of incompatibility in the positional arguments between the two. If you're working on splitting it up, I think it's best to wait to see what comes out before I review this further.

tools/llvm-objcopy/llvm-objcopy.cpp
334–335

This needs clang-formatting.

jakehehrlich abandoned this revision.May 9 2018, 5:50 PM

Alex did this (and this is a stupidly old change)

test/tools/llvm-objcopy/basic-strip.test
1

That was on purpose, there's another diff up for review that needs to be reviewed first.