@@ -107,26 +107,38 @@ class AutolinkExtractInvocation {
107
107
108
108
// / Look inside the object file 'ObjectFile' and append any linker flags found in
109
109
// / its ".swift1_autolink_entries" section to 'LinkerFlags'.
110
- static void
110
+ // / Return 'true' if there was an error, and 'false' otherwise.
111
+ static bool
111
112
extractLinkerFlagsFromObjectFile (const llvm::object::ObjectFile *ObjectFile,
112
- std::vector<std::string> &LinkerFlags) {
113
+ std::vector<std::string> &LinkerFlags,
114
+ CompilerInstance &Instance) {
113
115
// Search for the section we hold autolink entries in
114
116
for (auto &Section : ObjectFile->sections ()) {
115
117
llvm::StringRef SectionName;
116
118
Section.getName (SectionName);
117
119
if (SectionName == " .swift1_autolink_entries" ) {
118
- llvm::StringRef SectionData;
119
- Section.getContents (SectionData);
120
+ llvm::Expected<llvm::StringRef> SectionData = Section.getContents ();
121
+ if (!SectionData) {
122
+ std::string message;
123
+ {
124
+ llvm::raw_string_ostream os (message);
125
+ logAllUnhandledErrors (SectionData.takeError (), os, " " );
126
+ }
127
+ Instance.getDiags ().diagnose (SourceLoc (), diag::error_open_input_file,
128
+ ObjectFile->getFileName () , message);
129
+ return true ;
130
+ }
120
131
121
132
// entries are null-terminated, so extract them and push them into
122
133
// the set.
123
134
llvm::SmallVector<llvm::StringRef, 4 > SplitFlags;
124
- SectionData. split (SplitFlags, llvm::StringRef (" \0 " , 1 ), -1 ,
125
- /* KeepEmpty=*/ false );
135
+ SectionData-> split (SplitFlags, llvm::StringRef (" \0 " , 1 ), -1 ,
136
+ /* KeepEmpty=*/ false );
126
137
for (const auto &Flag : SplitFlags)
127
138
LinkerFlags.push_back (Flag);
128
139
}
129
140
}
141
+ return false ;
130
142
}
131
143
132
144
// / 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,
138
150
StringRef BinaryFileName,
139
151
std::vector<std::string> &LinkerFlags) {
140
152
if (auto *ObjectFile = llvm::dyn_cast<llvm::object::ELFObjectFileBase>(Bin)) {
141
- extractLinkerFlagsFromObjectFile (ObjectFile, LinkerFlags);
142
- return false ;
153
+ return extractLinkerFlagsFromObjectFile (ObjectFile, LinkerFlags, Instance);
143
154
} else if (auto *ObjectFile =
144
155
llvm::dyn_cast<llvm::object::COFFObjectFile>(Bin)) {
145
- extractLinkerFlagsFromObjectFile (ObjectFile, LinkerFlags);
146
- return false ;
156
+ return extractLinkerFlagsFromObjectFile (ObjectFile, LinkerFlags, Instance);
147
157
} else if (auto *Archive = llvm::dyn_cast<llvm::object::Archive>(Bin)) {
148
158
llvm::Error Error = llvm::Error::success ();
149
159
for (const auto &Child : Archive->children (Error)) {
0 commit comments