Skip to content

Commit f9dee72

Browse files
authored
fix: fix shadowstack pass discard debuginfo (#2496)
1 parent 078a4d0 commit f9dee72

File tree

71 files changed

+18347
-18324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+18347
-18324
lines changed

src/passes/shadowstack.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ import {
132132
ExternalKind,
133133
ExportRef,
134134
expandType,
135-
isConstZero
135+
isConstZero,
136136
} from "../module";
137137

138138
import {
@@ -477,7 +477,11 @@ export class ShadowStackPass extends Pass {
477477
let moduleRef = this.module.ref;
478478
_BinaryenRemoveFunction(moduleRef, name);
479479
let cArr = allocPtrArray(vars);
480-
_BinaryenAddFunction(moduleRef, name, params, results, cArr, vars.length, body);
480+
let newFuncRef = _BinaryenAddFunction(moduleRef, name, params, results, cArr, vars.length, body);
481+
if (this.options.sourceMap || this.options.debugInfo) {
482+
let func = this.compiler.program.searchFunctionByRef(newFuncRef);
483+
if (func) func.addDebugInfo(this.module, newFuncRef);
484+
}
481485
_free(cArr);
482486
}
483487

src/program.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ import {
117117
import {
118118
Module,
119119
FunctionRef,
120-
MemorySegment
120+
MemorySegment,
121+
getFunctionName
121122
} from "./module";
122123

123124
import {
@@ -812,6 +813,20 @@ export class Program extends DiagnosticEmitter {
812813
return this.blockOverhead + this.objectOverhead;
813814
}
814815

816+
searchFunctionByRef(ref: FunctionRef): Function | null {
817+
const modifiedFunctionName = getFunctionName(ref);
818+
if (modifiedFunctionName) {
819+
const instancesByName = this.instancesByName;
820+
if (instancesByName.has(modifiedFunctionName)) {
821+
const element = assert(instancesByName.get(modifiedFunctionName));
822+
if (element.kind == ElementKind.FUNCTION) {
823+
return <Function>element;
824+
}
825+
}
826+
}
827+
return null;
828+
}
829+
815830
/** Computes the next properly aligned offset of a memory manager block, given the current bump offset. */
816831
computeBlockStart(currentOffset: i32): i32 {
817832
var blockOverhead = this.blockOverhead;
@@ -3763,6 +3778,10 @@ export class Function extends TypedElement {
37633778
this.breakStack = breakStack = null;
37643779
this.breakLabel = null;
37653780
this.tempI32s = this.tempI64s = this.tempF32s = this.tempF64s = null;
3781+
this.addDebugInfo(module, ref);
3782+
}
3783+
3784+
addDebugInfo(module: Module, ref: FunctionRef): void {
37663785
if (this.program.options.sourceMap) {
37673786
let debugLocations = this.debugLocations;
37683787
for (let i = 0, k = debugLocations.length; i < k; ++i) {

0 commit comments

Comments
 (0)