[lld] 8db61ed - [WebAssembly] Stabilize custom section order
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 22 09:37:26 PDT 2023
Author: Fangrui Song
Date: 2023-07-22T09:37:22-07:00
New Revision: 8db61ed29df0776046e64a0bd444f0baa7bc37e9
URL: https://github.com/llvm/llvm-project/commit/8db61ed29df0776046e64a0bd444f0baa7bc37e9
DIFF: https://github.com/llvm/llvm-project/commit/8db61ed29df0776046e64a0bd444f0baa7bc37e9.diff
LOG: [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.
Added:
Modified:
lld/test/wasm/custom-sections.ll
lld/test/wasm/debug-undefined-fs.s
lld/test/wasm/section-symbol-relocs.yaml
lld/wasm/Writer.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/custom-sections.ll b/lld/test/wasm/custom-sections.ll
index c33ca2774afa7e..9d30283a9d0258 100644
--- a/lld/test/wasm/custom-sections.ll
+++ b/lld/test/wasm/custom-sections.ll
@@ -15,8 +15,8 @@ entry:
!wasm.custom_sections = !{ !0 }
; CHECK: - Type: CUSTOM
-; CHECK-NEXT: Name: green
-; CHECK-NEXT: Payload: '626172717578'
-; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: red
; CHECK-NEXT: Payload: 6578747261666F6F
+; CHECK-NEXT: - Type: CUSTOM
+; CHECK-NEXT: Name: green
+; CHECK-NEXT: Payload: '626172717578'
diff --git a/lld/test/wasm/debug-undefined-fs.s b/lld/test/wasm/debug-undefined-fs.s
index 4426e840c944dc..06d248b3149b70 100644
--- a/lld/test/wasm/debug-undefined-fs.s
+++ b/lld/test/wasm/debug-undefined-fs.s
@@ -31,7 +31,7 @@ _start:
.int32 undef
.int32 .Ld
-# CHECK: Name: .debug_info
-# CHECK-NEXT: Payload: 02000000FFFFFFFF00000000
# CHECK: Name: .debug_int
# CHECK-NEXT: Payload: '01000000'
+# CHECK: Name: .debug_info
+# CHECK-NEXT: Payload: 02000000FFFFFFFF00000000
diff --git a/lld/test/wasm/section-symbol-relocs.yaml b/lld/test/wasm/section-symbol-relocs.yaml
index 34126cbf12520e..050aaa602a8f28 100644
--- a/lld/test/wasm/section-symbol-relocs.yaml
+++ b/lld/test/wasm/section-symbol-relocs.yaml
@@ -34,18 +34,18 @@ Sections:
Flags: [ BINDING_LOCAL ]
...
-# CHECK: Name: green
-# CHECK-NEXT: Payload: 626172717578AA0600000003000000
# CHECK: Name: red
# CHECK-NEXT: Payload: 666F6FBB0000000000000000
+# CHECK: Name: green
+# CHECK-NEXT: Payload: 626172717578AA0600000003000000
# RELOC: Relocations:
# RELOC-NEXT: - Type: R_WASM_SECTION_OFFSET_I32
-# RELOC-NEXT: Index: 0
+# RELOC-NEXT: Index: 1
# RELOC-NEXT: Offset: 0x7
# RELOC-NEXT: Addend: 6
# RELOC-NEXT: - Type: R_WASM_SECTION_OFFSET_I32
-# RELOC-NEXT: Index: 1
+# RELOC-NEXT: Index: 0
# RELOC-NEXT: Offset: 0xB
# RELOC-NEXT: Addend: 3
# RELOC-NEXT: Name: green
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 25a9c15957f455..eb64783156e730 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -22,6 +22,7 @@
#include "lld/Common/Strings.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
@@ -112,7 +113,7 @@ class Writer {
uint64_t fileSize = 0;
std::vector<WasmInitEntry> initFunctions;
- llvm::StringMap<std::vector<InputChunk *>> customSectionMapping;
+ llvm::MapVector<StringRef, std::vector<InputChunk *>> customSectionMapping;
// Stable storage for command export wrapper function name strings.
std::list<std::string> commandExportWrapperNames;
@@ -162,7 +163,7 @@ void Writer::calculateCustomSections() {
void Writer::createCustomSections() {
log("createCustomSections");
for (auto &pair : customSectionMapping) {
- StringRef name = pair.first();
+ StringRef name = pair.first;
LLVM_DEBUG(dbgs() << "createCustomSection: " << name << "\n");
OutputSection *sec = make<CustomSection>(std::string(name), pair.second);
More information about the llvm-commits
mailing list