Skip to content

Commit

Permalink
[IRObjectFile] Handle undefined weak symbols in RecordStreamer.
Browse files Browse the repository at this point in the history
Differential Revision:  https://reviews.llvm.org/D24594

llvm-svn: 281629
  • Loading branch information
dcci committed Sep 15, 2016
1 parent b385f2a commit f751849
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
5 changes: 4 additions & 1 deletion llvm/lib/Object/IRObjectFile.cpp
Expand Up @@ -113,10 +113,13 @@ void IRObjectFile::CollectAsmUndefinedRefs(
Res |= BasicSymbolRef::SF_Undefined;
Res |= BasicSymbolRef::SF_Global;
break;
case RecordStreamer::GlobalWeak:
case RecordStreamer::DefinedWeak:
Res |= BasicSymbolRef::SF_Weak;
Res |= BasicSymbolRef::SF_Global;
break;
case RecordStreamer::UndefinedWeak:
Res |= BasicSymbolRef::SF_Weak;
Res |= BasicSymbolRef::SF_Undefined;
}
AsmUndefinedRefs(Key, BasicSymbolRef::Flags(Res));
}
Expand Down
14 changes: 9 additions & 5 deletions llvm/lib/Object/RecordStreamer.cpp
Expand Up @@ -23,8 +23,10 @@ void RecordStreamer::markDefined(const MCSymbol &Symbol) {
case Used:
S = Defined;
break;
case GlobalWeak:
case DefinedWeak:
break;
case UndefinedWeak:
S = DefinedWeak;
}
}

Expand All @@ -34,15 +36,16 @@ void RecordStreamer::markGlobal(const MCSymbol &Symbol,
switch (S) {
case DefinedGlobal:
case Defined:
S = (Attribute == MCSA_Weak) ? GlobalWeak : DefinedGlobal;
S = (Attribute == MCSA_Weak) ? DefinedWeak : DefinedGlobal;
break;

case NeverSeen:
case Global:
case Used:
S = (Attribute == MCSA_Weak) ? GlobalWeak : Global;
S = (Attribute == MCSA_Weak) ? UndefinedWeak : Global;
break;
case GlobalWeak:
case UndefinedWeak:
case DefinedWeak:
break;
}
}
Expand All @@ -53,7 +56,8 @@ void RecordStreamer::markUsed(const MCSymbol &Symbol) {
case DefinedGlobal:
case Defined:
case Global:
case GlobalWeak:
case DefinedWeak:
case UndefinedWeak:
break;

case NeverSeen:
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Object/RecordStreamer.h
Expand Up @@ -15,7 +15,8 @@
namespace llvm {
class RecordStreamer : public MCStreamer {
public:
enum State { NeverSeen, Global, GlobalWeak, Defined, DefinedGlobal, Used };
enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
UndefinedWeak};

private:
StringMap<State> Symbols;
Expand Down
3 changes: 3 additions & 0 deletions llvm/test/Object/X86/nm-bitcodeweak.test
@@ -1,10 +1,13 @@
; RUN: llvm-as %s -o=%t1
; RUN: llvm-nm %t1 | FileCheck %s

; Check that __libc_blah is reported as defined weak.
; 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"

module asm ".weak __libc_blah"
module asm ".equ __libc_blah, blah"
module asm ".globl blah"
module asm "blah: ret"
10 changes: 10 additions & 0 deletions llvm/test/Object/X86/nm-undefinedweak.test
@@ -0,0 +1,10 @@
; RUN: llvm-as %s -o=%t1
; RUN: llvm-nm %t1 | FileCheck %s

; Check that patatino is reported as undefined weak.
; CHECK: w patatino

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-freebsd11.0"

module asm ".weak patatino"

0 comments on commit f751849

Please sign in to comment.