summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-11-27 18:03:34 +0000
committerRui Ueyama <ruiu@google.com>2013-11-27 18:03:34 +0000
commita5e09c84cad1810d332a03a2befd0c5c860ebb72 (patch)
tree89b2b0069058c29a6c0d41452e1ddd5b85afb241
parent951dd1d411e1ff812282b6d2b465b636fcb9ef36 (diff)
downloadbcm5719-llvm-a5e09c84cad1810d332a03a2befd0c5c860ebb72.tar.gz
bcm5719-llvm-a5e09c84cad1810d332a03a2befd0c5c860ebb72.zip
[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. llvm-svn: 195856
-rw-r--r--lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp12
-rw-r--r--lld/test/pecoff/section-renaming.test61
2 files changed, 68 insertions, 5 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
index a3dfccd0a12..66116cdd991 100644
--- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -883,18 +883,20 @@ StringRef chooseSectionByContent(const DefinedAtom *atom) {
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, AtomVectorMap &result,
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);
diff --git a/lld/test/pecoff/section-renaming.test b/lld/test/pecoff/section-renaming.test
new file mode 100644
index 00000000000..d4fc154693a
--- /dev/null
+++ b/lld/test/pecoff/section-renaming.test
@@ -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: ]
OpenPOWER on IntegriCloud