[PECOFF] Implement /alternatename weak symbols.

llvm-svn: 196754
This commit is contained in:
Rui Ueyama 2013-12-09 05:02:57 +00:00
parent 94abb8ffed
commit 61580376b6
4 changed files with 80 additions and 4 deletions

View File

@ -62,7 +62,7 @@ private:
SectionToAtomsT;
public:
FileCOFF(const LinkingContext &context, std::unique_ptr<MemoryBuffer> mb,
FileCOFF(const PECOFFLinkingContext &context, std::unique_ptr<MemoryBuffer> mb,
error_code &ec);
virtual const atom_collection<DefinedAtom> &defined() const {
@ -156,7 +156,7 @@ private:
_definedAtomLocations;
mutable llvm::BumpPtrAllocator _alloc;
const LinkingContext &_context;
const PECOFFLinkingContext &_context;
uint64_t _ordinal;
};
@ -278,7 +278,7 @@ DefinedAtom::Merge getMerge(const coff_aux_section_definition *auxsym) {
}
}
FileCOFF::FileCOFF(const LinkingContext &context,
FileCOFF::FileCOFF(const PECOFFLinkingContext &context,
std::unique_ptr<MemoryBuffer> mb, error_code &ec)
: File(mb->getBufferIdentifier(), kindObject), _context(context),
_ordinal(0) {
@ -626,6 +626,18 @@ FileCOFF::AtomizeDefinedSymbolsInSection(const coff_section *section,
// if this is the last symbol, take up the remaining data.
const uint8_t *end = (si + 1 == se) ? secData.data() + secData.size()
: secData.data() + (*(si + 1))->Value;
StringRef symbolName = _symbolName[*si];
StringRef alias = _context.getAlternateName(symbolName);
if (!alias.empty()) {
auto *atom = new (_alloc) COFFDefinedAtom(
*this, alias, sectionName, getScope(*si), type, isComdat,
perms, DefinedAtom::mergeAsWeak, ArrayRef<uint8_t>(), _ordinal++);
atoms.push_back(atom);
_symbolAtom[*si] = atom;
_definedAtomLocations[section][(*si)->Value].push_back(atom);
}
ArrayRef<uint8_t> data(start, end);
auto *atom = new (_alloc) COFFDefinedAtom(
*this, _symbolName[*si], sectionName, getScope(*si), type, isComdat,
@ -953,7 +965,7 @@ ReaderCOFF::parseCOFFFile(std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File> > &result) const {
// Parse the memory buffer as PECOFF file.
error_code ec;
std::unique_ptr<FileCOFF> file(new FileCOFF(_context, std::move(mb), ec));
std::unique_ptr<FileCOFF> file(new FileCOFF(_PECOFFLinkingContext, std::move(mb), ec));
if (ec)
return ec;

View File

@ -0,0 +1,23 @@
---
header:
Machine: IMAGE_FILE_MACHINE_I386
Characteristics: [ ]
sections:
- Name: .text
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 1
SectionData: 90909090
symbols:
- Name: .text
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: _foo
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
...

View File

@ -0,0 +1,23 @@
---
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: CCCCCCCC
symbols:
- Name: .text
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: _main
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
...

View File

@ -0,0 +1,18 @@
# RUN: yaml2obj %p/Inputs/alternatename1.obj.yaml > %t1.obj
# RUN: yaml2obj %p/Inputs/alternatename2.obj.yaml > %t2.obj
#
# RUN: lld -flavor link /out:%t1.exe /alternatename:_main=_foo -- %t1.obj
# RUN: llvm-objdump -d %t2.exe | FileCheck -check-prefix=CHECK1 %s
#
# RUN: lld -flavor link /out:%t2.exe /alternatename:_main=_foo -- %t1.obj %t2.obj
# RUN: llvm-objdump -d %t2.exe | FileCheck -check-prefix=CHECK2 %s
CHECK1: nop
CHECK1-NEXT: nop
CHECK1-NEXT: nop
CHECK1-NEXT: nop
CHECK2: int3
CHECK2-NEXT: int3
CHECK2-NEXT: int3
CHECK2-NEXT: int3