[llvm] r204581 - Propagate section from base to derived symbol.

Rafael Espindola rafael.espindola at gmail.com
Sun Mar 23 20:43:22 PDT 2014


Author: rafael
Date: Sun Mar 23 22:43:21 2014
New Revision: 204581

URL: http://llvm.org/viewvc/llvm-project?rev=204581&view=rev
Log:
Propagate section from base to derived symbol.

We were already propagating the section in

a = b

With this patch we also propagate it for

a = b + 1

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/test/MC/ELF/offset.s
    llvm/trunk/test/MC/ELF/type-propagate.s

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=204581&r1=204580&r2=204581&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Sun Mar 23 22:43:21 2014
@@ -264,13 +264,13 @@ class ELFObjectWriter : public MCObjectW
     // Map from a section to its offset
     typedef DenseMap<const MCSectionELF*, uint64_t> SectionOffsetMapTy;
 
-    /// ComputeSymbolTable - Compute the symbol table data
+    /// Compute the symbol table data
     ///
     /// \param Asm - The assembler.
     /// \param SectionIndexMap - Maps a section to its index.
     /// \param RevGroupMap - Maps a signature symbol to the group section.
     /// \param NumRegularSections - Number of non-relocation sections.
-    void ComputeSymbolTable(MCAssembler &Asm,
+    void computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
                             const SectionIndexMapTy &SectionIndexMap,
                             RevGroupMapTy RevGroupMap,
                             unsigned NumRegularSections);
@@ -937,10 +937,11 @@ void ELFObjectWriter::ComputeIndexMap(MC
   }
 }
 
-void ELFObjectWriter::ComputeSymbolTable(MCAssembler &Asm,
-                                      const SectionIndexMapTy &SectionIndexMap,
-                                         RevGroupMapTy RevGroupMap,
-                                         unsigned NumRegularSections) {
+void
+ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
+                                    const SectionIndexMapTy &SectionIndexMap,
+                                    RevGroupMapTy RevGroupMap,
+                                    unsigned NumRegularSections) {
   // FIXME: Is this the correct place to do this?
   // FIXME: Why is an undefined reference to _GLOBAL_OFFSET_TABLE_ needed?
   if (NeedsGOT) {
@@ -988,33 +989,33 @@ void ELFObjectWriter::ComputeSymbolTable
 
     ELFSymbolData MSD;
     MSD.SymbolData = it;
-    const MCSymbol &RefSymbol = Symbol.AliasedSymbol();
+    const MCSymbol *BaseSymbol = getBaseSymbol(Layout, Symbol);
 
     // Undefined symbols are global, but this is the first place we
     // are able to set it.
     bool Local = isLocal(*it, isSignature, Used);
     if (!Local && MCELF::GetBinding(*it) == ELF::STB_LOCAL) {
-      MCSymbolData &SD = Asm.getSymbolData(RefSymbol);
+      assert(BaseSymbol);
+      MCSymbolData &SD = Asm.getSymbolData(*BaseSymbol);
       MCELF::SetBinding(*it, ELF::STB_GLOBAL);
       MCELF::SetBinding(SD, ELF::STB_GLOBAL);
     }
 
-    if (RefSymbol.isUndefined() && !Used && WeakrefUsed)
-      MCELF::SetBinding(*it, ELF::STB_WEAK);
-
-    if (it->isCommon()) {
+    if (!BaseSymbol) {
+      MSD.SectionIndex = ELF::SHN_ABS;
+    } else if (it->isCommon()) {
       assert(!Local);
       MSD.SectionIndex = ELF::SHN_COMMON;
-    } else if (Symbol.isAbsolute() || RefSymbol.isVariable()) {
-      MSD.SectionIndex = ELF::SHN_ABS;
-    } else if (RefSymbol.isUndefined()) {
+    } else if (BaseSymbol->isUndefined()) {
       if (isSignature && !Used)
         MSD.SectionIndex = SectionIndexMap.lookup(RevGroupMap[&Symbol]);
       else
         MSD.SectionIndex = ELF::SHN_UNDEF;
+      if (!Used && WeakrefUsed)
+        MCELF::SetBinding(*it, ELF::STB_WEAK);
     } else {
       const MCSectionELF &Section =
-        static_cast<const MCSectionELF&>(RefSymbol.getSection());
+        static_cast<const MCSectionELF&>(BaseSymbol->getSection());
       MSD.SectionIndex = SectionIndexMap.lookup(&Section);
       if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
         NeedsSymtabShndx = true;
@@ -1600,8 +1601,8 @@ void ELFObjectWriter::WriteObject(MCAsse
   unsigned NumRegularSections = NumUserSections + NumIndexedSections;
 
   // Compute symbol table information.
-  ComputeSymbolTable(Asm, SectionIndexMap, RevGroupMap, NumRegularSections);
-
+  computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap,
+                     NumRegularSections);
 
   WriteRelocations(Asm, const_cast<MCAsmLayout&>(Layout), RelMap);
 

Modified: llvm/trunk/test/MC/ELF/offset.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/offset.s?rev=204581&r1=204580&r2=204581&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/offset.s (original)
+++ llvm/trunk/test/MC/ELF/offset.s Sun Mar 23 22:43:21 2014
@@ -23,5 +23,5 @@ sym_d = sym_a + 1
 // CHECK-NEXT:    Binding: Local (0x0)
 // CHECK-NEXT:    Type: None (0x0)
 // CHECK-NEXT:    Other: 0
-// CHECK-NEXT:    Section:  (0xFFF1)
+// CHECK-NEXT:    Section: .text (0x1)
 // CHECK-NEXT:  }

Modified: llvm/trunk/test/MC/ELF/type-propagate.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/type-propagate.s?rev=204581&r1=204580&r2=204581&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/type-propagate.s (original)
+++ llvm/trunk/test/MC/ELF/type-propagate.s Sun Mar 23 22:43:21 2014
@@ -114,10 +114,7 @@ sym10:
 // CHECK-NEXT:    Type: Function (0x2)
 
 // CHECK-NEXT:    Other: 0
-
-// GAS:           Section: .text (0x1)
-// CHECK-NEXT:    Section: (0xFFF1)
-
+// CHECK-NEXT:    Section: .text (0x1)
 // CHECK-NEXT:  }
 // CHECK-NEXT:  Symbol {
 // CHECK-NEXT:    Name: sym10
@@ -150,8 +147,5 @@ sym10:
 // CHECK-NEXT:    Type: Function (0x2)
 
 // CHECK-NEXT:    Other: 0
-
-// GAS:           Section: .text (0x1)
-// CHECK-NEXT:    Section: (0xFFF1)
-
+// CHECK-NEXT:    Section: .text (0x1)
 // CHECK-NEXT:  }





More information about the llvm-commits mailing list