[PATCH] D64148: [lld][WebAssembly] Fix __start/__stop symbols when combining input segments
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 10:38:34 PDT 2019
sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.
We should be generating one __start/__stop pair per output segment
not per input segment. The test wasn't catching this because it was
only linking a single object file.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64148
Files:
lld/test/wasm/Inputs/explicit-section.ll
lld/test/wasm/startstop.ll
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -73,7 +73,6 @@
void addSection(OutputSection *Sec);
void addSections();
- void addStartStopSymbols(const InputSegment *Seg);
void createCustomSections();
void createSyntheticSections();
@@ -302,15 +301,15 @@
// __stop_<secname> symbols. They are at beginning and end of the section,
// respectively. This is not requested by the ELF standard, but GNU ld and
// gold provide the feature, and used by many programs.
-void Writer::addStartStopSymbols(const InputSegment *Seg) {
- StringRef S = Seg->getName();
- LLVM_DEBUG(dbgs() << "addStartStopSymbols: " << S << "\n");
- if (!isValidCIdentifier(S))
+static void addStartStopSymbols(const OutputSegment *Seg) {
+ StringRef Name = Seg->Name;
+ LLVM_DEBUG(dbgs() << "addStartStopSymbols: " << Name << "\n");
+ if (!isValidCIdentifier(Name))
return;
- uint32_t Start = Seg->OutputSeg->StartVA + Seg->OutputSegmentOffset;
- uint32_t Stop = Start + Seg->getSize();
- Symtab->addOptionalDataSymbol(Saver.save("__start_" + S), Start);
- Symtab->addOptionalDataSymbol(Saver.save("__stop_" + S), Stop);
+ uint32_t Start = Seg->StartVA;
+ uint32_t Stop = Start + Seg->Size;
+ Symtab->addOptionalDataSymbol(Saver.save("__start_" + Name), Start);
+ Symtab->addOptionalDataSymbol(Saver.save("__stop_" + Name), Stop);
}
void Writer::addSections() {
@@ -766,8 +765,7 @@
// Create linker synthesized __start_SECNAME/__stop_SECNAME symbols
// This has to be done after memory layout is performed.
for (const OutputSegment *Seg : Segments)
- for (const InputSegment *S : Seg->InputSegments)
- addStartStopSymbols(S);
+ addStartStopSymbols(Seg);
}
log("-- scanRelocations");
Index: lld/test/wasm/startstop.ll
===================================================================
--- lld/test/wasm/startstop.ll
+++ lld/test/wasm/startstop.ll
@@ -1,5 +1,6 @@
; RUN: llc -filetype=obj -o %t.o %s
-; RUN: wasm-ld --no-gc-sections %t.o -o %t.wasm
+; RUN: llc -filetype=obj %p/Inputs/explicit-section.ll -o %t2.o
+; RUN: wasm-ld --no-gc-sections --export=var1 %t.o %t2.o -o %t.wasm
; RUN: obj2yaml %t.wasm | FileCheck %s
target triple = "wasm32-unknown-unknown"
@@ -32,7 +33,7 @@
; CHECK-NEXT: Body: 4180888080000B
; CHECK-NEXT: - Index: 2
; CHECK-NEXT: Locals: []
-; CHECK-NEXT: Body: 4188888080000B
+; CHECK-NEXT: Body: 4190888080000B
; CHECK-NEXT: - Index: 3
; CHECK-NEXT: Locals: []
; CHECK-NEXT: Body: 0B
@@ -43,7 +44,7 @@
; CHECK-NEXT: Offset:
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 1024
-; CHECK-NEXT: Content: '0300000004000000'
+; CHECK-NEXT: Content: 03000000040000002A0000002B000000
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: name
; CHECK-NEXT: FunctionNames:
Index: lld/test/wasm/Inputs/explicit-section.ll
===================================================================
--- /dev/null
+++ lld/test/wasm/Inputs/explicit-section.ll
@@ -0,0 +1,4 @@
+target triple = "wasm32-unknown-unknown"
+
+ at var1 = global i32 42, section "mysection", align 4
+ at var2 = global i32 43, section "mysection", align 4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64148.207839.patch
Type: text/x-patch
Size: 3453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190703/0a484117/attachment.bin>
More information about the llvm-commits
mailing list