mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SectionRef::getContents() now returns Expected
Updated uses of object::SectionRef::getContents() since it now returns an Expected<StringRef> instead of modifying the one it's passed. See also: git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360892 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
committed by
Gwen Mittertreiner
parent
dff6b6e258
commit
67cfef2d60
@@ -107,26 +107,38 @@ public:
|
||||
|
||||
/// Look inside the object file 'ObjectFile' and append any linker flags found in
|
||||
/// its ".swift1_autolink_entries" section to 'LinkerFlags'.
|
||||
static void
|
||||
/// Return 'true' if there was an error, and 'false' otherwise.
|
||||
static bool
|
||||
extractLinkerFlagsFromObjectFile(const llvm::object::ObjectFile *ObjectFile,
|
||||
std::vector<std::string> &LinkerFlags) {
|
||||
std::vector<std::string> &LinkerFlags,
|
||||
CompilerInstance &Instance) {
|
||||
// Search for the section we hold autolink entries in
|
||||
for (auto &Section : ObjectFile->sections()) {
|
||||
llvm::StringRef SectionName;
|
||||
Section.getName(SectionName);
|
||||
if (SectionName == ".swift1_autolink_entries") {
|
||||
llvm::StringRef SectionData;
|
||||
Section.getContents(SectionData);
|
||||
llvm::Expected<llvm::StringRef> SectionData = Section.getContents();
|
||||
if (!SectionData) {
|
||||
std::string message;
|
||||
{
|
||||
llvm::raw_string_ostream os(message);
|
||||
logAllUnhandledErrors(SectionData.takeError(), os, "");
|
||||
}
|
||||
Instance.getDiags().diagnose(SourceLoc(), diag::error_open_input_file,
|
||||
ObjectFile->getFileName() , message);
|
||||
return true;
|
||||
}
|
||||
|
||||
// entries are null-terminated, so extract them and push them into
|
||||
// the set.
|
||||
llvm::SmallVector<llvm::StringRef, 4> SplitFlags;
|
||||
SectionData.split(SplitFlags, llvm::StringRef("\0", 1), -1,
|
||||
/*KeepEmpty=*/false);
|
||||
SectionData->split(SplitFlags, llvm::StringRef("\0", 1), -1,
|
||||
/*KeepEmpty=*/false);
|
||||
for (const auto &Flag : SplitFlags)
|
||||
LinkerFlags.push_back(Flag);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Look inside the binary 'Bin' and append any linker flags found in its
|
||||
@@ -138,12 +150,10 @@ static bool extractLinkerFlags(const llvm::object::Binary *Bin,
|
||||
StringRef BinaryFileName,
|
||||
std::vector<std::string> &LinkerFlags) {
|
||||
if (auto *ObjectFile = llvm::dyn_cast<llvm::object::ELFObjectFileBase>(Bin)) {
|
||||
extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags);
|
||||
return false;
|
||||
return extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags, Instance);
|
||||
} else if (auto *ObjectFile =
|
||||
llvm::dyn_cast<llvm::object::COFFObjectFile>(Bin)) {
|
||||
extractLinkerFlagsFromObjectFile(ObjectFile, LinkerFlags);
|
||||
return false;
|
||||
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)) {
|
||||
|
||||
Reference in New Issue
Block a user