From 9302bd664d930e7e6b61e208b0cca06fe71e8eb3 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 11 Nov 2010 17:24:43 +0000 Subject: [PATCH] Make AliasedSymbol able to handle MCTargetExpr. They can get here if a weakref is used with a VariantKind. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118798 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 19 ++++++++++++++++--- test/MC/ELF/weakref-plt.s | 8 ++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/MC/ELF/weakref-plt.s diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index f84164d253b..93ea77a0e1c 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -470,10 +470,23 @@ static const MCSymbol &AliasedSymbol(const MCSymbol &Symbol) { const MCSymbol *S = &Symbol; while (S->isVariable()) { const MCExpr *Value = S->getVariableValue(); - if (Value->getKind() != MCExpr::SymbolRef) + MCExpr::ExprKind Kind = Value->getKind(); + switch (Kind) { + case MCExpr::SymbolRef: { + const MCSymbolRefExpr *Ref = static_cast(Value); + S = &Ref->getSymbol(); + break; + } + case MCExpr::Target: { + const MCTargetExpr *TExp = static_cast(Value); + MCValue Res; + TExp->EvaluateAsRelocatableImpl(Res, NULL); + S = &Res.getSymA()->getSymbol(); + break; + } + default: return *S; - const MCSymbolRefExpr *Ref = static_cast(Value); - S = &Ref->getSymbol(); + } } return *S; } diff --git a/test/MC/ELF/weakref-plt.s b/test/MC/ELF/weakref-plt.s new file mode 100644 index 00000000000..26ba3f6df54 --- /dev/null +++ b/test/MC/ELF/weakref-plt.s @@ -0,0 +1,8 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + + .weakref bar,foo + call bar@PLT + +// CHECK: # Symbol 0x00000005 +// CHECK-NEXT: (('st_name', 0x00000001) # 'foo' +// CHECK-NEXT: ('st_bind', 0x00000002)