[PATCH] D36379: LLVM: Make GNU COFF Aligncomm optional

Martell Malone via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 6 08:34:11 PDT 2017


martell created this revision.

This is a patch I created to remove aligncomm which limits us to the 32 bytes.

My real goal however is to make aligncomm a compile time flag.
So that if someone really wants >32 bytes alignment the can enable it with a clang flag.

I am not sure how I would have a flag propagate all the way down to LLVM
I would also like a name suggestion for the flag.

Adding reid here because he is super helpful with these kind of things :)

Why you may ask.
With https://reviews.llvm.org/D36304 we will have support for aligncomm in lld but we will never have support in msvc link.
I would like mingw-w64 to be linkable with link.exe
Achieving this also requires a patch for binutils to rename __image_base__ to __ImageBase for MSVC link.


Repository:
  rL LLVM

https://reviews.llvm.org/D36379

Files:
  lib/MC/WinCOFFStreamer.cpp
  test/MC/COFF/comm-align.s


Index: test/MC/COFF/comm-align.s
===================================================================
--- test/MC/COFF/comm-align.s
+++ /dev/null
@@ -1,57 +0,0 @@
-# RUN: llvm-mc -triple i686-windows-gnu -filetype obj -o - %s \
-# RUN:    | llvm-readobj -coff-directives -symbols | FileCheck %s
-
-# NOTE: this test checks multiple things:
-# - that -aligncomm is not emitted for 1-byte alignment
-# - that -aligncomm is emitted for the various alignments (greater than 1)
-# - that the alignment is represented as a log_2 of the alignment
-# - that the section switching occurs correctly
-# - that functions after the switch also are emitted into the correct section
-
-	.text
-
-	.def _a
-		.scl 3
-		.type 32
-	.endef
-_a:
-	ret
-
-	.data
-
-	.comm _s_1,4,0                  # @s_1
-	.comm _s_2,4,1                  # @s_2
-	.comm _s_4,4,2                  # @s_3
-	.comm _s_8,4,3                  # @s_4
-
-	.comm _small_but_overaligned,1,3                  # @s_4
-
-	.text
-
-	.def _b
-		.scl 3
-		.type 32
-	.endef
-_b:
-	ret
-
-# CHECK-NOT: -aligncomm:"_s_1",0
-
-# CHECK: Symbols [
-# CHECK:   Symbol {
-# CHECK:     Name: _a
-# CHECK:     Section: .text (1)
-# CHECK:   }
-# CHECK:   Symbol {
-# CHECK:     Name: _small_but_overaligned
-# CHECK-NEXT:Value: 1
-# CHECK-NEXT:Section: IMAGE_SYM_UNDEFINED (0)
-# CHECK:   }
-# CHECK:   Symbol {
-# CHECK:     Name: _b
-# CHECK:     Section: .text (1)
-# CHECK:   }
-# CHECK: ]
-
-# CHECK: Directive(s): -aligncomm:"_s_2",1 -aligncomm:"_s_4",2 -aligncomm:"_s_8",3 -aligncomm:"_small_but_overaligned",3
-
Index: lib/MC/WinCOFFStreamer.cpp
===================================================================
--- lib/MC/WinCOFFStreamer.cpp
+++ lib/MC/WinCOFFStreamer.cpp
@@ -220,7 +220,7 @@
   auto *Symbol = cast<MCSymbolCOFF>(S);
 
   const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
-  if (T.isKnownWindowsMSVCEnvironment()) {
+  if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsGNUEnvironment()) {
     if (ByteAlignment > 32)
       report_fatal_error("alignment is limited to 32-bytes");
 
@@ -232,7 +232,8 @@
   Symbol->setExternal(true);
   Symbol->setCommon(Size, ByteAlignment);
 
-  if (!T.isKnownWindowsMSVCEnvironment() && ByteAlignment > 1) {
+  if (!T.isKnownWindowsMSVCEnvironment() &&
+      !T.isWindowsGNUEnvironment() && ByteAlignment > 1) {
     SmallString<128> Directive;
     raw_svector_ostream OS(Directive);
     const MCObjectFileInfo *MFI = getContext().getObjectFileInfo();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36379.109925.patch
Type: text/x-patch
Size: 2480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170806/bf248789/attachment.bin>


More information about the llvm-commits mailing list