diff options
author | Alexander Shaposhnikov <shal1t712@gmail.com> | 2018-10-11 22:33:50 +0000 |
---|---|---|
committer | Alexander Shaposhnikov <shal1t712@gmail.com> | 2018-10-11 22:33:50 +0000 |
commit | 8d0b74c9405316e2f6c2f11e093c0109e4cc8038 (patch) | |
tree | b06ef2a729300a339313967ff150ff730efcdc39 /llvm/tools/llvm-objcopy/CopyConfig.h | |
parent | c5cd5911ec1a9a35d8ac75f32076d32eb23fdba5 (diff) | |
download | bcm5719-llvm-8d0b74c9405316e2f6c2f11e093c0109e4cc8038.tar.gz bcm5719-llvm-8d0b74c9405316e2f6c2f11e093c0109e4cc8038.zip |
[llvm-objcopy] Factor out CopyConfig
In this diff we move out CopyConfig from llvm-oobjcopy.cpp into a separate header CopyConfig.h
to enable us (in the future) reuse this class in the other implementations of objcopy (for coff, mach-o).
Additionally this enables us to unload the complexity from llvm-objcopy.cpp a little bit.
Test plan: make check-all
Differential revision: https://reviews.llvm.org/D53006
llvm-svn: 344307
Diffstat (limited to 'llvm/tools/llvm-objcopy/CopyConfig.h')
-rw-r--r-- | llvm/tools/llvm-objcopy/CopyConfig.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.h b/llvm/tools/llvm-objcopy/CopyConfig.h new file mode 100644 index 00000000000..203432a11a6 --- /dev/null +++ b/llvm/tools/llvm-objcopy/CopyConfig.h @@ -0,0 +1,113 @@ +//===- CopyConfig.h -------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H +#define LLVM_TOOLS_LLVM_OBJCOPY_COPY_CONFIG_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +// Necessary for llvm::DebugCompressionType::None +#include "llvm/Target/TargetOptions.h" +#include <string> +#include <vector> + +namespace llvm { +namespace objcopy { + +// This type keeps track of the machine info for various architectures. This +// lets us map architecture names to ELF types and the e_machine value of the +// ELF file. +struct MachineInfo { + uint16_t EMachine; + bool Is64Bit; + bool IsLittleEndian; +}; + +struct SectionRename { + StringRef OriginalName; + StringRef NewName; + Optional<uint64_t> NewFlags; +}; + +// Configuration for copying/stripping a single file. +struct CopyConfig { + // Main input/output options + StringRef InputFilename; + StringRef InputFormat; + StringRef OutputFilename; + StringRef OutputFormat; + + // Only applicable for --input-format=Binary + MachineInfo BinaryArch; + + // Advanced options + StringRef AddGnuDebugLink; + StringRef SplitDWO; + StringRef SymbolsPrefix; + + // Repeated options + std::vector<StringRef> AddSection; + std::vector<StringRef> DumpSection; + std::vector<StringRef> Keep; + std::vector<StringRef> OnlyKeep; + std::vector<StringRef> SymbolsToGlobalize; + std::vector<StringRef> SymbolsToKeep; + std::vector<StringRef> SymbolsToLocalize; + std::vector<StringRef> SymbolsToRemove; + std::vector<StringRef> SymbolsToWeaken; + std::vector<StringRef> ToRemove; + std::vector<std::string> SymbolsToKeepGlobal; + + // Map options + StringMap<SectionRename> SectionsToRename; + StringMap<StringRef> SymbolsToRename; + + // Boolean options + bool DiscardAll = false; + bool ExtractDWO = false; + bool KeepFileSymbols = false; + bool LocalizeHidden = false; + bool OnlyKeepDebug = false; + bool PreserveDates = false; + bool StripAll = false; + bool StripAllGNU = false; + bool StripDWO = false; + bool StripDebug = false; + bool StripNonAlloc = false; + bool StripSections = false; + bool StripUnneeded = false; + bool Weaken = false; + bool DecompressDebugSections = false; + DebugCompressionType CompressionType = DebugCompressionType::None; +}; + +// Configuration for the overall invocation of this tool. When invoked as +// objcopy, will always contain exactly one CopyConfig. When invoked as strip, +// will contain one or more CopyConfigs. +struct DriverConfig { + SmallVector<CopyConfig, 1> CopyConfigs; +}; + +// ParseObjcopyOptions returns the config and sets the input arguments. If a +// help flag is set then ParseObjcopyOptions will print the help messege and +// exit. +DriverConfig parseObjcopyOptions(ArrayRef<const char *> ArgsArr); + +// ParseStripOptions returns the config and sets the input arguments. If a +// help flag is set then ParseStripOptions will print the help messege and +// exit. +DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr); + +} // namespace objcopy +} // namespace llvm + +#endif |