Bug 1829268 - Update wasm2c compiler used with RLBox to support MinGW r=glandium

Differential Revision: https://phabricator.services.mozilla.com/D176254
This commit is contained in:
Shravan Narayan 2023-04-25 07:00:41 +00:00
Родитель 8abc8bdd2a
Коммит df636672ed
10 изменённых файлов: 46 добавлений и 26 удалений

Просмотреть файл

@ -9,8 +9,8 @@ origin:
description: wasm2c fork used for rlbox sandboxing
url: https://github.com/WebAssembly/wabt
release: ad5f1385fa7afe29e98d69b6167132162675228f (2023-04-13T05:14:45Z).
revision: ad5f1385fa7afe29e98d69b6167132162675228f
release: 3ec45c662746a7094914fccaebae4648765ef56e (2023-04-24T08:07:03Z).
revision: 3ec45c662746a7094914fccaebae4648765ef56e
license: Apache-2.0
license-file: LICENSE

Просмотреть файл

@ -385,7 +385,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Address alignment,
uint32_t flags) override;
Result OnInitFunctionCount(Index count) override;
Result OnInitFunction(uint32_t priority, Index function_index) override;
Result OnInitFunction(uint32_t priority, Index symbol_index) override;
Result OnComdatCount(Index count) override;
Result OnComdatBegin(std::string_view name,
uint32_t flags,

Просмотреть файл

@ -569,7 +569,7 @@ class BinaryReaderNop : public BinaryReaderDelegate {
return Result::Ok;
}
Result OnInitFunctionCount(Index count) override { return Result::Ok; }
Result OnInitFunction(uint32_t priority, Index function_index) override {
Result OnInitFunction(uint32_t priority, Index symbol_index) override {
return Result::Ok;
}
Result OnComdatCount(Index count) override { return Result::Ok; }

Просмотреть файл

@ -460,7 +460,7 @@ class BinaryReaderDelegate {
Address alignment_log2,
uint32_t flags) = 0;
virtual Result OnInitFunctionCount(Index count) = 0;
virtual Result OnInitFunction(uint32_t priority, Index function_index) = 0;
virtual Result OnInitFunction(uint32_t priority, Index symbol_index) = 0;
virtual Result OnComdatCount(Index count) = 0;
virtual Result OnComdatBegin(std::string_view name,
uint32_t flags,

Просмотреть файл

@ -619,9 +619,9 @@ Result BinaryReaderLogging::OnSegmentInfo(Index index,
}
Result BinaryReaderLogging::OnInitFunction(uint32_t priority,
Index func_index) {
LOGF("OnInitFunction(%d priority: %d)\n", func_index, priority);
return reader_->OnInitFunction(priority, func_index);
Index symbol_index) {
LOGF("OnInitFunction(%d priority: %d)\n", symbol_index, priority);
return reader_->OnInitFunction(priority, symbol_index);
}
Result BinaryReaderLogging::OnComdatBegin(std::string_view name,

Просмотреть файл

@ -1193,7 +1193,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
Address alignment_log2,
uint32_t flags) override;
Result OnInitFunctionCount(Index count) override;
Result OnInitFunction(uint32_t priority, Index function_index) override;
Result OnInitFunction(uint32_t priority, Index symbol_index) override;
Result OnComdatCount(Index count) override;
Result OnComdatBegin(std::string_view name,
uint32_t flags,
@ -2264,10 +2264,16 @@ Result BinaryReaderObjdump::OnInitFunctionCount(Index count) {
}
Result BinaryReaderObjdump::OnInitFunction(uint32_t priority,
Index function_index) {
PrintDetails(" - %d: priority=%d\n", function_index, priority);
Index symbol_index) {
PrintDetails(" - %d: priority=%d", symbol_index, priority);
auto name = GetSymbolName(symbol_index);
if (!name.empty()) {
PrintDetails(" <" PRIstringview ">", WABT_PRINTF_STRING_VIEW_ARG(name));
}
PrintDetails("\n");
return Result::Ok;
}
Result BinaryReaderObjdump::OnComdatCount(Index count) {
PrintDetails(" - comdat groups [count=%d]\n", count);
return Result::Ok;

6
third_party/wasm2c/src/binary-reader.cc поставляемый
Просмотреть файл

@ -2256,10 +2256,10 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) {
CALLBACK(OnInitFunctionCount, count);
while (count--) {
uint32_t priority;
uint32_t func;
uint32_t symbol;
CHECK_RESULT(ReadU32Leb128(&priority, "priority"));
CHECK_RESULT(ReadU32Leb128(&func, "function index"));
CALLBACK(OnInitFunction, priority, func);
CHECK_RESULT(ReadU32Leb128(&symbol, "symbol index"));
CALLBACK(OnInitFunction, priority, symbol);
}
break;
case LinkingEntryType::ComdatInfo:

27
third_party/wasm2c/src/c-writer.cc поставляемый
Просмотреть файл

@ -326,7 +326,7 @@ class CWriter {
void Write(Newline);
void Write(OpenBrace);
void Write(CloseBrace);
void Write(Index);
void Write(uint64_t);
void Write(std::string_view);
void Write(const ParamName&);
void Write(const LabelName&);
@ -1012,8 +1012,8 @@ void CWriter::Write(CloseBrace) {
Write("}");
}
void CWriter::Write(Index index) {
Writef("%" PRIindex, index);
void CWriter::Write(uint64_t val) {
Writef("%" PRIu64, val);
}
void CWriter::Write(std::string_view s) {
@ -1086,15 +1086,15 @@ void CWriter::Write(const GotoLabel& goto_label) {
StackVar(amount - i - 1), "; ");
}
}
}
assert(try_catch_stack_.size() >= label->try_catch_stack_size);
assert(try_catch_stack_.size() >= label->try_catch_stack_size);
if (try_catch_stack_.size() != label->try_catch_stack_size) {
const std::string& name =
try_catch_stack_.at(label->try_catch_stack_size).name;
if (try_catch_stack_.size() != label->try_catch_stack_size) {
const std::string& name =
try_catch_stack_.at(label->try_catch_stack_size).name;
Write("wasm_rt_set_unwind_target(", name, "_outer_target);", Newline());
}
Write("wasm_rt_set_unwind_target(", name, "_outer_target);", Newline());
}
if (goto_label.var.is_name()) {
@ -1972,8 +1972,13 @@ void CWriter::WriteDataInitializers() {
Index memory_idx = module_->num_memory_imports;
for (Index i = memory_idx; i < module_->memories.size(); i++) {
const Memory* memory = module_->memories[i];
uint32_t max =
memory->page_limits.has_max ? memory->page_limits.max : 65536;
uint64_t max;
if (memory->page_limits.has_max) {
max = memory->page_limits.max;
} else {
max = memory->page_limits.is_64 ? (static_cast<uint64_t>(1) << 48)
: 65536;
}
Write("wasm_rt_allocate_memory(",
ExternalInstancePtr(ModuleFieldType::Memory, memory->name), ", ",
memory->page_limits.initial, ", ", max, ", ",

Просмотреть файл

@ -8,7 +8,11 @@ R"w2c_template(#include <stddef.h>
)w2c_template"
R"w2c_template(#include <string.h>
)w2c_template"
R"w2c_template(#if defined(_MSC_VER)
R"w2c_template(#if defined(__MINGW32__)
)w2c_template"
R"w2c_template(#include <malloc.h>
)w2c_template"
R"w2c_template(#elif defined(_MSC_VER)
)w2c_template"
R"w2c_template(#include <intrin.h>
)w2c_template"
@ -16,6 +20,10 @@ R"w2c_template(#include <malloc.h>
)w2c_template"
R"w2c_template(#define alloca _alloca
)w2c_template"
R"w2c_template(#elif defined(__FreeBSD__)
)w2c_template"
R"w2c_template(#include <stdlib.h>
)w2c_template"
R"w2c_template(#else
)w2c_template"
R"w2c_template(#include <alloca.h>

1
third_party/wasm2c/wasm2c/wasm-rt-impl.c поставляемый
Просмотреть файл

@ -294,6 +294,7 @@ bool wasm_rt_is_initialized(void) {
void wasm_rt_free(void) {
#if WASM_RT_INSTALL_SIGNAL_HANDLER
os_cleanup_signal_handler();
g_signal_handler_installed = false;
#endif
}