[lld] r189573 - [PECOFF] Fix bug that section grouping may lay out atoms in a wrong order.
Rui Ueyama
ruiu at google.com
Thu Aug 29 00:46:23 PDT 2013
Author: ruiu
Date: Thu Aug 29 02:46:23 2013
New Revision: 189573
URL: http://llvm.org/viewvc/llvm-project?rev=189573&view=rev
Log:
[PECOFF] Fix bug that section grouping may lay out atoms in a wrong order.
We added layout edges to the head atoms in grouped sections. That was wrong,
because the head atom needs to be followed by the other atoms in the *same*
section, not by the other section contents. With this patch, layout edges are
added from tail atom, which is the last atom in a section, to head atom.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
lld/trunk/test/pecoff/Inputs/grouped-sections.obj.yaml
lld/trunk/test/pecoff/lib.test
lld/trunk/test/pecoff/multi.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h?rev=189573&r1=189572&r2=189573&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h Thu Aug 29 02:46:23 2013
@@ -66,7 +66,7 @@ public:
std::vector<std::vector<COFFDefinedAtom *>> groupedAtomsList(
groupBySectionName(sectionToHeadAtoms));
for (auto &groupedAtoms : groupedAtomsList)
- connectAtomsWithLayoutEdge(groupedAtoms);
+ connectAtoms(groupedAtoms);
}
private:
@@ -107,6 +107,36 @@ private:
vec.push_back(std::move(i.second));
return std::move(vec);
}
+
+ /// For each pair of atoms in the given vector, add a layout edge from the
+ /// follow-on tail of the first atom to the second atom. As a result, the
+ /// atoms in the vectors will be output as the same order as in the vector.
+ void connectAtoms(std::vector<COFFDefinedAtom *> heads) {
+ if (heads.empty())
+ return;
+ COFFDefinedAtom *tail = getTail(heads[0]);
+ for (auto i = heads.begin() + 1, e = heads.end(); i != e; ++i) {
+ COFFDefinedAtom *head = *i;
+ connectWithLayoutEdge(tail, head);
+ tail = getTail(head);
+ }
+ }
+
+ /// Follows the follow-on chain and returns the last atom.
+ COFFDefinedAtom *getTail(COFFDefinedAtom *atom) {
+ for (;;) {
+ COFFDefinedAtom *next = nullptr;
+ for (const Reference *r : *atom) {
+ if (r->kind() != lld::Reference::kindLayoutAfter)
+ continue;
+ next = (COFFDefinedAtom *)(r->target());
+ break;
+ }
+ if (!next)
+ return atom;
+ atom = next;
+ }
+ }
};
} // namespace pecoff
Modified: lld/trunk/test/pecoff/Inputs/grouped-sections.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/grouped-sections.obj.yaml?rev=189573&r1=189572&r2=189573&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/grouped-sections.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/grouped-sections.obj.yaml Thu Aug 29 02:46:23 2013
@@ -19,21 +19,7 @@ sections:
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 1
SectionData: 6F2C2077
- - Name: ".debug$S"
- Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
- Alignment: 1
- SectionData: 04000000F1000000590000001E000111000000005A3A5C67726F757065642D73656374696F6E732E6F626A0037003C1103020000030000000000000000000A0000001B9D01004D6963726F736F667420285229204D6163726F20417373656D626C65720000000000
- - Name: .drectve
- Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
- Alignment: 2147483648
- SectionData: 2F454E5452593A6D61696E20
symbols:
- - Name: "@comp.id"
- Value: 10394907
- SectionNumber: 65535
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: .text
Value: 0
SectionNumber: 1
@@ -66,26 +52,16 @@ symbols:
StorageClass: IMAGE_SYM_CLASS_STATIC
NumberOfAuxSymbols: 1
AuxiliaryData: 040000000000000000000000000000000000
- - Name: ".debug$S"
- Value: 0
- SectionNumber: 5
+ - Name: foo
+ Value: 2
+ SectionNumber: 4
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 680000000000000000000000000000000000
- Name: _main
Value: 0
SectionNumber: 1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- - Name: .drectve
- Value: 0
- SectionNumber: 6
- SimpleType: IMAGE_SYM_TYPE_NULL
- ComplexType: IMAGE_SYM_DTYPE_NULL
- StorageClass: IMAGE_SYM_CLASS_STATIC
- NumberOfAuxSymbols: 1
- AuxiliaryData: 0C0000000000000000000000000000000000
...
Modified: lld/trunk/test/pecoff/lib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/lib.test?rev=189573&r1=189572&r2=189573&view=diff
==============================================================================
--- lld/trunk/test/pecoff/lib.test (original)
+++ lld/trunk/test/pecoff/lib.test Thu Aug 29 02:46:23 2013
@@ -7,6 +7,6 @@
CHECK: Disassembly of section .text:
CHECK: .text:
-CHECK: 1000: a1 00 20 40 00
-CHECK: 1005: 03 05 04 20 40 00
-CHECK: 100b: c3
+CHECK: 1000: a1 04 20 40 00 movl 4202500, %eax
+CHECK: 1005: 03 05 00 20 40 00 addl 4202496, %eax
+CHECK: 100b: c3 ret
Modified: lld/trunk/test/pecoff/multi.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/multi.test?rev=189573&r1=189572&r2=189573&view=diff
==============================================================================
--- lld/trunk/test/pecoff/multi.test (original)
+++ lld/trunk/test/pecoff/multi.test Thu Aug 29 02:46:23 2013
@@ -9,6 +9,6 @@
CHECK: Disassembly of section .text:
CHECK: .text:
-CHECK: 1000: a1 00 20 40 00
-CHECK: 1005: 03 05 04 20 40 00
-CHECK: 100b: c3
+CHECK: 1000: a1 04 20 40 00 movl 4202500, %eax
+CHECK: 1005: 03 05 00 20 40 00 addl 4202496, %eax
+CHECK: 100b: c3 ret
More information about the llvm-commits
mailing list