Skip to content

Commit 4c7ee01

Browse files
committed
fix: isStaticFramework when linked libraries are set explicitly
First check whether a file with the same name as the framework exists and only after that try the first specified link library
1 parent 840af44 commit 4c7ee01

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/Binary/binarySerializer.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,42 +197,59 @@ void binary::BinarySerializer::serializeContainer(std::vector<std::pair<clang::M
197197
this->finish(container);
198198
}
199199

200-
static llvm::ErrorOr<bool> isStaticFramework(clang::Module* framework)
201-
{
200+
static llvm::ErrorOr<llvm::SmallString<128>> getFrameworkLib(clang::Module* framework, const std::string& library) {
202201
using namespace llvm;
203-
using namespace llvm::object;
204202
using namespace llvm::sys;
205203

206-
if (framework->LinkLibraries.size() == 0) {
207-
return errc::no_such_file_or_directory;
208-
}
209-
210-
std::string library = framework->LinkLibraries[0].Library;
211-
212204
SmallString<128> path;
213205
if (!path::is_absolute(library)) {
214206
path::append(path, framework->Directory->getName());
215207
}
216208
path::append(path, library);
217-
209+
218210
if (!fs::exists(path)) {
219211
path.append(".tbd");
220212
if (fs::exists(path)) {
221213
// A TBD file is a text-based file used by Apple. It contains information about a .DYLIB library.
222214
// TBD files were introduced in Xcode 7 in September 2015 in order to reduce the size of SDKs
223215
// that come with Xcode by linking to DYLIB libraries instead of storing the actual, larger DYLIB libraries.
224-
return false;
216+
return path;
225217
}
226218

227219
return errc::no_such_file_or_directory;
228220
}
221+
222+
return path;
223+
}
224+
225+
static llvm::ErrorOr<bool> isStaticFramework(clang::Module* framework)
226+
{
227+
using namespace llvm;
228+
using namespace llvm::object;
229+
using namespace llvm::sys;
230+
231+
llvm::ErrorOr<SmallString<128>> path = getFrameworkLib(framework, framework->Name);
232+
233+
if(path.getError()) {
234+
if (framework->LinkLibraries.size() == 0) {
235+
return errc::no_such_file_or_directory;
236+
}
237+
238+
path = getFrameworkLib(framework, framework->LinkLibraries[0].Library);
239+
}
240+
241+
if (path.getError()) {
242+
return path.getError();
243+
} else if (path.get().endswith(".tbd")) {
244+
return true;
245+
}
229246

230247
auto isDylib = [](MachOObjectFile* machObjectFile) -> bool {
231248
uint32_t filetype = (machObjectFile->is64Bit() ? machObjectFile->getHeader64().filetype : machObjectFile->getHeader().filetype);
232249
return (filetype == MachO::MH_DYLIB || filetype == MachO::MH_DYLIB_STUB || filetype == MachO::MH_DYLINKER);
233250
};
234251

235-
if (Expected<OwningBinary<Binary> > binaryOrErr = createBinary(path)) {
252+
if (Expected<OwningBinary<Binary> > binaryOrErr = createBinary(path.get())) {
236253
Binary& binary = *binaryOrErr.get().getBinary();
237254

238255
if (MachOUniversalBinary* machoBinary = dyn_cast<MachOUniversalBinary>(&binary)) {

0 commit comments

Comments
 (0)