[llvm-branch-commits] [llvm-branch] r195823 - Merging r195798:

Bill Wendling isanbard at gmail.com
Tue Nov 26 22:44:45 PST 2013


Author: void
Date: Wed Nov 27 00:44:45 2013
New Revision: 195823

URL: http://llvm.org/viewvc/llvm-project?rev=195823&view=rev
Log:
Merging r195798:
------------------------------------------------------------------------
r195798 | rafael | 2013-11-26 17:18:37 -0800 (Tue, 26 Nov 2013) | 9 lines

Use simple section names for COMDAT sections on COFF.

With this patch we use simple names for COMDAT sections (like .text or .bss).
This matches the MSVC behavior.

When merging it is the COMDAT symbol that is used to decide if two sections
should be merged, so there is no point in building a fancy name.

This survived a bootstrap on mingw32.
------------------------------------------------------------------------

Modified:
    llvm/branches/release_34/   (props changed)
    llvm/branches/release_34/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
    llvm/branches/release_34/lib/MC/MCSectionCOFF.cpp
    llvm/branches/release_34/test/MC/COFF/tricky-names.ll
    llvm/branches/release_34/test/MC/COFF/weak-symbol.ll

Propchange: llvm/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 27 00:44:45 2013
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,195092-195094,195100,195102-195103,195118,195129,195136,195138,195148,195152,195156-195157,195161-195162,195193,195272,195317-195318,195327,195330,195333,195339,195343,195355,195364,195379,195397-195399,195408,195421,195423-195424,195432,195439,195444,195455-195456,195469,195476-195477,195479,195491-195493,195514,195528,195547,195567,195591,195599,195632,195635-195636,195670,195679,195682,195684,195713,195716,195769,195773,195779,195791
+/llvm/trunk:155241,195092-195094,195100,195102-195103,195118,195129,195136,195138,195148,195152,195156-195157,195161-195162,195193,195272,195317-195318,195327,195330,195333,195339,195343,195355,195364,195379,195397-195399,195408,195421,195423-195424,195432,195439,195444,195455-195456,195469,195476-195477,195479,195491-195493,195514,195528,195547,195567,195591,195599,195632,195635-195636,195670,195679,195682,195684,195713,195716,195769,195773,195779,195791,195798

Modified: llvm/branches/release_34/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=195823&r1=195822&r2=195823&view=diff
==============================================================================
--- llvm/branches/release_34/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/branches/release_34/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Wed Nov 27 00:44:45 2013
@@ -723,33 +723,31 @@ getExplicitSectionGlobal(const GlobalVal
                          Mangler *Mang, const TargetMachine &TM) const {
   int Selection = 0;
   unsigned Characteristics = getCOFFSectionFlags(Kind);
-  SmallString<128> Name(GV->getSection().c_str());
+  StringRef Name = GV->getSection();
+  StringRef COMDATSymName = "";
   if (GV->isWeakForLinker()) {
     Selection = COFF::IMAGE_COMDAT_SELECT_ANY;
     Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
-    Name.append("$");
-    Mang->getNameWithPrefix(Name, GV, false, false);
+    MCSymbol *Sym = getSymbol(*Mang, GV);
+    COMDATSymName = Sym->getName();
   }
   return getContext().getCOFFSection(Name,
                                      Characteristics,
                                      Kind,
-                                     "",
+                                     COMDATSymName,
                                      Selection);
 }
 
-static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
+static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
   if (Kind.isText())
-    return ".text$";
+    return ".text";
   if (Kind.isBSS ())
-    return ".bss$";
-  if (Kind.isThreadLocal()) {
-    // 'LLVM' is just an arbitary string to ensure that the section name gets
-    // sorted in between '.tls$AAA' and '.tls$ZZZ' by the linker.
-    return ".tls$LLVM";
-  }
+    return ".bss";
+  if (Kind.isThreadLocal())
+    return ".tls";
   if (Kind.isWriteable())
-    return ".data$";
-  return ".rdata$";
+    return ".data";
+  return ".rdata";
 }
 
 
@@ -760,16 +758,14 @@ SelectSectionForGlobal(const GlobalValue
   // If this global is linkonce/weak and the target handles this by emitting it
   // into a 'uniqued' section name, create and return the section now.
   if (GV->isWeakForLinker()) {
-    const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind);
-    SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
-    Mang->getNameWithPrefix(Name, GV, false, false);
-
+    const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
     unsigned Characteristics = getCOFFSectionFlags(Kind);
 
     Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
-
-    return getContext().getCOFFSection(Name.str(), Characteristics,
-                                       Kind, "", COFF::IMAGE_COMDAT_SELECT_ANY);
+    MCSymbol *Sym = getSymbol(*Mang, GV);
+    return getContext().getCOFFSection(Name, Characteristics,
+                                       Kind, Sym->getName(),
+                                       COFF::IMAGE_COMDAT_SELECT_ANY);
   }
 
   if (Kind.isText())

Modified: llvm/branches/release_34/lib/MC/MCSectionCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/lib/MC/MCSectionCOFF.cpp?rev=195823&r1=195822&r2=195823&view=diff
==============================================================================
--- llvm/branches/release_34/lib/MC/MCSectionCOFF.cpp (original)
+++ llvm/branches/release_34/lib/MC/MCSectionCOFF.cpp Wed Nov 27 00:44:45 2013
@@ -20,6 +20,8 @@ MCSectionCOFF::~MCSectionCOFF() {} // an
 // should be printed before the section name
 bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
                                                const MCAsmInfo &MAI) const {
+  if (COMDATSymbol)
+    return false;
 
   // FIXME: Does .section .bss/.data/.text work everywhere??
   if (Name == ".text" || Name == ".data" || Name == ".bss")
@@ -58,36 +60,41 @@ void MCSectionCOFF::PrintSwitchToSection
     OS << 'r';
   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE)
     OS << 'n';
