Page MenuHomePhabricator

[objcopy][NFC] Add doc comments to the executeObjcopy* functions.
AcceptedPublic

Authored by avl on Tue, Nov 23, 2:58 AM.

Details

Diff Detail

Event Timeline

avl created this revision.Tue, Nov 23, 2:58 AM
avl requested review of this revision.Tue, Nov 23, 2:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Nov 23, 2:58 AM
jhenderson added inline comments.Thu, Nov 25, 1:19 AM
llvm/include/llvm/Object/ObjCopy/COFF/COFFObjcopy.h
27
llvm/include/llvm/Object/ObjCopy/ELF/ELFObjcopy.h
27
35

"Binary" format isn't particularly descriptive, since it's more that objcopy should just wrap the data in a section and add some symbols. Technically all files on disk are "binary" format, since they are written in binary!

43

I'm a little thrown by the "Unspecified" format. I'm guessing that's just because earlier logic will detect that the input buffer is an ELF file if no explicit input format is specified, and feed it through to here. If that's the case, we shouldn't be mentioning this case, since in both cases, we're working with an ELF file.

llvm/include/llvm/Object/ObjCopy/MachO/MachOObjcopy.h
28

I'm assuming this is correct, i.e. that the input binary must be Mach-O to get here?

35
llvm/include/llvm/Object/ObjCopy/wasm/WasmObjcopy.h
26
avl added inline comments.Thu, Nov 25, 2:12 AM
llvm/include/llvm/Object/ObjCopy/ELF/ELFObjcopy.h
43

The idea of these descriptions is to match with values which are in:

struct CommonConfig {
...
  FileFormat InputFormat = FileFormat::Unspecified;
...
};

enum class FileFormat {
  Unspecified,
  ELF,
  Binary,
  IHex,
};

It would probably be better to make FileFormat more descriptive by adding values: COFF, MachO, Wasm instead of Unspecified; RawELF instead of Binary... But I think this refactoring should be done separately. The idea of current doc comments is to show connection of CommonConfig.InputFormat and corresponding executeObjcopyOn* functions.

avl added inline comments.Thu, Nov 25, 3:15 AM
llvm/include/llvm/Object/ObjCopy/ELF/ELFObjcopy.h
43

Current logic is that Unspecified is used for all formats:

// FIXME:  Currently, we ignore the target for non-binary/ihex formats
// explicitly specified by -I option (e.g. -Ielf32-x86-64) and guess the
// format by llvm::object::createBinary regardless of the option value.
Config.InputFormat = StringSwitch<FileFormat>(InputFormat)
                         .Case("binary", FileFormat::Binary)
                         .Case("ihex", FileFormat::IHex)
                         .Default(FileFormat::Unspecified);

So, How about that variant:

/// Applies the transformations described by \p Config and \p ELFConfig to
/// \p In, which must be an ELF object(FileFormat::Unspecified), and writes
/// the result into \p Out.

?

jhenderson added inline comments.Thu, Nov 25, 3:31 AM
llvm/include/llvm/Object/ObjCopy/COFF/COFFObjcopy.h
27

See below: actually just delete the bit in brackets, so it's "... \p In and writes...".

llvm/include/llvm/Object/ObjCopy/ELF/ELFObjcopy.h
43

The FileFormat specified in the Config is completely irrelevant in these functions - a future piece of code may not use the FileFormat, so mentioning it in the comments is confusing at best, and at worst directly misleading.

What matters is what the code in the function expects the format of the input to be. In fact, I realised in this case that we are already passing in an ELFObjectFileBase for In, so we probably don't need to say anything specifically about In at all, i.e. the comment should be "... to \p In and writes ..."

llvm/include/llvm/Object/ObjCopy/MachO/MachOObjcopy.h
28

Scratch this: just delete the the bit between "In" and the "and writes". The type is already defined by the type of In.

35

Same as above: delete the bit after "In" up to (but not including) "and writes".

llvm/include/llvm/Object/ObjCopy/wasm/WasmObjcopy.h
26

As above, just delete the bit between "In" and "and writes".

avl updated this revision to Diff 389863.Thu, Nov 25, 12:25 PM

addressed comments.

jhenderson added inline comments.Fri, Nov 26, 12:09 AM
llvm/include/llvm/Object/ObjCopy/ELF/ELFObjcopy.h
27

In this and the next case, you probably still want the full inline suggestion, as the format isn't defined by the input type (a MemoryBuffer doesn't know whether it's to be treated as IHex or raw binary, or something else entirely).

avl updated this revision to Diff 389984.Fri, Nov 26, 3:53 AM

addressed comments.

Please use my inline suggestions, not your original text, as requested in the comment already...

avl updated this revision to Diff 390005.Fri, Nov 26, 4:24 AM

addressed comments.

jhenderson accepted this revision.Fri, Nov 26, 5:35 AM

Thanks, LGTM.

This revision is now accepted and ready to land.Fri, Nov 26, 5:35 AM
avl added a comment.Fri, Nov 26, 6:20 AM

Thank you for the review.

MaskRay accepted this revision.Fri, Nov 26, 10:34 AM
MaskRay added inline comments.
llvm/include/llvm/Object/ObjCopy/ELF/ELFObjcopy.h
26

I think imperative sentences are more common: Applies => Apply