This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy][NFC] remove split dwo file creation from executeObjcopyOnBinary.
ClosedPublic

Authored by avl on Mar 13 2021, 8:37 AM.

Details

Summary

This patch removes creation of the resulting file from the
executeObjcopyOnBinary() function. For the most use cases, the
executeObjcopyOnBinary receives output file as a parameter

  • raw_ostream &Out. The splitting .dwo file is implemented differently:

file containg .dwo tables is created inside executeObjcopyOnBinary().
When objcopy functionality would be moved into separate library,
current implementation will become inconvenient. The goal of that
refactoring is to separate concerns: It might be convenient to
to do dwo tables splitting but to create resulting file differently.

Diff Detail

Event Timeline

avl created this revision.Mar 13 2021, 8:37 AM
avl requested review of this revision.Mar 13 2021, 8:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2021, 8:37 AM
avl updated this revision to Diff 330474.Mar 13 2021, 2:15 PM

fix a mistake.

avl retitled this revision from [llvm-objcopy] remove split dwo file creation from executeObjcopyOnBinary. to [llvm-objcopy][NFC] remove split dwo file creation from executeObjcopyOnBinary..Mar 13 2021, 2:16 PM
MaskRay accepted this revision.Mar 16 2021, 11:52 AM

LGTM.

This revision is now accepted and ready to land.Mar 16 2021, 11:52 AM
jhenderson added inline comments.Mar 17 2021, 2:36 AM
llvm/tools/llvm-objcopy/llvm-objcopy.cpp
329–332

You don't need the = nullptr here, I believe.

347–351

This code duplication is a real step backwards from what was there before. I think it would be far better to share the code for ihex and binary, with only a very localised if, probably inside the lambda, to choose the right function to run. Possible example:

if (Config.InputFormat == FileFormat::Binary || Config.InputFormat == FileFormat::IHex) {
    ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
        MemoryBuffer::getFileOrSTDIN(Config.InputFilename);
    if (!BufOrErr)
      return createFileError(Config.InputFilename, BufOrErr.getError());
    MemoryBufferHolder = std::move(*BufOrErr);
    ObjcopyFunc = [&](raw_ostream &OutFile) -> Error {
      switch(Config.InputFormat) {
      case FileFormat::Binary:
        return executeObjcopyOnRawBinary(Config, *MemoryBufferHolder, OutFile);
      case FileFormat::IHex:
        return executeObjcopyOnIHex(Config, *MemoryBufferHolder, OutFile);
    };
} else {
  ...
}
380–381

I think this should be pulled out into a helper variable, since it's repeated in each instance.

385

A pair of short comments at each of this and the following stage would be helpful to show which part is doing what.

avl added inline comments.Mar 17 2021, 5:51 AM
llvm/tools/llvm-objcopy/llvm-objcopy.cpp
380–381

I left this code assuming it would be deleted by by D98511.

avl updated this revision to Diff 331299.Mar 17 2021, 10:01 AM

addressed comments.

jhenderson accepted this revision.Mar 18 2021, 1:03 AM

LGTM.

llvm/tools/llvm-objcopy/llvm-objcopy.cpp
384–385

A bit more verbose than I had in mind, but it's fine.

avl added a comment.Mar 18 2021, 3:24 AM

Thank you for the review.

This revision was landed with ongoing or failed builds.Mar 18 2021, 3:46 AM
This revision was automatically updated to reflect the committed changes.