Index: llvm/trunk/lib/LTO/LTO.cpp
===================================================================
--- llvm/trunk/lib/LTO/LTO.cpp
+++ llvm/trunk/lib/LTO/LTO.cpp
@@ -60,23 +60,14 @@
     // but turned into a weak, while the others will drop it when possible.
     if (!HasMultipleCopies) {
       // Exported Linkonce needs to be promoted to not be discarded.
-      // FIXME: This should handle LinkOnceAny as well, but that should be a
-      // follow-on to the NFC restructuring:
-      // if (GlobalValue::isLinkOnceLinkage(OriginalLinkage) &&
-      //     isExported(S->modulePath(), GUID))
-      //   S->setLinkage(GlobalValue::getWeakLinkage(
-      //       GlobalValue::isLinkOnceODRLinkage(OriginalLinkage)));
-      if (GlobalValue::isLinkOnceODRLinkage(OriginalLinkage) &&
+      if (GlobalValue::isLinkOnceLinkage(OriginalLinkage) &&
           isExported(S->modulePath(), GUID))
-        S->setLinkage(GlobalValue::WeakODRLinkage);
+        S->setLinkage(GlobalValue::getWeakLinkage(
+            GlobalValue::isLinkOnceODRLinkage(OriginalLinkage)));
     } else if (isPrevailing(GUID, S.get())) {
-      // FIXME: This should handle LinkOnceAny as well, but that should be a
-      // follow-on to the NFC restructuring:
-      // if (GlobalValue::isLinkOnceLinkage(OriginalLinkage))
-      //   S->setLinkage(GlobalValue::getWeakLinkage(
-      //       GlobalValue::isLinkOnceODRLinkage(OriginalLinkage)));
-      if (GlobalValue::isLinkOnceODRLinkage(OriginalLinkage))
-        S->setLinkage(GlobalValue::WeakODRLinkage);
+      if (GlobalValue::isLinkOnceLinkage(OriginalLinkage))
+        S->setLinkage(GlobalValue::getWeakLinkage(
+            GlobalValue::isLinkOnceODRLinkage(OriginalLinkage)));
     }
     // Alias can't be turned into available_externally.
     else if (!isa<AliasSummary>(S.get()) &&
Index: llvm/trunk/test/ThinLTO/X86/Inputs/odr_resolution.ll
===================================================================
--- llvm/trunk/test/ThinLTO/X86/Inputs/odr_resolution.ll
+++ llvm/trunk/test/ThinLTO/X86/Inputs/odr_resolution.ll
@@ -1,29 +0,0 @@
-target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-apple-macosx10.11.0"
-
-; Alias are not optimized
-@linkoncealias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
-
-; Function with an alias are not optimized
-define linkonce_odr void @linkonceodrfuncwithalias() #0 {
-entry:
-  ret void
-}
-
-define linkonce_odr void @linkonceodrfunc() #0 {
-entry:
-  ret void
-}
-define linkonce void @linkoncefunc() #0 {
-entry:
-  ret void
-}
-define weak_odr void @weakodrfunc() #0 {
-entry:
-  ret void
-}
-define weak void @weakfunc() #0 {
-entry:
-  ret void
-}
-
Index: llvm/trunk/test/ThinLTO/X86/Inputs/weak_resolution.ll
===================================================================
--- llvm/trunk/test/ThinLTO/X86/Inputs/weak_resolution.ll
+++ llvm/trunk/test/ThinLTO/X86/Inputs/weak_resolution.ll
@@ -0,0 +1,38 @@
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; Alias are not optimized
+@linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
+
+; Alias are not optimized
+@linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
+
+; Function with an alias are not optimized
+define linkonce_odr void @linkonceodrfuncwithalias() #0 {
+entry:
+  ret void
+}
+
+; Function with an alias are not optimized
+define linkonce void @linkoncefuncwithalias() #0 {
+entry:
+  ret void
+}
+
+define linkonce_odr void @linkonceodrfunc() #0 {
+entry:
+  ret void
+}
+define linkonce void @linkoncefunc() #0 {
+entry:
+  ret void
+}
+define weak_odr void @weakodrfunc() #0 {
+entry:
+  ret void
+}
+define weak void @weakfunc() #0 {
+entry:
+  ret void
+}
+
Index: llvm/trunk/test/ThinLTO/X86/alias_resolution.ll
===================================================================
--- llvm/trunk/test/ThinLTO/X86/alias_resolution.ll
+++ llvm/trunk/test/ThinLTO/X86/alias_resolution.ll
@@ -8,7 +8,8 @@
 
 ; NOTPROMOTED: @linkonceODRfuncAlias = alias void (...), bitcast (void ()* @linkonceODRfunc{{.*}} to void (...)*)
 ; NOTPROMOTED: @linkonceODRfuncWeakAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc{{.*}} to void (...)*)
