<p dir="ltr">Lgtm.</p>
<p dir="ltr">We should also add support for weak undefined, but that can be a followup patch.</p>
<p dir="ltr">Cheers,<br>
Rafael</p>
<div class="gmail_quote">On Jun 22, 2016 3:47 PM, "Davide Italiano" <<a href="mailto:dccitaliano@gmail.com">dccitaliano@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">davide created this revision.<br>
davide added a reviewer: rafael.<br>
davide added a subscriber: llvm-commits.<br>
<br>
This should fix PR28256, see <a href="https://llvm.org/bugs/show_bug.cgi?id=28256" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=28256</a> for reference.<br>
<br>
<a href="http://reviews.llvm.org/D21616" rel="noreferrer" target="_blank">http://reviews.llvm.org/D21616</a><br>
<br>
Files:<br>
lib/Object/IRObjectFile.cpp<br>
lib/Object/RecordStreamer.cpp<br>
lib/Object/RecordStreamer.h<br>
test/Object/X86/nm-bitcodeweak.test<br>
<br>
Index: test/Object/X86/nm-bitcodeweak.test<br>
===================================================================<br>
--- test/Object/X86/nm-bitcodeweak.test<br>
+++ test/Object/X86/nm-bitcodeweak.test<br>
@@ -1,7 +1,7 @@<br>
; RUN: llvm-as %s -o=%t1<br>
; RUN: llvm-nm %t1 | FileCheck %s<br>
<br>
-; CHECK: T __libc_blah<br>
+; CHECK: W __libc_blah<br>
<br>
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
target triple = "x86_64-unknown-freebsd11.0"<br>
Index: lib/Object/RecordStreamer.h<br>
===================================================================<br>
--- lib/Object/RecordStreamer.h<br>
+++ lib/Object/RecordStreamer.h<br>
@@ -15,12 +15,12 @@<br>
namespace llvm {<br>
class RecordStreamer : public MCStreamer {<br>
public:<br>
- enum State { NeverSeen, Global, Defined, DefinedGlobal, Used };<br>
+ enum State { NeverSeen, Global, GlobalWeak, Defined, DefinedGlobal, Used };<br>
<br>
private:<br>
StringMap<State> Symbols;<br>
void markDefined(const MCSymbol &Symbol);<br>
- void markGlobal(const MCSymbol &Symbol);<br>
+ void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);<br>
void markUsed(const MCSymbol &Symbol);<br>
void visitUsedSymbol(const MCSymbol &Sym) override;<br>
<br>
Index: lib/Object/RecordStreamer.cpp<br>
===================================================================<br>
--- lib/Object/RecordStreamer.cpp<br>
+++ lib/Object/RecordStreamer.cpp<br>
@@ -23,21 +23,26 @@<br>
case Used:<br>
S = Defined;<br>
break;<br>
+ case GlobalWeak:<br>
+ break;<br>
}<br>
}<br>
<br>
-void RecordStreamer::markGlobal(const MCSymbol &Symbol) {<br>
+void RecordStreamer::markGlobal(const MCSymbol &Symbol,<br>
+ MCSymbolAttr Attribute) {<br>
State &S = Symbols[Symbol.getName()];<br>
switch (S) {<br>
case DefinedGlobal:<br>
case Defined:<br>
- S = DefinedGlobal;<br>
+ S = (Attribute == MCSA_Weak) ? GlobalWeak : DefinedGlobal;<br>
break;<br>
<br>
case NeverSeen:<br>
case Global:<br>
case Used:<br>
- S = Global;<br>
+ S = (Attribute == MCSA_Weak) ? GlobalWeak : Global;<br>
+ break;<br>
+ case GlobalWeak:<br>
break;<br>
}<br>
}<br>
@@ -48,6 +53,7 @@<br>
case DefinedGlobal:<br>
case Defined:<br>
case Global:<br>
+ case GlobalWeak:<br>
break;<br>
<br>
case NeverSeen:<br>
@@ -85,7 +91,7 @@<br>
bool RecordStreamer::EmitSymbolAttribute(MCSymbol *Symbol,<br>
MCSymbolAttr Attribute) {<br>
if (Attribute == MCSA_Global || Attribute == MCSA_Weak)<br>
- markGlobal(*Symbol);<br>
+ markGlobal(*Symbol, Attribute);<br>
return true;<br>
}<br>
<br>
Index: lib/Object/IRObjectFile.cpp<br>
===================================================================<br>
--- lib/Object/IRObjectFile.cpp<br>
+++ lib/Object/IRObjectFile.cpp<br>
@@ -116,6 +116,9 @@<br>
Res |= BasicSymbolRef::SF_Undefined;<br>
Res |= BasicSymbolRef::SF_Global;<br>
break;<br>
+ case RecordStreamer::GlobalWeak:<br>
+ Res |= BasicSymbolRef::SF_Weak;<br>
+ Res |= BasicSymbolRef::SF_Global;<br>
}<br>
AsmUndefinedRefs(Key, BasicSymbolRef::Flags(Res));<br>
}<br>
<br>
<br>
</blockquote></div>