[lld] r188235 - [PECOFF] Treat the common symbol as mergeable symbol.
Rui Ueyama
ruiu at google.com
Mon Aug 12 17:03:21 PDT 2013
Author: ruiu
Date: Mon Aug 12 19:03:21 2013
New Revision: 188235
URL: http://llvm.org/viewvc/llvm-project?rev=188235&view=rev
Log:
[PECOFF] Treat the common symbol as mergeable symbol.
This is a temporary measure because the semantics of the common symbol is
actually more compilcated than the simple mergeable symbol.
Added:
lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml
- copied, changed from r188187, lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml
lld/trunk/test/pecoff/common-symbol.test
- copied, changed from r188187, lld/trunk/test/pecoff/bss-undef.test
Removed:
lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml
lld/trunk/test/pecoff/bss-undef.test
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h?rev=188235&r1=188234&r2=188235&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h Mon Aug 12 19:03:21 2013
@@ -193,16 +193,18 @@ private:
class COFFBSSAtom : public COFFDefinedFileAtom {
public:
COFFBSSAtom(const File &file, StringRef name, Scope scope,
- ContentPermissions perms, uint32_t size, uint64_t ordinal)
+ ContentPermissions perms, Merge merge, uint32_t size,
+ uint64_t ordinal)
: COFFDefinedFileAtom(file, name, "", scope, typeZeroFill, perms,
ordinal),
- _size(size) {}
+ _merge(merge), _size(size) {}
- virtual Merge merge() const { return mergeNo; }
+ virtual Merge merge() const { return _merge; }
virtual uint64_t size() const { return _size; }
virtual ArrayRef<uint8_t> rawContent() const { return _contents; }
private:
+ Merge _merge;
uint32_t _size;
std::vector<uint8_t> _contents;
};
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=188235&r1=188234&r2=188235&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Mon Aug 12 19:03:21 2013
@@ -234,16 +234,28 @@ private:
// Filter non-defined atoms, and group defined atoms by its section.
SectionToSymbolsT definedSymbols;
for (const coff_symbol *sym : symbols) {
- // A symbol with section number 0 and non-zero value represents an
- // uninitialized data. I don't understand why there are two ways to define
- // an uninitialized data symbol (.bss and this way), but that's how COFF
- // works.
+ // A symbol with section number 0 and non-zero value represents a common
+ // symbol. The MS COFF spec did not give a definition of what the common
+ // symbol is. We should probably follow ELF's definition shown below.
+ //
+ // - If one object file has a common symbol and another has a definition,
+ // the common symbol is treated as an undefined reference.
+ // - If there is no definition for a common symbol, the program linker
+ // acts as though it saw a definition initialized to zero of the
+ // appropriate size.
+ // - Two object files may have common symbols of
+ // different sizes, in which case the program linker will use the
+ // largest size.
+ //
+ // FIXME: We are currently treating the common symbol as a normal
+ // mergeable atom. Implement the above semantcis.
if (sym->SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED &&
sym->Value > 0) {
StringRef name = _symbolName[sym];
uint32_t size = sym->Value;
auto *atom = new (_alloc) COFFBSSAtom(
- *this, name, getScope(sym), DefinedAtom::permRW_, size, 0);
+ *this, name, getScope(sym), DefinedAtom::permRW_,
+ DefinedAtom::mergeAsWeakAndAddressUsed, size, 0);
result.push_back(atom);
continue;
}
@@ -370,7 +382,7 @@ private:
: si[1]->Value - sym->Value;
auto *atom = new (_alloc) COFFBSSAtom(
*this, _symbolName[sym], getScope(sym), getPermissions(section),
- size, ++ordinal);
+ DefinedAtom::mergeAsWeakAndAddressUsed, size, ++ordinal);
atoms.push_back(atom);
_symbolAtom[sym] = atom;
}
Removed: lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml?rev=188234&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml (removed)
@@ -1,43 +0,0 @@
----
-header:
- Machine: IMAGE_FILE_MACHINE_I386
- Characteristics: [ ]
-sections:
- - Name: .text
- Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
- Alignment: 4
- SectionData: ""
- - Name: .data
- Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
- Alignment: 4
- SectionData: 03000000
-symbols:
- - Name: .text
- Value: 0
- SectionNumber: 1
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 000000000000000000000000000000000000
- - Name: .data
- Value: 0
- SectionNumber: 2
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 040000000000000000000000000000000000
- - Name: _bssdata1
- Value: 4
- SectionNumber: 0
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- - Name: _bssdata2
- Value: 4
- SectionNumber: 0
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_EXTERNAL
-...
Copied: lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml (from r188187, lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml?p2=lld/trunk/test/pecoff/Inputs/common-symbol.obj.yaml&p1=lld/trunk/test/pecoff/Inputs/bss-undef.obj.yaml&r1=188187&r2=188235&rev=188235&view=diff
==============================================================================
(empty)
Removed: lld/trunk/test/pecoff/bss-undef.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/bss-undef.test?rev=188234&view=auto
==============================================================================
--- lld/trunk/test/pecoff/bss-undef.test (original)
+++ lld/trunk/test/pecoff/bss-undef.test (removed)
@@ -1,22 +0,0 @@
-# RUN: yaml2obj %p/Inputs/bss-undef.obj.yaml > %t.obj
-#
-# RUN: lld -flavor link /out:%t /subsystem:console /force -- %t.obj \
-# RUN: && llvm-readobj -sections %t | FileCheck %s
-
-CHECK: Section {
-CHECK: Number: 2
-CHECK-NEXT: Name: .bss
-CHECK-NEXT: VirtualSize: 0x0
-CHECK-NEXT: VirtualAddress: 0x2000
-CHECK-NEXT: RawDataSize: 512
-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: }
Copied: lld/trunk/test/pecoff/common-symbol.test (from r188187, lld/trunk/test/pecoff/bss-undef.test)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/common-symbol.test?p2=lld/trunk/test/pecoff/common-symbol.test&p1=lld/trunk/test/pecoff/bss-undef.test&r1=188187&r2=188235&rev=188235&view=diff
==============================================================================
--- lld/trunk/test/pecoff/bss-undef.test (original)
+++ lld/trunk/test/pecoff/common-symbol.test Mon Aug 12 19:03:21 2013
@@ -1,6 +1,6 @@
-# RUN: yaml2obj %p/Inputs/bss-undef.obj.yaml > %t.obj
+# RUN: yaml2obj %p/Inputs/common-symbol.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t /subsystem:console /force -- %t.obj \
+# RUN: lld -flavor link /out:%t /subsystem:console /force -- %t.obj %t.obj \
# RUN: && llvm-readobj -sections %t | FileCheck %s
CHECK: Section {
More information about the llvm-commits
mailing list