From 0ad137e98e1f001f24178cf5c06ab2d4c4fa8737 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 5 Oct 2010 22:26:43 +0000 Subject: [PATCH] Implement more alias cases. llvm-svn: 115699 --- llvm/lib/MC/ELFObjectWriter.cpp | 11 ++++++++++ llvm/test/MC/ELF/alias.s | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 73362583ce53..d79029106b05 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -807,9 +807,20 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { MSD.SymbolData = it; MSD.StringIndex = Entry; + // FIXME: There is duplicated code with the local case. if (it->isCommon()) { MSD.SectionIndex = ELF::SHN_COMMON; ExternalSymbolData.push_back(MSD); + } else if (Symbol.isVariable()) { + const MCExpr *Value = Symbol.getVariableValue(); + assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented"); + const MCSymbolRefExpr *Ref = static_cast(Value); + const MCSymbol &RefSymbol = Ref->getSymbol(); + if (RefSymbol.isDefined()) { + MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection()); + assert(MSD.SectionIndex && "Invalid section index!"); + ExternalSymbolData.push_back(MSD); + } } else if (Symbol.isUndefined()) { MSD.SectionIndex = ELF::SHN_UNDEF; // FIXME: Undefined symbols are global, but this is the first place we diff --git a/llvm/test/MC/ELF/alias.s b/llvm/test/MC/ELF/alias.s index 5da8635c1f94..0f6cce1ca1fc 100644 --- a/llvm/test/MC/ELF/alias.s +++ b/llvm/test/MC/ELF/alias.s @@ -3,6 +3,13 @@ foo: bar = foo + .globl foo2 +foo2 = bar2 + +foo3: + .globl bar3 +bar3 = foo3 + // CHECK: # Symbol 1 // CHECK-NEXT: (('st_name', 5) # 'bar' // CHECK-NEXT: ('st_bind', 0) @@ -20,3 +27,33 @@ bar = foo // CHECK-NEXT: ('st_shndx', 1) // CHECK-NEXT: ('st_value', 0) // CHECK-NEXT: ('st_size', 0) +// CHECK: # Symbol 3 +// CHECK-NEXT: (('st_name', 9) # 'foo3' +// CHECK-NEXT: ('st_bind', 0) +// CHECK-NEXT: ('st_type', 0) +// CHECK-NEXT: ('st_other', 0) +// CHECK-NEXT: ('st_shndx', 1) +// CHECK-NEXT: ('st_value', 0) +// CHECK-NEXT: ('st_size', 0) +// CHECK: # Symbol 4 +// CHECK-NEXT: (('st_name', 0) # '' +// CHECK: # Symbol 5 +// CHECK-NEXT: (('st_name', 0) # '' +// CHECK: # Symbol 6 +// CHECK-NEXT: (('st_name', 0) # '' +// CHECK: # Symbol 7 +// CHECK-NEXT: (('st_name', 24) # 'bar3' +// CHECK-NEXT: ('st_bind', 1) +// CHECK-NEXT: ('st_type', 0) +// CHECK-NEXT: ('st_other', 0) +// CHECK-NEXT: ('st_shndx', 1) +// CHECK-NEXT: ('st_value', 0) +// CHECK-NEXT: ('st_size', 0) +// CHECK: # Symbol 8 +// CHECK-NEXT: (('st_name', 19) # 'bar2' +// CHECK-NEXT: ('st_bind', 1) +// CHECK-NEXT: ('st_type', 0) +// CHECK-NEXT: ('st_other', 0) +// CHECK-NEXT: ('st_shndx', 0) +// CHECK-NEXT: ('st_value', 0) +// CHECK-NEXT: ('st_size', 0)