This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] [COFF] Error out on use of unhandled options
ClosedPublic

Authored by mstorsjo on Jan 22 2019, 3:49 AM.

Details

Summary

Prefer erroring out than silently not doing what was requested.

The current set of implemented options are the only ones used in my test corpus.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Jan 22 2019, 3:49 AM
rupprecht accepted this revision.Jan 22 2019, 3:48 PM

This doesn't seem like the best solution long-term, but probably makes testing llvm-objcopy on COFF much easier (expose missing functionality more loudly).

Maybe we could add something to the tablegen saying which object type each flag is supported for, and if that flag is set & we detect the input is not that object type, error?

This revision is now accepted and ready to land.Jan 22 2019, 3:48 PM

This doesn't seem like the best solution long-term, but probably makes testing llvm-objcopy on COFF much easier (expose missing functionality more loudly).

Maybe we could add something to the tablegen saying which object type each flag is supported for, and if that flag is set & we detect the input is not that object type, error?

That's probably a better long term solution, but also not quite trivial to do. The detection of which format is being handled happens long after the options are parsed:

static void executeObjcopyOnBinary(const CopyConfig &Config, object::Binary &In,
                                   Buffer &Out) {
  if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In))
    return elf::executeObjcopyOnBinary(Config, *ELFBinary, Out);
  else if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In))
    return coff::executeObjcopyOnBinary(Config, *COFFBinary, Out);
  else
    error("Unsupported object file format");
}

At this point, the options have already been parsed out from the arguments and set in CopyConfig.

Also in a pathological case, with an archive file you could have different archive members of different formats...

This revision was automatically updated to reflect the committed changes.