r253060 - Fix auto-link for text-based dynamic library SDKs.

Juergen Ributzka via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 13 11:08:07 PST 2015


Author: ributzka
Date: Fri Nov 13 13:08:07 2015
New Revision: 253060

URL: http://llvm.org/viewvc/llvm-project?rev=253060&view=rev
Log:
Fix auto-link for text-based dynamic library SDKs.

When linking against text-based dynamic library SDKs the library name of a
framework has now more than one possible filename extensions. This fix tests for
both possible extensions (none, and .tbd).

This fixes rdar://problem/20609975

Added:
    cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/
    cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/AutolinkTBD.tbd
    cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/Headers/
    cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/Headers/AutolinkTBD.h
    cfe/trunk/test/Modules/autolinkTBD.m
Modified:
    cfe/trunk/lib/Lex/ModuleMap.cpp

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=253060&r1=253059&r2=253060&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Nov 13 13:08:07 2015
@@ -581,9 +581,18 @@ static void inferFrameworkLink(Module *M
   SmallString<128> LibName;
   LibName += FrameworkDir->getName();
   llvm::sys::path::append(LibName, Mod->Name);
-  if (FileMgr.getFile(LibName)) {
-    Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
-                                                     /*IsFramework=*/true));
+
+  // The library name of a framework has more than one possible extension since
+  // the introduction of the text-based dynamic library format. We need to check
+  // for both before we give up.
+  static const char *frameworkExtensions[] = {"", ".tbd"};
+  for (const auto *extension : frameworkExtensions) {
+    llvm::sys::path::replace_extension(LibName, extension);
+    if (FileMgr.getFile(LibName)) {
+      Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
+                                                       /*IsFramework=*/true));
+      return;
+    }
   }
 }
 

Added: cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/AutolinkTBD.tbd
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/AutolinkTBD.tbd?rev=253060&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/AutolinkTBD.tbd (added)
+++ cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/AutolinkTBD.tbd Fri Nov 13 13:08:07 2015
@@ -0,0 +1 @@
+empty file - clang only needs to check if it exists.

Added: cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/Headers/AutolinkTBD.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/Headers/AutolinkTBD.h?rev=253060&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/Headers/AutolinkTBD.h (added)
+++ cfe/trunk/test/Modules/Inputs/AutolinkTBD.framework/Headers/AutolinkTBD.h Fri Nov 13 13:08:07 2015
@@ -0,0 +1 @@
+extern int foo();

Added: cfe/trunk/test/Modules/autolinkTBD.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/autolinkTBD.m?rev=253060&view=auto
==============================================================================
--- cfe/trunk/test/Modules/autolinkTBD.m (added)
+++ cfe/trunk/test/Modules/autolinkTBD.m Fri Nov 13 13:08:07 2015
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -fno-autolink -o - -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s | FileCheck --check-prefix=CHECK-AUTOLINK-DISABLED %s
+
+ at import AutolinkTBD;
+
+int f() {
+  return foo();
+}
+
+// CHECK: !llvm.module.flags = !{{{.*}}}
+// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[AUTOLINK_OPTIONS:[0-9]+]]}
+// CHECK: ![[AUTOLINK_OPTIONS]] = !{![[AUTOLINK_FRAMEWORK:[0-9]+]]}
+// CHECK: ![[AUTOLINK_FRAMEWORK]] = !{!"-framework", !"AutolinkTBD"}
+
+// CHECK-AUTOLINK-DISABLED: !llvm.module.flags
+// CHECK-AUTOLINK-DISABLED-NOT: "Linker Options"




More information about the cfe-commits mailing list