Fix Whitespace.
[oota-llvm.git] / lib / MC / ELFObjectWriter.cpp
index cbe0ebfa4adfa3503d908692a76a90ebd0fff6bd..8a8d68e55a8b526991f61e54470f21d5a90af602 100644 (file)
@@ -58,6 +58,14 @@ static void SetBinding(MCSymbolData &SD, unsigned Binding) {
   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 @@ static uint64_t SymbolValue(MCSymbolData &Data, const MCAsmLayout &Layout) {
 
 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;
@@ -539,12 +561,12 @@ static bool ShouldRelocOnSymbol(const MCSymbolData &SD,
   const MCSectionELF &Section =
     static_cast<const MCSectionELF&>(Symbol.getSection());
 
-  if (Section.getFlags() & MCSectionELF::SHF_MERGE)
-    return Target.getConstant() != 0;
-
   if (SD.isExternal())
     return true;
 
+  if (Section.getFlags() & MCSectionELF::SHF_MERGE)
+    return Target.getConstant() != 0;
+
   MCSymbolRefExpr::VariantKind Kind = Target.getSymA()->getKind();
   const MCSectionELF &Sec2 =
     static_cast<const MCSectionELF&>(F.getParent()->getSection());
@@ -1106,7 +1128,7 @@ void ELFObjectWriterImpl::WriteObject(MCAssembler &Asm,
   // ... then all of the sections ...
   DenseMap<const MCSection*, uint64_t> SectionOffsetMap;
 
-  DenseMap<const MCSection*, uint8_t> SectionIndexMap;
+  DenseMap<const MCSection*, uint32_t> SectionIndexMap;
 
   unsigned Index = 1;
   for (MCAssembler::const_iterator it = Asm.begin(),