Skip to content

Commit

Permalink
[IRObjectFile] Propagate .weak attribute correctly for ASM symbols.
Browse files Browse the repository at this point in the history
PR: 28256
Differential Revision:  http://reviews.llvm.org/D21616

llvm-svn: 273474
  • Loading branch information
dcci committed Jun 22, 2016
1 parent 84d6372 commit ec7e29e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Object/IRObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ void IRObjectFile::CollectAsmUndefinedRefs(
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));
}
Expand Down
14 changes: 10 additions & 4 deletions llvm/lib/Object/RecordStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,26 @@ void RecordStreamer::markDefined(const MCSymbol &Symbol) {
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;
}
}
Expand All @@ -48,6 +53,7 @@ void RecordStreamer::markUsed(const MCSymbol &Symbol) {
case DefinedGlobal:
case Defined:
case Global:
case GlobalWeak:
break;

case NeverSeen:
Expand Down Expand Up @@ -85,7 +91,7 @@ void RecordStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
bool RecordStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
MCSymbolAttr Attribute) {
if (Attribute == MCSA_Global || Attribute == MCSA_Weak)
markGlobal(*Symbol);
markGlobal(*Symbol, Attribute);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Object/RecordStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Object/X86/nm-bitcodeweak.test
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit ec7e29e

Please sign in to comment.