From 2e2563bf8e0f0a7f8c923000c0206855f16968b2 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 26 Jan 2010 20:21:43 +0000 Subject: [PATCH] Emit .comm alignment in bytes but .align in powers of 2 for ARM ELF. 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 | 7 +++++++ lib/MC/MCAsmInfo.cpp | 1 + lib/MC/MCAsmInfoCOFF.cpp | 2 +- lib/MC/MCAsmInfoDarwin.cpp | 1 + lib/MC/MCAsmStreamer.cpp | 2 +- lib/Target/ARM/ARMMCAsmInfo.cpp | 3 +++ test/CodeGen/ARM/align.ll | 10 +++++----- test/CodeGen/ARM/globals.ll | 4 ++-- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h index 614639e5bc1..1703a69adbc 100644 --- a/include/llvm/MC/MCAsmInfo.h +++ b/include/llvm/MC/MCAsmInfo.h @@ -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; } diff --git a/lib/MC/MCAsmInfo.cpp b/lib/MC/MCAsmInfo.cpp index 4a86e1df89a..12d2fcbadc6 100644 --- a/lib/MC/MCAsmInfo.cpp +++ b/lib/MC/MCAsmInfo.cpp @@ -51,6 +51,7 @@ MCAsmInfo::MCAsmInfo() { GlobalDirective = "\t.globl\t"; SetDirective = 0; HasLCOMMDirective = false; + COMMDirectiveAlignmentIsInBytes = true; HasDotTypeDotSizeDirective = true; HasSingleParameterDotFile = true; HasNoDeadStrip = false; diff --git a/lib/MC/MCAsmInfoCOFF.cpp b/lib/MC/MCAsmInfoCOFF.cpp index e6b79dd9d12..ab8a585480f 100644 --- a/lib/MC/MCAsmInfoCOFF.cpp +++ b/lib/MC/MCAsmInfoCOFF.cpp @@ -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"; } - diff --git a/lib/MC/MCAsmInfoDarwin.cpp b/lib/MC/MCAsmInfoDarwin.cpp index 2cf982f3938..e84131f5990 100644 --- a/lib/MC/MCAsmInfoDarwin.cpp +++ b/lib/MC/MCAsmInfoDarwin.cpp @@ -26,6 +26,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() { HasSubsectionsViaSymbols = true; AlignmentIsInBytes = false; + COMMDirectiveAlignmentIsInBytes = false; InlineAsmStart = " InlineAsm Start"; InlineAsmEnd = " InlineAsm End"; diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index d177f9525a1..b544d04f14f 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -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); diff --git a/lib/Target/ARM/ARMMCAsmInfo.cpp b/lib/Target/ARM/ARMMCAsmInfo.cpp index cc59ec8ce84..911a71fbdd8 100644 --- a/lib/Target/ARM/ARMMCAsmInfo.cpp +++ b/lib/Target/ARM/ARMMCAsmInfo.cpp @@ -52,6 +52,9 @@ ARMMCAsmInfoDarwin::ARMMCAsmInfoDarwin() { } ARMELFMCAsmInfo::ARMELFMCAsmInfo() { + // ".comm align is in bytes but .align is pow-2." + AlignmentIsInBytes = false; + Data64bitsDirective = 0; CommentString = "@"; diff --git a/test/CodeGen/ARM/align.ll b/test/CodeGen/ARM/align.ll index 492d7af4e71..d4d01288f29 100644 --- a/test/CodeGen/ARM/align.ll +++ b/test/CodeGen/ARM/align.ll @@ -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: diff --git a/test/CodeGen/ARM/globals.ll b/test/CodeGen/ARM/globals.ll index 83849f42329..886c0d55cfa 100644 --- a/test/CodeGen/ARM/globals.ll +++ b/test/CodeGen/ARM/globals.ll @@ -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) -- 2.11.0