2018-10-12 00:33:50 +02:00
|
|
|
//===- CopyConfig.cpp -----------------------------------------------------===//
|
|
|
|
//
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CopyConfig.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2019-06-18 02:39:10 +02:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2018-10-12 00:33:50 +02:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
2019-10-09 11:06:30 +02:00
|
|
|
#include "llvm/Support/CRC.h"
|
2018-10-12 00:33:50 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Compression.h"
|
2019-02-08 11:33:16 +01:00
|
|
|
#include "llvm/Support/Errc.h"
|
2018-10-12 00:33:50 +02:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2019-02-04 19:38:00 +01:00
|
|
|
#include "llvm/Support/StringSaver.h"
|
2018-10-12 00:33:50 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace objcopy {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
enum ObjcopyID {
|
|
|
|
OBJCOPY_INVALID = 0, // This is not an option ID.
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
OBJCOPY_##ID,
|
|
|
|
#include "ObjcopyOpts.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PREFIX(NAME, VALUE) const char *const OBJCOPY_##NAME[] = VALUE;
|
|
|
|
#include "ObjcopyOpts.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
|
|
|
static const opt::OptTable::Info ObjcopyInfoTable[] = {
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
{OBJCOPY_##PREFIX, \
|
|
|
|
NAME, \
|
|
|
|
HELPTEXT, \
|
|
|
|
METAVAR, \
|
|
|
|
OBJCOPY_##ID, \
|
|
|
|
opt::Option::KIND##Class, \
|
|
|
|
PARAM, \
|
|
|
|
FLAGS, \
|
|
|
|
OBJCOPY_##GROUP, \
|
|
|
|
OBJCOPY_##ALIAS, \
|
|
|
|
ALIASARGS, \
|
|
|
|
VALUES},
|
|
|
|
#include "ObjcopyOpts.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
class ObjcopyOptTable : public opt::OptTable {
|
|
|
|
public:
|
[llvm-strip] Support -s alias for --strip-all. Make both strip and objcopy case sensitive to support both -s (--strip-all) and -S (--strip-debug).
Summary:
GNU strip supports both `-s` and `-S` as aliases for `--strip-all` and `--strip-debug`, respectfully.
As part of this, it turns out that strip/objcopy were accepting case insensitive command line args. I'm not sure if there was an explicit reason for this. The only others uses of this are llvm-cvtres/llvm-mt/llvm-lib, which are all tools specific for windows support. Forcing case sensitivity allows both aliases to exist, but seems like a good idea anyway.
And as a surprise test case adjustment, the llvm-strip unit test was running with `-keep=unavailable_symbol`, despite `keep` not be a valid flag for strip. This is because there is a flag `-K` which, when case insensitivity is permitted, allows it to be interpreted as `-K` = `eep=unavailable_symbol` (e.g. to allow `-Kfoo` == `--keep-symbol=foo`).
Reviewers: jakehehrlich, jhenderson, alexshap
Reviewed By: jakehehrlich
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53163
llvm-svn: 345068
2018-10-23 20:46:33 +02:00
|
|
|
ObjcopyOptTable() : OptTable(ObjcopyInfoTable) {}
|
2018-10-12 00:33:50 +02:00
|
|
|
};
|
|
|
|
|
2019-11-20 08:30:52 +01:00
|
|
|
enum InstallNameToolID {
|
|
|
|
INSTALL_NAME_TOOL_INVALID = 0, // This is not an option ID.
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
INSTALL_NAME_TOOL_##ID,
|
|
|
|
#include "InstallNameToolOpts.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PREFIX(NAME, VALUE) \
|
|
|
|
const char *const INSTALL_NAME_TOOL_##NAME[] = VALUE;
|
|
|
|
#include "InstallNameToolOpts.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
|
|
|
static const opt::OptTable::Info InstallNameToolInfoTable[] = {
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
{INSTALL_NAME_TOOL_##PREFIX, \
|
|
|
|
NAME, \
|
|
|
|
HELPTEXT, \
|
|
|
|
METAVAR, \
|
|
|
|
INSTALL_NAME_TOOL_##ID, \
|
|
|
|
opt::Option::KIND##Class, \
|
|
|
|
PARAM, \
|
|
|
|
FLAGS, \
|
|
|
|
INSTALL_NAME_TOOL_##GROUP, \
|
|
|
|
INSTALL_NAME_TOOL_##ALIAS, \
|
|
|
|
ALIASARGS, \
|
|
|
|
VALUES},
|
|
|
|
#include "InstallNameToolOpts.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
class InstallNameToolOptTable : public opt::OptTable {
|
|
|
|
public:
|
|
|
|
InstallNameToolOptTable() : OptTable(InstallNameToolInfoTable) {}
|
|
|
|
};
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
enum StripID {
|
|
|
|
STRIP_INVALID = 0, // This is not an option ID.
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
STRIP_##ID,
|
|
|
|
#include "StripOpts.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PREFIX(NAME, VALUE) const char *const STRIP_##NAME[] = VALUE;
|
|
|
|
#include "StripOpts.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
|
|
|
static const opt::OptTable::Info StripInfoTable[] = {
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
{STRIP_##PREFIX, NAME, HELPTEXT, \
|
|
|
|
METAVAR, STRIP_##ID, opt::Option::KIND##Class, \
|
|
|
|
PARAM, FLAGS, STRIP_##GROUP, \
|
|
|
|
STRIP_##ALIAS, ALIASARGS, VALUES},
|
|
|
|
#include "StripOpts.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
class StripOptTable : public opt::OptTable {
|
|
|
|
public:
|
[llvm-strip] Support -s alias for --strip-all. Make both strip and objcopy case sensitive to support both -s (--strip-all) and -S (--strip-debug).
Summary:
GNU strip supports both `-s` and `-S` as aliases for `--strip-all` and `--strip-debug`, respectfully.
As part of this, it turns out that strip/objcopy were accepting case insensitive command line args. I'm not sure if there was an explicit reason for this. The only others uses of this are llvm-cvtres/llvm-mt/llvm-lib, which are all tools specific for windows support. Forcing case sensitivity allows both aliases to exist, but seems like a good idea anyway.
And as a surprise test case adjustment, the llvm-strip unit test was running with `-keep=unavailable_symbol`, despite `keep` not be a valid flag for strip. This is because there is a flag `-K` which, when case insensitivity is permitted, allows it to be interpreted as `-K` = `eep=unavailable_symbol` (e.g. to allow `-Kfoo` == `--keep-symbol=foo`).
Reviewers: jakehehrlich, jhenderson, alexshap
Reviewed By: jakehehrlich
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D53163
llvm-svn: 345068
2018-10-23 20:46:33 +02:00
|
|
|
StripOptTable() : OptTable(StripInfoTable) {}
|
2018-10-12 00:33:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
static SectionFlag parseSectionRenameFlag(StringRef SectionName) {
|
|
|
|
return llvm::StringSwitch<SectionFlag>(SectionName)
|
2019-04-03 16:40:27 +02:00
|
|
|
.CaseLower("alloc", SectionFlag::SecAlloc)
|
|
|
|
.CaseLower("load", SectionFlag::SecLoad)
|
|
|
|
.CaseLower("noload", SectionFlag::SecNoload)
|
|
|
|
.CaseLower("readonly", SectionFlag::SecReadonly)
|
|
|
|
.CaseLower("debug", SectionFlag::SecDebug)
|
|
|
|
.CaseLower("code", SectionFlag::SecCode)
|
|
|
|
.CaseLower("data", SectionFlag::SecData)
|
|
|
|
.CaseLower("rom", SectionFlag::SecRom)
|
|
|
|
.CaseLower("merge", SectionFlag::SecMerge)
|
|
|
|
.CaseLower("strings", SectionFlag::SecStrings)
|
|
|
|
.CaseLower("contents", SectionFlag::SecContents)
|
|
|
|
.CaseLower("share", SectionFlag::SecShare)
|
2020-01-21 02:06:03 +01:00
|
|
|
.CaseLower("exclude", SectionFlag::SecExclude)
|
2018-10-12 00:33:50 +02:00
|
|
|
.Default(SectionFlag::SecNone);
|
|
|
|
}
|
|
|
|
|
2019-03-28 19:27:00 +01:00
|
|
|
static Expected<SectionFlag>
|
2019-02-21 18:05:19 +01:00
|
|
|
parseSectionFlagSet(ArrayRef<StringRef> SectionFlags) {
|
[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
|
|
|
SectionFlag ParsedFlags = SectionFlag::SecNone;
|
|
|
|
for (StringRef Flag : SectionFlags) {
|
|
|
|
SectionFlag ParsedFlag = parseSectionRenameFlag(Flag);
|
|
|
|
if (ParsedFlag == SectionFlag::SecNone)
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"unrecognized section flag '%s'. Flags supported for GNU "
|
2020-01-21 02:06:03 +01:00
|
|
|
"compatibility: alloc, load, noload, readonly, exclude, debug, "
|
|
|
|
"code, data, rom, share, contents, merge, strings",
|
2019-02-21 18:05:19 +01:00
|
|
|
Flag.str().c_str());
|
[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
|
|
|
ParsedFlags |= ParsedFlag;
|
|
|
|
}
|
|
|
|
|
2019-03-28 19:27:00 +01:00
|
|
|
return ParsedFlags;
|
[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
|
|
|
}
|
|
|
|
|
2019-02-21 18:05:19 +01:00
|
|
|
static Expected<SectionRename> parseRenameSectionValue(StringRef FlagValue) {
|
2018-10-12 00:33:50 +02:00
|
|
|
if (!FlagValue.contains('='))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"bad format for --rename-section: missing '='");
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
// Initial split: ".foo" = ".bar,f1,f2,..."
|
|
|
|
auto Old2New = FlagValue.split('=');
|
|
|
|
SectionRename SR;
|
|
|
|
SR.OriginalName = Old2New.first;
|
|
|
|
|
|
|
|
// Flags split: ".bar" "f1" "f2" ...
|
|
|
|
SmallVector<StringRef, 6> NameAndFlags;
|
|
|
|
Old2New.second.split(NameAndFlags, ',');
|
|
|
|
SR.NewName = NameAndFlags[0];
|
|
|
|
|
2019-02-21 18:05:19 +01:00
|
|
|
if (NameAndFlags.size() > 1) {
|
2019-03-28 19:27:00 +01:00
|
|
|
Expected<SectionFlag> ParsedFlagSet =
|
2019-02-21 18:05:19 +01:00
|
|
|
parseSectionFlagSet(makeArrayRef(NameAndFlags).drop_front());
|
|
|
|
if (!ParsedFlagSet)
|
|
|
|
return ParsedFlagSet.takeError();
|
|
|
|
SR.NewFlags = *ParsedFlagSet;
|
|
|
|
}
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
return SR;
|
|
|
|
}
|
|
|
|
|
2019-10-02 14:41:25 +02:00
|
|
|
static Expected<std::pair<StringRef, uint64_t>>
|
|
|
|
parseSetSectionAlignment(StringRef FlagValue) {
|
|
|
|
if (!FlagValue.contains('='))
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"bad format for --set-section-alignment: missing '='");
|
|
|
|
auto Split = StringRef(FlagValue).split('=');
|
|
|
|
if (Split.first.empty())
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"bad format for --set-section-alignment: missing section name");
|
|
|
|
uint64_t NewAlign;
|
|
|
|
if (Split.second.getAsInteger(0, NewAlign))
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"invalid alignment for --set-section-alignment: '%s'",
|
|
|
|
Split.second.str().c_str());
|
|
|
|
return std::make_pair(Split.first, NewAlign);
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:05:19 +01:00
|
|
|
static Expected<SectionFlagsUpdate>
|
|
|
|
parseSetSectionFlagValue(StringRef FlagValue) {
|
[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
|
|
|
if (!StringRef(FlagValue).contains('='))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"bad format for --set-section-flags: missing '='");
|
[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
|
|
|
|
|
|
|
// Initial split: ".foo" = "f1,f2,..."
|
|
|
|
auto Section2Flags = StringRef(FlagValue).split('=');
|
|
|
|
SectionFlagsUpdate SFU;
|
|
|
|
SFU.Name = Section2Flags.first;
|
|
|
|
|
|
|
|
// Flags split: "f1" "f2" ...
|
|
|
|
SmallVector<StringRef, 6> SectionFlags;
|
|
|
|
Section2Flags.second.split(SectionFlags, ',');
|
2019-03-28 19:27:00 +01:00
|
|
|
Expected<SectionFlag> ParsedFlagSet = parseSectionFlagSet(SectionFlags);
|
2019-02-21 18:05:19 +01:00
|
|
|
if (!ParsedFlagSet)
|
|
|
|
return ParsedFlagSet.takeError();
|
|
|
|
SFU.NewFlags = *ParsedFlagSet;
|
[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
|
|
|
|
|
|
|
return SFU;
|
|
|
|
}
|
|
|
|
|
2019-07-05 07:28:38 +02:00
|
|
|
struct TargetInfo {
|
|
|
|
FileFormat Format;
|
|
|
|
MachineInfo Machine;
|
|
|
|
};
|
|
|
|
|
[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
|
|
|
// FIXME: consolidate with the bfd parsing used by lld.
|
2019-07-05 07:28:38 +02:00
|
|
|
static const StringMap<MachineInfo> TargetMap{
|
[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
|
|
|
// Name, {EMachine, 64bit, LittleEndian}
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
// x86
|
[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
|
|
|
{"elf32-i386", {ELF::EM_386, false, true}},
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
{"elf32-x86-64", {ELF::EM_X86_64, false, true}},
|
|
|
|
{"elf64-x86-64", {ELF::EM_X86_64, true, true}},
|
|
|
|
// Intel MCU
|
[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
|
|
|
{"elf32-iamcu", {ELF::EM_IAMCU, false, true}},
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
// ARM
|
[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
|
|
|
{"elf32-littlearm", {ELF::EM_ARM, false, true}},
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
// ARM AArch64
|
[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
|
|
|
{"elf64-aarch64", {ELF::EM_AARCH64, true, true}},
|
|
|
|
{"elf64-littleaarch64", {ELF::EM_AARCH64, true, true}},
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
// RISC-V
|
|
|
|
{"elf32-littleriscv", {ELF::EM_RISCV, false, true}},
|
|
|
|
{"elf64-littleriscv", {ELF::EM_RISCV, true, true}},
|
|
|
|
// PowerPC
|
[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
|
|
|
{"elf32-powerpc", {ELF::EM_PPC, false, false}},
|
|
|
|
{"elf32-powerpcle", {ELF::EM_PPC, false, true}},
|
|
|
|
{"elf64-powerpc", {ELF::EM_PPC64, true, false}},
|
|
|
|
{"elf64-powerpcle", {ELF::EM_PPC64, true, true}},
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
// MIPS
|
[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
|
|
|
{"elf32-bigmips", {ELF::EM_MIPS, false, false}},
|
|
|
|
{"elf32-ntradbigmips", {ELF::EM_MIPS, false, false}},
|
|
|
|
{"elf32-ntradlittlemips", {ELF::EM_MIPS, false, true}},
|
[llvm-objcopy] Add RISC-V support for -B/-O
Reviewers: jorgbrown, espindola, alexshap, jhenderson
Subscribers: emaste, arichardson, fedor.sergeev, jakehehrlich, kito-cheng, shiva0217, MaskRay, rogfer01, rkruppe, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61272
llvm-svn: 359568
2019-04-30 17:21:36 +02:00
|
|
|
{"elf32-tradbigmips", {ELF::EM_MIPS, false, false}},
|
|
|
|
{"elf32-tradlittlemips", {ELF::EM_MIPS, false, true}},
|
[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
|
|
|
{"elf64-tradbigmips", {ELF::EM_MIPS, true, false}},
|
|
|
|
{"elf64-tradlittlemips", {ELF::EM_MIPS, true, true}},
|
[llvm-objcopy] Add elf32-sparc and elf32-sparcel target
Summary:
The "sparc"/"sparcel" architectures appears in ArchMap (used by -B option) but not in OutputFormatMap (used by -I/-O option). Add their targets into OutputFormatMap for consistency.
Note that AFAIK there're no targets for 32-bit little-endian SPARC ("elf32-sparcel") in GNU binutils.
Reviewers: espindola, alexshap, rupprecht, jhenderson, compnerd, jakehehrlich
Reviewed By: jhenderson, compnerd, jakehehrlich
Subscribers: jyknight, emaste, arichardson, fedor.sergeev, jakehehrlich, MaskRay, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63238
llvm-svn: 363524
2019-06-17 04:03:45 +02:00
|
|
|
// SPARC
|
|
|
|
{"elf32-sparc", {ELF::EM_SPARC, false, false}},
|
|
|
|
{"elf32-sparcel", {ELF::EM_SPARC, false, true}},
|
2019-01-07 17:59:12 +01:00
|
|
|
};
|
|
|
|
|
2019-07-05 07:28:38 +02:00
|
|
|
static Expected<TargetInfo>
|
|
|
|
getOutputTargetInfoByTargetName(StringRef TargetName) {
|
|
|
|
StringRef OriginalTargetName = TargetName;
|
|
|
|
bool IsFreeBSD = TargetName.consume_back("-freebsd");
|
|
|
|
auto Iter = TargetMap.find(TargetName);
|
|
|
|
if (Iter == std::end(TargetMap))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"invalid output format: '%s'",
|
2019-07-05 07:28:38 +02:00
|
|
|
OriginalTargetName.str().c_str());
|
[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 MI = Iter->getValue();
|
|
|
|
if (IsFreeBSD)
|
|
|
|
MI.OSABI = ELF::ELFOSABI_FREEBSD;
|
2019-07-05 07:28:38 +02:00
|
|
|
|
|
|
|
FileFormat Format;
|
|
|
|
if (TargetName.startswith("elf"))
|
|
|
|
Format = FileFormat::ELF;
|
|
|
|
else
|
|
|
|
// This should never happen because `TargetName` is valid (it certainly
|
|
|
|
// exists in the TargetMap).
|
|
|
|
llvm_unreachable("unknown target prefix");
|
|
|
|
|
|
|
|
return {TargetInfo{Format, MI}};
|
2019-01-07 17:59:12 +01: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
|
|
|
static Error
|
|
|
|
addSymbolsFromFile(NameMatcher &Symbols, BumpPtrAllocator &Alloc,
|
|
|
|
StringRef Filename, MatchStyle MS,
|
|
|
|
llvm::function_ref<Error(Error)> ErrorCallback) {
|
2019-02-04 19:38:00 +01:00
|
|
|
StringSaver Saver(Alloc);
|
2018-10-12 00:33:50 +02:00
|
|
|
SmallVector<StringRef, 16> Lines;
|
|
|
|
auto BufOrErr = MemoryBuffer::getFile(Filename);
|
|
|
|
if (!BufOrErr)
|
2019-02-21 18:05:19 +01:00
|
|
|
return createFileError(Filename, BufOrErr.getError());
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
BufOrErr.get()->getBuffer().split(Lines, '\n');
|
|
|
|
for (StringRef Line : Lines) {
|
|
|
|
// Ignore everything after '#', trim whitespace, and only add the symbol if
|
|
|
|
// it's not empty.
|
|
|
|
auto TrimmedLine = Line.split('#').first.trim();
|
|
|
|
if (!TrimmedLine.empty())
|
[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
|
|
|
if (Error E = Symbols.addMatcher(NameOrPattern::create(
|
|
|
|
Saver.save(TrimmedLine), MS, ErrorCallback)))
|
|
|
|
return E;
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
2019-02-21 18:05:19 +01:00
|
|
|
|
|
|
|
return Error::success();
|
2018-10-12 00:33:50 +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
|
|
|
Expected<NameOrPattern>
|
|
|
|
NameOrPattern::create(StringRef Pattern, MatchStyle MS,
|
|
|
|
llvm::function_ref<Error(Error)> ErrorCallback) {
|
|
|
|
switch (MS) {
|
|
|
|
case MatchStyle::Literal:
|
|
|
|
return NameOrPattern(Pattern);
|
|
|
|
case MatchStyle::Wildcard: {
|
|
|
|
SmallVector<char, 32> Data;
|
|
|
|
bool IsPositiveMatch = true;
|
|
|
|
if (Pattern[0] == '!') {
|
|
|
|
IsPositiveMatch = false;
|
|
|
|
Pattern = Pattern.drop_front();
|
|
|
|
}
|
|
|
|
Expected<GlobPattern> GlobOrErr = GlobPattern::create(Pattern);
|
|
|
|
|
|
|
|
// If we couldn't create it as a glob, report the error, but try again with
|
|
|
|
// a literal if the error reporting is non-fatal.
|
|
|
|
if (!GlobOrErr) {
|
|
|
|
if (Error E = ErrorCallback(GlobOrErr.takeError()))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
[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 create(Pattern, MatchStyle::Literal, ErrorCallback);
|
|
|
|
}
|
2019-02-06 12:00:07 +01: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 NameOrPattern(std::make_shared<GlobPattern>(*GlobOrErr),
|
|
|
|
IsPositiveMatch);
|
|
|
|
}
|
|
|
|
case MatchStyle::Regex: {
|
|
|
|
SmallVector<char, 32> Data;
|
|
|
|
return NameOrPattern(std::make_shared<Regex>(
|
|
|
|
("^" + Pattern.ltrim('^').rtrim('$') + "$").toStringRef(Data)));
|
|
|
|
}
|
|
|
|
}
|
2019-10-18 11:59:40 +02:00
|
|
|
llvm_unreachable("Unhandled llvm.objcopy.MatchStyle enum");
|
2019-02-06 12:00:07 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 11:33:16 +01:00
|
|
|
static Error addSymbolsToRenameFromFile(StringMap<StringRef> &SymbolsToRename,
|
|
|
|
BumpPtrAllocator &Alloc,
|
|
|
|
StringRef Filename) {
|
|
|
|
StringSaver Saver(Alloc);
|
|
|
|
SmallVector<StringRef, 16> Lines;
|
|
|
|
auto BufOrErr = MemoryBuffer::getFile(Filename);
|
|
|
|
if (!BufOrErr)
|
2019-02-11 10:49:37 +01:00
|
|
|
return createFileError(Filename, BufOrErr.getError());
|
2019-02-08 11:33:16 +01:00
|
|
|
|
|
|
|
BufOrErr.get()->getBuffer().split(Lines, '\n');
|
|
|
|
size_t NumLines = Lines.size();
|
|
|
|
for (size_t LineNo = 0; LineNo < NumLines; ++LineNo) {
|
|
|
|
StringRef TrimmedLine = Lines[LineNo].split('#').first.trim();
|
|
|
|
if (TrimmedLine.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::pair<StringRef, StringRef> Pair = Saver.save(TrimmedLine).split(' ');
|
|
|
|
StringRef NewName = Pair.second.trim();
|
|
|
|
if (NewName.empty())
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"%s:%zu: missing new symbol name",
|
|
|
|
Filename.str().c_str(), LineNo + 1);
|
|
|
|
SymbolsToRename.insert({Pair.first, NewName});
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
2019-02-26 10:24:22 +01:00
|
|
|
|
|
|
|
template <class T> static ErrorOr<T> getAsInteger(StringRef Val) {
|
|
|
|
T Result;
|
|
|
|
if (Val.getAsInteger(0, Result))
|
|
|
|
return errc::invalid_argument;
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2019-09-14 03:14:43 +02:00
|
|
|
static void printHelp(const opt::OptTable &OptTable, raw_ostream &OS,
|
|
|
|
StringRef ToolName) {
|
|
|
|
OptTable.PrintHelp(OS, (ToolName + " input [output]").str().c_str(),
|
|
|
|
(ToolName + " tool").str().c_str());
|
|
|
|
// TODO: Replace this with libOption call once it adds extrahelp support.
|
|
|
|
// The CommandLine library has a cl::extrahelp class to support this,
|
|
|
|
// but libOption does not have that yet.
|
|
|
|
OS << "\nPass @FILE as argument to read options from FILE.\n";
|
|
|
|
}
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
// ParseObjcopyOptions returns the config and sets the input arguments. If a
|
|
|
|
// help flag is set then ParseObjcopyOptions will print the help messege and
|
|
|
|
// exit.
|
[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
|
|
|
Expected<DriverConfig>
|
|
|
|
parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
|
|
|
|
llvm::function_ref<Error(Error)> ErrorCallback) {
|
2019-02-04 19:38:00 +01:00
|
|
|
DriverConfig DC;
|
2018-10-12 00:33:50 +02:00
|
|
|
ObjcopyOptTable T;
|
|
|
|
unsigned MissingArgumentIndex, MissingArgumentCount;
|
|
|
|
llvm::opt::InputArgList InputArgs =
|
|
|
|
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
|
|
|
|
|
|
|
|
if (InputArgs.size() == 0) {
|
2019-09-14 03:14:43 +02:00
|
|
|
printHelp(T, errs(), "llvm-objcopy");
|
2018-10-12 00:33:50 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InputArgs.hasArg(OBJCOPY_help)) {
|
2019-09-14 03:14:43 +02:00
|
|
|
printHelp(T, outs(), "llvm-objcopy");
|
2018-10-12 00:33:50 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InputArgs.hasArg(OBJCOPY_version)) {
|
2018-11-28 07:51:50 +01:00
|
|
|
outs() << "llvm-objcopy, compatible with GNU objcopy\n";
|
2018-10-12 00:33:50 +02:00
|
|
|
cl::PrintVersionMessage();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<const char *, 2> Positional;
|
|
|
|
|
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_UNKNOWN))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument, "unknown argument '%s'",
|
|
|
|
Arg->getAsString(InputArgs).c_str());
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_INPUT))
|
|
|
|
Positional.push_back(Arg->getValue());
|
|
|
|
|
|
|
|
if (Positional.empty())
|
2019-06-14 04:04:02 +02:00
|
|
|
return createStringError(errc::invalid_argument, "no input file specified");
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
if (Positional.size() > 2)
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"too many positional arguments");
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
CopyConfig Config;
|
|
|
|
Config.InputFilename = Positional[0];
|
|
|
|
Config.OutputFilename = Positional[Positional.size() == 1 ? 0 : 1];
|
2018-10-12 02:36:01 +02:00
|
|
|
if (InputArgs.hasArg(OBJCOPY_target) &&
|
|
|
|
(InputArgs.hasArg(OBJCOPY_input_target) ||
|
|
|
|
InputArgs.hasArg(OBJCOPY_output_target)))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"--target cannot be used with --input-target or --output-target");
|
2018-10-12 02:36:01 +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
|
|
|
if (InputArgs.hasArg(OBJCOPY_regex) && InputArgs.hasArg(OBJCOPY_wildcard))
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"--regex and --wildcard are incompatible");
|
|
|
|
|
|
|
|
MatchStyle SectionMatchStyle = InputArgs.hasArg(OBJCOPY_regex)
|
|
|
|
? MatchStyle::Regex
|
|
|
|
: MatchStyle::Wildcard;
|
|
|
|
MatchStyle SymbolMatchStyle = InputArgs.hasArg(OBJCOPY_regex)
|
|
|
|
? MatchStyle::Regex
|
|
|
|
: InputArgs.hasArg(OBJCOPY_wildcard)
|
|
|
|
? MatchStyle::Wildcard
|
|
|
|
: MatchStyle::Literal;
|
2019-07-05 07:28:38 +02:00
|
|
|
StringRef InputFormat, OutputFormat;
|
2018-10-12 02:36:01 +02:00
|
|
|
if (InputArgs.hasArg(OBJCOPY_target)) {
|
2019-07-05 07:28:38 +02:00
|
|
|
InputFormat = InputArgs.getLastArgValue(OBJCOPY_target);
|
|
|
|
OutputFormat = InputArgs.getLastArgValue(OBJCOPY_target);
|
2018-10-12 02:36:01 +02:00
|
|
|
} else {
|
2019-07-05 07:28:38 +02:00
|
|
|
InputFormat = InputArgs.getLastArgValue(OBJCOPY_input_target);
|
|
|
|
OutputFormat = InputArgs.getLastArgValue(OBJCOPY_output_target);
|
2018-10-12 02:36:01 +02:00
|
|
|
}
|
2019-07-05 07:28:38 +02:00
|
|
|
|
|
|
|
// FIXME: Currently, we ignore the target for non-binary/ihex formats
|
|
|
|
// explicitly specified by -I option (e.g. -Ielf32-x86-64) and guess the
|
|
|
|
// format by llvm::object::createBinary regardless of the option value.
|
|
|
|
Config.InputFormat = StringSwitch<FileFormat>(InputFormat)
|
|
|
|
.Case("binary", FileFormat::Binary)
|
|
|
|
.Case("ihex", FileFormat::IHex)
|
|
|
|
.Default(FileFormat::Unspecified);
|
|
|
|
|
2019-09-24 14:43:44 +02:00
|
|
|
if (InputArgs.hasArg(OBJCOPY_new_symbol_visibility))
|
[llvm-objcopy] Refactor ELF-specific config out to ELFCopyConfig. NFC.
Summary:
This patch splits the command-line parsing into two phases:
First, parse cross-platform options and leave ELF-specific options unparsed.
Second, in the ELF implementation, parse ELF-specific options and construct ELFCopyConfig.
Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich, MaskRay
Reviewed By: alexshap, jhenderson, jakehehrlich, MaskRay
Subscribers: mgorny, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67139
llvm-svn: 372712
2019-09-24 11:38:23 +02:00
|
|
|
Config.NewSymbolVisibility =
|
|
|
|
InputArgs.getLastArgValue(OBJCOPY_new_symbol_visibility);
|
2019-08-30 12:17:16 +02:00
|
|
|
|
2019-07-05 07:28:38 +02:00
|
|
|
Config.OutputFormat = StringSwitch<FileFormat>(OutputFormat)
|
|
|
|
.Case("binary", FileFormat::Binary)
|
|
|
|
.Case("ihex", FileFormat::IHex)
|
|
|
|
.Default(FileFormat::Unspecified);
|
2019-09-14 03:36:16 +02:00
|
|
|
if (Config.OutputFormat == FileFormat::Unspecified) {
|
|
|
|
if (OutputFormat.empty()) {
|
|
|
|
Config.OutputFormat = Config.InputFormat;
|
|
|
|
} else {
|
|
|
|
Expected<TargetInfo> Target =
|
|
|
|
getOutputTargetInfoByTargetName(OutputFormat);
|
|
|
|
if (!Target)
|
|
|
|
return Target.takeError();
|
|
|
|
Config.OutputFormat = Target->Format;
|
|
|
|
Config.OutputArch = Target->Machine;
|
|
|
|
}
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (auto Arg = InputArgs.getLastArg(OBJCOPY_compress_debug_sections,
|
|
|
|
OBJCOPY_compress_debug_sections_eq)) {
|
|
|
|
Config.CompressionType = DebugCompressionType::Z;
|
|
|
|
|
|
|
|
if (Arg->getOption().getID() == OBJCOPY_compress_debug_sections_eq) {
|
|
|
|
Config.CompressionType =
|
|
|
|
StringSwitch<DebugCompressionType>(
|
|
|
|
InputArgs.getLastArgValue(OBJCOPY_compress_debug_sections_eq))
|
|
|
|
.Case("zlib-gnu", DebugCompressionType::GNU)
|
|
|
|
.Case("zlib", DebugCompressionType::Z)
|
|
|
|
.Default(DebugCompressionType::None);
|
|
|
|
if (Config.CompressionType == DebugCompressionType::None)
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"invalid or unsupported --compress-debug-sections format: %s",
|
2019-02-21 18:05:19 +01:00
|
|
|
InputArgs.getLastArgValue(OBJCOPY_compress_debug_sections_eq)
|
|
|
|
.str()
|
|
|
|
.c_str());
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
2019-03-05 12:32:14 +01:00
|
|
|
if (!zlib::isAvailable())
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"LLVM was not compiled with LLVM_ENABLE_ZLIB: can not compress");
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Config.AddGnuDebugLink = InputArgs.getLastArgValue(OBJCOPY_add_gnu_debuglink);
|
2019-05-14 12:59:04 +02:00
|
|
|
// The gnu_debuglink's target is expected to not change or else its CRC would
|
|
|
|
// become invalidated and get rejected. We can avoid recalculating the
|
|
|
|
// checksum for every target file inside an archive by precomputing the CRC
|
|
|
|
// here. This prevents a significant amount of I/O.
|
|
|
|
if (!Config.AddGnuDebugLink.empty()) {
|
|
|
|
auto DebugOrErr = MemoryBuffer::getFile(Config.AddGnuDebugLink);
|
|
|
|
if (!DebugOrErr)
|
|
|
|
return createFileError(Config.AddGnuDebugLink, DebugOrErr.getError());
|
|
|
|
auto Debug = std::move(*DebugOrErr);
|
2019-10-09 11:06:30 +02:00
|
|
|
Config.GnuDebugLinkCRC32 =
|
|
|
|
llvm::crc32(arrayRefFromStringRef(Debug->getBuffer()));
|
2019-05-14 12:59:04 +02:00
|
|
|
}
|
2018-12-03 20:49:23 +01:00
|
|
|
Config.BuildIdLinkDir = InputArgs.getLastArgValue(OBJCOPY_build_id_link_dir);
|
|
|
|
if (InputArgs.hasArg(OBJCOPY_build_id_link_input))
|
|
|
|
Config.BuildIdLinkInput =
|
|
|
|
InputArgs.getLastArgValue(OBJCOPY_build_id_link_input);
|
|
|
|
if (InputArgs.hasArg(OBJCOPY_build_id_link_output))
|
|
|
|
Config.BuildIdLinkOutput =
|
|
|
|
InputArgs.getLastArgValue(OBJCOPY_build_id_link_output);
|
|
|
|
Config.SplitDWO = InputArgs.getLastArgValue(OBJCOPY_split_dwo);
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.SymbolsPrefix = InputArgs.getLastArgValue(OBJCOPY_prefix_symbols);
|
2019-05-08 11:49:35 +02:00
|
|
|
Config.AllocSectionsPrefix =
|
|
|
|
InputArgs.getLastArgValue(OBJCOPY_prefix_alloc_sections);
|
2019-06-07 19:57:48 +02:00
|
|
|
if (auto Arg = InputArgs.getLastArg(OBJCOPY_extract_partition))
|
|
|
|
Config.ExtractPartition = Arg->getValue();
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_redefine_symbol)) {
|
|
|
|
if (!StringRef(Arg->getValue()).contains('='))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"bad format for --redefine-sym");
|
2018-10-12 00:33:50 +02:00
|
|
|
auto Old2New = StringRef(Arg->getValue()).split('=');
|
|
|
|
if (!Config.SymbolsToRename.insert(Old2New).second)
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"multiple redefinition of symbol '%s'",
|
2019-02-21 18:05:19 +01:00
|
|
|
Old2New.first.str().c_str());
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 11:33:16 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_redefine_symbols))
|
|
|
|
if (Error E = addSymbolsToRenameFromFile(Config.SymbolsToRename, DC.Alloc,
|
|
|
|
Arg->getValue()))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-08 11:33:16 +01:00
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_rename_section)) {
|
2019-02-21 18:05:19 +01:00
|
|
|
Expected<SectionRename> SR =
|
|
|
|
parseRenameSectionValue(StringRef(Arg->getValue()));
|
|
|
|
if (!SR)
|
|
|
|
return SR.takeError();
|
|
|
|
if (!Config.SectionsToRename.try_emplace(SR->OriginalName, *SR).second)
|
|
|
|
return createStringError(errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"multiple renames of section '%s'",
|
2019-02-21 18:05:19 +01:00
|
|
|
SR->OriginalName.str().c_str());
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
2019-10-02 14:41:25 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_set_section_alignment)) {
|
|
|
|
Expected<std::pair<StringRef, uint64_t>> NameAndAlign =
|
|
|
|
parseSetSectionAlignment(Arg->getValue());
|
|
|
|
if (!NameAndAlign)
|
|
|
|
return NameAndAlign.takeError();
|
|
|
|
Config.SetSectionAlignment[NameAndAlign->first] = NameAndAlign->second;
|
|
|
|
}
|
[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
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_set_section_flags)) {
|
2019-02-21 18:05:19 +01:00
|
|
|
Expected<SectionFlagsUpdate> SFU =
|
|
|
|
parseSetSectionFlagValue(Arg->getValue());
|
|
|
|
if (!SFU)
|
|
|
|
return SFU.takeError();
|
|
|
|
if (!Config.SetSectionFlags.try_emplace(SFU->Name, *SFU).second)
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"--set-section-flags set multiple times for section '%s'",
|
2019-02-21 18:05:19 +01:00
|
|
|
SFU->Name.str().c_str());
|
[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
|
|
|
}
|
|
|
|
// Prohibit combinations of --set-section-flags when the section name is used
|
|
|
|
// by --rename-section, either as a source or a destination.
|
|
|
|
for (const auto &E : Config.SectionsToRename) {
|
|
|
|
const SectionRename &SR = E.second;
|
|
|
|
if (Config.SetSectionFlags.count(SR.OriginalName))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"--set-section-flags=%s conflicts with --rename-section=%s=%s",
|
|
|
|
SR.OriginalName.str().c_str(), SR.OriginalName.str().c_str(),
|
|
|
|
SR.NewName.str().c_str());
|
[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
|
|
|
if (Config.SetSectionFlags.count(SR.NewName))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"--set-section-flags=%s conflicts with --rename-section=%s=%s",
|
|
|
|
SR.NewName.str().c_str(), SR.OriginalName.str().c_str(),
|
|
|
|
SR.NewName.str().c_str());
|
[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
|
|
|
}
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_remove_section))
|
[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
|
|
|
if (Error E = Config.ToRemove.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SectionMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
[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-13 20:32:27 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_keep_section))
|
[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
|
|
|
if (Error E = Config.KeepSection.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SectionMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-12-06 03:03:53 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_only_section))
|
[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
|
|
|
if (Error E = Config.OnlySection.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SectionMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-07-29 18:22:40 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_add_section)) {
|
|
|
|
StringRef ArgValue(Arg->getValue());
|
|
|
|
if (!ArgValue.contains('='))
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"bad format for --add-section: missing '='");
|
|
|
|
if (ArgValue.split("=").second.empty())
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"bad format for --add-section: missing file name");
|
|
|
|
Config.AddSection.push_back(ArgValue);
|
|
|
|
}
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_dump_section))
|
|
|
|
Config.DumpSection.push_back(Arg->getValue());
|
|
|
|
Config.StripAll = InputArgs.hasArg(OBJCOPY_strip_all);
|
|
|
|
Config.StripAllGNU = InputArgs.hasArg(OBJCOPY_strip_all_gnu);
|
|
|
|
Config.StripDebug = InputArgs.hasArg(OBJCOPY_strip_debug);
|
|
|
|
Config.StripDWO = InputArgs.hasArg(OBJCOPY_strip_dwo);
|
|
|
|
Config.StripSections = InputArgs.hasArg(OBJCOPY_strip_sections);
|
|
|
|
Config.StripNonAlloc = InputArgs.hasArg(OBJCOPY_strip_non_alloc);
|
|
|
|
Config.StripUnneeded = InputArgs.hasArg(OBJCOPY_strip_unneeded);
|
|
|
|
Config.ExtractDWO = InputArgs.hasArg(OBJCOPY_extract_dwo);
|
2019-06-07 19:57:48 +02:00
|
|
|
Config.ExtractMainPartition =
|
|
|
|
InputArgs.hasArg(OBJCOPY_extract_main_partition);
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.LocalizeHidden = InputArgs.hasArg(OBJCOPY_localize_hidden);
|
|
|
|
Config.Weaken = InputArgs.hasArg(OBJCOPY_weaken);
|
[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
|
|
|
if (InputArgs.hasArg(OBJCOPY_discard_all, OBJCOPY_discard_locals))
|
|
|
|
Config.DiscardMode =
|
|
|
|
InputArgs.hasFlag(OBJCOPY_discard_all, OBJCOPY_discard_locals)
|
|
|
|
? DiscardType::All
|
|
|
|
: DiscardType::Locals;
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.OnlyKeepDebug = InputArgs.hasArg(OBJCOPY_only_keep_debug);
|
|
|
|
Config.KeepFileSymbols = InputArgs.hasArg(OBJCOPY_keep_file_symbols);
|
|
|
|
Config.DecompressDebugSections =
|
|
|
|
InputArgs.hasArg(OBJCOPY_decompress_debug_sections);
|
2019-05-03 16:14:01 +02:00
|
|
|
if (Config.DiscardMode == DiscardType::All)
|
|
|
|
Config.StripDebug = true;
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToLocalize.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-08 15:37:54 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbols))
|
2019-02-21 18:05:19 +01:00
|
|
|
if (Error E = addSymbolsFromFile(Config.SymbolsToLocalize, DC.Alloc,
|
[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
|
|
|
Arg->getValue(), SymbolMatchStyle,
|
|
|
|
ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_keep_global_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToKeepGlobal.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_keep_global_symbols))
|
2019-02-21 18:05:19 +01:00
|
|
|
if (Error E = addSymbolsFromFile(Config.SymbolsToKeepGlobal, DC.Alloc,
|
[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
|
|
|
Arg->getValue(), SymbolMatchStyle,
|
|
|
|
ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToGlobalize.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-08 15:37:54 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_globalize_symbols))
|
2019-02-21 18:05:19 +01:00
|
|
|
if (Error E = addSymbolsFromFile(Config.SymbolsToGlobalize, DC.Alloc,
|
[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
|
|
|
Arg->getValue(), SymbolMatchStyle,
|
|
|
|
ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_weaken_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToWeaken.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-08 15:37:54 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_weaken_symbols))
|
2019-02-21 18:05:19 +01:00
|
|
|
if (Error E = addSymbolsFromFile(Config.SymbolsToWeaken, DC.Alloc,
|
[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
|
|
|
Arg->getValue(), SymbolMatchStyle,
|
|
|
|
ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_strip_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToRemove.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-08 15:37:54 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_strip_symbols))
|
2019-02-21 18:05:19 +01:00
|
|
|
if (Error E = addSymbolsFromFile(Config.SymbolsToRemove, DC.Alloc,
|
[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
|
|
|
Arg->getValue(), SymbolMatchStyle,
|
|
|
|
ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-13 08:34:54 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_strip_unneeded_symbol))
|
[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
|
|
|
if (Error E =
|
|
|
|
Config.UnneededSymbolsToRemove.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-02-13 08:34:54 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_strip_unneeded_symbols))
|
2019-02-21 18:05:19 +01:00
|
|
|
if (Error E = addSymbolsFromFile(Config.UnneededSymbolsToRemove, DC.Alloc,
|
[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
|
|
|
Arg->getValue(), SymbolMatchStyle,
|
|
|
|
ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_keep_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToKeep.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-04-01 20:12:43 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_keep_symbols))
|
[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
|
|
|
if (Error E =
|
|
|
|
addSymbolsFromFile(Config.SymbolsToKeep, DC.Alloc, Arg->getValue(),
|
|
|
|
SymbolMatchStyle, ErrorCallback))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
[llvm-objcopy] Refactor ELF-specific config out to ELFCopyConfig. NFC.
Summary:
This patch splits the command-line parsing into two phases:
First, parse cross-platform options and leave ELF-specific options unparsed.
Second, in the ELF implementation, parse ELF-specific options and construct ELFCopyConfig.
Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich, MaskRay
Reviewed By: alexshap, jhenderson, jakehehrlich, MaskRay
Subscribers: mgorny, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67139
llvm-svn: 372712
2019-09-24 11:38:23 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(OBJCOPY_add_symbol))
|
|
|
|
Config.SymbolsToAdd.push_back(Arg->getValue());
|
2018-10-12 00:33:50 +02:00
|
|
|
|
2019-04-18 11:13:30 +02:00
|
|
|
Config.AllowBrokenLinks = InputArgs.hasArg(OBJCOPY_allow_broken_links);
|
|
|
|
|
2018-11-01 18:36:37 +01:00
|
|
|
Config.DeterministicArchives = InputArgs.hasFlag(
|
|
|
|
OBJCOPY_enable_deterministic_archives,
|
|
|
|
OBJCOPY_disable_deterministic_archives, /*default=*/true);
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.PreserveDates = InputArgs.hasArg(OBJCOPY_preserve_dates);
|
|
|
|
|
2019-06-15 07:32:23 +02:00
|
|
|
if (Config.PreserveDates &&
|
|
|
|
(Config.OutputFilename == "-" || Config.InputFilename == "-"))
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"--preserve-dates requires a file");
|
|
|
|
|
2019-02-26 10:24:22 +01:00
|
|
|
for (auto Arg : InputArgs)
|
|
|
|
if (Arg->getOption().matches(OBJCOPY_set_start)) {
|
|
|
|
auto EAddr = getAsInteger<uint64_t>(Arg->getValue());
|
|
|
|
if (!EAddr)
|
|
|
|
return createStringError(
|
|
|
|
EAddr.getError(), "bad entry point address: '%s'", Arg->getValue());
|
|
|
|
|
|
|
|
Config.EntryExpr = [EAddr](uint64_t) { return *EAddr; };
|
|
|
|
} else if (Arg->getOption().matches(OBJCOPY_change_start)) {
|
|
|
|
auto EIncr = getAsInteger<int64_t>(Arg->getValue());
|
|
|
|
if (!EIncr)
|
|
|
|
return createStringError(EIncr.getError(),
|
|
|
|
"bad entry point increment: '%s'",
|
|
|
|
Arg->getValue());
|
|
|
|
auto Expr = Config.EntryExpr ? std::move(Config.EntryExpr)
|
|
|
|
: [](uint64_t A) { return A; };
|
|
|
|
Config.EntryExpr = [Expr, EIncr](uint64_t EAddr) {
|
|
|
|
return Expr(EAddr) + *EIncr;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
if (Config.DecompressDebugSections &&
|
|
|
|
Config.CompressionType != DebugCompressionType::None) {
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"cannot specify both --compress-debug-sections and "
|
|
|
|
"--decompress-debug-sections");
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Config.DecompressDebugSections && !zlib::isAvailable())
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"LLVM was not compiled with LLVM_ENABLE_ZLIB: cannot decompress");
|
2018-10-12 00:33:50 +02:00
|
|
|
|
2019-06-07 19:57:48 +02:00
|
|
|
if (Config.ExtractPartition && Config.ExtractMainPartition)
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"cannot specify --extract-partition together with "
|
|
|
|
"--extract-main-partition");
|
|
|
|
|
2018-10-23 22:54:51 +02:00
|
|
|
DC.CopyConfigs.push_back(std::move(Config));
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(DC);
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
|
|
|
|
2019-11-20 08:30:52 +01:00
|
|
|
// ParseInstallNameToolOptions returns the config and sets the input arguments.
|
|
|
|
// If a help flag is set then ParseInstallNameToolOptions will print the help
|
|
|
|
// messege and exit.
|
|
|
|
Expected<DriverConfig>
|
|
|
|
parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr) {
|
|
|
|
DriverConfig DC;
|
|
|
|
CopyConfig Config;
|
|
|
|
InstallNameToolOptTable T;
|
|
|
|
unsigned MissingArgumentIndex, MissingArgumentCount;
|
|
|
|
llvm::opt::InputArgList InputArgs =
|
|
|
|
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
|
|
|
|
|
|
|
|
if (InputArgs.size() == 0) {
|
|
|
|
printHelp(T, errs(), "llvm-install-name-tool");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InputArgs.hasArg(INSTALL_NAME_TOOL_help)) {
|
|
|
|
printHelp(T, outs(), "llvm-install-name-tool");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InputArgs.hasArg(INSTALL_NAME_TOOL_version)) {
|
|
|
|
outs() << "llvm-install-name-tool, compatible with cctools "
|
|
|
|
"install_name_tool\n";
|
|
|
|
cl::PrintVersionMessage();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_add_rpath))
|
|
|
|
Config.RPathToAdd.push_back(Arg->getValue());
|
|
|
|
|
|
|
|
SmallVector<StringRef, 2> Positional;
|
|
|
|
for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN))
|
|
|
|
return createStringError(errc::invalid_argument, "unknown argument '%s'",
|
|
|
|
Arg->getAsString(InputArgs).c_str());
|
|
|
|
for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_INPUT))
|
|
|
|
Positional.push_back(Arg->getValue());
|
|
|
|
if (Positional.empty())
|
|
|
|
return createStringError(errc::invalid_argument, "no input file specified");
|
|
|
|
if (Positional.size() > 1)
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"llvm-install-name-tool expects a single input file");
|
|
|
|
Config.InputFilename = Positional[0];
|
|
|
|
Config.OutputFilename = Positional[0];
|
|
|
|
|
|
|
|
DC.CopyConfigs.push_back(std::move(Config));
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(DC);
|
2019-11-20 08:30:52 +01:00
|
|
|
}
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
// ParseStripOptions returns the config and sets the input arguments. If a
|
|
|
|
// help flag is set then ParseStripOptions will print the help messege and
|
|
|
|
// exit.
|
2019-06-18 02:39:10 +02:00
|
|
|
Expected<DriverConfig>
|
|
|
|
parseStripOptions(ArrayRef<const char *> ArgsArr,
|
[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
|
|
|
llvm::function_ref<Error(Error)> ErrorCallback) {
|
2018-10-12 00:33:50 +02:00
|
|
|
StripOptTable T;
|
|
|
|
unsigned MissingArgumentIndex, MissingArgumentCount;
|
|
|
|
llvm::opt::InputArgList InputArgs =
|
|
|
|
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
|
|
|
|
|
|
|
|
if (InputArgs.size() == 0) {
|
2019-09-14 03:14:43 +02:00
|
|
|
printHelp(T, errs(), "llvm-strip");
|
2018-10-12 00:33:50 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InputArgs.hasArg(STRIP_help)) {
|
2019-09-14 03:14:43 +02:00
|
|
|
printHelp(T, outs(), "llvm-strip");
|
2018-10-12 00:33:50 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InputArgs.hasArg(STRIP_version)) {
|
2018-11-28 07:51:50 +01:00
|
|
|
outs() << "llvm-strip, compatible with GNU strip\n";
|
2018-10-12 00:33:50 +02:00
|
|
|
cl::PrintVersionMessage();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2019-06-15 07:32:23 +02:00
|
|
|
SmallVector<StringRef, 2> Positional;
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(STRIP_UNKNOWN))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(errc::invalid_argument, "unknown argument '%s'",
|
|
|
|
Arg->getAsString(InputArgs).c_str());
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(STRIP_INPUT))
|
|
|
|
Positional.push_back(Arg->getValue());
|
|
|
|
|
|
|
|
if (Positional.empty())
|
2019-06-14 04:04:02 +02:00
|
|
|
return createStringError(errc::invalid_argument, "no input file specified");
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
if (Positional.size() > 1 && InputArgs.hasArg(STRIP_output))
|
2019-02-21 18:05:19 +01:00
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
2019-06-14 04:04:02 +02:00
|
|
|
"multiple input files cannot be used in combination with -o");
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
CopyConfig Config;
|
[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
|
|
|
|
|
|
|
if (InputArgs.hasArg(STRIP_regex) && InputArgs.hasArg(STRIP_wildcard))
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"--regex and --wildcard are incompatible");
|
|
|
|
MatchStyle SectionMatchStyle =
|
|
|
|
InputArgs.hasArg(STRIP_regex) ? MatchStyle::Regex : MatchStyle::Wildcard;
|
|
|
|
MatchStyle SymbolMatchStyle = InputArgs.hasArg(STRIP_regex)
|
|
|
|
? MatchStyle::Regex
|
|
|
|
: InputArgs.hasArg(STRIP_wildcard)
|
|
|
|
? MatchStyle::Wildcard
|
|
|
|
: MatchStyle::Literal;
|
2019-04-18 11:13:30 +02:00
|
|
|
Config.AllowBrokenLinks = InputArgs.hasArg(STRIP_allow_broken_links);
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug);
|
|
|
|
|
[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
|
|
|
if (InputArgs.hasArg(STRIP_discard_all, STRIP_discard_locals))
|
|
|
|
Config.DiscardMode =
|
|
|
|
InputArgs.hasFlag(STRIP_discard_all, STRIP_discard_locals)
|
|
|
|
? DiscardType::All
|
|
|
|
: DiscardType::Locals;
|
2019-08-08 02:35:16 +02:00
|
|
|
Config.StripSections = InputArgs.hasArg(STRIP_strip_sections);
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded);
|
2019-05-02 13:53:02 +02:00
|
|
|
if (auto Arg = InputArgs.getLastArg(STRIP_strip_all, STRIP_no_strip_all))
|
|
|
|
Config.StripAll = Arg->getOption().getID() == STRIP_strip_all;
|
2018-11-01 18:48:46 +01:00
|
|
|
Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
|
2019-03-14 22:51:42 +01:00
|
|
|
Config.OnlyKeepDebug = InputArgs.hasArg(STRIP_only_keep_debug);
|
2019-02-01 16:25:15 +01:00
|
|
|
Config.KeepFileSymbols = InputArgs.hasArg(STRIP_keep_file_symbols);
|
2018-10-12 00:33:50 +02:00
|
|
|
|
[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-13 20:32:27 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(STRIP_keep_section))
|
[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
|
|
|
if (Error E = Config.KeepSection.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SectionMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-11-01 18:48:46 +01:00
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(STRIP_remove_section))
|
[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
|
|
|
if (Error E = Config.ToRemove.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SectionMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
|
2019-01-31 13:16:20 +01:00
|
|
|
for (auto Arg : InputArgs.filtered(STRIP_strip_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToRemove.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-01-31 13:16:20 +01:00
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
for (auto Arg : InputArgs.filtered(STRIP_keep_symbol))
|
[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
|
|
|
if (Error E = Config.SymbolsToKeep.addMatcher(NameOrPattern::create(
|
|
|
|
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2018-10-12 00:33:50 +02:00
|
|
|
|
2019-05-02 13:53:02 +02:00
|
|
|
if (!InputArgs.hasArg(STRIP_no_strip_all) && !Config.StripDebug &&
|
|
|
|
!Config.StripUnneeded && Config.DiscardMode == DiscardType::None &&
|
|
|
|
!Config.StripAllGNU && Config.SymbolsToRemove.empty())
|
2019-01-31 13:16:20 +01:00
|
|
|
Config.StripAll = true;
|
|
|
|
|
2019-05-03 16:14:01 +02:00
|
|
|
if (Config.DiscardMode == DiscardType::All)
|
|
|
|
Config.StripDebug = true;
|
|
|
|
|
2018-11-01 18:36:37 +01:00
|
|
|
Config.DeterministicArchives =
|
|
|
|
InputArgs.hasFlag(STRIP_enable_deterministic_archives,
|
|
|
|
STRIP_disable_deterministic_archives, /*default=*/true);
|
|
|
|
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.PreserveDates = InputArgs.hasArg(STRIP_preserve_dates);
|
2019-07-05 07:28:38 +02:00
|
|
|
Config.InputFormat = FileFormat::Unspecified;
|
|
|
|
Config.OutputFormat = FileFormat::Unspecified;
|
2018-10-12 00:33:50 +02:00
|
|
|
|
|
|
|
DriverConfig DC;
|
|
|
|
if (Positional.size() == 1) {
|
|
|
|
Config.InputFilename = Positional[0];
|
|
|
|
Config.OutputFilename =
|
|
|
|
InputArgs.getLastArgValue(STRIP_output, Positional[0]);
|
|
|
|
DC.CopyConfigs.push_back(std::move(Config));
|
|
|
|
} else {
|
2019-06-18 02:39:10 +02:00
|
|
|
StringMap<unsigned> InputFiles;
|
2019-06-15 07:32:23 +02:00
|
|
|
for (StringRef Filename : Positional) {
|
2019-06-18 02:39:10 +02:00
|
|
|
if (InputFiles[Filename]++ == 1) {
|
|
|
|
if (Filename == "-")
|
|
|
|
return createStringError(
|
|
|
|
errc::invalid_argument,
|
|
|
|
"cannot specify '-' as an input file more than once");
|
|
|
|
if (Error E = ErrorCallback(createStringError(
|
|
|
|
errc::invalid_argument, "'%s' was already specified",
|
|
|
|
Filename.str().c_str())))
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(E);
|
2019-06-18 02:39:10 +02:00
|
|
|
}
|
2018-10-12 00:33:50 +02:00
|
|
|
Config.InputFilename = Filename;
|
|
|
|
Config.OutputFilename = Filename;
|
|
|
|
DC.CopyConfigs.push_back(Config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 07:32:23 +02:00
|
|
|
if (Config.PreserveDates && (is_contained(Positional, "-") ||
|
|
|
|
InputArgs.getLastArgValue(STRIP_output) == "-"))
|
|
|
|
return createStringError(errc::invalid_argument,
|
|
|
|
"--preserve-dates requires a file");
|
|
|
|
|
2020-02-10 16:06:45 +01:00
|
|
|
return std::move(DC);
|
2018-10-12 00:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace objcopy
|
|
|
|
} // namespace llvm
|