[lld] r205826 - [PECOFF] Fix common symbol alignment.
Rui Ueyama
ruiu at google.com
Tue Apr 8 18:01:51 PDT 2014
Author: ruiu
Date: Tue Apr 8 20:01:51 2014
New Revision: 205826
URL: http://llvm.org/viewvc/llvm-project?rev=205826&view=rev
Log:
[PECOFF] Fix common symbol alignment.
Differential Revision: http://reviews.llvm.org/D3322
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml
lld/trunk/test/pecoff/common-symbol.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=205826&r1=205825&r2=205826&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Tue Apr 8 20:01:51 2014
@@ -33,6 +33,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
+#include <algorithm>
#include <map>
#include <set>
#include <vector>
@@ -469,6 +470,13 @@ error_code FileCOFF::createDefinedSymbol
auto *atom = new (_alloc)
COFFBSSAtom(*this, name, getScope(sym), DefinedAtom::permRW_,
DefinedAtom::mergeAsWeakAndAddressUsed, size, _ordinal++);
+
+ // Common symbols should be aligned on natural boundaries with the maximum
+ // of 32 byte. It's not documented anywhere, but it's what MSVC link.exe
+ // seems to be doing.
+ uint64_t alignment = std::min((uint64_t)32, llvm::NextPowerOf2(size));
+ atom->setAlignment(
+ DefinedAtom::Alignment(llvm::countTrailingZeros(alignment)));
result.push_back(atom);
continue;
}
Modified: lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml?rev=205826&r1=205825&r2=205826&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml Tue Apr 8 20:01:51 2014
@@ -1,12 +1,28 @@
---
header:
- Machine: IMAGE_FILE_MACHINE_I386
+ Machine: IMAGE_FILE_MACHINE_AMD64
Characteristics: [ ]
sections:
- Name: .text
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 4
- SectionData: ""
+ SectionData: b800000000b800000000b800000000b800000000b800000000
+ Relocations:
+ - VirtualAddress: 1
+ SymbolName: _bssdata4
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 6
+ SymbolName: _bsspad1
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 11
+ SymbolName: _bssdata64
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 16
+ SymbolName: _bsspad2
+ Type: IMAGE_REL_AMD64_ADDR32
+ - VirtualAddress: 21
+ SymbolName: _bssdata16
+ Type: IMAGE_REL_AMD64_ADDR32
- Name: .data
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
@@ -20,7 +36,7 @@ symbols:
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 0
- NumberOfRelocations: 0
+ NumberOfRelocations: 5
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
@@ -36,14 +52,32 @@ symbols:
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- - Name: _bssdata1
+ - Name: _bssdata4
Value: 4
SectionNumber: 0
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- - Name: _bssdata2
- Value: 4
+ - Name: _bsspad1
+ Value: 1
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _bssdata64
+ Value: 64
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _bsspad2
+ Value: 1
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _bssdata16
+ Value: 16
SectionNumber: 0
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
Modified: lld/trunk/test/pecoff/common-symbol.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/common-symbol.test?rev=205826&r1=205825&r2=205826&view=diff
==============================================================================
--- lld/trunk/test/pecoff/common-symbol.test (original)
+++ lld/trunk/test/pecoff/common-symbol.test Tue Apr 8 20:01:51 2014
@@ -1,23 +1,12 @@
# RUN: yaml2obj %p/Inputs/common-symbol.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /opt:noref \
-# RUN: -- %t.obj %t.obj
-# RUN: llvm-readobj -sections %t.exe | FileCheck %s
+# RUN: lld -flavor link /machine:x64 /out:%t.exe /subsystem:console /force \
+# RUN: /opt:noref -- %t.obj %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
-CHECK: Section {
-CHECK: Number: 1
-CHECK-NEXT: Name: .bss (2E 62 73 73 00 00 00 00)
-CHECK-NEXT: VirtualSize: 0x0
-CHECK-NEXT: VirtualAddress: 0x1000
-CHECK-NEXT: RawDataSize: 8
-CHECK-NEXT: PointerToRawData: 0x0
-CHECK-NEXT: PointerToRelocations: 0x0
-CHECK-NEXT: PointerToLineNumbers: 0x0
-CHECK-NEXT: RelocationCount: 0
-CHECK-NEXT: LineNumberCount: 0
-CHECK-NEXT: Characteristics [
-CHECK-NEXT: IMAGE_SCN_CNT_UNINITIALIZED_DATA
-CHECK-NEXT: IMAGE_SCN_MEM_READ
-CHECK-NEXT: IMAGE_SCN_MEM_WRITE
-CHECK-NEXT: ]
-CHECK-NEXT: }
+# Operands of B8 (MOV EAX) are common symbols
+CHECK: 3000: b8 00 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 80 10 00 40
More information about the llvm-commits
mailing list