-; NOTPROMOTED: @linkonceODRfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @linkonceODRfunc{{.*}} to void (...)*)
+; PROMOTE_MOD1: @linkonceODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc{{.*}} to void (...)*)
+; PROMOTE_MOD2: @linkonceODRfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @linkonceODRfunc{{.*}} to void (...)*)
 ; PROMOTE_MOD1: @linkonceODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc.mod1 to void (...)*)
 ; PROMOTE_MOD2: @linkonceODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
 ; PROMOTE_MOD1: @linkonceODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc.mod1 to void (...)*)
@@ -16,7 +17,8 @@
 
 ; NOTPROMOTED: @weakODRfuncAlias = alias void (...), bitcast (void ()* @weakODRfunc{{.*}} to void (...)*)
 ; NOTPROMOTED: @weakODRfuncWeakAlias = weak alias void (...), bitcast (void ()* @weakODRfunc{{.*}} to void (...)*)
-; NOTPROMOTED: @weakODRfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @weakODRfunc{{.*}} to void (...)*)
+; PROMOTE_MOD1: @weakODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @weakODRfunc{{.*}} to void (...)*)
+; PROMOTE_MOD2: @weakODRfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @weakODRfunc{{.*}} to void (...)*)
 ; PROMOTE_MOD1: @weakODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc.mod1 to void (...)*)
 ; PROMOTE_MOD2: @weakODRfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc to void (...)*)
 ; PROMOTE_MOD1: @weakODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @weakODRfunc.mod1 to void (...)*)
@@ -24,7 +26,8 @@
 
 ; NOTPROMOTED: @linkoncefuncAlias = alias void (...), bitcast (void ()* @linkoncefunc{{.*}} to void (...)*)
 ; NOTPROMOTED: @linkoncefuncWeakAlias = weak alias void (...), bitcast (void ()* @linkoncefunc{{.*}} to void (...)*)
-; NOTPROMOTED: @linkoncefuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @linkoncefunc{{.*}} to void (...)*)
+; PROMOTE_MOD1: @linkoncefuncLinkonceAlias = weak alias void (...), bitcast (void ()* @linkoncefunc{{.*}} to void (...)*)
+; PROMOTE_MOD2: @linkoncefuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @linkoncefunc{{.*}} to void (...)*)
 ; PROMOTE_MOD1: @linkoncefuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkoncefunc.mod1 to void (...)*)
 ; PROMOTE_MOD2: @linkoncefuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @linkoncefunc to void (...)*)
 ; PROMOTE_MOD1: @linkoncefuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkoncefunc.mod1 to void (...)*)
@@ -32,7 +35,8 @@
 
 ; NOTPROMOTED: @weakfuncAlias = alias void (...), bitcast (void ()* @weakfunc{{.*}} to void (...)*)
 ; NOTPROMOTED: @weakfuncWeakAlias = weak alias void (...), bitcast (void ()* @weakfunc{{.*}} to void (...)*)
-; NOTPROMOTED: @weakfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @weakfunc{{.*}} to void (...)*)
+; PROMOTE_MOD1: @weakfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @weakfunc{{.*}} to void (...)*)
+; PROMOTE_MOD2: @weakfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @weakfunc{{.*}} to void (...)*)
 ; FIXME: The "resolution" should turn one of these to linkonce_odr
 ; PROMOTE_MOD1: @weakfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakfunc.mod1 to void (...)*)
 ; PROMOTE_MOD2: @weakfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @weakfunc to void (...)*)
