[llvm-commits] [llvm] r117570 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/symref.s

Rafael Espindola rafael.espindola at gmail.com
Thu Oct 28 11:33:03 PDT 2010


Author: rafael
Date: Thu Oct 28 13:33:03 2010
New Revision: 117570

URL: http://llvm.org/viewvc/llvm-project?rev=117570&view=rev
Log:
Aliases defined with .symver should copy the binding of the symbols they alias.
Move the existing patching for undefined symbols so that all the patching
is done in the same function.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/test/MC/ELF/symref.s

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=117570&r1=117569&r2=117570&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Oct 28 13:33:03 2010
@@ -465,14 +465,32 @@
   for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
          ie = Asm.symbol_end(); it != ie; ++it) {
     const MCSymbol &Alias = it->getSymbol();
-    if (!Alias.isVariable())
-      continue;
     const MCSymbol &Symbol = AliasedSymbol(Alias);
+    MCSymbolData &SD = Asm.getSymbolData(Symbol);
+
+    // Undefined symbols are global, but this is the first place we
+    // are able to set it.
+    if (Symbol.isUndefined() && !Symbol.isVariable()) {
+      if (GetBinding(SD) == ELF::STB_LOCAL) {
+        SetBinding(SD, ELF::STB_GLOBAL);
+        SetBinding(*it, ELF::STB_GLOBAL);
+      }
+    }
+
+    // Not an alias.
+    if (&Symbol == &Alias)
+      continue;
+
     StringRef AliasName = Alias.getName();
     size_t Pos = AliasName.find('@');
     if (Pos == StringRef::npos)
       continue;
 
+    // Aliases defined with .symvar copy the binding from the symbol they alias.
+    // This is the first place we are able to copy this information.
+    it->setExternal(SD.isExternal());
+    SetBinding(*it, GetBinding(SD));
+
     StringRef Rest = AliasName.substr(Pos);
     if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
       continue;
@@ -881,6 +899,7 @@
     MCSymbol *Sym = Asm.getContext().GetOrCreateSymbol(Name);
     MCSymbolData &Data = Asm.getOrCreateSymbolData(*Sym);
     Data.setExternal(true);
+    SetBinding(Data, ELF::STB_GLOBAL);
   }
 
   // Build section lookup table.
@@ -916,10 +935,6 @@
       MSD.SectionIndex = ELF::SHN_ABS;
     } else if (RefSymbol.isUndefined()) {
       MSD.SectionIndex = ELF::SHN_UNDEF;
-      // FIXME: Undefined symbols are global, but this is the first place we
-      // are able to set it.
-      if (GetBinding(*it) == ELF::STB_LOCAL)
-        SetBinding(*it, ELF::STB_GLOBAL);
     } else {
       MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection());
       assert(MSD.SectionIndex && "Invalid section index!");

Modified: llvm/trunk/test/MC/ELF/symref.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/symref.s?rev=117570&r1=117569&r2=117570&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/symref.s (original)
+++ llvm/trunk/test/MC/ELF/symref.s Thu Oct 28 13:33:03 2010
@@ -17,6 +17,11 @@
         .long defined3
         .long undefined3
 
+        .global global1
+        .symver global1, g1@@zed
+global1:
+
+
 // CHECK:      # Symbol 0x00000001
 // CHECK-NEXT: (('st_name', 0x00000013) # 'bar1 at zed'
 // CHECK-NEXT:  ('st_bind', 0x00000000)
@@ -90,6 +95,24 @@
 // CHECK-NEXT:  ('st_size', 0x00000000)
 // CHECK-NEXT: ),
 // CHECK-NEXT: # Symbol 0x00000009
+// CHECK-NEXT: (('st_name', 0x0000004a) # 'g1@@zed'
+// CHECK-NEXT:  ('st_bind', 0x00000001)
+// CHECK-NEXT:  ('st_type', 0x00000000)
+// CHECK-NEXT:  ('st_other', 0x00000000)
+// CHECK-NEXT:  ('st_shndx', 0x00000001)
+// CHECK-NEXT:  ('st_value', 0x00000014)
+// CHECK-NEXT:  ('st_size', 0x00000000)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Symbol 0x0000000a
+// CHECK-NEXT: (('st_name', 0x00000042) # 'global1'
+// CHECK-NEXT:  ('st_bind', 0x00000001)
+// CHECK-NEXT:  ('st_type', 0x00000000)
+// CHECK-NEXT:  ('st_other', 0x00000000)
+// CHECK-NEXT:  ('st_shndx', 0x00000001)
+// CHECK-NEXT:  ('st_value', 0x00000014)
+// CHECK-NEXT:  ('st_size', 0x00000000)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Symbol 0x0000000b
 // CHECK-NEXT: (('st_name', 0x0000001c) # 'bar2 at zed'
 // CHECK-NEXT:  ('st_bind', 0x00000001)
 // CHECK-NEXT:  ('st_type', 0x00000000)
@@ -98,7 +121,7 @@
 // CHECK-NEXT:  ('st_value', 0x00000000)
 // CHECK-NEXT:  ('st_size', 0x00000000)
 // CHECK-NEXT: ),
-// CHECK-NEXT: # Symbol 0x0000000a
+// CHECK-NEXT: # Symbol 0x0000000c
 // CHECK-NEXT: (('st_name', 0x00000039) # 'bar6 at zed'
 // CHECK-NEXT:  ('st_bind', 0x00000001)
 // CHECK-NEXT:  ('st_type', 0x00000000)
@@ -117,7 +140,7 @@
 // CHECK-NEXT: ),
 // CHECK-NEXT: # Relocation 0x00000001
 // CHECK-NEXT: (('r_offset', 0x00000004)
-// CHECK-NEXT:  ('r_sym', 0x00000009)
+// CHECK-NEXT:  ('r_sym', 0x0000000b)
 // CHECK-NEXT:  ('r_type', 0x0000000a)
 // CHECK-NEXT:  ('r_addend', 0x00000000)
 // CHECK-NEXT: ),
@@ -135,7 +158,7 @@
 // CHECK-NEXT: ),
 // CHECK-NEXT: # Relocation 0x00000004
 // CHECK-NEXT: (('r_offset', 0x00000010)
-// CHECK-NEXT:  ('r_sym', 0x0000000a)
+// CHECK-NEXT:  ('r_sym', 0x0000000c)
 // CHECK-NEXT:  ('r_type', 0x0000000a)
 // CHECK-NEXT:  ('r_addend', 0x00000000)
 // CHECK-NEXT: ),





More information about the llvm-commits mailing list