[lld] r195856 - [PECOFF] Implement /merge option.
Rui Ueyama
ruiu at google.com
Wed Nov 27 10:03:34 PST 2013
Author: ruiu
Date: Wed Nov 27 12:03:34 2013
New Revision: 195856
URL: http://llvm.org/viewvc/llvm-project?rev=195856&view=rev
Log:
[PECOFF] Implement /merge option.
/MERGE:foo=bar command line option merges section foo to section bar. If
section bar does not exist, foo is just renamed as bar.
Added:
lld/trunk/test/pecoff/section-renaming.test
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=195856&r1=195855&r2=195856&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Wed Nov 27 12:03:34 2013
@@ -883,18 +883,20 @@ StringRef chooseSectionByContent(const D
typedef std::map<StringRef, std::vector<const DefinedAtom *> > AtomVectorMap;
-void groupAtoms(const File &file, AtomVectorMap &result,
- const DefinedAtom *&datadir) {
+void groupAtoms(const PECOFFLinkingContext &ctx, const File &file,
+ AtomVectorMap &result, const DefinedAtom *&datadir) {
for (const DefinedAtom *atom : file.defined()) {
if (atom->sectionChoice() == DefinedAtom::sectionCustomRequired) {
- result[customSectionName(atom)].push_back(atom);
+ StringRef section = customSectionName(atom);
+ result[ctx.getOutputSectionName(section)].push_back(atom);
continue;
}
if (atom->sectionChoice() == DefinedAtom::sectionBasedOnContent) {
if (atom->contentType() == DefinedAtom::typeDataDirectoryEntry) {
datadir = atom;
} else {
- result[chooseSectionByContent(atom)].push_back(atom);
+ StringRef section = chooseSectionByContent(atom);
+ result[ctx.getOutputSectionName(section)].push_back(atom);
}
continue;
}
@@ -906,7 +908,7 @@ void groupAtoms(const File &file, AtomVe
void ExecutableWriter::build(const File &linkedFile) {
AtomVectorMap atoms;
const DefinedAtom *dataDirAtom = nullptr;
- groupAtoms(linkedFile, atoms, dataDirAtom);
+ groupAtoms(_PECOFFLinkingContext, linkedFile, atoms, dataDirAtom);
// Create file chunks and add them to the list.
auto *dosStub = new DOSStubChunk(_PECOFFLinkingContext);
Added: lld/trunk/test/pecoff/section-renaming.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/section-renaming.test?rev=195856&view=auto
==============================================================================
--- lld/trunk/test/pecoff/section-renaming.test (added)
+++ lld/trunk/test/pecoff/section-renaming.test Wed Nov 27 12:03:34 2013
@@ -0,0 +1,61 @@
+# RUN: yaml2obj %p/Inputs/nonstandard-sections.obj.yaml > %t.obj
+# RUN: lld -flavor link /out:%t.exe /subsystem:console /force \
+# RUN: /merge:.foo=.hoge /merge:.bar=.text -- %t.obj
+# RUN: llvm-readobj -sections %t.exe | FileCheck %s
+
+CHECK: Format: COFF-i386
+CHECK-NEXT: Arch: i386
+CHECK-NEXT: AddressSize: 32bit
+CHECK-NEXT: Sections [
+CHECK-NEXT: Section {
+CHECK-NEXT: Number: 1
+CHECK-NEXT: Name: .data (2E 64 61 74 61 00 00 00)
+CHECK-NEXT: VirtualSize: 0x4
+CHECK-NEXT: VirtualAddress: 0x1000
+CHECK-NEXT: RawDataSize: 512
+CHECK-NEXT: PointerToRawData: 0x200
+CHECK-NEXT: PointerToRelocations: 0x0
+CHECK-NEXT: PointerToLineNumbers: 0x0
+CHECK-NEXT: RelocationCount: 0
+CHECK-NEXT: LineNumberCount: 0
+CHECK-NEXT: Characteristics [ (0xC0000040)
+CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
+CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+CHECK-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000)
+CHECK-NEXT: ]
+CHECK-NEXT: }
+CHECK-NEXT: Section {
+CHECK-NEXT: Number: 2
+CHECK-NEXT: Name: .hoge (2E 68 6F 67 65 00 00 00)
+CHECK-NEXT: VirtualSize: 0x4
+CHECK-NEXT: VirtualAddress: 0x2000
+CHECK-NEXT: RawDataSize: 512
+CHECK-NEXT: PointerToRawData: 0x400
+CHECK-NEXT: PointerToRelocations: 0x0
+CHECK-NEXT: PointerToLineNumbers: 0x0
+CHECK-NEXT: RelocationCount: 0
+CHECK-NEXT: LineNumberCount: 0
+CHECK-NEXT: Characteristics [ (0xC0000040)
+CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
+CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+CHECK-NEXT: IMAGE_SCN_MEM_WRITE (0x80000000)
+CHECK-NEXT: ]
+CHECK-NEXT: }
+CHECK-NEXT: Section {
+CHECK-NEXT: Number: 3
+CHECK-NEXT: Name: .text (2E 74 65 78 74 00 00 00)
+CHECK-NEXT: VirtualSize: 0x8
+CHECK-NEXT: VirtualAddress: 0x3000
+CHECK-NEXT: RawDataSize: 512
+CHECK-NEXT: PointerToRawData: 0x600
+CHECK-NEXT: PointerToRelocations: 0x0
+CHECK-NEXT: PointerToLineNumbers: 0x0
+CHECK-NEXT: RelocationCount: 0
+CHECK-NEXT: LineNumberCount: 0
+CHECK-NEXT: Characteristics [ (0x60000020)
+CHECK-NEXT: IMAGE_SCN_CNT_CODE (0x20)
+CHECK-NEXT: IMAGE_SCN_MEM_EXECUTE (0x20000000)
+CHECK-NEXT: IMAGE_SCN_MEM_READ (0x40000000)
+CHECK-NEXT: ]
+CHECK-NEXT: }
+CHECK-NEXT: ]
More information about the llvm-commits
mailing list