fix build issue

This commit is contained in:
Mayukha Vadari
2026-02-06 12:44:05 -05:00
parent e6ee492822
commit 4318b2ebf7
2 changed files with 15 additions and 15 deletions

View File

@@ -23,13 +23,11 @@ pushLeb128(std::vector<uint8_t>& buf, uint32_t val)
}
// Helper: append bytes from a C-style array to a vector
// Uses a loop to avoid GCC false positive -Werror=stringop-overflow with insert()
template <std::size_t N>
void
appendBytes(std::vector<uint8_t>& buf, uint8_t const (&arr)[N])
{
for (std::size_t i = 0; i < N; ++i)
buf.push_back(arr[i]);
buf.insert(buf.end(), &arr[0], &arr[N]);
}
// Helper: append bytes from a vector to a vector
@@ -59,6 +57,7 @@ std::vector<uint8_t>
generateCodeBlob(uint32_t num_instructions)
{
std::vector<uint8_t> wasm;
wasm.reserve(sizeof(WASM_HEADER) + sizeof(TYPE_EMPTY_FUNC) + sizeof(FUNC_TYPE0) + sizeof(EXPORT_FINISH));
appendBytes(wasm, WASM_HEADER);
appendBytes(wasm, TYPE_EMPTY_FUNC);
appendBytes(wasm, FUNC_TYPE0);
@@ -82,6 +81,7 @@ std::vector<uint8_t>
generateDataBlob(uint32_t data_size)
{
std::vector<uint8_t> wasm;
wasm.reserve(sizeof(WASM_HEADER) + sizeof(TYPE_EMPTY_FUNC) + sizeof(FUNC_TYPE0));
appendBytes(wasm, WASM_HEADER);
appendBytes(wasm, TYPE_EMPTY_FUNC);
appendBytes(wasm, FUNC_TYPE0);

View File

@@ -10,7 +10,7 @@
namespace wasm_constants {
// Magic + version header
static constexpr uint8_t WASM_HEADER[] = {
uint8_t const WASM_HEADER[] = {
0x00,
0x61,
0x73,
@@ -22,31 +22,31 @@ static constexpr uint8_t WASM_HEADER[] = {
};
// Type section: () -> ()
static constexpr uint8_t TYPE_EMPTY_FUNC[] = {0x01, 0x04, 0x01, 0x60, 0x00, 0x00};
uint8_t const TYPE_EMPTY_FUNC[] = {0x01, 0x04, 0x01, 0x60, 0x00, 0x00};
// Function section: one function using type 0
static constexpr uint8_t FUNC_TYPE0[] = {0x03, 0x02, 0x01, 0x00};
uint8_t const FUNC_TYPE0[] = {0x03, 0x02, 0x01, 0x00};
// Export section: export func 0 as "finish"
static constexpr uint8_t EXPORT_FINISH[] = {0x07, 0x0a, 0x01, 0x06, 'f', 'i', 'n', 'i', 's', 'h', 0x00, 0x00};
uint8_t const EXPORT_FINISH[] = {0x07, 0x0a, 0x01, 0x06, 'f', 'i', 'n', 'i', 's', 'h', 0x00, 0x00};
// Empty function body: 0 locals, end
static constexpr uint8_t EMPTY_BODY[] = {0x00, 0x0b};
uint8_t const EMPTY_BODY[] = {0x00, 0x0b};
// Data segment offset: i32.const 0, end
static constexpr uint8_t DATA_OFFSET_ZERO[] = {0x41, 0x00, 0x0b};
uint8_t const DATA_OFFSET_ZERO[] = {0x41, 0x00, 0x0b};
// Section IDs
static constexpr uint8_t SECTION_MEMORY = 0x05;
static constexpr uint8_t SECTION_CODE = 0x0a;
static constexpr uint8_t SECTION_DATA = 0x0b;
uint8_t const SECTION_MEMORY = 0x05;
uint8_t const SECTION_CODE = 0x0a;
uint8_t const SECTION_DATA = 0x0b;
// Instructions
static constexpr uint8_t INSTR_NOP = 0x01;
static constexpr uint8_t INSTR_END = 0x0b;
uint8_t const INSTR_NOP = 0x01;
uint8_t const INSTR_END = 0x0b;
// Fill byte for data section bloat
static constexpr uint8_t DATA_FILL_BYTE = 0xEE;
uint8_t const DATA_FILL_BYTE = 0xEE;
// Generator for WASM module with large code section (many NOPs)
std::vector<uint8_t>