[PATCH] D99055: [llvm-objcopy] Refactor CopyConfig structure.
Alexey Lapshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 27 03:24:12 PDT 2021
avl added a comment.
> I think before you go too much further with this refactoring, it would be a good idea if we have subsequent patches ready to see which make use of this. Without a concrete use-case, we are making change for no particular reason. With the subsequent patches, we can then see whether the refactoring here and elsewhere actually makes sense for the final use-case.
https://reviews.llvm.org/D86539 is the example of possible use(it is a bit outdated, but still shows a usecase).
Please, consider following fragment:
template <class ELFT>
Error writeOutputFile(const Options &Options, ELFObjectFile<ELFT> &InputFile,
DataBits &OutBits) {
DwarfutilConfigManager Config;
Config.InputFilename = Options.InputFileName;
Config.OutputFilename = Options.OutputFileName;
if (Options.Compress)
Config.CompressionType = DebugCompressionType::GNU;
Config.DecompressDebugSections = Options.Decompress;
if (Options.StripAll) {
Config.StripDebug = true;
} else if (Options.Decompress) {
Config.DecompressDebugSections = true;
} else {
if (Expected<ELFObjectFile<ELFT>> MemFile =
ELFObjectFile<ELFT>::create(MemoryBufferRef(OutBits, ""))) {
if (Options.StripUnoptimizedDebug) {
// Delete all debug sections. Debug sections which have optimized
// pair should be deleted as they would be replaced with paired
// optimized version. Debug section which does not have optimized pair
// should be deleted since they could become incorrect after debug
// info has been optimized.
Error Err =
Config.ToRemove.addMatcher(objectcopy::NameOrPattern::create(
"\\.debug*", objectcopy::MatchStyle::Wildcard,
[](Error Err) -> Error { return Err; }));
error(ToolName, std::move(Err));
Err = Config.ToRemove.addMatcher(objectcopy::NameOrPattern::create(
"\\.gdb_index", objectcopy::MatchStyle::Wildcard,
[](Error Err) -> Error { return Err; }));
error(ToolName, std::move(Err));
} else {
// Delete debug sections which have optimized pair as they should be
// replaced with paired optimized version.
for (const auto &Section : MemFile->sections()) {
if (Expected<StringRef> SectionName = Section.getName()) {
if (SectionName->startswith(".debug") ||
*SectionName == ".gdb_index") {
Error Err =
Config.ToRemove.addMatcher(objectcopy::NameOrPattern::create(
*SectionName, objectcopy::MatchStyle::Wildcard,
[](Error Err) -> Error { return Err; }));
error(ToolName, std::move(Err));
}
}
}
}
// Add new debug sections.
for (const SectionRef &Sec : MemFile->sections()) {
if (Expected<StringRef> SecName = Sec.getName())
if (SecName->startswith(".debug") || *SecName == ".gdb_index") {
if (Expected<StringRef> SecData = Sec.getContents()) {
Config.NewDebugSections.insert(
std::make_pair(*SecName, *SecData));
}
}
}
} else {
error(ToolName, createStringError(std::errc::invalid_argument,
"unknown command line option."));
}
}
objectcopy::FileBuffer FB(Config.OutputFilename);
return objectcopy::elf::executeObjcopyOnBinary(Config.getCommonConfig(), Config.getElfConfig(), InputFile, FB); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
With the design suggested by the current(D99055 <https://reviews.llvm.org/D99055>) patch there would be created local DwarfutilConfigManager which implements MultiFormatConfig interface. The objectcopy::elf::executeObjcopyOnBinary function from object library would get the options by call to getCommonConfig(), getElfConfig(). To have access to objectcopy functions the https://reviews.llvm.org/D88827 is created. The goal of https://reviews.llvm.org/D88827 is to move object copy functions from the specific tool to the object library area. So that object copy functions would be available to the alternative usages(not only from llvm-objcopy tool):
Error executeObjcopyOnIHex(const CommonConfig &CommonCfg, const ElfConfig &ElfCfg, MemoryBuffer &In,
raw_ostream &Out);
Error executeObjcopyOnRawBinary(const CommonConfig &CommonCfg, const ElfConfig &ElfCfg, MemoryBuffer &In,
raw_ostream &Out);
Error executeObjcopyOnBinary(const CommonConfig &CommonCfg, const ElfConfig &ElfCfg,
object::ELFObjectFileBase &In, raw_ostream &Out);
Error executeObjcopyOnBinary(const CommonConfig &CommonCfg, const COFFConfig &COFFCfg,
object::COFFObjectFile &In, raw_ostream &Out);
Error executeObjcopyOnBinary(const CommonConfig &CommonCfg, const MachOConfig &MachOCfg,
object::MachOObjectFile &In, raw_ostream &Out);
Error executeObjcopyOnMachOUniversalBinary(
const MultiFormatConfig &Config, const object::MachOUniversalBinary &In, raw_ostream &Out);
Error executeObjcopyOnBinary(const CommonConfig &CommonCfg, const MachOConfig &MachOCfg,
object::WasmObjectFile &In, raw_ostream &Out);
Error executeObjcopyOnArchive(const MultiFormatConfig &Config, const object::Archive &Ar)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99055/new/
https://reviews.llvm.org/D99055
More information about the llvm-commits
mailing list