From 5e31d0b2e903be88df2b6813718e5de38b9e5ac4 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 20 Jun 2015 07:25:45 +0000 Subject: [PATCH] COFF: Fix common symbol alignment. llvm-svn: 240217 --- lld/COFF/Chunks.cpp | 8 ++++---- lld/test/COFF/common.test | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index e6403c2fc50a..18963f283259 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -16,6 +16,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Endian.h" #include "llvm/Support/raw_ostream.h" +#include using namespace llvm; using namespace llvm::object; @@ -169,10 +170,9 @@ SectionRef SectionChunk::getSectionRef() { } CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) { - // Alignment is a section attribute, but common symbols don't - // belong to any section. How do we know common data alignments? - // Needs investigating. For now, we set a large number as an alignment. - Align = 16; + // Common symbols are aligned on natural boundaries up to 32 bytes. + // This is what MSVC link.exe does. + Align = std::min(uint64_t(32), NextPowerOf2(Sym.getValue())); } uint32_t CommonChunk::getPermissions() const { diff --git a/lld/test/COFF/common.test b/lld/test/COFF/common.test index b9c0a2b6e30c..b74dffb64ade 100644 --- a/lld/test/COFF/common.test +++ b/lld/test/COFF/common.test @@ -4,7 +4,7 @@ # Operands of B8 (MOV EAX) are common symbols CHECK: 3000: b8 00 10 00 40 -CHECK: 3005: b8 10 10 00 40 +CHECK: 3005: b8 04 10 00 40 CHECK: 300a: b8 20 10 00 40 CHECK: 300f: b8 60 10 00 40 -CHECK: 3014: b8 70 10 00 40 +CHECK: 3014: b8 80 10 00 40