[llvm-commits] [llvm] r125526 - in /llvm/trunk: lib/CodeGen/TargetLoweringObjectFileImpl.cpp lib/MC/MCSectionELF.cpp test/CodeGen/X86/global-sections.ll test/CodeGen/X86/pic_jumptable.ll tools/gold/gold-plugin.cpp

Rafael Espindola rafael.espindola at gmail.com
Mon Feb 14 14:23:49 PST 2011


Author: rafael
Date: Mon Feb 14 16:23:49 2011
New Revision: 125526

URL: http://llvm.org/viewvc/llvm-project?rev=125526&view=rev
Log:
Switch llvm to using comdats. For now always use groups with a single
section.

Modified:
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/trunk/lib/MC/MCSectionELF.cpp
    llvm/trunk/test/CodeGen/X86/global-sections.ll
    llvm/trunk/test/CodeGen/X86/pic_jumptable.ll
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=125526&r1=125525&r2=125526&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Mon Feb 14 16:23:49 2011
@@ -266,22 +266,6 @@
                                     getELFSectionFlags(Kind), Kind);
 }
 
-static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
-  if (Kind.isText())                 return ".gnu.linkonce.t.";
-  if (Kind.isReadOnly())             return ".gnu.linkonce.r.";
-
-  if (Kind.isThreadData())           return ".gnu.linkonce.td.";
-  if (Kind.isThreadBSS())            return ".gnu.linkonce.tb.";
-
-  if (Kind.isDataNoRel())            return ".gnu.linkonce.d.";
-  if (Kind.isDataRelLocal())         return ".gnu.linkonce.d.rel.local.";
-  if (Kind.isDataRel())              return ".gnu.linkonce.d.rel.";
-  if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local.";
-
-  assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
-  return ".gnu.linkonce.d.rel.ro.";
-}
-
 /// getSectionPrefixForGlobal - Return the section prefix name used by options
 /// FunctionsSections and DataSections.
 static const char *getSectionPrefixForGlobal(SectionKind Kind) {
@@ -317,19 +301,21 @@
   if ((GV->isWeakForLinker() || EmitUniquedSection) &&
       !Kind.isCommon() && !Kind.isBSS()) {
     const char *Prefix;
-    if (GV->isWeakForLinker())
-      Prefix = getSectionPrefixForUniqueGlobal(Kind);
-    else {
-      assert(EmitUniquedSection);
-      Prefix = getSectionPrefixForGlobal(Kind);
-    }
+    Prefix = getSectionPrefixForGlobal(Kind);
 
     SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
     MCSymbol *Sym = Mang->getSymbol(GV);
     Name.append(Sym->getName().begin(), Sym->getName().end());
+    StringRef Group = "";
+    unsigned Flags = getELFSectionFlags(Kind);
+    if (GV->isWeakForLinker()) {
+      Group = Sym->getName();
+      Flags |= ELF::SHF_GROUP;
+    }
+
     return getContext().getELFSection(Name.str(),
                                       getELFSectionType(Name.str(), Kind),
-                                      getELFSectionFlags(Kind), Kind);
+                                      Flags, Kind, 0, Group);
   }
 
   if (Kind.isText()) return TextSection;

Modified: llvm/trunk/lib/MC/MCSectionELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSectionELF.cpp?rev=125526&r1=125525&r2=125526&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSectionELF.cpp (original)
+++ llvm/trunk/lib/MC/MCSectionELF.cpp Mon Feb 14 16:23:49 2011
@@ -61,6 +61,8 @@
     OS << 'a';
   if (Flags & ELF::SHF_EXECINSTR)
     OS << 'x';
+  if (Flags & ELF::SHF_GROUP)
+    OS << 'G';
   if (Flags & ELF::SHF_WRITE)
     OS << 'w';
   if (Flags & ELF::SHF_MERGE)
@@ -104,6 +106,8 @@
     OS << "," << EntrySize;
   }
 
+  if (Flags & ELF::SHF_GROUP)
+    OS << "," << Group->getName() << ",comdat";
   OS << '\n';
 }
 

Modified: llvm/trunk/test/CodeGen/X86/global-sections.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-sections.ll?rev=125526&r1=125525&r2=125526&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/global-sections.ll (original)
+++ llvm/trunk/test/CodeGen/X86/global-sections.ll Mon Feb 14 16:23:49 2011
@@ -66,7 +66,7 @@
 @"foo bar" = linkonce global i32 42
 
 ; LINUX: .type	foo_20_bar, at object
-; LINUX:.section	.gnu.linkonce.d.foo_20_bar,"aw", at progbits
+; LINUX: .section .data.foo_20_bar,"aGw", at progbits,foo_20_bar,comdat
 ; LINUX: .weak	foo_20_bar
 ; LINUX: foo_20_bar:
 
@@ -79,7 +79,7 @@
 @G6 = weak_odr unnamed_addr constant [1 x i8] c"\01"
 
 ; LINUX:   .type	G6, at object
-; LINUX:   .section	.gnu.linkonce.r.G6,"a", at progbits
+; LINUX:   .section	.rodata.G6,"aG", at progbits,G6,comdat
 ; LINUX:   .weak	G6
 ; LINUX: G6:
 ; LINUX:   .byte	1

Modified: llvm/trunk/test/CodeGen/X86/pic_jumptable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pic_jumptable.ll?rev=125526&r1=125525&r2=125526&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pic_jumptable.ll (original)
+++ llvm/trunk/test/CodeGen/X86/pic_jumptable.ll Mon Feb 14 16:23:49 2011
@@ -1,4 +1,4 @@
-; RUN: llc < %s -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | not grep -F .text
+; RUN: llc < %s -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | grep -F .text._Z3fooILi1EEvi,"axG", at progbits,_Z3fooILi1EEvi,comdat
 ; RUN: llc < %s -relocation-model=pic -mtriple=i686-apple-darwin -asm-verbose=false | FileCheck %s
 ; RUN: llc < %s                       -mtriple=x86_64-apple-darwin | not grep 'lJTI'
 ; rdar://6971437

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=125526&r1=125525&r2=125526&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Mon Feb 14 16:23:49 2011
@@ -339,6 +339,7 @@
     }
 
     int definition = attrs & LTO_SYMBOL_DEFINITION_MASK;
+    sym.comdat_key = NULL;
     switch (definition) {
       case LTO_SYMBOL_DEFINITION_REGULAR:
         sym.def = LDPK_DEF;
@@ -350,6 +351,7 @@
         sym.def = LDPK_COMMON;
         break;
       case LTO_SYMBOL_DEFINITION_WEAK:
+        sym.comdat_key = sym.name;
         sym.def = LDPK_WEAKDEF;
         break;
       case LTO_SYMBOL_DEFINITION_WEAKUNDEF:
@@ -360,9 +362,7 @@
         return LDPS_ERR;
     }
 
-    // LLVM never emits COMDAT.
     sym.size = 0;
-    sym.comdat_key = NULL;
 
     sym.resolution = LDPR_UNKNOWN;
   }





More information about the llvm-commits mailing list