fix abi methods crash on wasm
This commit is contained in:
@@ -691,7 +691,7 @@ func buildLdflags(goos, goarch, targetTriple string) []string {
|
|||||||
"-lwasi-emulated-signal",
|
"-lwasi-emulated-signal",
|
||||||
"-fwasm-exceptions",
|
"-fwasm-exceptions",
|
||||||
"-mllvm", "-wasm-enable-sjlj",
|
"-mllvm", "-wasm-enable-sjlj",
|
||||||
"-mllvm", "-wasm-enable-eh",
|
// "-mllvm", "-wasm-enable-eh", // unreachable error if enabled
|
||||||
// "-mllvm", "-wasm-disable-explicit-locals", // WASM module load failed: type mismatch: expect data but stack was empty if enabled
|
// "-mllvm", "-wasm-disable-explicit-locals", // WASM module load failed: type mismatch: expect data but stack was empty if enabled
|
||||||
)
|
)
|
||||||
if IsWasiThreadsEnabled() {
|
if IsWasiThreadsEnabled() {
|
||||||
|
|||||||
@@ -342,14 +342,28 @@ func (t *UncommonType) Methods() []Method {
|
|||||||
if t.Mcount == 0 {
|
if t.Mcount == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return (*[1 << 16]Method)(addChecked(unsafe.Pointer(t), uintptr(t.Moff), "t.mcount > 0"))[:t.Mcount:t.Mcount]
|
methodsPtr := addChecked(unsafe.Pointer(t), uintptr(t.Moff), "t.mcount > 0")
|
||||||
|
methods := make([]Method, t.Mcount)
|
||||||
|
for i := 0; i < int(t.Mcount); i++ {
|
||||||
|
elemPtr := addChecked(methodsPtr, uintptr(i)*unsafe.Sizeof(Method{}), "accessing method element")
|
||||||
|
elem := (*Method)(elemPtr)
|
||||||
|
methods[i] = *elem
|
||||||
|
}
|
||||||
|
return methods
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *UncommonType) ExportedMethods() []Method {
|
func (t *UncommonType) ExportedMethods() []Method {
|
||||||
if t.Xcount == 0 {
|
if t.Xcount == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return (*[1 << 16]Method)(addChecked(unsafe.Pointer(t), uintptr(t.Moff), "t.xcount > 0"))[:t.Xcount:t.Xcount]
|
mthdsPtr := addChecked(unsafe.Pointer(t), uintptr(t.Moff), "t.xcount > 0")
|
||||||
|
mthds := make([]Method, t.Xcount)
|
||||||
|
for i := 0; i < int(t.Xcount); i++ {
|
||||||
|
elemPtr := addChecked(mthdsPtr, uintptr(i)*unsafe.Sizeof(Method{}), "accessing method element")
|
||||||
|
elem := (*Method)(elemPtr)
|
||||||
|
mthds[i] = *elem
|
||||||
|
}
|
||||||
|
return mthds
|
||||||
}
|
}
|
||||||
|
|
||||||
// Imethod represents a method on an interface type
|
// Imethod represents a method on an interface type
|
||||||
|
|||||||
Reference in New Issue
Block a user