2018-10-12 06:33:50 +08:00
|
|
|
//===- CopyConfig.h -------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-10-12 06:33:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2019-01-08 00:59:12 +08:00
|
|
|
// Only applicable for --input-format=binary
|
2018-10-12 06:33:50 +08:00
|
|
|
MachineInfo BinaryArch;
|
2019-01-08 00:59:12 +08:00
|
|
|
// Only applicable when --output-format!=binary (e.g. elf64-x86-64).
|
|
|
|
Optional<MachineInfo> OutputArch;
|
2018-10-12 06:33:50 +08:00
|
|
|
|
|
|
|
// Advanced options
|
|
|
|
StringRef AddGnuDebugLink;
|
2018-12-04 03:49:23 +08:00
|
|
|
StringRef BuildIdLinkDir;
|
|
|
|
Optional<StringRef> BuildIdLinkInput;
|
|
|
|
Optional<StringRef> BuildIdLinkOutput;
|
2018-10-12 06:33:50 +08:00
|
|
|
StringRef SplitDWO;
|
|
|
|
StringRef SymbolsPrefix;
|
|
|
|
|
|
|
|
// Repeated options
|
|
|
|
std::vector<StringRef> AddSection;
|
|
|
|
std::vector<StringRef> DumpSection;
|
[llvm-objcopy] Rename --keep to --keep-section.
Summary:
llvm-objcopy/strip support `--keep` (for sections) and `--keep-symbols` (for symbols). For consistency and clarity, rename `--keep` to `--keep-section`.
In fact, for GNU compatability, -K is --keep-symbol, so it's weird that the alias `-K` is not the same as the short-ish `--keep`.
Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola
Reviewed By: jakehehrlich, MaskRay
Subscribers: emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D54477
llvm-svn: 346782
2018-11-14 03:32:27 +08:00
|
|
|
std::vector<StringRef> KeepSection;
|
2018-12-06 10:03:53 +08:00
|
|
|
std::vector<StringRef> OnlySection;
|
2018-10-12 06:33:50 +08:00
|
|
|
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
|
2018-11-02 01:36:37 +08:00
|
|
|
bool DeterministicArchives = true;
|
2018-10-12 06:33:50 +08:00
|
|
|
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
|