2021-04-23 13:19:11 +02:00
|
|
|
//===- CommonConfig.h -------------------------------------------*- C++ -*-===//
|
2018-10-12 00:33:50 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01: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 00:33:50 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-04-23 13:19:11 +02:00
|
|
|
#ifndef LLVM_TOOLS_LLVM_OBJCOPY_COMMONCONFIG_H
|
|
|
|
#define LLVM_TOOLS_LLVM_OBJCOPY_COMMONCONFIG_H
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2021-07-12 18:03:33 +02:00
|
|
|
#include "llvm/ADT/CachedHashString.h"
|
2020-06-23 01:49:14 +02:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2018-10-12 00:33:50 +02:00
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2019-02-25 15:12:41 +01:00
|
|
|
#include "llvm/Object/ELFTypes.h"
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
#include "llvm/Support/GlobPattern.h"
|
2019-02-06 12:00:07 +01:00
|
|
|
#include "llvm/Support/Regex.h"
|
2018-10-12 00:33:50 +02:00
|
|
|
// Necessary for llvm::DebugCompressionType::None
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace objcopy {
|
|
|
|
|
2019-07-05 07:28:38 +02:00
|
|
|
enum class FileFormat {
|
|
|
|
Unspecified,
|
|
|
|
ELF,
|
|
|
|
Binary,
|
|
|
|
IHex,
|
|
|
|
};
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
// 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 {
|
[llvm-objcopy] Support full list of bfd targets that lld uses.
Summary:
This change takes the full list of bfd targets that lld supports (see `ScriptParser.cpp`), including generic handling for `*-freebsd` targets (which uses the same settings but with a FreeBSD OSABI). In particular this adds mips support for `--output-target` (but not yet via `--binary-architecture`).
lld and llvm-objcopy use their own different custom data structures, so I'd prefer to check this in as-is (add support directly in llvm-objcopy, including all the test coverage) and do a separate NFC patch(s) that consolidate the two by putting this mapping into libobject.
See [[ https://bugs.llvm.org/show_bug.cgi?id=41462 | PR41462 ]].
Reviewers: jhenderson, jakehehrlich, espindola, alexshap, arichardson
Reviewed By: arichardson
Subscribers: fedor.sergeev, emaste, sdardis, krytarowski, atanasyan, llvm-commits, MaskRay, arichardson
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60773
llvm-svn: 358562
2019-04-17 09:42:31 +02:00
|
|
|
MachineInfo(uint16_t EM, uint8_t ABI, bool Is64, bool IsLittle)
|
|
|
|
: EMachine(EM), OSABI(ABI), Is64Bit(Is64), IsLittleEndian(IsLittle) {}
|
|
|
|
// Alternative constructor that defaults to NONE for OSABI.
|
|
|
|
MachineInfo(uint16_t EM, bool Is64, bool IsLittle)
|
|
|
|
: MachineInfo(EM, ELF::ELFOSABI_NONE, Is64, IsLittle) {}
|
|
|
|
// Default constructor for unset fields.
|
|
|
|
MachineInfo() : MachineInfo(0, 0, false, false) {}
|
2018-10-12 00:33:50 +02:00
|
|
|
uint16_t EMachine;
|
2019-03-22 11:21:09 +01:00
|
|
|
uint8_t OSABI;
|
2018-10-12 00:33:50 +02:00
|
|
|
bool Is64Bit;
|
|
|
|
bool IsLittleEndian;
|
|
|
|
};
|
|
|
|
|
2019-03-28 19:27:00 +01:00
|
|
|
// Flags set by --set-section-flags or --rename-section. Interpretation of these
|
|
|
|
// is format-specific and not all flags are meaningful for all object file
|
|
|
|
// formats. This is a bitmask; many section flags may be set.
|
|
|
|
enum SectionFlag {
|
|
|
|
SecNone = 0,
|
|
|
|
SecAlloc = 1 << 0,
|
|
|
|
SecLoad = 1 << 1,
|
|
|
|
SecNoload = 1 << 2,
|
|
|
|
SecReadonly = 1 << 3,
|
|
|
|
SecDebug = 1 << 4,
|
|
|
|
SecCode = 1 << 5,
|
|
|
|
SecData = 1 << 6,
|
|
|
|
SecRom = 1 << 7,
|
|
|
|
SecMerge = 1 << 8,
|
|
|
|
SecStrings = 1 << 9,
|
|
|
|
SecContents = 1 << 10,
|
|
|
|
SecShare = 1 << 11,
|
2020-01-21 02:06:03 +01:00
|
|
|
SecExclude = 1 << 12,
|
|
|
|
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SecExclude)
|
2019-03-28 19:27:00 +01:00
|
|
|
};
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
struct SectionRename {
|
|
|
|
StringRef OriginalName;
|
|
|
|
StringRef NewName;
|
2019-03-28 19:27:00 +01:00
|
|
|
Optional<SectionFlag> NewFlags;
|
2018-10-12 00:33:50 +02:00
|
|
|
};
|
|
|
|
|
[llvm-objcopy] Implement --set-section-flags.
Summary:
--set-section-flags is used to change the section flags (e.g. SHF_ALLOC) for given sections. The flags allowed are the same from the existing --rename-section=.old=.new[,flags] feature.
Additionally, make sure that --set-section-flag cannot be used with --rename-section (either the source or destination), since --rename-section accepts flags. This avoids ambiguity for something like "--rename-section=.foo=.bar,alloc --set-section-flag=.bar,code".
Reviewers: jhenderson, jakehehrlich, alexshap, espindola
Reviewed By: jhenderson, jakehehrlich
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57198
llvm-svn: 352505
2019-01-29 16:05:38 +01:00
|
|
|
struct SectionFlagsUpdate {
|
|
|
|
StringRef Name;
|
2019-03-28 19:27:00 +01:00
|
|
|
SectionFlag NewFlags;
|
[llvm-objcopy] Implement --set-section-flags.
Summary:
--set-section-flags is used to change the section flags (e.g. SHF_ALLOC) for given sections. The flags allowed are the same from the existing --rename-section=.old=.new[,flags] feature.
Additionally, make sure that --set-section-flag cannot be used with --rename-section (either the source or destination), since --rename-section accepts flags. This avoids ambiguity for something like "--rename-section=.foo=.bar,alloc --set-section-flag=.bar,code".
Reviewers: jhenderson, jakehehrlich, alexshap, espindola
Reviewed By: jhenderson, jakehehrlich
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57198
llvm-svn: 352505
2019-01-29 16:05:38 +01:00
|
|
|
};
|
|
|
|
|
[llvm-objcopy] Support -X|--discard-locals.
Summary:
This adds support for the --discard-locals flag, which acts similarly to --discard-all, except it only applies to compiler-generated symbols (i.e. symbols starting with `.L` in ELF).
I am not sure about COFF local symbols: those appear to also use `.L` in most cases, but also use just `L` in other cases, so for now I am just leaving it unimplemented there.
Fixes PR36160
Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola
Reviewed By: jhenderson
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57248
llvm-svn: 352626
2019-01-30 15:58:13 +01:00
|
|
|
enum class DiscardType {
|
|
|
|
None, // Default
|
|
|
|
All, // --discard-all (-x)
|
|
|
|
Locals, // --discard-locals (-X)
|
|
|
|
};
|
|
|
|
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
enum class MatchStyle {
|
|
|
|
Literal, // Default for symbols.
|
|
|
|
Wildcard, // Default for sections, or enabled with --wildcard (-w).
|
|
|
|
Regex, // Enabled with --regex.
|
|
|
|
};
|
|
|
|
|
|
|
|
class NameOrPattern {
|
2019-02-06 12:00:07 +01:00
|
|
|
StringRef Name;
|
2021-04-23 13:19:11 +02:00
|
|
|
// Regex is shared between multiple CommonConfig instances.
|
2019-02-06 12:00:07 +01:00
|
|
|
std::shared_ptr<Regex> R;
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
std::shared_ptr<GlobPattern> G;
|
|
|
|
bool IsPositiveMatch = true;
|
|
|
|
|
|
|
|
NameOrPattern(StringRef N) : Name(N) {}
|
|
|
|
NameOrPattern(std::shared_ptr<Regex> R) : R(R) {}
|
|
|
|
NameOrPattern(std::shared_ptr<GlobPattern> G, bool IsPositiveMatch)
|
|
|
|
: G(G), IsPositiveMatch(IsPositiveMatch) {}
|
2019-02-06 12:00:07 +01:00
|
|
|
|
|
|
|
public:
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
// ErrorCallback is used to handle recoverable errors. An Error returned
|
|
|
|
// by the callback aborts the parsing and is then returned by this function.
|
|
|
|
static Expected<NameOrPattern>
|
|
|
|
create(StringRef Pattern, MatchStyle MS,
|
|
|
|
llvm::function_ref<Error(Error)> ErrorCallback);
|
|
|
|
|
|
|
|
bool isPositiveMatch() const { return IsPositiveMatch; }
|
2021-07-12 18:03:33 +02:00
|
|
|
Optional<StringRef> getName() const {
|
|
|
|
if (!R && !G)
|
|
|
|
return Name;
|
|
|
|
return None;
|
|
|
|
}
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
bool operator==(StringRef S) const {
|
|
|
|
return R ? R->match(S) : G ? G->match(S) : Name == S;
|
|
|
|
}
|
2019-02-06 12:00:07 +01:00
|
|
|
bool operator!=(StringRef S) const { return !operator==(S); }
|
|
|
|
};
|
|
|
|
|
[llvm-objcopy][NFC] Refactor symbol/section matching
Summary:
The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard.
To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching.
Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap
Reviewed By: jhenderson, MaskRay
Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66432
llvm-svn: 369689
2019-08-22 21:17:50 +02:00
|
|
|
// Matcher that checks symbol or section names against the command line flags
|
|
|
|
// provided for that option.
|
|
|
|
class NameMatcher {
|
2021-07-12 18:03:33 +02:00
|
|
|
DenseSet<CachedHashStringRef> PosNames;
|
|
|
|
std::vector<NameOrPattern> PosPatterns;
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
std::vector<NameOrPattern> NegMatchers;
|
[llvm-objcopy][NFC] Refactor symbol/section matching
Summary:
The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard.
To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching.
Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap
Reviewed By: jhenderson, MaskRay
Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66432
llvm-svn: 369689
2019-08-22 21:17:50 +02:00
|
|
|
|
|
|
|
public:
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
Error addMatcher(Expected<NameOrPattern> Matcher) {
|
|
|
|
if (!Matcher)
|
|
|
|
return Matcher.takeError();
|
2021-07-12 18:03:33 +02:00
|
|
|
if (Matcher->isPositiveMatch()) {
|
|
|
|
if (Optional<StringRef> MaybeName = Matcher->getName())
|
|
|
|
PosNames.insert(CachedHashStringRef(*MaybeName));
|
|
|
|
else
|
|
|
|
PosPatterns.push_back(std::move(*Matcher));
|
|
|
|
} else {
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
NegMatchers.push_back(std::move(*Matcher));
|
2021-07-12 18:03:33 +02:00
|
|
|
}
|
[llvm-objcopy] Add support for shell wildcards
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags).
The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag.
Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway).
Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap
Reviewed By: MaskRay
Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66613
llvm-svn: 375169
2019-10-17 22:51:00 +02:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
bool matches(StringRef S) const {
|
2021-07-12 18:03:33 +02:00
|
|
|
return (PosNames.contains(CachedHashStringRef(S)) ||
|
|
|
|
is_contained(PosPatterns, S)) &&
|
|
|
|
!is_contained(NegMatchers, S);
|
|
|
|
}
|
|
|
|
bool empty() const {
|
|
|
|
return PosNames.empty() && PosPatterns.empty() && NegMatchers.empty();
|
[llvm-objcopy][NFC] Refactor symbol/section matching
Summary:
The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard.
To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching.
Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap
Reviewed By: jhenderson, MaskRay
Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66432
llvm-svn: 369689
2019-08-22 21:17:50 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-27 13:07:35 +02:00
|
|
|
enum class SymbolFlag {
|
|
|
|
Global,
|
|
|
|
Local,
|
|
|
|
Weak,
|
|
|
|
Default,
|
|
|
|
Hidden,
|
|
|
|
Protected,
|
|
|
|
File,
|
|
|
|
Section,
|
|
|
|
Object,
|
|
|
|
Function,
|
|
|
|
IndirectFunction,
|
|
|
|
Debug,
|
|
|
|
Constructor,
|
|
|
|
Warning,
|
|
|
|
Indirect,
|
|
|
|
Synthetic,
|
|
|
|
UniqueObject,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Symbol info specified by --add-symbol option. Symbol flags not supported
|
|
|
|
// by a concrete format should be ignored.
|
|
|
|
struct NewSymbolInfo {
|
|
|
|
StringRef SymbolName;
|
|
|
|
StringRef SectionName;
|
|
|
|
uint64_t Value = 0;
|
|
|
|
std::vector<SymbolFlag> Flags;
|
|
|
|
std::vector<StringRef> BeforeSyms;
|
|
|
|
};
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
// Configuration for copying/stripping a single file.
|
2021-04-23 13:19:11 +02:00
|
|
|
struct CommonConfig {
|
2018-10-12 00:33:50 +02:00
|
|
|
// Main input/output options
|
|
|
|
StringRef InputFilename;
|
2019-11-20 08:30:52 +01:00
|
|
|
FileFormat InputFormat = FileFormat::Unspecified;
|
2018-10-12 00:33:50 +02:00
|
|
|
StringRef OutputFilename;
|
2019-11-20 08:30:52 +01:00
|
|
|
FileFormat OutputFormat = FileFormat::Unspecified;
|
2018-10-12 00:33:50 +02:00
|
|
|
|
2019-01-07 17:59:12 +01:00
|
|
|
// Only applicable when --output-format!=binary (e.g. elf64-x86-64).
|
|
|
|
Optional<MachineInfo> OutputArch;
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
// Advanced options
|
|
|
|
StringRef AddGnuDebugLink;
|
2019-05-14 12:59:04 +02:00
|
|
|
// Cached gnu_debuglink's target CRC
|
|
|
|
uint32_t GnuDebugLinkCRC32;
|
2019-06-07 19:57:48 +02:00
|
|
|
Optional<StringRef> ExtractPartition;
|
2018-10-12 00:33:50 +02:00
|
|
|
StringRef SplitDWO;
|
|
|
|
StringRef SymbolsPrefix;
|
2019-05-08 11:49:35 +02:00
|
|
|
StringRef AllocSectionsPrefix;
|
[llvm-objcopy] Support -X|--discard-locals.
Summary:
This adds support for the --discard-locals flag, which acts similarly to --discard-all, except it only applies to compiler-generated symbols (i.e. symbols starting with `.L` in ELF).
I am not sure about COFF local symbols: those appear to also use `.L` in most cases, but also use just `L` in other cases, so for now I am just leaving it unimplemented there.
Fixes PR36160
Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola
Reviewed By: jhenderson
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57248
llvm-svn: 352626
2019-01-30 15:58:13 +01:00
|
|
|
DiscardType DiscardMode = DiscardType::None;
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
// Repeated options
|
|
|
|
std::vector<StringRef> AddSection;
|
|
|
|
std::vector<StringRef> DumpSection;
|
2019-11-20 08:30:52 +01:00
|
|
|
std::vector<StringRef> RPathToAdd;
|
2020-10-24 00:00:25 +02:00
|
|
|
std::vector<StringRef> RPathToPrepend;
|
2020-07-06 23:53:24 +02:00
|
|
|
DenseMap<StringRef, StringRef> RPathsToUpdate;
|
|
|
|
DenseMap<StringRef, StringRef> InstallNamesToUpdate;
|
2020-06-23 01:49:14 +02:00
|
|
|
DenseSet<StringRef> RPathsToRemove;
|
[llvm-objcopy][NFC] Refactor symbol/section matching
Summary:
The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard.
To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching.
Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap
Reviewed By: jhenderson, MaskRay
Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66432
llvm-svn: 369689
2019-08-22 21:17:50 +02:00
|
|
|
|
2020-06-30 20:01:45 +02:00
|
|
|
// install-name-tool's id option
|
|
|
|
Optional<StringRef> SharedLibId;
|
|
|
|
|
[llvm-objcopy][NFC] Refactor symbol/section matching
Summary:
The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard.
To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching.
Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap
Reviewed By: jhenderson, MaskRay
Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66432
llvm-svn: 369689
2019-08-22 21:17:50 +02:00
|
|
|
// Section matchers
|
|
|
|
NameMatcher KeepSection;
|
|
|
|
NameMatcher OnlySection;
|
|
|
|
NameMatcher ToRemove;
|
|
|
|
|
|
|
|
// Symbol matchers
|
|
|
|
NameMatcher SymbolsToGlobalize;
|
|
|
|
NameMatcher SymbolsToKeep;
|
|
|
|
NameMatcher SymbolsToLocalize;
|
|
|
|
NameMatcher SymbolsToRemove;
|
|
|
|
NameMatcher UnneededSymbolsToRemove;
|
|
|
|
NameMatcher SymbolsToWeaken;
|
|
|
|
NameMatcher SymbolsToKeepGlobal;
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
// Map options
|
|
|
|
StringMap<SectionRename> SectionsToRename;
|
2019-10-02 14:41:25 +02:00
|
|
|
StringMap<uint64_t> SetSectionAlignment;
|
[llvm-objcopy] Implement --set-section-flags.
Summary:
--set-section-flags is used to change the section flags (e.g. SHF_ALLOC) for given sections. The flags allowed are the same from the existing --rename-section=.old=.new[,flags] feature.
Additionally, make sure that --set-section-flag cannot be used with --rename-section (either the source or destination), since --rename-section accepts flags. This avoids ambiguity for something like "--rename-section=.foo=.bar,alloc --set-section-flag=.bar,code".
Reviewers: jhenderson, jakehehrlich, alexshap, espindola
Reviewed By: jhenderson, jakehehrlich
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D57198
llvm-svn: 352505
2019-01-29 16:05:38 +01:00
|
|
|
StringMap<SectionFlagsUpdate> SetSectionFlags;
|
2018-10-12 00:33:50 +02:00
|
|
|
StringMap<StringRef> SymbolsToRename;
|
|
|
|
|
2019-02-26 10:24:22 +01:00
|
|
|
// ELF entry point address expression. The input parameter is an entry point
|
|
|
|
// address in the input ELF file. The entry address in the output file is
|
|
|
|
// calculated with EntryExpr(input_address), when either --set-start or
|
|
|
|
// --change-start is used.
|
|
|
|
std::function<uint64_t(uint64_t)> EntryExpr;
|
|
|
|
|
2021-05-27 13:07:35 +02:00
|
|
|
// Symbol info specified by --add-symbol option.
|
|
|
|
std::vector<NewSymbolInfo> SymbolsToAdd;
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
// Boolean options
|
2019-04-18 11:13:30 +02:00
|
|
|
bool AllowBrokenLinks = false;
|
2018-11-01 18:36:37 +01:00
|
|
|
bool DeterministicArchives = true;
|
2018-10-12 00:33:50 +02:00
|
|
|
bool ExtractDWO = false;
|
2019-06-07 19:57:48 +02:00
|
|
|
bool ExtractMainPartition = false;
|
2018-10-12 00:33:50 +02:00
|
|
|
bool KeepFileSymbols = false;
|
2021-03-09 03:54:00 +01:00
|
|
|
bool KeepUndefined = false;
|
2018-10-12 00:33:50 +02:00
|
|
|
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;
|
2020-05-27 01:49:56 +02:00
|
|
|
bool StripSwiftSymbols = false;
|
2018-10-12 00:33:50 +02:00
|
|
|
bool StripUnneeded = false;
|
|
|
|
bool Weaken = false;
|
|
|
|
bool DecompressDebugSections = false;
|
2020-10-13 09:45:14 +02:00
|
|
|
// install-name-tool's --delete_all_rpaths
|
|
|
|
bool RemoveAllRpaths = false;
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
DebugCompressionType CompressionType = DebugCompressionType::None;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace objcopy
|
|
|
|
} // namespace llvm
|
|
|
|
|
2021-04-23 13:19:11 +02:00
|
|
|
#endif // LLVM_TOOLS_LLVM_OBJCOPY_COMMONCONFIG_H
|