// with a path of .*/libfoo.{dylib, tbd}.
// XXX ld64 seems to ignore the extension entirely when matching sub-libraries;
// I'm not sure what the use case for that is.
-static bool markSubLibrary(StringRef searchName) {
+static bool markReexport(StringRef searchName, ArrayRef<StringRef> extensions) {
for (InputFile *file : inputFiles) {
if (auto *dylibFile = dyn_cast<DylibFile>(file)) {
StringRef filename = path::filename(dylibFile->getName());
if (filename.consume_front(searchName) &&
- (filename == ".dylib" || filename == ".tbd")) {
+ (filename.empty() ||
+ find(extensions, filename) != extensions.end())) {
dylibFile->reexport = true;
return true;
}
// Now that all dylibs have been loaded, search for those that should be
// re-exported.
- for (opt::Arg *arg : args.filtered(OPT_sub_library)) {
+ for (opt::Arg *arg : args.filtered(OPT_sub_library, OPT_sub_umbrella)) {
config->hasReexports = true;
StringRef searchName = arg->getValue();
- if (!markSubLibrary(searchName))
- error("-sub_library " + searchName + " does not match a supplied dylib");
+ std::vector<StringRef> extensions;
+ if (arg->getOption().getID() == OPT_sub_library)
+ extensions = {".dylib", ".tbd"};
+ else
+ extensions = {".tbd"};
+ if (!markReexport(searchName, extensions))
+ error(arg->getSpelling() + " " + searchName +
+ " does not match a supplied dylib");
}
// Parse LTO options.
# RUN: --check-prefix=HELLO-HEADERS
# HELLO-HEADERS: NO_REEXPORTED_DYLIBS
-# RUN: llvm-objdump --macho --all-headers %t/libgoodbye.dylib | FileCheck %s -DDIR=%t \
-# RUN: --check-prefix=GOODBYE-HEADERS
-# GOODBYE-HEADERS-NOT: NO_REEXPORTED_DYLIBS
-# GOODBYE-HEADERS: cmd LC_REEXPORT_DYLIB
-# GOODBYE-HEADERS-NOT: Load command
-# GOODBYE-HEADERS: name [[DIR]]/libhello.dylib
-
-# RUN: llvm-objdump --macho --all-headers %t/libsuper.dylib | FileCheck %s -DDIR=%t \
-# RUN: --check-prefix=SUPER-HEADERS
-# SUPER-HEADERS-NOT: NO_REEXPORTED_DYLIBS
-# SUPER-HEADERS: cmd LC_REEXPORT_DYLIB
-# SUPER-HEADERS-NOT: Load command
-# SUPER-HEADERS: name [[DIR]]/libgoodbye.dylib
+# RUN: llvm-objdump --macho --all-headers %t/libgoodbye.dylib | FileCheck %s \
+# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libhello.dylib
+
+# RUN: llvm-objdump --macho --all-headers %t/libsuper.dylib | FileCheck %s \
+# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib
+
+# REEXPORT-HEADERS-NOT: NO_REEXPORTED_DYLIBS
+# REEXPORT-HEADERS: cmd LC_REEXPORT_DYLIB
+# REEXPORT-HEADERS-NOT: Load command
+# REEXPORT-HEADERS: name [[PATH]]
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/sub-library.o
# RUN: %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o
# RUN: | FileCheck %s --check-prefix=MISSING-REEXPORT -DDIR=%t
# MISSING-REEXPORT: error: unable to locate re-export with install name [[DIR]]/libgoodbye.dylib
+
+## We can match dylibs without extensions too.
+# RUN: mkdir -p %t/Hello.framework/Versions
+# RUN: %lld -dylib %t/libhello.o -o %t/Hello.framework/Versions/Hello
+# RUN: %lld -dylib -o %t/libgoodbye2.dylib -sub_library Hello %t/Hello.framework/Versions/Hello %t/libgoodbye.o
+# RUN: llvm-objdump --macho --all-headers %t/libgoodbye2.dylib | FileCheck %s \
+# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Versions/Hello
+
+## -sub_umbrella works almost identically...
+# RUN: %lld -dylib -o %t/libgoodbye3.dylib -sub_umbrella Hello %t/Hello.framework/Versions/Hello %t/libgoodbye.o
+# RUN: llvm-objdump --macho --all-headers %t/libgoodbye3.dylib | FileCheck %s \
+# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Versions/Hello
+
+## But it doesn't match .dylib extensions:
+# RUN: not %lld -dylib -L%t -sub_umbrella libhello -lhello %t/libgoodbye.o \
+# RUN: -o %t/libgoodbye.dylib 2>&1 | FileCheck %s --check-prefix=MISSING-FRAMEWORK
+# MISSING-FRAMEWORK: error: -sub_umbrella libhello does not match a supplied dylib
+
.text
.globl _main