Skip to content

Commit ad08022

Browse files
authored
1 parent cde2a52 commit ad08022

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/wasm-binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ extern const char* Dylink;
414414
extern const char* Dylink0;
415415
extern const char* Linking;
416416
extern const char* Producers;
417+
extern const char* BuildId;
417418
extern const char* TargetFeatures;
418419

419420
extern const char* AtomicsFeature;

src/wasm/wasm-binary.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <algorithm>
1818
#include <fstream>
19+
#include <iomanip>
1920

2021
#include "ir/eh-utils.h"
2122
#include "ir/module-utils.h"
@@ -1212,7 +1213,31 @@ void WasmBinaryWriter::initializeDebugInfo() {
12121213
}
12131214

12141215
void WasmBinaryWriter::writeSourceMapProlog() {
1215-
*sourceMap << "{\"version\":3,\"sources\":[";
1216+
*sourceMap << "{\"version\":3,";
1217+
1218+
for (const auto& section : wasm->customSections) {
1219+
if (section.name == BinaryConsts::CustomSections::BuildId) {
1220+
U32LEB ret;
1221+
size_t pos = 0;
1222+
ret.read([&]() { return section.data[pos++]; });
1223+
1224+
if (section.data.size() != pos + ret.value) {
1225+
std::cerr
1226+
<< "warning: build id section with an incorrect size detected!\n";
1227+
break;
1228+
}
1229+
1230+
*sourceMap << "\"debugId\":\"";
1231+
for (size_t i = pos; i < section.data.size(); i++) {
1232+
*sourceMap << std::setfill('0') << std::setw(2) << std::hex
1233+
<< static_cast<int>(static_cast<uint8_t>(section.data[i]));
1234+
}
1235+
*sourceMap << "\",";
1236+
break;
1237+
}
1238+
}
1239+
1240+
*sourceMap << "\"sources\":[";
12161241
for (size_t i = 0; i < wasm->debugInfoFileNames.size(); i++) {
12171242
if (i > 0) {
12181243
*sourceMap << ",";

src/wasm/wasm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const char* Dylink = "dylink";
3636
const char* Dylink0 = "dylink.0";
3737
const char* Linking = "linking";
3838
const char* Producers = "producers";
39+
const char* BuildId = "build_id";
3940
const char* TargetFeatures = "target_features";
4041
const char* AtomicsFeature = "atomics";
4142
const char* BulkMemoryFeature = "bulk-memory";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Verify that the build id is included in the source map.
2+
3+
;; RUN: wasm-opt %s.wasm -o %t.wasm -osm %t.map
4+
;; RUN: cat %t.map | filecheck %s
5+
6+
;; CHECK: {"version":3,"debugId":"01ab23cd45ef67ab89","sources":[],"names":[],"mappings":""}
7+
29 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)