-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --strip that removes debug info (#1787)
This is sort of like --strip on a native binary. The more specific use case for us is e.g. you link with a library that has -g in its CFLAGS, but you don't want debug info in your final executable (I hit this with poppler now). We can make emcc pass this to binaryen if emcc is not building an output with intended debug info.
- Loading branch information
Showing
10 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2018 WebAssembly Community Group participants | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// | ||
// Similar to strip-ing a native binary, this removes debug info | ||
// and related things like source map URLs, names section, etc. | ||
// | ||
|
||
#include "wasm.h" | ||
#include "wasm-binary.h" | ||
#include "pass.h" | ||
|
||
using namespace std; | ||
|
||
namespace wasm { | ||
|
||
struct Strip : public Pass { | ||
void run(PassRunner* runner, Module* module) override { | ||
// Remove name and debug sections. | ||
auto& sections = module->userSections; | ||
sections.erase( | ||
std::remove_if( | ||
sections.begin(), | ||
sections.end(), | ||
[&](const UserSection& curr) { | ||
return curr.name == BinaryConsts::UserSections::Name || | ||
curr.name == BinaryConsts::UserSections::SourceMapUrl || | ||
curr.name.find(".debug") == 0 || | ||
curr.name.find("reloc..debug") == 0; | ||
} | ||
), | ||
sections.end() | ||
); | ||
// Clean up internal data structures. | ||
module->clearDebugInfo(); | ||
for (auto& func : module->functions) { | ||
func->clearNames(); | ||
func->clearDebugInfo(); | ||
} | ||
} | ||
}; | ||
|
||
Pass *createStripPass() { | ||
return new Strip(); | ||
} | ||
|
||
} // namespace wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(module | ||
(type $0 (func (result i32))) | ||
(import "env" "__linear_memory" (memory $0 0)) | ||
(import "env" "__indirect_function_table" (table $timport$1 0 anyfunc)) | ||
(func $0 (; 0 ;) (type $0) (result i32) | ||
(local $0 i32) | ||
(set_local $0 | ||
(i32.const 1) | ||
) | ||
(return | ||
(get_local $0) | ||
) | ||
) | ||
;; custom section "zinking", size 28 | ||
) |
Binary file not shown.