[PATCH] D49645: [MC] Add a separate flag for skipping comdat constant sections for MinGW. NFC.

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 21 22:29:32 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, majnemer, compnerd, smeenai, mgrang, ssijaric.

This actually has nothing to do with the associative comdat sections that aren't supported by GNU binutils ld.

Clarify the comments from SVN r335918 and use a separate flag for it.


Repository:
  rL LLVM

https://reviews.llvm.org/D49645

Files:
  include/llvm/MC/MCAsmInfo.h
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  lib/MC/MCAsmInfoCOFF.cpp


Index: lib/MC/MCAsmInfoCOFF.cpp
===================================================================
--- lib/MC/MCAsmInfoCOFF.cpp
+++ lib/MC/MCAsmInfoCOFF.cpp
@@ -45,6 +45,11 @@
   // If this is a COFF target, assume that it supports associative comdats. It's
   // part of the spec.
   HasCOFFAssociativeComdats = true;
+
+  // We can generate constants in comdat sections that can be shared,
+  // but in order not to create null typed symbols, we actually need to
+  // make them global symbols as well.
+  HasCOFFComdatConstants = true;
 }
 
 void MCAsmInfoMicrosoft::anchor() {}
@@ -58,4 +63,7 @@
   // comdats for jump tables, unwind information, and other data associated with
   // a function.
   HasCOFFAssociativeComdats = false;
+
+  // We don't create constants in comdat sections for MinGW.
+  HasCOFFComdatConstants = false;
 }
Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1397,9 +1397,11 @@
     const DataLayout &DL, SectionKind Kind, const Constant *C,
     unsigned &Align) const {
   if (Kind.isMergeableConst() && C &&
-      getContext().getAsmInfo()->hasCOFFAssociativeComdats()) {
-    // GNU binutils doesn't support the kind of symbol with a null
-    // storage class that this generates.
+      getContext().getAsmInfo()->hasCOFFComdatConstants()) {
+    // This creates comdat sections with the given symbol name, but unless
+    // AsmPrinter::GetCPISymbol actually makes the symbol global, the symbol
+    // will be created with a null storage class, which makes GNU binutils
+    // error out.
     const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
                                      COFF::IMAGE_SCN_MEM_READ |
                                      COFF::IMAGE_SCN_LNK_COMDAT;
Index: include/llvm/MC/MCAsmInfo.h
===================================================================
--- include/llvm/MC/MCAsmInfo.h
+++ include/llvm/MC/MCAsmInfo.h
@@ -89,6 +89,10 @@
   /// them.
   bool HasCOFFAssociativeComdats = false;
 
+  /// True if this is a non-GNU COFF target. For GNU targets, we don't generate
+  /// constants into comdat sections.
+  bool HasCOFFComdatConstants = false;
+
   /// This is the maximum possible length of an instruction, which is needed to
   /// compute the size of an inline asm.  Defaults to 4.
   unsigned MaxInstLength = 4;
@@ -469,6 +473,7 @@
   bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
   bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
   bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
+  bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
   unsigned getMaxInstLength() const { return MaxInstLength; }
   unsigned getMinInstAlignment() const { return MinInstAlignment; }
   bool getDollarIsPC() const { return DollarIsPC; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49645.156701.patch
Type: text/x-patch
Size: 2997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180722/6c2274ab/attachment.bin>


More information about the llvm-commits mailing list