2021-04-08 06:50:12 +08:00
|
|
|
//===- IFSHandler.cpp -----------------------------------------------------===//
|
2018-12-04 03:30:52 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-12-04 03:30:52 +08:00
|
|
|
//
|
|
|
|
//===-----------------------------------------------------------------------===/
|
|
|
|
|
2021-04-08 06:50:12 +08:00
|
|
|
#include "llvm/InterfaceStub/IFSHandler.h"
|
2022-02-19 03:13:55 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2018-12-04 03:30:52 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2020-08-12 02:44:22 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2021-04-01 07:48:56 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2021-04-08 06:50:12 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
|
|
|
#include "llvm/InterfaceStub/IFSStub.h"
|
2018-12-04 03:30:52 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2022-02-19 03:13:55 +08:00
|
|
|
#include "llvm/Support/GlobPattern.h"
|
2021-04-01 07:48:56 +08:00
|
|
|
#include "llvm/Support/LineIterator.h"
|
2018-12-04 03:30:52 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2022-02-19 03:13:55 +08:00
|
|
|
#include <functional>
|
2018-12-04 03:30:52 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
2021-04-02 11:55:11 +08:00
|
|
|
using namespace llvm::ifs;
|
2018-12-04 03:30:52 +08:00
|
|
|
|
2021-04-08 06:50:12 +08:00
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(IFSSymbol)
|
2018-12-04 03:30:52 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
|
|
|
|
/// YAML traits for ELFSymbolType.
|
2021-04-08 06:50:12 +08:00
|
|
|
template <> struct ScalarEnumerationTraits<IFSSymbolType> {
|
|
|
|
static void enumeration(IO &IO, IFSSymbolType &SymbolType) {
|
|
|
|
IO.enumCase(SymbolType, "NoType", IFSSymbolType::NoType);
|
|
|
|
IO.enumCase(SymbolType, "Func", IFSSymbolType::Func);
|
|
|
|
IO.enumCase(SymbolType, "Object", IFSSymbolType::Object);
|
|
|
|
IO.enumCase(SymbolType, "TLS", IFSSymbolType::TLS);
|
|
|
|
IO.enumCase(SymbolType, "Unknown", IFSSymbolType::Unknown);
|
2018-12-04 03:30:52 +08:00
|
|
|
// Treat other symbol types as noise, and map to Unknown.
|
|
|
|
if (!IO.outputting() && IO.matchEnumFallback())
|
2021-04-08 06:50:12 +08:00
|
|
|
SymbolType = IFSSymbolType::Unknown;
|
2018-12-04 03:30:52 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-08 06:50:12 +08:00
|
|
|
template <> struct ScalarTraits<IFSEndiannessType> {
|
|
|
|
static void output(const IFSEndiannessType &Value, void *,
|
2018-12-04 03:30:52 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
|
|
|
switch (Value) {
|
2021-04-08 06:50:12 +08:00
|
|
|
case IFSEndiannessType::Big:
|
2021-04-01 07:48:56 +08:00
|
|
|
Out << "big";
|
2018-12-04 03:30:52 +08:00
|
|
|
break;
|
2021-04-08 06:50:12 +08:00
|
|
|
case IFSEndiannessType::Little:
|
2021-04-01 07:48:56 +08:00
|
|
|
Out << "little";
|
2018-12-04 03:30:52 +08:00
|
|
|
break;
|
|
|
|
default:
|
2021-04-01 07:48:56 +08:00
|
|
|
llvm_unreachable("Unsupported endianness");
|
2018-12-04 03:30:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 06:50:12 +08:00
|
|
|
static StringRef input(StringRef Scalar, void *, IFSEndiannessType &Value) {
|
|
|
|
Value = StringSwitch<IFSEndiannessType>(Scalar)
|
|
|
|
.Case("big", IFSEndiannessType::Big)
|
|
|
|
.Case("little", IFSEndiannessType::Little)
|
|
|
|
.Default(IFSEndiannessType::Unknown);
|
|
|
|
if (Value == IFSEndiannessType::Unknown) {
|
2021-04-01 07:48:56 +08:00
|
|
|
return "Unsupported endianness";
|
|
|
|
}
|
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
static QuotingType mustQuote(StringRef) { return QuotingType::None; }
|
|
|
|
};
|
|
|
|
|
2021-04-08 06:50:12 +08:00
|
|
|
template <> struct ScalarTraits<IFSBitWidthType> {
|
|
|
|
static void output(const IFSBitWidthType &Value, void *,
|
2021-04-01 07:48:56 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
|
|
|
switch (Value) {
|
2021-04-08 06:50:12 +08:00
|
|
|
case IFSBitWidthType::IFS32:
|
2021-04-01 07:48:56 +08:00
|
|
|
Out << "32";
|
|
|
|
break;
|
2021-04-08 06:50:12 +08:00
|
|
|
case IFSBitWidthType::IFS64:
|
2021-04-01 07:48:56 +08:00
|
|
|
Out << "64";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported bit width");
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 03:30:52 +08:00
|
|
|
|
2021-04-08 06:50:12 +08:00
|
|
|
static StringRef input(StringRef Scalar, void *, IFSBitWidthType &Value) {
|
|
|
|
Value = StringSwitch<IFSBitWidthType>(Scalar)
|
|
|
|
.Case("32", IFSBitWidthType::IFS32)
|
|
|
|
.Case("64", IFSBitWidthType::IFS64)
|
|
|
|
.Default(IFSBitWidthType::Unknown);
|
|
|
|
if (Value == IFSBitWidthType::Unknown) {
|
2021-04-01 07:48:56 +08:00
|
|
|
return "Unsupported bit width";
|
|
|
|
}
|
2018-12-04 03:30:52 +08:00
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
static QuotingType mustQuote(StringRef) { return QuotingType::None; }
|
|
|
|
};
|
|
|
|
|
2021-04-01 07:48:56 +08:00
|
|
|
template <> struct MappingTraits<IFSTarget> {
|
|
|
|
static void mapping(IO &IO, IFSTarget &Target) {
|
|
|
|
IO.mapOptional("ObjectFormat", Target.ObjectFormat);
|
|
|
|
IO.mapOptional("Arch", Target.ArchString);
|
|
|
|
IO.mapOptional("Endianness", Target.Endianness);
|
|
|
|
IO.mapOptional("BitWidth", Target.BitWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compacts symbol information into a single line.
|
|
|
|
static const bool flow = true; // NOLINT(readability-identifier-naming)
|
|
|
|
};
|
|
|
|
|
2018-12-04 03:30:52 +08:00
|
|
|
/// YAML traits for ELFSymbol.
|
2021-04-08 06:50:12 +08:00
|
|
|
template <> struct MappingTraits<IFSSymbol> {
|
|
|
|
static void mapping(IO &IO, IFSSymbol &Symbol) {
|
2021-04-01 07:48:56 +08:00
|
|
|
IO.mapRequired("Name", Symbol.Name);
|
2018-12-04 03:30:52 +08:00
|
|
|
IO.mapRequired("Type", Symbol.Type);
|
|
|
|
// The need for symbol size depends on the symbol type.
|
2021-04-08 06:50:12 +08:00
|
|
|
if (Symbol.Type == IFSSymbolType::NoType) {
|
2022-05-15 02:50:20 +08:00
|
|
|
// Size is None, so we are reading it in, or it is non 0 so we
|
|
|
|
// should emit it.
|
|
|
|
if (!Symbol.Size || *Symbol.Size)
|
|
|
|
IO.mapOptional("Size", Symbol.Size);
|
|
|
|
} else if (Symbol.Type != IFSSymbolType::Func) {
|
|
|
|
IO.mapOptional("Size", Symbol.Size);
|
2018-12-04 03:30:52 +08:00
|
|
|
}
|
|
|
|
IO.mapOptional("Undefined", Symbol.Undefined, false);
|
2018-12-22 04:45:58 +08:00
|
|
|
IO.mapOptional("Weak", Symbol.Weak, false);
|
2018-12-04 03:30:52 +08:00
|
|
|
IO.mapOptional("Warning", Symbol.Warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compacts symbol information into a single line.
|
2021-04-01 07:48:56 +08:00
|
|
|
static const bool flow = true; // NOLINT(readability-identifier-naming)
|
2018-12-04 03:30:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// YAML traits for ELFStub objects.
|
2021-04-08 06:50:12 +08:00
|
|
|
template <> struct MappingTraits<IFSStub> {
|
|
|
|
static void mapping(IO &IO, IFSStub &Stub) {
|
2021-04-01 07:48:56 +08:00
|
|
|
if (!IO.mapTag("!ifs-v1", true))
|
2018-12-04 03:30:52 +08:00
|
|
|
IO.setError("Not a .tbe YAML file.");
|
2021-04-08 06:50:12 +08:00
|
|
|
IO.mapRequired("IfsVersion", Stub.IfsVersion);
|
2018-12-11 09:00:16 +08:00
|
|
|
IO.mapOptional("SoName", Stub.SoName);
|
2021-04-01 07:48:56 +08:00
|
|
|
IO.mapOptional("Target", Stub.Target);
|
2018-12-07 09:31:28 +08:00
|
|
|
IO.mapOptional("NeededLibs", Stub.NeededLibs);
|
2018-12-04 03:30:52 +08:00
|
|
|
IO.mapRequired("Symbols", Stub.Symbols);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-01 07:48:56 +08:00
|
|
|
/// YAML traits for ELFStubTriple objects.
|
2021-04-08 06:50:12 +08:00
|
|
|
template <> struct MappingTraits<IFSStubTriple> {
|
|
|
|
static void mapping(IO &IO, IFSStubTriple &Stub) {
|
2021-04-01 07:48:56 +08:00
|
|
|
if (!IO.mapTag("!ifs-v1", true))
|
|
|
|
IO.setError("Not a .tbe YAML file.");
|
2021-04-08 06:50:12 +08:00
|
|
|
IO.mapRequired("IfsVersion", Stub.IfsVersion);
|
2021-04-01 07:48:56 +08:00
|
|
|
IO.mapOptional("SoName", Stub.SoName);
|
|
|
|
IO.mapOptional("Target", Stub.Target.Triple);
|
|
|
|
IO.mapOptional("NeededLibs", Stub.NeededLibs);
|
|
|
|
IO.mapRequired("Symbols", Stub.Symbols);
|
|
|
|
}
|
|
|
|
};
|
2018-12-04 03:30:52 +08:00
|
|
|
} // end namespace yaml
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2021-04-01 07:48:56 +08:00
|
|
|
/// Attempt to determine if a Text stub uses target triple.
|
|
|
|
bool usesTriple(StringRef Buf) {
|
|
|
|
for (line_iterator I(MemoryBufferRef(Buf, "ELFStub")); !I.is_at_eof(); ++I) {
|
|
|
|
StringRef Line = (*I).trim();
|
|
|
|
if (Line.startswith("Target:")) {
|
2021-10-23 23:45:27 +08:00
|
|
|
if (Line == "Target:" || Line.contains("{")) {
|
2021-04-01 07:48:56 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
Expected<std::unique_ptr<IFSStub>> ifs::readIFSFromBuffer(StringRef Buf) {
|
2018-12-04 03:30:52 +08:00
|
|
|
yaml::Input YamlIn(Buf);
|
2021-04-08 06:50:12 +08:00
|
|
|
std::unique_ptr<IFSStubTriple> Stub(new IFSStubTriple());
|
2021-04-01 07:48:56 +08:00
|
|
|
if (usesTriple(Buf)) {
|
|
|
|
YamlIn >> *Stub;
|
|
|
|
} else {
|
2021-04-08 06:50:12 +08:00
|
|
|
YamlIn >> *static_cast<IFSStub *>(Stub.get());
|
2021-04-01 07:48:56 +08:00
|
|
|
}
|
|
|
|
if (std::error_code Err = YamlIn.error()) {
|
2021-04-08 06:50:12 +08:00
|
|
|
return createStringError(Err, "YAML failed reading as IFS");
|
2021-04-01 07:48:56 +08:00
|
|
|
}
|
2018-12-10 10:36:33 +08:00
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
if (Stub->IfsVersion > IFSVersionCurrent)
|
2020-10-21 08:50:29 +08:00
|
|
|
return make_error<StringError>(
|
2021-04-08 06:50:12 +08:00
|
|
|
"IFS version " + Stub->IfsVersion.getAsString() + " is unsupported.",
|
2020-10-21 08:50:29 +08:00
|
|
|
std::make_error_code(std::errc::invalid_argument));
|
2021-04-01 07:48:56 +08:00
|
|
|
if (Stub->Target.ArchString) {
|
|
|
|
Stub->Target.Arch =
|
2022-06-21 13:45:45 +08:00
|
|
|
ELF::convertArchNameToEMachine(*Stub->Target.ArchString);
|
2021-04-01 07:48:56 +08:00
|
|
|
}
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(Stub);
|
2018-12-04 03:30:52 +08:00
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
Error ifs::writeIFSToOutputStream(raw_ostream &OS, const IFSStub &Stub) {
|
2021-12-29 00:52:25 +08:00
|
|
|
yaml::Output YamlOut(OS, nullptr, /*WrapColumn =*/0);
|
2021-04-08 06:50:12 +08:00
|
|
|
std::unique_ptr<IFSStubTriple> CopyStub(new IFSStubTriple(Stub));
|
2021-04-01 07:48:56 +08:00
|
|
|
if (Stub.Target.Arch) {
|
|
|
|
CopyStub->Target.ArchString = std::string(
|
|
|
|
ELF::convertEMachineToArchName(Stub.Target.Arch.getValue()));
|
|
|
|
}
|
|
|
|
IFSTarget Target = Stub.Target;
|
|
|
|
|
|
|
|
if (CopyStub->Target.Triple ||
|
|
|
|
(!CopyStub->Target.ArchString && !CopyStub->Target.Endianness &&
|
|
|
|
!CopyStub->Target.BitWidth))
|
|
|
|
YamlOut << *CopyStub;
|
|
|
|
else
|
2021-04-08 06:50:12 +08:00
|
|
|
YamlOut << *static_cast<IFSStub *>(CopyStub.get());
|
2021-04-01 07:48:56 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
Error ifs::overrideIFSTarget(IFSStub &Stub, Optional<IFSArch> OverrideArch,
|
|
|
|
Optional<IFSEndiannessType> OverrideEndianness,
|
|
|
|
Optional<IFSBitWidthType> OverrideBitWidth,
|
|
|
|
Optional<std::string> OverrideTriple) {
|
2021-04-01 07:48:56 +08:00
|
|
|
std::error_code OverrideEC(1, std::generic_category());
|
|
|
|
if (OverrideArch) {
|
|
|
|
if (Stub.Target.Arch &&
|
|
|
|
Stub.Target.Arch.getValue() != OverrideArch.getValue()) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"Supplied Arch conflicts with the text stub", OverrideEC);
|
|
|
|
}
|
|
|
|
Stub.Target.Arch = OverrideArch.getValue();
|
|
|
|
}
|
|
|
|
if (OverrideEndianness) {
|
|
|
|
if (Stub.Target.Endianness &&
|
|
|
|
Stub.Target.Endianness.getValue() != OverrideEndianness.getValue()) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"Supplied Endianness conflicts with the text stub", OverrideEC);
|
|
|
|
}
|
|
|
|
Stub.Target.Endianness = OverrideEndianness.getValue();
|
|
|
|
}
|
|
|
|
if (OverrideBitWidth) {
|
|
|
|
if (Stub.Target.BitWidth &&
|
|
|
|
Stub.Target.BitWidth.getValue() != OverrideBitWidth.getValue()) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"Supplied BitWidth conflicts with the text stub", OverrideEC);
|
|
|
|
}
|
|
|
|
Stub.Target.BitWidth = OverrideBitWidth.getValue();
|
|
|
|
}
|
|
|
|
if (OverrideTriple) {
|
|
|
|
if (Stub.Target.Triple &&
|
|
|
|
Stub.Target.Triple.getValue() != OverrideTriple.getValue()) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"Supplied Triple conflicts with the text stub", OverrideEC);
|
|
|
|
}
|
|
|
|
Stub.Target.Triple = OverrideTriple.getValue();
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
2018-12-04 03:30:52 +08:00
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
Error ifs::validateIFSTarget(IFSStub &Stub, bool ParseTriple) {
|
2021-04-01 07:48:56 +08:00
|
|
|
std::error_code ValidationEC(1, std::generic_category());
|
|
|
|
if (Stub.Target.Triple) {
|
|
|
|
if (Stub.Target.Arch || Stub.Target.BitWidth || Stub.Target.Endianness ||
|
|
|
|
Stub.Target.ObjectFormat) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"Target triple cannot be used simultaneously with ELF target format",
|
|
|
|
ValidationEC);
|
|
|
|
}
|
|
|
|
if (ParseTriple) {
|
2022-06-21 13:45:45 +08:00
|
|
|
IFSTarget TargetFromTriple = parseTriple(*Stub.Target.Triple);
|
2021-04-01 07:48:56 +08:00
|
|
|
Stub.Target.Arch = TargetFromTriple.Arch;
|
|
|
|
Stub.Target.BitWidth = TargetFromTriple.BitWidth;
|
|
|
|
Stub.Target.Endianness = TargetFromTriple.Endianness;
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
if (!Stub.Target.Arch || !Stub.Target.BitWidth || !Stub.Target.Endianness) {
|
|
|
|
// TODO: unify the error message.
|
|
|
|
if (!Stub.Target.Arch) {
|
|
|
|
return make_error<StringError>("Arch is not defined in the text stub",
|
|
|
|
ValidationEC);
|
|
|
|
}
|
|
|
|
if (!Stub.Target.BitWidth) {
|
|
|
|
return make_error<StringError>("BitWidth is not defined in the text stub",
|
|
|
|
ValidationEC);
|
|
|
|
}
|
|
|
|
if (!Stub.Target.Endianness) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"Endianness is not defined in the text stub", ValidationEC);
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 03:30:52 +08:00
|
|
|
return Error::success();
|
|
|
|
}
|
2021-04-01 07:48:56 +08:00
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
IFSTarget ifs::parseTriple(StringRef TripleStr) {
|
2021-04-01 07:48:56 +08:00
|
|
|
Triple IFSTriple(TripleStr);
|
|
|
|
IFSTarget RetTarget;
|
|
|
|
// TODO: Implement a Triple Arch enum to e_machine map.
|
|
|
|
switch (IFSTriple.getArch()) {
|
|
|
|
case Triple::ArchType::aarch64:
|
2021-04-08 06:50:12 +08:00
|
|
|
RetTarget.Arch = (IFSArch)ELF::EM_AARCH64;
|
2021-04-01 07:48:56 +08:00
|
|
|
break;
|
|
|
|
case Triple::ArchType::x86_64:
|
2021-04-08 06:50:12 +08:00
|
|
|
RetTarget.Arch = (IFSArch)ELF::EM_X86_64;
|
2021-04-01 07:48:56 +08:00
|
|
|
break;
|
|
|
|
default:
|
2021-04-08 06:50:12 +08:00
|
|
|
RetTarget.Arch = (IFSArch)ELF::EM_NONE;
|
2021-04-01 07:48:56 +08:00
|
|
|
}
|
2021-04-08 06:50:12 +08:00
|
|
|
RetTarget.Endianness = IFSTriple.isLittleEndian() ? IFSEndiannessType::Little
|
|
|
|
: IFSEndiannessType::Big;
|
2021-04-01 07:48:56 +08:00
|
|
|
RetTarget.BitWidth =
|
2021-04-08 06:50:12 +08:00
|
|
|
IFSTriple.isArch64Bit() ? IFSBitWidthType::IFS64 : IFSBitWidthType::IFS32;
|
2021-04-01 07:48:56 +08:00
|
|
|
return RetTarget;
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
void ifs::stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
|
|
|
|
bool StripEndianness, bool StripBitWidth) {
|
2021-04-01 07:48:56 +08:00
|
|
|
if (StripTriple || StripArch) {
|
|
|
|
Stub.Target.Arch.reset();
|
|
|
|
Stub.Target.ArchString.reset();
|
|
|
|
}
|
|
|
|
if (StripTriple || StripEndianness) {
|
|
|
|
Stub.Target.Endianness.reset();
|
|
|
|
}
|
|
|
|
if (StripTriple || StripBitWidth) {
|
|
|
|
Stub.Target.BitWidth.reset();
|
|
|
|
}
|
|
|
|
if (StripTriple) {
|
|
|
|
Stub.Target.Triple.reset();
|
|
|
|
}
|
|
|
|
if (!Stub.Target.Arch && !Stub.Target.BitWidth && !Stub.Target.Endianness) {
|
|
|
|
Stub.Target.ObjectFormat.reset();
|
|
|
|
}
|
|
|
|
}
|
2021-08-20 08:39:36 +08:00
|
|
|
|
2022-02-19 03:13:55 +08:00
|
|
|
Error ifs::filterIFSSyms(IFSStub &Stub, bool StripUndefined,
|
|
|
|
const std::vector<std::string> &Exclude) {
|
|
|
|
std::function<bool(const IFSSymbol &)> Filter = [](const IFSSymbol &) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (StripUndefined) {
|
|
|
|
Filter = [Filter](const IFSSymbol &Sym) {
|
|
|
|
return Sym.Undefined || Filter(Sym);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
for (StringRef Glob : Exclude) {
|
|
|
|
Expected<llvm::GlobPattern> PatternOrErr = llvm::GlobPattern::create(Glob);
|
|
|
|
if (!PatternOrErr)
|
|
|
|
return PatternOrErr.takeError();
|
|
|
|
Filter = [Pattern = *PatternOrErr, Filter](const IFSSymbol &Sym) {
|
|
|
|
return Pattern.match(Sym.Name) || Filter(Sym);
|
|
|
|
};
|
2021-08-20 08:39:36 +08:00
|
|
|
}
|
2022-02-19 03:13:55 +08:00
|
|
|
|
|
|
|
llvm::erase_if(Stub.Symbols, Filter);
|
|
|
|
|
|
|
|
return Error::success();
|
2021-08-20 08:39:36 +08:00
|
|
|
}
|