Emit .comm alignment in bytes but .align in powers of 2 for ARM ELF.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 Jan 2010 20:21:43 +0000 (20:21 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 26 Jan 2010 20:21:43 +0000 (20:21 +0000)
Original patch by Sandeep Patel and updated by me.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94582 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmInfo.h
lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmInfoCOFF.cpp
lib/MC/MCAsmInfoDarwin.cpp
lib/MC/MCAsmStreamer.cpp
lib/Target/ARM/ARMMCAsmInfo.cpp
test/CodeGen/ARM/align.ll
test/CodeGen/ARM/globals.ll

index 614639e5bc1cd4a4a0af755dbc694d3cc55887a9..1703a69adbc7c2c3841b7d54e9157e8c1d880f20 100644 (file)
@@ -181,6 +181,10 @@ namespace llvm {
     /// directive.
     bool HasLCOMMDirective;              // Defaults to false.
     
+    /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
+    /// alignment is to be specified in bytes instead of log2(n).
+    bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
+    
     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
     /// directives, this is true for most ELF targets.
     bool HasDotTypeDotSizeDirective;         // Defaults to true.
@@ -378,6 +382,9 @@ namespace llvm {
     }
     bool hasLCOMMDirective() const { return HasLCOMMDirective; }
     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
+    bool getCOMMDirectiveAlignmentIsInBytes() const {
+      return COMMDirectiveAlignmentIsInBytes;
+    }
     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
     const char *getWeakRefDirective() const { return WeakRefDirective; }
index 4a86e1df89a71727a3cb7b127dad2074abca4717..12d2fcbadc6efa9b8765f234d7dcbf40afb58248 100644 (file)
@@ -51,6 +51,7 @@ MCAsmInfo::MCAsmInfo() {
   GlobalDirective = "\t.globl\t";
   SetDirective = 0;
   HasLCOMMDirective = false;
+  COMMDirectiveAlignmentIsInBytes = true;
   HasDotTypeDotSizeDirective = true;
   HasSingleParameterDotFile = true;
   HasNoDeadStrip = false;
index e6b79dd9d120bb3f6795c9154b4dff28e02f5985..ab8a585480f1ca7afbb830abb6ce7bf83e05c978 100644 (file)
@@ -18,6 +18,7 @@ using namespace llvm;
 
 MCAsmInfoCOFF::MCAsmInfoCOFF() {
   GlobalPrefix = "_";
+  COMMDirectiveAlignmentIsInBytes = false;
   HasLCOMMDirective = true;
   HasDotTypeDotSizeDirective = false;
   HasSingleParameterDotFile = false;
@@ -36,4 +37,3 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
   SupportsDebugInformation = true;
   DwarfSectionOffsetDirective = "\t.secrel32\t";
 }
-
index 2cf982f39389672a687b1abd3c11ca3c1e768dbe..e84131f5990d2b146f95427ef5d5727347413c09 100644 (file)
@@ -26,6 +26,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
   HasSubsectionsViaSymbols = true;
 
   AlignmentIsInBytes = false;
+  COMMDirectiveAlignmentIsInBytes = false;
   InlineAsmStart = " InlineAsm Start";
   InlineAsmEnd = " InlineAsm End";
 
index d177f9525a1f8ae163388d230944d0c4b465be43..b544d04f14f4931a26536d97f3da560fbdc3ded4 100644 (file)
@@ -282,7 +282,7 @@ void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
                                      unsigned ByteAlignment) {
   OS << "\t.comm\t" << *Symbol << ',' << Size;
   if (ByteAlignment != 0) {
-    if (MAI.getAlignmentIsInBytes())
+    if (MAI.getCOMMDirectiveAlignmentIsInBytes())
       OS << ',' << ByteAlignment;
     else
       OS << ',' << Log2_32(ByteAlignment);
index cc59ec8ce84acb619961dab330b7d9f99b3daa91..911a71fbdd86dd196c73cd248204820db59de6a5 100644 (file)
@@ -52,6 +52,9 @@ ARMMCAsmInfoDarwin::ARMMCAsmInfoDarwin() {
 }
 
 ARMELFMCAsmInfo::ARMELFMCAsmInfo() {
+  // ".comm align is in bytes but .align is pow-2."
+  AlignmentIsInBytes = false;
+
   Data64bitsDirective = 0;
   CommentString = "@";
 
index 492d7af4e7103dfaacf546a23a9755c8b392c2bc..d4d01288f29bf0e256163e8ca1679c8bcbc85a2b 100644 (file)
@@ -8,31 +8,31 @@
 ; no alignment
 
 @c = global i16 2
-;ELF: .align 2
+;ELF: .align 1
 ;ELF: c:
 ;DARWIN: .align 1
 ;DARWIN: _c:
 
 @d = global i32 3
-;ELF: .align 4
+;ELF: .align 2
 ;ELF: d:
 ;DARWIN: .align 2
 ;DARWIN: _d:
 
 @e = global i64 4
-;ELF: .align 8
+;ELF: .align 3
 ;ELF: e
 ;DARWIN: .align 2
 ;DARWIN: _e:
 
 @f = global float 5.0
-;ELF: .align 4
+;ELF: .align 2
 ;ELF: f:
 ;DARWIN: .align 2
 ;DARWIN: _f:
 
 @g = global double 6.0
-;ELF: .align 8
+;ELF: .align 3
 ;ELF: g:
 ;DARWIN: .align 2
 ;DARWIN: _g:
index 83849f42329b3ce10f59b8e4021f41575c11853d..886c0d55cfa8c3fd5872017b000c559e44cc4733 100644 (file)
@@ -67,9 +67,9 @@ define i32 @test1() {
 ; LinuxPIC:    ldr r0, [r0]
 ; LinuxPIC:    bx lr
 
-; LinuxPIC: .align 4
+; LinuxPIC: .align 2
 ; LinuxPIC: .LCPI1_0:
 ; LinuxPIC:     .long _GLOBAL_OFFSET_TABLE_-(.LPC1_0+8)
-; LinuxPIC: .align 4
+; LinuxPIC: .align 2
 ; LinuxPIC: .LCPI1_1:
 ; LinuxPIC:     .long  G(GOT)