[llvm-commits] [llvm] r115836 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/alias.s
Rafael Espindola
rafael.espindola at gmail.com
Wed Oct 6 14:02:29 PDT 2010
Author: rafael
Date: Wed Oct 6 16:02:29 2010
New Revision: 115836
URL: http://llvm.org/viewvc/llvm-project?rev=115836&view=rev
Log:
Get binding and visibility info from the the alias, but Type from the symbol
being aliased.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/test/MC/ELF/alias.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=115836&r1=115835&r2=115836&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Oct 6 16:02:29 2010
@@ -58,6 +58,14 @@
SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
}
+static unsigned GetVisibility(MCSymbolData &SD) {
+ unsigned Visibility =
+ (SD.getFlags() & (0xf << ELF_STV_Shift)) >> ELF_STV_Shift;
+ assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
+ Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
+ return Visibility;
+}
+
static bool isFixupKindX86PCRel(unsigned Kind) {
switch (Kind) {
default:
@@ -429,9 +437,23 @@
void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD,
const MCAsmLayout &Layout) {
- MCSymbolData &Data = *MSD.SymbolData;
- uint8_t Info = (Data.getFlags() & 0xff);
- uint8_t Other = ((Data.getFlags() & 0xf00) >> ELF_STV_Shift);
+ MCSymbolData &OrigData = *MSD.SymbolData;
+ MCSymbolData *AliasData = NULL;
+ if (OrigData.Symbol->isVariable()) {
+ const MCExpr *Value = OrigData.getSymbol().getVariableValue();
+ assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented");
+ const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Value);
+ AliasData = &Layout.getAssembler().getSymbolData(Ref->getSymbol());
+ }
+ MCSymbolData &Data = AliasData ? *AliasData : OrigData;
+
+ uint8_t Binding = GetBinding(OrigData);
+ uint8_t Visibility = GetVisibility(OrigData);
+ uint8_t Type = GetType(Data);
+
+ uint8_t Info = (Binding << ELF_STB_Shift) | (Type << ELF_STT_Shift);
+ uint8_t Other = Visibility;
+
uint64_t Value = SymbolValue(Data, Layout);
uint64_t Size = 0;
const MCExpr *ESize;
Modified: llvm/trunk/test/MC/ELF/alias.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/alias.s?rev=115836&r1=115835&r2=115836&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/alias.s (original)
+++ llvm/trunk/test/MC/ELF/alias.s Wed Oct 6 16:02:29 2010
@@ -10,6 +10,11 @@
.globl bar3
bar3 = foo3
+// Test that bar4 is also a function
+ .type foo4, at function
+foo4:
+bar4 = foo4
+
// CHECK: # Symbol 1
// CHECK-NEXT: (('st_name', 5) # 'bar'
// CHECK-NEXT: ('st_bind', 0)
@@ -20,6 +25,15 @@
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 2
+// CHECK-NEXT: (('st_name', 19) # 'bar4'
+// CHECK-NEXT: ('st_bind', 0)
+// CHECK-NEXT: ('st_type', 2)
+// CHECK-NEXT: ('st_other', 0)
+// CHECK-NEXT: ('st_shndx', 1)
+// CHECK-NEXT: ('st_value', 0)
+// CHECK-NEXT: ('st_size', 0)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Symbol 3
// CHECK-NEXT: (('st_name', 1) # 'foo'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 0)
@@ -27,7 +41,8 @@
// CHECK-NEXT: ('st_shndx', 1)
// CHECK-NEXT: ('st_value', 0)
// CHECK-NEXT: ('st_size', 0)
-// CHECK: # Symbol 3
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Symbol 4
// CHECK-NEXT: (('st_name', 9) # 'foo3'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 0)
@@ -35,22 +50,32 @@
// 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: ),
+// CHECK-NEXT: # Symbol 5
+// CHECK-NEXT: (('st_name', 14) # 'foo4'
+// CHECK-NEXT: ('st_bind', 0)
+// CHECK-NEXT: ('st_type', 2)
+// CHECK-NEXT: ('st_other', 0)
+// CHECK-NEXT: ('st_shndx', 1)
+// CHECK-NEXT: ('st_value', 0)
+// CHECK-NEXT: ('st_size', 0)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Symbol 6
+// CHECK-NEXT: (('st_name', 0) # ''
+// CHECK: # Symbol 7
// CHECK-NEXT: (('st_name', 0) # ''
-// CHECK: # Symbol 6
+// CHECK: # Symbol 8
// CHECK-NEXT: (('st_name', 0) # ''
-// CHECK: # Symbol 7
-// CHECK-NEXT: (('st_name', 24) # 'bar3'
+// CHECK: # Symbol 9
+// CHECK-NEXT: (('st_name', 34) # '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: # Symbol 10
+// CHECK-NEXT: (('st_name', 29) # 'bar2'
// CHECK-NEXT: ('st_bind', 1)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)
More information about the llvm-commits
mailing list