Skip to content

Commit 0e3d0bf

Browse files
committed
Revert "Remove --print-symbol-map / --symbolmap (WebAssembly#7862)"
This reverts commit beda737.
1 parent 4f25fee commit 0e3d0bf

15 files changed

+244
-8
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Current Trunk
1818
- The --mod-asyncify-never-unwind and --mod-asyncify-always-and-only-unwind
1919
passed were deleted. They only existed to support the lazy code loading
2020
support in emscripten that was removed. (#7893)
21-
- The --print-symbol-map/--symbolmap flags we removed. They only existed to
22-
support an emscripten feature which was re-implemented downstream. (#7862)
2321

2422
v124
2523
----

src/passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ set(passes_SOURCES
9191
Print.cpp
9292
PrintCallGraph.cpp
9393
PrintFeatures.cpp
94+
PrintFunctionMap.cpp
9495
RoundTrip.cpp
9596
SetGlobals.cpp
9697
SignaturePruning.cpp

src/passes/PrintFunctionMap.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2019 WebAssembly Community Group participants
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
//
18+
// Prints the a map of function indexes to function names. This can be
19+
// useful for interpreting a stack trace from a production environment
20+
// where names did not exist on the client. The map looks like this:
21+
//
22+
// 0:foo
23+
// 1:bar
24+
// 2:baz
25+
//
26+
27+
#include "ir/module-utils.h"
28+
#include "pass.h"
29+
#include "support/file.h"
30+
#include "wasm.h"
31+
32+
namespace wasm {
33+
34+
struct PrintFunctionMap : public Pass {
35+
bool modifiesBinaryenIR() override { return false; }
36+
37+
void run(Module* module) override {
38+
// If an argument is provided, write to that file; otherwise write to
39+
// stdout.
40+
auto outFile = getArgumentOrDefault("symbolmap", "");
41+
Output output(outFile, Flags::Text);
42+
auto& o = output.getStream();
43+
Index i = 0;
44+
auto write = [&](Function* func) {
45+
o << i++ << ':' << func->name.str << '\n';
46+
};
47+
ModuleUtils::iterImportedFunctions(*module, write);
48+
ModuleUtils::iterDefinedFunctions(*module, write);
49+
}
50+
};
51+
52+
Pass* createPrintFunctionMapPass() { return new PrintFunctionMap(); }
53+
54+
} // namespace wasm

src/passes/pass.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ void PassRegistry::registerPasses() {
391391
registerPass(
392392
"print-call-graph", "print call graph", createPrintCallGraphPass);
393393

394+
// Register PrintFunctionMap using its normal name.
395+
registerPass("print-function-map",
396+
"print a map of function indexes to names",
397+
createPrintFunctionMapPass);
398+
// Also register it as "symbolmap" so that wasm-opt --symbolmap=foo is the
399+
// same as wasm-as --symbolmap=foo even though the latter is not a pass
400+
// (wasm-as cannot run arbitrary passes).
401+
// TODO: switch emscripten to this name, then remove the old one
402+
registerPass(
403+
"symbolmap", "(alias for print-function-map)", createPrintFunctionMapPass);
404+
394405
registerPass("propagate-globals-globally",
395406
"propagate global values to other globals (useful for tests)",
396407
createPropagateGlobalsGloballyPass);

src/passes/passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Pass* createPrecomputePropagatePass();
129129
Pass* createPrinterPass();
130130
Pass* createPrintCallGraphPass();
131131
Pass* createPrintFeaturesPass();
132+
Pass* createPrintFunctionMapPass();
132133
Pass* createPropagateGlobalsGloballyPass();
133134
Pass* createRandomizeBranchHintsPass();
134135
Pass* createRemoveNonJSOpsPass();

src/tools/wasm-opt.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ For more on how to optimize effectively, see
436436

437437
if (options.extra.count("output") == 0) {
438438
if (!options.quiet) {
439-
bool printsToStdout =
440-
std::any_of(options.passes.begin(),
441-
options.passes.end(),
442-
[](const OptimizationOptions::PassInfo& info) {
443-
return info.name == "print";
444-
});
439+
bool printsToStdout = std::any_of(
440+
options.passes.begin(),
441+
options.passes.end(),
442+
[](const OptimizationOptions::PassInfo& info) {
443+
return info.name == "print" || info.name == "print-function-map";
444+
});
445445
if (!printsToStdout) {
446446
std::cerr << "warning: no output file specified, not emitting output\n";
447447
}

test/lit/help/wasm-metadce.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@
367367
;; CHECK-NEXT: --print-full print in full s-expression
368368
;; CHECK-NEXT: format
369369
;; CHECK-NEXT:
370+
;; CHECK-NEXT: --print-function-map print a map of function indexes
371+
;; CHECK-NEXT: to names
372+
;; CHECK-NEXT:
370373
;; CHECK-NEXT: --print-minified print in minified s-expression
371374
;; CHECK-NEXT: format
372375
;; CHECK-NEXT:
@@ -519,6 +522,8 @@
519522
;; CHECK-NEXT: --stub-unsupported-js stub out unsupported JS
520523
;; CHECK-NEXT: operations
521524
;; CHECK-NEXT:
525+
;; CHECK-NEXT: --symbolmap (alias for print-function-map)
526+
;; CHECK-NEXT:
522527
;; CHECK-NEXT: --table64-lowering alias for memory64-lowering
523528
;; CHECK-NEXT:
524529
;; CHECK-NEXT: --trace-calls instrument the build with code

test/lit/help/wasm-opt.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@
391391
;; CHECK-NEXT: --print-full print in full s-expression
392392
;; CHECK-NEXT: format
393393
;; CHECK-NEXT:
394+
;; CHECK-NEXT: --print-function-map print a map of function indexes
395+
;; CHECK-NEXT: to names
396+
;; CHECK-NEXT:
394397
;; CHECK-NEXT: --print-minified print in minified s-expression
395398
;; CHECK-NEXT: format
396399
;; CHECK-NEXT:
@@ -543,6 +546,8 @@
543546
;; CHECK-NEXT: --stub-unsupported-js stub out unsupported JS
544547
;; CHECK-NEXT: operations
545548
;; CHECK-NEXT:
549+
;; CHECK-NEXT: --symbolmap (alias for print-function-map)
550+
;; CHECK-NEXT:
546551
;; CHECK-NEXT: --table64-lowering alias for memory64-lowering
547552
;; CHECK-NEXT:
548553
;; CHECK-NEXT: --trace-calls instrument the build with code

test/lit/help/wasm2js.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@
331331
;; CHECK-NEXT: --print-full print in full s-expression
332332
;; CHECK-NEXT: format
333333
;; CHECK-NEXT:
334+
;; CHECK-NEXT: --print-function-map print a map of function indexes
335+
;; CHECK-NEXT: to names
336+
;; CHECK-NEXT:
334337
;; CHECK-NEXT: --print-minified print in minified s-expression
335338
;; CHECK-NEXT: format
336339
;; CHECK-NEXT:
@@ -483,6 +486,8 @@
483486
;; CHECK-NEXT: --stub-unsupported-js stub out unsupported JS
484487
;; CHECK-NEXT: operations
485488
;; CHECK-NEXT:
489+
;; CHECK-NEXT: --symbolmap (alias for print-function-map)
490+
;; CHECK-NEXT:
486491
;; CHECK-NEXT: --table64-lowering alias for memory64-lowering
487492
;; CHECK-NEXT:
488493
;; CHECK-NEXT: --trace-calls instrument the build with code
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
;; RUN: wasm-split -all --multi-split %s --manifest %S/multi-split.wast.manifest --out-prefix=%t --symbolmap -o %t.wasm
2+
;; RUN: filecheck %s --check-prefix PRIMARY-MAP < %t.wasm.symbols
3+
;; RUN: filecheck %s --check-prefix MOD1-MAP < %t1.wasm.symbols
4+
;; RUN: filecheck %s --check-prefix MOD2-MAP < %t2.wasm.symbols
5+
;; RUN: filecheck %s --check-prefix MOD3-MAP < %t3.wasm.symbols
6+
7+
;; PRIMARY-MAP: 0:placeholder_0
8+
;; PRIMARY-MAP: 1:placeholder_0_4
9+
;; PRIMARY-MAP: 2:placeholder_0_5
10+
;; PRIMARY-MAP: 3:trampoline_A
11+
;; PRIMARY-MAP: 4:trampoline_B
12+
;; PRIMARY-MAP: 5:trampoline_C
13+
14+
;; MOD1-MAP: 0:B
15+
;; MOD1-MAP: 1:C
16+
;; MOD1-MAP: 2:A
17+
18+
;; MOD2-MAP: 0:C
19+
;; MOD2-MAP: 1:trampoline_A
20+
;; MOD2-MAP: 2:B
21+
22+
;; MOD3-MAP: 0:trampoline_A
23+
;; MOD3-MAP: 1:trampoline_B
24+
;; MOD3-MAP: 2:C
25+
26+
(module
27+
(type $ret-i32 (func (result i32)))
28+
(type $ret-i64 (func (result i64)))
29+
(type $ret-f32 (func (result f32)))
30+
31+
(func $A (type $ret-i32) (result i32)
32+
(drop
33+
(call_ref $ret-i32
34+
(ref.func $A)
35+
)
36+
)
37+
(drop
38+
(call_ref $ret-i64
39+
(ref.func $B)
40+
)
41+
)
42+
(drop
43+
(call_ref $ret-f32
44+
(ref.func $C)
45+
)
46+
)
47+
(i32.const 0)
48+
)
49+
50+
(func $B (type $ret-i64) (result i64)
51+
(drop
52+
(call_ref $ret-i32
53+
(ref.func $A)
54+
)
55+
)
56+
(drop
57+
(call_ref $ret-i64
58+
(ref.func $B)
59+
)
60+
)
61+
(drop
62+
(call_ref $ret-f32
63+
(ref.func $C)
64+
)
65+
)
66+
(i64.const 0)
67+
)
68+
69+
(func $C (type $ret-f32) (result f32)
70+
(drop
71+
(call_ref $ret-i32
72+
(ref.func $A)
73+
)
74+
)
75+
(drop
76+
(call_ref $ret-i64
77+
(ref.func $B)
78+
)
79+
)
80+
(drop
81+
(call_ref $ret-f32
82+
(ref.func $C)
83+
)
84+
)
85+
(f32.const 0)
86+
)
87+
)

0 commit comments

Comments
 (0)