Skip to content

Commit 8db61ed

Browse files
committed
[WebAssembly] Stabilize custom section order
It currently depends on the StringMap iteration order, which is not guaranteed to be deterministic. Use MapVector to stabilize the order.
1 parent 874217f commit 8db61ed

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

lld/test/wasm/custom-sections.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ entry:
1515
!wasm.custom_sections = !{ !0 }
1616

1717
; CHECK: - Type: CUSTOM
18-
; CHECK-NEXT: Name: green
19-
; CHECK-NEXT: Payload: '626172717578'
20-
; CHECK-NEXT: - Type: CUSTOM
2118
; CHECK-NEXT: Name: red
2219
; CHECK-NEXT: Payload: 6578747261666F6F
20+
; CHECK-NEXT: - Type: CUSTOM
21+
; CHECK-NEXT: Name: green
22+
; CHECK-NEXT: Payload: '626172717578'

lld/test/wasm/debug-undefined-fs.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _start:
3131
.int32 undef
3232
.int32 .Ld
3333

34-
# CHECK: Name: .debug_info
35-
# CHECK-NEXT: Payload: 02000000FFFFFFFF00000000
3634
# CHECK: Name: .debug_int
3735
# CHECK-NEXT: Payload: '01000000'
36+
# CHECK: Name: .debug_info
37+
# CHECK-NEXT: Payload: 02000000FFFFFFFF00000000

lld/test/wasm/section-symbol-relocs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ Sections:
3434
Flags: [ BINDING_LOCAL ]
3535
...
3636

37-
# CHECK: Name: green
38-
# CHECK-NEXT: Payload: 626172717578AA0600000003000000
3937
# CHECK: Name: red
4038
# CHECK-NEXT: Payload: 666F6FBB0000000000000000
39+
# CHECK: Name: green
40+
# CHECK-NEXT: Payload: 626172717578AA0600000003000000
4141

4242
# RELOC: Relocations:
4343
# RELOC-NEXT: - Type: R_WASM_SECTION_OFFSET_I32
44-
# RELOC-NEXT: Index: 0
44+
# RELOC-NEXT: Index: 1
4545
# RELOC-NEXT: Offset: 0x7
4646
# RELOC-NEXT: Addend: 6
4747
# RELOC-NEXT: - Type: R_WASM_SECTION_OFFSET_I32
48-
# RELOC-NEXT: Index: 1
48+
# RELOC-NEXT: Index: 0
4949
# RELOC-NEXT: Offset: 0xB
5050
# RELOC-NEXT: Addend: 3
5151
# RELOC-NEXT: Name: green

lld/wasm/Writer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "lld/Common/Strings.h"
2323
#include "llvm/ADT/ArrayRef.h"
2424
#include "llvm/ADT/DenseSet.h"
25+
#include "llvm/ADT/MapVector.h"
2526
#include "llvm/ADT/SmallSet.h"
2627
#include "llvm/ADT/SmallVector.h"
2728
#include "llvm/ADT/StringMap.h"
@@ -112,7 +113,7 @@ class Writer {
112113
uint64_t fileSize = 0;
113114

114115
std::vector<WasmInitEntry> initFunctions;
115-
llvm::StringMap<std::vector<InputChunk *>> customSectionMapping;
116+
llvm::MapVector<StringRef, std::vector<InputChunk *>> customSectionMapping;
116117

117118
// Stable storage for command export wrapper function name strings.
118119
std::list<std::string> commandExportWrapperNames;
@@ -162,7 +163,7 @@ void Writer::calculateCustomSections() {
162163
void Writer::createCustomSections() {
163164
log("createCustomSections");
164165
for (auto &pair : customSectionMapping) {
165-
StringRef name = pair.first();
166+
StringRef name = pair.first;
166167
LLVM_DEBUG(dbgs() << "createCustomSection: " << name << "\n");
167168

168169
OutputSection *sec = make<CustomSection>(std::string(name), pair.second);

0 commit comments

Comments
 (0)