From 8089fee2dde31fbad24871e4c3dcdb953b9ce7cc Mon Sep 17 00:00:00 2001
From: Rafael Espindola <rafael.espindola@gmail.com>
Date: Fri, 4 Jul 2014 19:08:22 +0000
Subject: [PATCH] Ignore llvm.* globals.

It is not clear if llvm.global_ctors should or should not be in llvm.metadata,
but in practice it is not and we need to ignore it for LTO.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212351 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Object/IRObjectFile.cpp   | 9 +++------
 test/Object/Inputs/trivial.ll | 1 +
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/Object/IRObjectFile.cpp b/lib/Object/IRObjectFile.cpp
index e927447739e..62eaac7a2f0 100644
--- a/lib/Object/IRObjectFile.cpp
+++ b/lib/Object/IRObjectFile.cpp
@@ -238,16 +238,13 @@ uint32_t IRObjectFile::getSymbolFlags(DataRefImpl Symb) const {
   if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage())
     Res |= BasicSymbolRef::SF_Weak;
 
-  if (auto *Var = dyn_cast<GlobalVariable>(GV)) {
+  if (GV->getName().startswith("llvm."))
+    Res |= BasicSymbolRef::SF_FormatSpecific;
+  else if (auto *Var = dyn_cast<GlobalVariable>(GV)) {
     if (Var->getSection() == StringRef("llvm.metadata"))
       Res |= BasicSymbolRef::SF_FormatSpecific;
   }
 
-  if (auto *F = dyn_cast<Function>(GV)) {
-    if (F->getName().startswith("llvm."))
-      Res |= BasicSymbolRef::SF_FormatSpecific;
-  }
-
   return Res;
 }
 
diff --git a/test/Object/Inputs/trivial.ll b/test/Object/Inputs/trivial.ll
index 622d1e97f1e..463442eb90a 100644
--- a/test/Object/Inputs/trivial.ll
+++ b/test/Object/Inputs/trivial.ll
@@ -13,3 +13,4 @@ declare void @SomeOtherFunction(...)
 
 @var = global i32 0
 @llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @var to i8*)], section "llvm.metadata"
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* null, i8* null }]