2019-03-22 23:46:52 +01:00
|
|
|
//===- InterfaceFile.cpp --------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implements the Interface File.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-04-05 18:59:50 +02:00
|
|
|
#include "llvm/TextAPI/InterfaceFile.h"
|
2019-03-22 23:46:52 +01:00
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
|
2020-06-24 23:39:54 +02:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::MachO;
|
|
|
|
|
|
|
|
namespace {
|
2019-03-22 23:46:52 +01:00
|
|
|
template <typename C>
|
|
|
|
typename C::iterator addEntry(C &Container, StringRef InstallName) {
|
2019-06-30 13:19:56 +02:00
|
|
|
auto I = partition_point(Container, [=](const InterfaceFileRef &O) {
|
|
|
|
return O.getInstallName() < InstallName;
|
2019-06-21 07:40:31 +02:00
|
|
|
});
|
2019-06-30 13:19:56 +02:00
|
|
|
if (I != Container.end() && I->getInstallName() == InstallName)
|
2019-03-22 23:46:52 +01:00
|
|
|
return I;
|
|
|
|
|
|
|
|
return Container.emplace(I, InstallName);
|
|
|
|
}
|
2019-09-20 16:32:34 +02:00
|
|
|
|
|
|
|
template <typename C>
|
|
|
|
typename C::iterator addEntry(C &Container, const Target &Target_) {
|
|
|
|
auto Iter =
|
|
|
|
lower_bound(Container, Target_, [](const Target &LHS, const Target &RHS) {
|
|
|
|
return LHS < RHS;
|
|
|
|
});
|
|
|
|
if ((Iter != std::end(Container)) && !(Target_ < *Iter))
|
|
|
|
return Iter;
|
|
|
|
|
|
|
|
return Container.insert(Iter, Target_);
|
|
|
|
}
|
2020-06-24 23:39:54 +02:00
|
|
|
} // end namespace
|
2019-03-22 23:46:52 +01:00
|
|
|
|
2019-09-20 16:32:34 +02:00
|
|
|
void InterfaceFileRef::addTarget(const Target &Target) {
|
2020-06-24 23:39:54 +02:00
|
|
|
addEntry(Targets, Target);
|
2019-09-20 16:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceFile::addAllowableClient(StringRef InstallName,
|
|
|
|
const Target &Target) {
|
2020-06-24 23:39:54 +02:00
|
|
|
auto Client = addEntry(AllowableClients, InstallName);
|
2019-09-20 16:32:34 +02:00
|
|
|
Client->addTarget(Target);
|
2019-03-22 23:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceFile::addReexportedLibrary(StringRef InstallName,
|
2019-09-20 16:32:34 +02:00
|
|
|
const Target &Target) {
|
2020-06-24 23:39:54 +02:00
|
|
|
auto Lib = addEntry(ReexportedLibraries, InstallName);
|
2019-09-20 16:32:34 +02:00
|
|
|
Lib->addTarget(Target);
|
2019-03-22 23:46:52 +01:00
|
|
|
}
|
|
|
|
|
2019-09-20 16:32:34 +02:00
|
|
|
void InterfaceFile::addParentUmbrella(const Target &Target_, StringRef Parent) {
|
|
|
|
auto Iter = lower_bound(ParentUmbrellas, Target_,
|
|
|
|
[](const std::pair<Target, std::string> &LHS,
|
|
|
|
Target RHS) { return LHS.first < RHS; });
|
2019-03-22 23:46:52 +01:00
|
|
|
|
2019-09-20 16:32:34 +02:00
|
|
|
if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {
|
2020-01-28 20:23:46 +01:00
|
|
|
Iter->second = std::string(Parent);
|
2019-03-22 23:46:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:49:54 +01:00
|
|
|
ParentUmbrellas.emplace(Iter, Target_, std::string(Parent));
|
2019-03-22 23:46:52 +01:00
|
|
|
}
|
|
|
|
|
2019-09-20 16:32:34 +02:00
|
|
|
void InterfaceFile::addUUID(const Target &Target_, StringRef UUID) {
|
|
|
|
auto Iter = lower_bound(UUIDs, Target_,
|
|
|
|
[](const std::pair<Target, std::string> &LHS,
|
|
|
|
Target RHS) { return LHS.first < RHS; });
|
|
|
|
|
|
|
|
if ((Iter != UUIDs.end()) && !(Target_ < Iter->first)) {
|
2020-01-28 20:23:46 +01:00
|
|
|
Iter->second = std::string(UUID);
|
2019-09-20 16:32:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-29 02:09:24 +01:00
|
|
|
UUIDs.emplace(Iter, Target_, std::string(UUID));
|
2019-09-20 16:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceFile::addUUID(const Target &Target, uint8_t UUID[16]) {
|
2019-03-22 23:46:52 +01:00
|
|
|
std::stringstream Stream;
|
|
|
|
for (unsigned i = 0; i < 16; ++i) {
|
|
|
|
if (i == 4 || i == 6 || i == 8 || i == 10)
|
|
|
|
Stream << '-';
|
|
|
|
Stream << std::setfill('0') << std::setw(2) << std::uppercase << std::hex
|
|
|
|
<< static_cast<int>(UUID[i]);
|
|
|
|
}
|
2019-09-20 16:32:34 +02:00
|
|
|
addUUID(Target, Stream.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceFile::addTarget(const Target &Target) {
|
2020-06-24 23:39:54 +02:00
|
|
|
addEntry(Targets, Target);
|
2019-09-20 16:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InterfaceFile::const_filtered_target_range
|
|
|
|
InterfaceFile::targets(ArchitectureSet Archs) const {
|
|
|
|
std::function<bool(const Target &)> fn = [Archs](const Target &Target_) {
|
|
|
|
return Archs.has(Target_.Arch);
|
|
|
|
};
|
|
|
|
return make_filter_range(Targets, fn);
|
2019-03-22 23:46:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceFile::addSymbol(SymbolKind Kind, StringRef Name,
|
2019-09-20 16:32:34 +02:00
|
|
|
const TargetList &Targets, SymbolFlags Flags) {
|
2019-03-22 23:46:52 +01:00
|
|
|
Name = copyString(Name);
|
|
|
|
auto result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
|
|
|
|
if (result.second)
|
2019-09-20 16:32:34 +02:00
|
|
|
result.first->second = new (Allocator) Symbol{Kind, Name, Targets, Flags};
|
2019-03-22 23:46:52 +01:00
|
|
|
else
|
2019-09-20 16:32:34 +02:00
|
|
|
for (const auto &Target : Targets)
|
|
|
|
result.first->second->addTarget(Target);
|
2019-03-22 23:46:52 +01:00
|
|
|
}
|
2021-02-18 20:27:54 +01:00
|
|
|
|
|
|
|
void InterfaceFile::addDocument(std::shared_ptr<InterfaceFile> &&Document) {
|
|
|
|
auto Pos = llvm::lower_bound(Documents, Document,
|
|
|
|
[](const std::shared_ptr<InterfaceFile> &LHS,
|
|
|
|
const std::shared_ptr<InterfaceFile> &RHS) {
|
|
|
|
return LHS->InstallName < RHS->InstallName;
|
|
|
|
});
|
[lld-macho] Change loadReexport to handle the case where a TAPI re-exports to reference documents nested within other TBD.
Currently, it was delibrately impleneted to not handle this case, but as it has turnt out, we need this feature.
The concrete use case is
`System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa` reexports
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit , which then rexports
/System/Library/PrivateFrameworks/UIFoundation.framework/Versions/A/UIFoundation
The current implemention uses a global currentTopLevelTapi, which is not reset until it finishes loading the whole tree.
This is a problem because if the top-level is set to Cocoa, then when we get to UIFoundation, it will try to find UIFoundation in the current top level, which is Cocoa and will not find it.
The right thing should be:
- When loading a library from a TBD file, re-exports need to be looked up in the auxiliary documents within the same TBD.
- When loading from an actual dylib, no additional TBD documents need to be examined.
- In no case does a re-export mentioned in one TBD file need to be looked up in a document in an auxiliary document from a different TBD file
Differential Revision: https://reviews.llvm.org/D97438
2021-02-25 05:47:22 +01:00
|
|
|
Document->Parent = this;
|
2021-02-18 20:27:54 +01:00
|
|
|
Documents.insert(Pos, Document);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InterfaceFile::operator==(const InterfaceFile &O) const {
|
2021-04-02 20:42:48 +02:00
|
|
|
if (Targets != O.Targets)
|
|
|
|
return false;
|
|
|
|
if (InstallName != O.InstallName)
|
|
|
|
return false;
|
|
|
|
if ((CurrentVersion != O.CurrentVersion) ||
|
|
|
|
(CompatibilityVersion != O.CompatibilityVersion))
|
|
|
|
return false;
|
|
|
|
if (SwiftABIVersion != O.SwiftABIVersion)
|
|
|
|
return false;
|
|
|
|
if (IsTwoLevelNamespace != O.IsTwoLevelNamespace)
|
|
|
|
return false;
|
|
|
|
if (IsAppExtensionSafe != O.IsAppExtensionSafe)
|
|
|
|
return false;
|
|
|
|
if (IsInstallAPI != O.IsInstallAPI)
|
|
|
|
return false;
|
|
|
|
if (ParentUmbrellas != O.ParentUmbrellas)
|
|
|
|
return false;
|
|
|
|
if (AllowableClients != O.AllowableClients)
|
|
|
|
return false;
|
|
|
|
if (ReexportedLibraries != O.ReexportedLibraries)
|
|
|
|
return false;
|
|
|
|
if (Symbols != O.Symbols)
|
|
|
|
return false;
|
|
|
|
if (!std::equal(Documents.begin(), Documents.end(), O.Documents.begin(),
|
|
|
|
O.Documents.end(),
|
|
|
|
[](const std::shared_ptr<InterfaceFile> LHS,
|
|
|
|
const std::shared_ptr<InterfaceFile> RHS) {
|
|
|
|
return *LHS == *RHS;
|
|
|
|
}))
|
|
|
|
return false;
|
|
|
|
return true;
|
2021-02-18 20:27:54 +01:00
|
|
|
}
|