diff options
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h | 32 | ||||
| -rw-r--r-- | lld/test/pecoff/Inputs/grouped-sections.obj.yaml | 30 | ||||
| -rw-r--r-- | lld/test/pecoff/lib.test | 6 | ||||
| -rw-r--r-- | lld/test/pecoff/multi.test | 6 |
4 files changed, 40 insertions, 34 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h index 521f5379ccc..f8836061a07 100644 --- a/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h +++ b/lld/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h @@ -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 diff --git a/lld/test/pecoff/Inputs/grouped-sections.obj.yaml b/lld/test/pecoff/Inputs/grouped-sections.obj.yaml index b118490e31b..056a80b925d 100644 --- a/lld/test/pecoff/Inputs/grouped-sections.obj.yaml +++ b/lld/test/pecoff/Inputs/grouped-sections.obj.yaml @@ -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 ... diff --git a/lld/test/pecoff/lib.test b/lld/test/pecoff/lib.test index 661e32ad15b..b7042616e4a 100644 --- a/lld/test/pecoff/lib.test +++ b/lld/test/pecoff/lib.test @@ -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 diff --git a/lld/test/pecoff/multi.test b/lld/test/pecoff/multi.test index 8687678ecbc..fdc4374523a 100644 --- a/lld/test/pecoff/multi.test +++ b/lld/test/pecoff/multi.test @@ -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 |

