Revert "[Autolink Extract] Keep a set of linker flags instead of vector"

This commit is contained in:
Artem Chikin
2022-05-23 16:03:09 -07:00
committed by GitHub
parent 54102ef207
commit 3e8a115195
2 changed files with 9 additions and 35 deletions

View File

@@ -18,7 +18,6 @@
#include <string>
#include <vector>
#include <unordered_set>
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/Frontend/Frontend.h"
@@ -113,7 +112,6 @@ public:
/// Return 'true' if there was an error, and 'false' otherwise.
static bool
extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
std::unordered_set<std::string> &SeenLinkerLibraryFlags,
std::vector<std::string> &LinkerFlags,
CompilerInstance &Instance) {
// Search for the section we hold autolink entries in
@@ -142,15 +140,8 @@ extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
llvm::SmallVector<llvm::StringRef, 4> SplitFlags;
SectionData->split(SplitFlags, llvm::StringRef("\0", 1), -1,
/*KeepEmpty=*/false);
for (const auto &Flag : SplitFlags) {
// If this is a library '-lxxx' flag, only add it if we have not seen it before
if (Flag.str().rfind("-l", 0) == 0) {
auto SeenFlagsInsertResult = SeenLinkerLibraryFlags.insert(Flag.str());
if (SeenFlagsInsertResult.second == true)
LinkerFlags.push_back(Flag.str());
} else
LinkerFlags.push_back(Flag.str());
}
for (const auto &Flag : SplitFlags)
LinkerFlags.push_back(Flag.str());
}
}
return false;
@@ -161,7 +152,6 @@ extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
/// 'true' if there was an error, and 'false' otherwise.
static bool
extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
std::unordered_set<std::string> &SeenLinkerLibraryFlags,
std::vector<std::string> &LinkerFlags,
CompilerInstance &Instance) {
// Search for the data segment we hold autolink entries in
@@ -174,15 +164,8 @@ extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
llvm::SmallVector<llvm::StringRef, 4> SplitFlags;
SegmentData.split(SplitFlags, llvm::StringRef("\0", 1), -1,
/*KeepEmpty=*/false);
for (const auto &Flag : SplitFlags) {
// If this is a library '-lxxx' flag, only add it if we have not seen it before
if (Flag.str().rfind("-l", 0) == 0) {
auto SeenFlagsInsertResult = SeenLinkerLibraryFlags.insert(Flag.str());
if (SeenFlagsInsertResult.second == true)
LinkerFlags.push_back(Flag.str());
} else
LinkerFlags.push_back(Flag.str());
}
for (const auto &Flag : SplitFlags)
LinkerFlags.push_back(Flag.str());
}
}
return false;
@@ -195,13 +178,12 @@ extractLinkerFlagsFromObjectFile(const llvm::object::WasmObjectFile *ObjectFile,
static bool extractLinkerFlags(const llvm::object::Binary *Bin,
CompilerInstance &Instance,
StringRef BinaryFileName,
std::unordered_set<std::string> &SeenLinkerLibraryFlags,
std::vector<std::string> &LinkerFlags) {
if (auto *ObjectFile = llvm::dyn_cast<llvm::object::ELFObjectFileBase>(Bin)) {
return extractLinkerFlagsFromObjectFile(ObjectFile, SeenLinkerLibraryFlags, LinkerFlags, Instance);
return extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags, Instance);
} else if (auto *ObjectFile =
llvm::dyn_cast<llvm::object::WasmObjectFile>(Bin)) {
return extractLinkerFlagsFromObjectFile(ObjectFile, SeenLinkerLibraryFlags, LinkerFlags, Instance);
return extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags, Instance);
} else if (auto *Archive = llvm::dyn_cast<llvm::object::Archive>(Bin)) {
llvm::Error Error = llvm::Error::success();
for (const auto &Child : Archive->children(Error)) {
@@ -215,7 +197,7 @@ static bool extractLinkerFlags(const llvm::object::Binary *Bin,
return true;
}
if (extractLinkerFlags(ChildBinary->get(), Instance, BinaryFileName,
SeenLinkerLibraryFlags, LinkerFlags)) {
LinkerFlags)) {
return true;
}
}
@@ -246,8 +228,6 @@ int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
}
std::vector<std::string> LinkerFlags;
// Flags of the form '-lxxx' seen so far
std::unordered_set<std::string> SeenLinkerLibraryFlags;
// Extract the linker flags from the objects.
for (const auto &BinaryFileName : Invocation.getInputFilenames()) {
@@ -265,7 +245,7 @@ int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
}
if (extractLinkerFlags(BinaryOwner->getBinary(), Instance, BinaryFileName,
SeenLinkerLibraryFlags, LinkerFlags)) {
LinkerFlags)) {
return 1;
}
}