aboutsummaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-12-08 21:47:19 -0800
committerSam Clegg <sbc@chromium.org>2020-12-09 12:57:07 -0800
commit9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3 (patch)
treec5c4ab5b676f258c1128d518f0adbcabd597ee1f /lld
parent[NFC] Removed unused prefixes in llvm/test/CodeGen/AArch64 (diff)
downloadllvm-project-9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3.tar.gz
llvm-project-9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3.tar.bz2
llvm-project-9a72d3e3e456ffa9cfb4e0b2c2e81da78bb15dd3.zip
[WebAssembly] Add support for named data sections in wasm binaries
Followup to https://reviews.llvm.org/D91769 which added support for names globals. Differential Revision: https://reviews.llvm.org/D92909
Diffstat (limited to 'lld')
-rw-r--r--lld/test/wasm/call-indirect.ll3
-rw-r--r--lld/test/wasm/data-segment-merging.ll8
-rw-r--r--lld/test/wasm/gc-sections.ll6
-rw-r--r--lld/test/wasm/local-symbols.ll3
-rw-r--r--lld/test/wasm/locals-duplicate.test10
-rw-r--r--lld/test/wasm/map-file.s2
-rw-r--r--lld/test/wasm/signature-mismatch.ll3
-rw-r--r--lld/test/wasm/weak-symbols.s3
-rw-r--r--lld/wasm/SyntheticSections.cpp23
-rw-r--r--lld/wasm/SyntheticSections.h8
-rw-r--r--lld/wasm/Writer.cpp2
11 files changed, 66 insertions, 5 deletions
diff --git a/lld/test/wasm/call-indirect.ll b/lld/test/wasm/call-indirect.ll
index 84a84710f2ba..4acc1edae4f2 100644
--- a/lld/test/wasm/call-indirect.ll
+++ b/lld/test/wasm/call-indirect.ll
@@ -156,4 +156,7 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: GlobalNames:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: __stack_pointer
+; CHECK-NEXT: DataSegmentNames:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Name: .data
; CHECK-NEXT: ...
diff --git a/lld/test/wasm/data-segment-merging.ll b/lld/test/wasm/data-segment-merging.ll
index bc347d193574..1dee1ccbda29 100644
--- a/lld/test/wasm/data-segment-merging.ll
+++ b/lld/test/wasm/data-segment-merging.ll
@@ -31,7 +31,9 @@
; MERGE-NEXT: GlobalNames:
; MERGE-NEXT: - Index: 0
; MERGE-NEXT: Name: __stack_pointer
-; MERGE-NOT: - Index:
+; MERGE-NEXT: DataSegmentNames:
+; MERGE-NEXT: - Index: 0
+; MERGE-NEXT: Name: .rodata
; RUN: wasm-ld -no-gc-sections --no-entry --no-merge-data-segments -o %t.separate.wasm %t.o
; RUN: obj2yaml %t.separate.wasm | FileCheck %s --check-prefix=SEPARATE
@@ -71,7 +73,9 @@
; SEPARATE-NEXT: GlobalNames:
; SEPARATE-NEXT: - Index: 0
; SEPARATE-NEXT: Name: __stack_pointer
-; SEPARATE-NOT: - Index:
+; SEPARATE-NEXT: DataSegmentNames:
+; SEPARATE-NEXT: - Index: 0
+; SEPARATE-NEXT: Name: .rodata
; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 -o %t.merged.passive.wasm %t.passive.o
; RUN: obj2yaml %t.merged.passive.wasm | FileCheck %s --check-prefix=PASSIVE-MERGE
diff --git a/lld/test/wasm/gc-sections.ll b/lld/test/wasm/gc-sections.ll
index 8bac2fd07827..de8298697bf1 100644
--- a/lld/test/wasm/gc-sections.ll
+++ b/lld/test/wasm/gc-sections.ll
@@ -87,6 +87,9 @@ entry:
; CHECK-NEXT: Name: __stack_pointer
; CHECK-NEXT: - Index: 1
; CHECK-NEXT: Name: used_global
+; CHECK-NEXT: DataSegmentNames:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Name: .data
; CHECK-NEXT: ...
; RUN: wasm-ld -print-gc-sections --no-gc-sections -o %t1.no-gc.wasm \
@@ -162,6 +165,9 @@ entry:
; NO-GC-NEXT: Name: unused_global
; NO-GC-NEXT: - Index: 2
; NO-GC-NEXT: Name: used_global
+; NO-GC-NEXT: DataSegmentNames:
+; NO-GC-NEXT: - Index: 0
+; NO-GC-NEXT: Name: .data
; NO-GC-NEXT: ...
; RUN: not wasm-ld --gc-sections --relocatable -o %t1.no-gc.wasm %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR
diff --git a/lld/test/wasm/local-symbols.ll b/lld/test/wasm/local-symbols.ll
index d0a520a950a2..13c200d648e9 100644
--- a/lld/test/wasm/local-symbols.ll
+++ b/lld/test/wasm/local-symbols.ll
@@ -97,4 +97,7 @@ entry:
; CHECK-NEXT: GlobalNames:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: __stack_pointer
+; CHECK-NEXT: DataSegmentNames:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Name: .data
; CHECK-NEXT: ...
diff --git a/lld/test/wasm/locals-duplicate.test b/lld/test/wasm/locals-duplicate.test
index dc6b9c88be29..07abb7485381 100644
--- a/lld/test/wasm/locals-duplicate.test
+++ b/lld/test/wasm/locals-duplicate.test
@@ -212,6 +212,9 @@
; CHECK-NEXT: GlobalNames:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Name: __stack_pointer
+; CHECK-NEXT: DataSegmentNames:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Name: .data
; CHECK-NEXT: ...
@@ -546,4 +549,11 @@
; RELOC-NEXT: Name: get_func2B
; RELOC-NEXT: - Index: 17
; RELOC-NEXT: Name: get_func3B
+; RELOC-NEXT: DataSegmentNames:
+; RELOC-NEXT: - Index: 0
+; RELOC-NEXT: Name: .data.colliding_global1
+; RELOC-NEXT: - Index: 1
+; RELOC-NEXT: Name: .data.colliding_global2
+; RELOC-NEXT: - Index: 2
+; RELOC-NEXT: Name: .data.colliding_global3
; RELOC-NEXT: ...
diff --git a/lld/test/wasm/map-file.s b/lld/test/wasm/map-file.s
index e194662ea5d1..a5bd01605695 100644
--- a/lld/test/wasm/map-file.s
+++ b/lld/test/wasm/map-file.s
@@ -40,7 +40,7 @@ somedata:
# CHECK-NEXT: 400 5a 4 {{.*}}{{/|\\}}map-file.s.tmp1.o:(.data.somedata)
# CHECK-NEXT: 400 5a 4 somedata
# CHECK-NEXT: - 60 12 CUSTOM(.debug_info)
-# CHECK-NEXT: - 72 2b CUSTOM(name)
+# CHECK-NEXT: - 72 35 CUSTOM(name)
# RUN: not wasm-ld %t1.o -o /dev/null -Map=/ 2>&1 \
# RUN: | FileCheck -check-prefix=FAIL %s
diff --git a/lld/test/wasm/signature-mismatch.ll b/lld/test/wasm/signature-mismatch.ll
index 3e42a74d0f05..d5f95b0073c0 100644
--- a/lld/test/wasm/signature-mismatch.ll
+++ b/lld/test/wasm/signature-mismatch.ll
@@ -55,6 +55,9 @@ declare i32 @ret32(i32, i64, i32) local_unnamed_addr
; YAML-NEXT: GlobalNames:
; YAML-NEXT: - Index: 0
; YAML-NEXT: Name: __stack_pointer
+; YAML-NEXT: DataSegmentNames:
+; YAML-NEXT: - Index: 0
+; YAML-NEXT: Name: .data
; YAML-NEXT: ...
; RELOC: Name: linking
diff --git a/lld/test/wasm/weak-symbols.s b/lld/test/wasm/weak-symbols.s
index 41c8a1a38f55..7557dfb5535b 100644
--- a/lld/test/wasm/weak-symbols.s
+++ b/lld/test/wasm/weak-symbols.s
@@ -116,4 +116,7 @@ _start:
# CHECK-NEXT: GlobalNames:
# CHECK-NEXT: - Index: 0
# CHECK-NEXT: Name: __stack_pointer
+# CHECK-NEXT: DataSegmentNames:
+# CHECK-NEXT: - Index: 0
+# CHECK-NEXT: Name: .data
# CHECK-NEXT: ...
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 3fdcc6252fd9..95a48528db9e 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -562,6 +562,16 @@ unsigned NameSection::numNamedGlobals() const {
return numNames;
}
+unsigned NameSection::numNamedDataSegments() const {
+ unsigned numNames = 0;
+
+ for (const OutputSegment *s : segments)
+ if (!s->name.empty())
+ ++numNames;
+
+ return numNames;
+}
+
// Create the custom "name" section containing debug symbol names.
void NameSection::writeBody() {
unsigned count = numNamedFunctions();
@@ -619,6 +629,19 @@ void NameSection::writeBody() {
sub.writeTo(bodyOutputStream);
}
+
+ count = numNamedDataSegments();
+ if (count) {
+ SubSection sub(WASM_NAMES_DATA_SEGMENT);
+ writeUleb128(sub.os, count, "name count");
+
+ for (OutputSegment *s : segments) {
+ writeUleb128(sub.os, s->index, "global index");
+ writeStr(sub.os, s->name, "segment name");
+ }
+
+ sub.writeTo(bodyOutputStream);
+ }
}
void ProducersSection::addInfo(const WasmProducerInfo &info) {
diff --git a/lld/wasm/SyntheticSections.h b/lld/wasm/SyntheticSections.h
index f9ec7f288dbd..56ba66ffc08d 100644
--- a/lld/wasm/SyntheticSections.h
+++ b/lld/wasm/SyntheticSections.h
@@ -296,7 +296,9 @@ protected:
// Create the custom "name" section containing debug symbol names.
class NameSection : public SyntheticSection {
public:
- NameSection() : SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "name") {}
+ NameSection(ArrayRef<OutputSegment *> segments)
+ : SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "name"),
+ segments(segments) {}
bool isNeeded() const override {
return !config->stripDebug && !config->stripAll && numNames() > 0;
}
@@ -304,6 +306,10 @@ public:
unsigned numNames() const { return numNamedGlobals() + numNamedFunctions(); }
unsigned numNamedGlobals() const;
unsigned numNamedFunctions() const;
+ unsigned numNamedDataSegments() const;
+
+protected:
+ ArrayRef<OutputSegment *> segments;
};
class ProducersSection : public SyntheticSection {
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 851a6d366210..dca6c260d429 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -1210,7 +1210,7 @@ void Writer::createSyntheticSections() {
out.elemSec = make<ElemSection>();
out.dataCountSec = make<DataCountSection>(segments);
out.linkingSec = make<LinkingSection>(initFunctions, segments);
- out.nameSec = make<NameSection>();
+ out.nameSec = make<NameSection>(segments);
out.producersSec = make<ProducersSection>();
out.targetFeaturesSec = make<TargetFeaturesSection>();
}