Skip to content

fix: fix shadowstack pass discard debuginfo #2496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/passes/shadowstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import {
ExternalKind,
ExportRef,
expandType,
isConstZero
isConstZero,
} from "../module";

import {
Expand All @@ -147,6 +147,7 @@ import {
import {
BuiltinNames
} from "../builtins";
import { Function } from "../program";

type LocalIndex = Index;
type SlotIndex = Index;
Expand Down Expand Up @@ -477,7 +478,11 @@ export class ShadowStackPass extends Pass {
let moduleRef = this.module.ref;
_BinaryenRemoveFunction(moduleRef, name);
let cArr = allocPtrArray(vars);
_BinaryenAddFunction(moduleRef, name, params, results, cArr, vars.length, body);
let newFuncRef = _BinaryenAddFunction(moduleRef, name, params, results, cArr, vars.length, body);
if (this.options.sourceMap || this.options.debugInfo) {
let func = Function.searchFunctionByRef(this.compiler, newFuncRef);
if (func) func.addDebugInfo(this.module, newFuncRef);
}
_free(cArr);
}

Expand Down
22 changes: 21 additions & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
} from "./common";

import {
Compiler,
Options
} from "./compiler";

Expand Down Expand Up @@ -117,7 +118,8 @@ import {
import {
Module,
FunctionRef,
MemorySegment
MemorySegment,
getFunctionName
} from "./module";

import {
Expand Down Expand Up @@ -3759,6 +3761,10 @@ export class Function extends TypedElement {
this.breakStack = breakStack = null;
this.breakLabel = null;
this.tempI32s = this.tempI64s = this.tempF32s = this.tempF64s = null;
this.addDebugInfo(module, ref);
}

addDebugInfo(module: Module, ref: FunctionRef): void {
if (this.program.options.sourceMap) {
let debugLocations = this.debugLocations;
for (let i = 0, k = debugLocations.length; i < k; ++i) {
Expand Down Expand Up @@ -3790,6 +3796,20 @@ export class Function extends TypedElement {
}
}
}

static searchFunctionByRef(compiler: Compiler, ref: FunctionRef): Function | null {
const modifiedFunctionName = getFunctionName(ref);
if (modifiedFunctionName) {
const instancesByName = compiler.program.instancesByName;
if (instancesByName.has(modifiedFunctionName)) {
const element = assert(instancesByName.get(modifiedFunctionName));
if (element.kind == ElementKind.FUNCTION) {
return <Function>element;
}
}
}
return null;
}
}

/** A yet unresolved instance field prototype. */
Expand Down
Loading