Index: llvm/trunk/test/ThinLTO/X86/odr_resolution.ll
===================================================================
--- llvm/trunk/test/ThinLTO/X86/odr_resolution.ll
+++ llvm/trunk/test/ThinLTO/X86/odr_resolution.ll
@@ -1,58 +0,0 @@
-; Do setup work for all below tests: generate bitcode and combined index
-; RUN: opt -module-summary %s -o %t.bc
-; RUN: opt -module-summary %p/Inputs/odr_resolution.ll -o %t2.bc
-; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
-
-; Verify that only one ODR is selected across modules, but non ODR are not affected.
-; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD1
-; RUN: llvm-lto -thinlto-action=promote %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD2
-; When exported, we always preserve a linkonce
-; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - --exported-symbol=linkonceodrfuncInSingleModule | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTED
-
-target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-apple-macosx10.11.0"
-
-; Alias are resolved, but can't be turned into "available_externally"
-; MOD1: @linkoncealias = weak_odr alias void (), void ()* @linkonceodrfuncwithalias
-; MOD2: @linkoncealias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
-@linkoncealias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
-
-; Function with an alias are not optimized
-; MOD1: define linkonce_odr void @linkonceodrfuncwithalias()
-; MOD2: define linkonce_odr void @linkonceodrfuncwithalias()
-define linkonce_odr void @linkonceodrfuncwithalias() #0 {
-entry:
-  ret void
-}
-
-; MOD1: define weak_odr void @linkonceodrfunc()
-; MOD2: define available_externally void @linkonceodrfunc()
-define linkonce_odr void @linkonceodrfunc() #0 {
-entry:
-  ret void
-}
-; MOD1: define linkonce void @linkoncefunc()
-; MOD2: define linkonce void @linkoncefunc()
-define linkonce void @linkoncefunc() #0 {
-entry:
-  ret void
-}
-; MOD1: define weak_odr void @weakodrfunc()
-; MOD2: define available_externally void @weakodrfunc()
-define weak_odr void @weakodrfunc() #0 {
-entry:
-  ret void
-}
-; MOD1: define weak void @weakfunc()
-; MOD2: define weak void @weakfunc()
-define weak void @weakfunc() #0 {
-entry:
-  ret void
-}
-
-; MOD1: define linkonce_odr void @linkonceodrfuncInSingleModule()
-; EXPORTED: define weak_odr void @linkonceodrfuncInSingleModule()
-define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
-entry:
-  ret void
-}
Index: llvm/trunk/test/ThinLTO/X86/weak_resolution.ll
===================================================================
--- llvm/trunk/test/ThinLTO/X86/weak_resolution.ll
+++ llvm/trunk/test/ThinLTO/X86/weak_resolution.ll
@@ -0,0 +1,73 @@
+; Do setup work for all below tests: generate bitcode and combined index
+; RUN: opt -module-summary %s -o %t.bc
+; RUN: opt -module-summary %p/Inputs/weak_resolution.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
+
+; Verify that prevailing weak for linker symbol is selected across modules,
+; non-prevailing ODR are not kept when possible, but non-ODR non-prevailing
+; are not affected.
+; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD1
+; RUN: llvm-lto -thinlto-action=promote %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD2
+; When exported, we always preserve a linkonce
+; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - --exported-symbol=linkonceodrfuncInSingleModule | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTED
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; Alias are resolved, but can't be turned into "available_externally"
+; MOD1: @linkonceodralias = weak_odr alias void (), void ()* @linkonceodrfuncwithalias
+; MOD2: @linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
+@linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
+
+; Alias are resolved, but can't be turned into "available_externally"
+; MOD1: @linkoncealias = weak alias void (), void ()* @linkoncefuncwithalias
+; MOD2: @linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
+@linkoncealias = linkonce alias void (), void ()* @linkoncefuncwithalias
+
+; Function with an alias are not optimized
+; MOD1: define linkonce_odr void @linkonceodrfuncwithalias()
+; MOD2: define linkonce_odr void @linkonceodrfuncwithalias()
+define linkonce_odr void @linkonceodrfuncwithalias() #0 {
+entry:
+  ret void
+}
+
+; Function with an alias are not optimized
+; MOD1: define linkonce void @linkoncefuncwithalias()
+; MOD2: define linkonce void @linkoncefuncwithalias()
+define linkonce void @linkoncefuncwithalias() #0 {
+entry:
+  ret void
+}
+
+; MOD1: define weak_odr void @linkonceodrfunc()
+; MOD2: define available_externally void @linkonceodrfunc()
+define linkonce_odr void @linkonceodrfunc() #0 {
+entry:
+  ret void
+}
+; MOD1: define weak void @linkoncefunc()
+; MOD2: define linkonce void @linkoncefunc()
+define linkonce void @linkoncefunc() #0 {
+entry:
+  ret void
+}
+; MOD1: define weak_odr void @weakodrfunc()
+; MOD2: define available_externally void @weakodrfunc()
+define weak_odr void @weakodrfunc() #0 {
+entry:
+  ret void
+}
+; MOD1: define weak void @weakfunc()
+; MOD2: define weak void @weakfunc()
+define weak void @weakfunc() #0 {
+entry:
+  ret void
+}
+
+; MOD1: define linkonce_odr void @linkonceodrfuncInSingleModule()
+; EXPORTED: define weak_odr void @linkonceodrfuncInSingleModule()
+define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
+entry:
+  ret void
+}