lld: initial pass at supporting TBD

Add support to lld to use Text Based API stubs for linking.  This is
support is incomplete not filtering out platforms.  It also does not
account for architecture specific API handling and potentially does not
correctly handle trees of re-exports with inlined libraries being
treated as direct children of the top level library.
This commit is contained in:
Saleem Abdulrasool
2020-06-05 11:18:33 -07:00
parent 48c28d58c6
commit 6fe27b5fed
8 changed files with 141 additions and 4 deletions

View File

@@ -75,19 +75,20 @@ opt::InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
}
static Optional<std::string> findLibrary(StringRef name) {
std::string stub = (llvm::Twine("lib") + name + ".tbd").str();
std::string shared = (llvm::Twine("lib") + name + ".dylib").str();
std::string archive = (llvm::Twine("lib") + name + ".a").str();
llvm::SmallString<260> location;
for (StringRef dir : config->searchPaths) {
for (StringRef library : {shared, archive}) {
for (StringRef library : {stub, shared, archive}) {
location = dir;
llvm::sys::path::append(location, library);
if (fs::exists(location))
return location.str().str();
}
}
return None;
return {};
}
static TargetInfo *createTargetInfo(opt::InputArgList &args) {
@@ -135,6 +136,16 @@ static void addFile(StringRef path) {
case file_magic::macho_dynamically_linked_shared_lib:
inputFiles.push_back(make<DylibFile>(mbref));
break;
case file_magic::tapi_file: {
llvm::Expected<std::unique_ptr<llvm::MachO::InterfaceFile>> result =
TextAPIReader::get(mbref);
if (!result)
return;
std::unique_ptr<llvm::MachO::InterfaceFile> interface{std::move(*result)};
inputFiles.push_back(make<DylibFile>(std::move(interface)));
break;
}
default:
error(path + ": unhandled file type");
}