-  OS << "\"\n";
+
+  OS << '"';
 
   if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
+    OS << ",";
     switch (Selection) {
       case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
-        OS << "\t.linkonce one_only\n";
+        OS << "one_only,";
         break;
       case COFF::IMAGE_COMDAT_SELECT_ANY:
-        OS << "\t.linkonce discard\n";
+        OS << "discard,";
         break;
       case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
-        OS << "\t.linkonce same_size\n";
+        OS << "same_size,";
         break;
       case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
-        OS << "\t.linkonce same_contents\n";
+        OS << "same_contents,";
         break;
       case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
-        OS << "\t.linkonce associative " << Assoc->getSectionName() << "\n";
+        OS << "associative " << Assoc->getSectionName() << ",";
         break;
       case COFF::IMAGE_COMDAT_SELECT_LARGEST:
-        OS << "\t.linkonce largest\n";
+        OS << "largest,";
         break;
       case COFF::IMAGE_COMDAT_SELECT_NEWEST:
-        OS << "\t.linkonce newest\n";
+        OS << "newest,";
         break;
       default:
         assert (0 && "unsupported COFF selection type");
         break;
     }
+    assert(COMDATSymbol);
+    OS << *COMDATSymbol;
   }
+  OS << '\n';
 }
 
 bool MCSectionCOFF::UseCodeAlign() const {

Modified: llvm/branches/release_34/test/MC/COFF/tricky-names.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/test/MC/COFF/tricky-names.ll?rev=195823&r1=195822&r2=195823&view=diff
==============================================================================
--- llvm/branches/release_34/test/MC/COFF/tricky-names.ll (original)
+++ llvm/branches/release_34/test/MC/COFF/tricky-names.ll Wed Nov 27 00:44:45 2013
@@ -25,11 +25,11 @@ define weak i32 @"\01??_B?$num_put at _WV?$
 ; ASM-NOT: .globl "@foo.bar"
 
 ; READOBJ: Symbol
-; READOBJ: Name: .text$??_B?$num_put at _WV?$back_insert_iterator at V?$basic_string at _WU?$char_traits at _W@std@@V?$allocator at _W@2@@std@@@std@@@std@@51
-; READOBJ: Section: .text$??_B?$num_put at _WV?$back_insert_iterator at V?$basic_string at _WU?$char_traits at _W@std@@V?$allocator at _W@2@@std@@@std@@@std@@51
+; READOBJ: Name: .text
+; READOBJ: Section: .text
 ; READOBJ: Symbol
 ; READOBJ: Name: ??_B?$num_put at _WV?$back_insert_iterator at V?$basic_string at _WU?$char_traits at _W@std@@V?$allocator at _W@2@@std@@@std@@@std@@51
-; READOBJ: Section: .text$??_B?$num_put at _WV?$back_insert_iterator at V?$basic_string at _WU?$char_traits at _W@std@@V?$allocator at _W@2@@std@@@std@@@std@@51
+; READOBJ: Section: .text
 ; READOBJ: Symbol
 ; READOBJ: Name: ??__E_Generic_object@?$_Error_objects at H@std@@YAXXZ
 ; READOBJ: Symbol

Modified: llvm/branches/release_34/test/MC/COFF/weak-symbol.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/test/MC/COFF/weak-symbol.ll?rev=195823&r1=195822&r2=195823&view=diff
==============================================================================
--- llvm/branches/release_34/test/MC/COFF/weak-symbol.ll (original)
+++ llvm/branches/release_34/test/MC/COFF/weak-symbol.ll Wed Nov 27 00:44:45 2013
@@ -8,37 +8,31 @@
 ; RUN: llc -mtriple=x86_64-pc-mingw32 %s -o - | FileCheck %s --check-prefix=X64
 
 ; Mangled function
-; X86: .section .text$_Z3foo
-; X86: .linkonce discard
+; X86: .section .text,"xr",discard,__Z3foo
 ; X86: .globl __Z3foo
 ;
-; X64: .section .text$_Z3foo
-; X64: .linkonce discard
+; X64: .section .text,"xr",discard,_Z3foo
 ; X64: .globl _Z3foo
 define weak void @_Z3foo() {
   ret void
 }
 
 ; Unmangled function
-; X86: .section .sect$f
-; X86: .linkonce discard
+; X86: .section .sect,"xr",discard,_f
 ; X86: .globl _f
 ;
-; X64: .section .sect$f
-; X64: .linkonce discard
+; X64: .section .sect,"xr",discard,f
 ; X64: .globl f
 define weak void @f() section ".sect" {
   ret void
 }
 
 ; Weak global
-; X86: .section .data$a
-; X86: .linkonce discard
+; X86: .section .data,"r",discard,_a
 ; X86: .globl _a
 ; X86: .zero 12
 ;
-; X64: .section .data$a
-; X64: .linkonce discard
+; X64: .section .data,"r",discard,a
 ; X64: .globl a
 ; X64: .zero 12
 @a = weak unnamed_addr constant { i32, i32, i32 } { i32 0, i32 0, i32 0}, section ".data"





More information about the llvm-branch-commits mailing list