[llvm] r273474 - [IRObjectFile] Propagate .weak attribute correctly for ASM symbols.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 13:48:15 PDT 2016


Author: davide
Date: Wed Jun 22 15:48:15 2016
New Revision: 273474

URL: http://llvm.org/viewvc/llvm-project?rev=273474&view=rev
Log:
[IRObjectFile] Propagate .weak attribute correctly for ASM symbols.

PR: 28256
Differential Revision:  http://reviews.llvm.org/D21616

Modified:
    llvm/trunk/lib/Object/IRObjectFile.cpp
    llvm/trunk/lib/Object/RecordStreamer.cpp
    llvm/trunk/lib/Object/RecordStreamer.h
    llvm/trunk/test/Object/X86/nm-bitcodeweak.test

Modified: llvm/trunk/lib/Object/IRObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=273474&r1=273473&r2=273474&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/IRObjectFile.cpp Wed Jun 22 15:48:15 2016
@@ -116,6 +116,9 @@ void IRObjectFile::CollectAsmUndefinedRe
       Res |= BasicSymbolRef::SF_Undefined;
       Res |= BasicSymbolRef::SF_Global;
       break;
+    case RecordStreamer::GlobalWeak:
+      Res |= BasicSymbolRef::SF_Weak;
+      Res |= BasicSymbolRef::SF_Global;
     }
     AsmUndefinedRefs(Key, BasicSymbolRef::Flags(Res));
   }

Modified: llvm/trunk/lib/Object/RecordStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/RecordStreamer.cpp?rev=273474&r1=273473&r2=273474&view=diff
==============================================================================
--- llvm/trunk/lib/Object/RecordStreamer.cpp (original)
+++ llvm/trunk/lib/Object/RecordStreamer.cpp Wed Jun 22 15:48:15 2016
@@ -23,21 +23,26 @@ void RecordStreamer::markDefined(const M
   case Used:
     S = Defined;
     break;
+  case GlobalWeak:
+    break;
   }
 }
 
-void RecordStreamer::markGlobal(const MCSymbol &Symbol) {
+void RecordStreamer::markGlobal(const MCSymbol &Symbol,
+                                MCSymbolAttr Attribute) {
   State &S = Symbols[Symbol.getName()];
   switch (S) {
   case DefinedGlobal:
   case Defined:
-    S = DefinedGlobal;
+    S = (Attribute == MCSA_Weak) ? GlobalWeak : DefinedGlobal;
     break;
 
   case NeverSeen:
   case Global:
   case Used:
-    S = Global;
+    S = (Attribute == MCSA_Weak) ? GlobalWeak : Global;
+    break;
+  case GlobalWeak:
     break;
   }
 }
@@ -48,6 +53,7 @@ void RecordStreamer::markUsed(const MCSy
   case DefinedGlobal:
   case Defined:
   case Global:
+  case GlobalWeak:
     break;
 
   case NeverSeen:
@@ -85,7 +91,7 @@ void RecordStreamer::EmitAssignment(MCSy
 bool RecordStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
                                          MCSymbolAttr Attribute) {
   if (Attribute == MCSA_Global || Attribute == MCSA_Weak)
-    markGlobal(*Symbol);
+    markGlobal(*Symbol, Attribute);
   return true;
 }
 

Modified: llvm/trunk/lib/Object/RecordStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/RecordStreamer.h?rev=273474&r1=273473&r2=273474&view=diff
==============================================================================
--- llvm/trunk/lib/Object/RecordStreamer.h (original)
+++ llvm/trunk/lib/Object/RecordStreamer.h Wed Jun 22 15:48:15 2016
@@ -15,12 +15,12 @@
 namespace llvm {
 class RecordStreamer : public MCStreamer {
 public:
-  enum State { NeverSeen, Global, Defined, DefinedGlobal, Used };
+  enum State { NeverSeen, Global, GlobalWeak, Defined, DefinedGlobal, Used };
 
 private:
   StringMap<State> Symbols;
   void markDefined(const MCSymbol &Symbol);
-  void markGlobal(const MCSymbol &Symbol);
+  void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
   void markUsed(const MCSymbol &Symbol);
   void visitUsedSymbol(const MCSymbol &Sym) override;
 

Modified: llvm/trunk/test/Object/X86/nm-bitcodeweak.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/X86/nm-bitcodeweak.test?rev=273474&r1=273473&r2=273474&view=diff
==============================================================================
--- llvm/trunk/test/Object/X86/nm-bitcodeweak.test (original)
+++ llvm/trunk/test/Object/X86/nm-bitcodeweak.test Wed Jun 22 15:48:15 2016
@@ -1,7 +1,7 @@
 ; RUN: llvm-as %s -o=%t1
 ; RUN: llvm-nm %t1 | FileCheck %s
 
-; CHECK: T __libc_blah
+; CHECK: W __libc_blah
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-freebsd11.0"




More information about the llvm-commits mailing list