Link multiple .o or .a files
A question: is currently impossible to load second .o file? Would it result in error or just memory corruption?
@dobegor Yes, you can do it, goloader is designed for that. If there is any error or corruption, please create an issue.
Hi dearplain, do you have any plans on attempting to do this soon? I would very much appreciate it, and it would help me out a lot. If there's anything I can help with, please tell me.
OK, I'll try to finish it.
I haven't tried your latest commits yet. Do those work?
Has some other problem about interface method in go1.10+.
So I did some testing with the latest commit on the master branch. I tried reading all objects imported by the plugin I'm trying to load. The plugin looks as follows:
package plugin
import (
"fmt"
)
func main() {
fmt.Println("Test")
}
Basically, I parse the object produced when running go tool compile on that file, and go through the imports of it, in this case only fmt. I look that up, add it to my slice, then continue doing that so I get all dependencies of my plugin, then I read all those objects with goloader.
This caused some nasty behaviour though, I think because of something to do with the runtime. Basically, when I read the runtime packages with goloader along with the other packages, I get errors as such:
Exceptions and errors with runtime read
unresolve external: $f64.3fe4000000000000
unresolve external: $f32.5f000000
unresolve external: runtime.libpreinit
Exception 0xc0000005 0x0 0xffffffffffffffff 0x2880d45
PC=0x2880d45
runtime.asmcgocall(0x20, 0x0)
$GOROOT/src/runtime/asm_amd64.s:688 +0x71
runtime.persistentalloc.func1()
C:/Go/src/runtime/malloc.go:950 +0x4c
runtime.systemstack(0x0)
C:/Go/src/runtime/asm_amd64.s:409 +0x7e
runtime.mstart()
C:/Go/src/runtime/proc.go:1175
goroutine 18 [running]:
sync.runtime_nanotime(0x3)
$GOROOT/src/runtime/defs_windows_amd64.go:613 +0x29
panic: (runtime.errorString) (0x5a8100,0x6e7300)
fatal error: panic on system stack
runtime stack:
runtime: unexpected return pc for runtime.sigtramp called from 0x18ef740
stack: frame={sp:0x18eef20, fp:0x18eef30} stack=[0x18dff58,0x18eff58)
00000000018eee20: 000000000044d0e9 <runtime.traceback+89> ffffffffffffffff
00000000018eee30: ffffffffffffffff 0000000000000000
00000000018eee40: 000000c042050480 0000000000000000
00000000018eee50: 00000000018eeeb8 000000000044dd0c <runtime.tracebackothers+588>
00000000018eee60: ffffffffffffffff ffffffffffffffff
00000000018eee70: 0000000000000000 000000c042050480
00000000018eee80: 00000001018eeeb8 000000000044d159 <runtime.tracebacktrap+89>
00000000018eee90: 0000000002880d45 <runtime.asmcgocall+113> 00000000018efef0
00000000018eeea0: 000000c042050480 000000c042034780
00000000018eeeb0: 0000000000000002 00000000018eef10
00000000018eeec0: 000000000043d8cb <runtime.lastcontinuehandler+571> 000000c042034780
00000000018eeed0: 00000000018efef0 0000000000000000
00000000018eeee0: 000000c042034780 0000000002880d45 <runtime.asmcgocall+113>
00000000018eeef0: ffffffffffffffff 0000000002880d45 <runtime.asmcgocall+113>
00000000018eef00: 00000000c0000005 000000c042034780
00000000018eef10: 0000000000095090 00000000004579f8 <runtime.sigtramp+184>
00000000018eef20: <00000000018efc30 !00000000018ef740
00000000018eef30: >000000c042034780 0000000000000000
00000000018eef40: 0000000000095080 0000000000283000
00000000018eef50: 0000000000000003 0000000000457a70 <runtime.lastcontinuetramp+0>
00000000018eef60: 0000000000095090 0000000000000000
00000000018eef70: 0000000000000000 0000000000095080
00000000018eef80: 000000c042034780 00000000018eef20
00000000018eef90: 0000000000000246 00007ffa5f465678
00000000018eefa0: 0000000000000000 0000000000000000
00000000018eefb0: 0000000000000000 00000000018ef610
00000000018eefc0: 0000000000000000 00000000018ef098
00000000018eefd0: 0000000000000003 0000000000283000
00000000018eefe0: 00000000018efc30 00000000018ef740
00000000018eeff0: 00000000018ef610 0000000000000000
00000000018ef000: 00000000018ef610 00000000018efc30
00000000018ef010: 0000000000000000 0000000000000000
00000000018ef020: 00000000018ef740 00000000018ef140
runtime.throw(0x5f3d97, 0x15)
C:/Go/src/runtime/panic.go:616 +0x88
panic(0x5a8100, 0x6e7300)
C:/Go/src/runtime/panic.go:431 +0x6a4
runtime.panicindex()
C:/Go/src/runtime/panic.go:28 +0x65
runtime.funcline1(0xc046145411, 0xc0461e6000, 0x28baabb, 0x1, 0xc000000048, 0x12, 0xc0460f2a4d)
C:/Go/src/runtime/symtab.go:833 +0x184
runtime.funcline(0xc046145411, 0xc0461e6000, 0x28baabb, 0x100, 0x1, 0x8)
C:/Go/src/runtime/symtab.go:838 +0x4b
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480, 0x0, 0x0, 0x64, 0x0, 0x0, 0x0, ...)
C:/Go/src/runtime/traceback.go:378 +0x891
runtime.traceback1(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480, 0x0)
C:/Go/src/runtime/traceback.go:684 +0x100
runtime.traceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480)
C:/Go/src/runtime/traceback.go:645 +0x59
runtime.tracebackothers(0xc042034780)
C:/Go/src/runtime/traceback.go:816 +0x24c
runtime.lastcontinuehandler(0x18efc30, 0x18ef740, 0xc042034780, 0x0)
C:/Go/src/runtime/signal_windows.go:146 +0x23b
runtime: unexpected return pc for runtime.sigtramp called from 0x18ef740
stack: frame={sp:0x18eef20, fp:0x18eef30} stack=[0x18dff58,0x18eff58)
00000000018eee20: 000000000044d0e9 <runtime.traceback+89> ffffffffffffffff
00000000018eee30: ffffffffffffffff 0000000000000000
00000000018eee40: 000000c042050480 0000000000000000
00000000018eee50: 00000000018eeeb8 000000000044dd0c <runtime.tracebackothers+588>
00000000018eee60: ffffffffffffffff ffffffffffffffff
00000000018eee70: 0000000000000000 000000c042050480
00000000018eee80: 00000001018eeeb8 000000000044d159 <runtime.tracebacktrap+89>
00000000018eee90: 0000000002880d45 <runtime.asmcgocall+113> 00000000018efef0
00000000018eeea0: 000000c042050480 000000c042034780
00000000018eeeb0: 0000000000000002 00000000018eef10
00000000018eeec0: 000000000043d8cb <runtime.lastcontinuehandler+571> 000000c042034780
00000000018eeed0: 00000000018efef0 0000000000000000
00000000018eeee0: 000000c042034780 0000000002880d45 <runtime.asmcgocall+113>
00000000018eeef0: ffffffffffffffff 0000000002880d45 <runtime.asmcgocall+113>
00000000018eef00: 00000000c0000005 000000c042034780
00000000018eef10: 0000000000095090 00000000004579f8 <runtime.sigtramp+184>
00000000018eef20: <00000000018efc30 !00000000018ef740
00000000018eef30: >000000c042034780 0000000000000000
00000000018eef40: 0000000000095080 0000000000283000
00000000018eef50: 0000000000000003 0000000000457a70 <runtime.lastcontinuetramp+0>
00000000018eef60: 0000000000095090 0000000000000000
00000000018eef70: 0000000000000000 0000000000095080
00000000018eef80: 000000c042034780 00000000018eef20
00000000018eef90: 0000000000000246 00007ffa5f465678
00000000018eefa0: 0000000000000000 0000000000000000
00000000018eefb0: 0000000000000000 00000000018ef610
00000000018eefc0: 0000000000000000 00000000018ef098
00000000018eefd0: 0000000000000003 0000000000283000
00000000018eefe0: 00000000018efc30 00000000018ef740
00000000018eeff0: 00000000018ef610 0000000000000000
00000000018ef000: 00000000018ef610 00000000018efc30
00000000018ef010: 0000000000000000 0000000000000000
00000000018ef020: 00000000018ef740 00000000018ef140
runtime.sigtramp()
C:/Go/src/runtime/sys_windows_amd64.s:175 +0xb8
goroutine 18 [running]:
runtime.asmcgocall(0x203d212074787463, 0xc04203eb10)
$GOROOT/src/runtime/asm_amd64.s:673 +0x47 fp=0xc042f95be8 sp=0xc042f95be0 pc=0x2880d1b
runtime.stdcall(0x72465f706165484d, 0xc04203e800)
$GOROOT/src/runtime/os_windows.go:716 +0x81 fp=0xc042f95c18 sp=0xc042f95be8 pc=0x2880cae
runtime.stdcall1(0x72465f706165484d, 0xc042f95c50, 0x10c)
$GOROOT/src/runtime/os_windows.go:734 +0x47 fp=0xc042f95c38 sp=0xc042f95c18 pc=0x2881e32
runtime.nanotimeQPC(0x0)
$GOROOT/src/runtime/os_windows.go:336 +0x31 fp=0xc042f95c68 sp=0xc042f95c38 pc=0x2888b1e
sync.runtime_nanotime(0x3)
$GOROOT/src/runtime/defs_windows_amd64.go:613 +0x29 fp=0xc042f95c80 sp=0xc042f95c68 pc=0x28baca1
fatal error: index out of range
panic during panic
runtime stack:
runtime: unexpected return pc for runtime.sigtramp called from 0x18ef740
stack: frame={sp:0x18eef20, fp:0x18eef30} stack=[0x18dff58,0x18eff58)
00000000018eee20: 000000000044d0e9 <runtime.traceback+89> ffffffffffffffff
00000000018eee30: ffffffffffffffff 0000000000000000
00000000018eee40: 000000c042050480 0000000000000000
00000000018eee50: 00000000018eeeb8 000000000044dd0c <runtime.tracebackothers+588>
00000000018eee60: ffffffffffffffff ffffffffffffffff
00000000018eee70: 0000000000000000 000000c042050480
00000000018eee80: 00000001018eeeb8 000000000044d159 <runtime.tracebacktrap+89>
00000000018eee90: 0000000002880d45 <runtime.asmcgocall+113> 00000000018efef0
00000000018eeea0: 000000c042050480 000000c042034780
00000000018eeeb0: 0000000000000002 00000000018eef10
00000000018eeec0: 000000000043d8cb <runtime.lastcontinuehandler+571> 000000c042034780
00000000018eeed0: 00000000018efef0 0000000000000000
00000000018eeee0: 000000c042034780 0000000002880d45 <runtime.asmcgocall+113>
00000000018eeef0: ffffffffffffffff 0000000002880d45 <runtime.asmcgocall+113>
00000000018eef00: 00000000c0000005 000000c042034780
00000000018eef10: 0000000000095090 00000000004579f8 <runtime.sigtramp+184>
00000000018eef20: <00000000018efc30 !00000000018ef740
00000000018eef30: >000000c042034780 0000000000000000
00000000018eef40: 0000000000095080 0000000000283000
00000000018eef50: 0000000000000003 0000000000457a70 <runtime.lastcontinuetramp+0>
00000000018eef60: 0000000000095090 0000000000000000
00000000018eef70: 0000000000000000 0000000000095080
00000000018eef80: 000000c042034780 00000000018eef20
00000000018eef90: 0000000000000246 00007ffa5f465678
00000000018eefa0: 0000000000000000 0000000000000000
00000000018eefb0: 0000000000000000 00000000018ef610
00000000018eefc0: 0000000000000000 00000000018ef098
00000000018eefd0: 0000000000000003 0000000000283000
00000000018eefe0: 00000000018efc30 00000000018ef740
00000000018eeff0: 00000000018ef610 0000000000000000
00000000018ef000: 00000000018ef610 00000000018efc30
00000000018ef010: 0000000000000000 0000000000000000
00000000018ef020: 00000000018ef740 00000000018ef140
runtime.startpanic_m()
C:/Go/src/runtime/panic.go:690 +0x187
runtime.startpanic()
C:/Go/src/runtime/panic.go:589 +0x1e
runtime.throw(0x5f2c78, 0x12)
C:/Go/src/runtime/panic.go:615 +0x7b
runtime.panicCheckMalloc(0x612e60, 0x6e7300)
C:/Go/src/runtime/panic.go:20 +0x85
runtime.panicindex()
C:/Go/src/runtime/panic.go:27 +0x40
runtime.funcline1(0xc046145411, 0xc0461e6000, 0x28baabb, 0x444d01, 0xc0460f2a4d, 0xc0460f2a4d, 0x12)
C:/Go/src/runtime/symtab.go:833 +0x184
runtime.funcline(0xc046145411, 0xc0461e6000, 0x28baabb, 0x100, 0x1, 0x8)
C:/Go/src/runtime/symtab.go:838 +0x4b
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480, 0x0, 0x0, 0x64, 0x0, 0x0, 0x0, ...)
C:/Go/src/runtime/traceback.go:378 +0x891
runtime.traceback1(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480, 0x0)
C:/Go/src/runtime/traceback.go:684 +0x100
runtime.traceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480)
C:/Go/src/runtime/traceback.go:645 +0x59
runtime.tracebackothers(0xc042034780)
C:/Go/src/runtime/traceback.go:816 +0x24c
runtime.dopanic_m(0xc042034780, 0x42ba78, 0x18ee838)
C:/Go/src/runtime/panic.go:736 +0x19d
runtime.dopanic.func1()
C:/Go/src/runtime/panic.go:598 +0x43
runtime.dopanic(0x0)
C:/Go/src/runtime/panic.go:597 +0x51
runtime.throw(0x5f3d97, 0x15)
C:/Go/src/runtime/panic.go:616 +0x88
panic(0x5a8100, 0x6e7300)
C:/Go/src/runtime/panic.go:431 +0x6a4
runtime.panicindex()
C:/Go/src/runtime/panic.go:28 +0x65
runtime.funcline1(0xc046145411, 0xc0461e6000, 0x28baabb, 0x1, 0xc000000048, 0x12, 0xc0460f2a4d)
C:/Go/src/runtime/symtab.go:833 +0x184
runtime.funcline(0xc046145411, 0xc0461e6000, 0x28baabb, 0x100, 0x1, 0x8)
C:/Go/src/runtime/symtab.go:838 +0x4b
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480, 0x0, 0x0, 0x64, 0x0, 0x0, 0x0, ...)
C:/Go/src/runtime/traceback.go:378 +0x891
runtime.traceback1(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480, 0x0)
C:/Go/src/runtime/traceback.go:684 +0x100
runtime.traceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042050480)
C:/Go/src/runtime/traceback.go:645 +0x59
runtime.tracebackothers(0xc042034780)
C:/Go/src/runtime/traceback.go:816 +0x24c
runtime.lastcontinuehandler(0x18efc30, 0x18ef740, 0xc042034780, 0x0)
C:/Go/src/runtime/signal_windows.go:146 +0x23b
runtime: unexpected return pc for runtime.sigtramp called from 0x18ef740
stack: frame={sp:0x18eef20, fp:0x18eef30} stack=[0x18dff58,0x18eff58)
00000000018eee20: 000000000044d0e9 <runtime.traceback+89> ffffffffffffffff
00000000018eee30: ffffffffffffffff 0000000000000000
00000000018eee40: 000000c042050480 0000000000000000
00000000018eee50: 00000000018eeeb8 000000000044dd0c <runtime.tracebackothers+588>
00000000018eee60: ffffffffffffffff ffffffffffffffff
00000000018eee70: 0000000000000000 000000c042050480
00000000018eee80: 00000001018eeeb8 000000000044d159 <runtime.tracebacktrap+89>
00000000018eee90: 0000000002880d45 <runtime.asmcgocall+113> 00000000018efef0
00000000018eeea0: 000000c042050480 000000c042034780
00000000018eeeb0: 0000000000000002 00000000018eef10
00000000018eeec0: 000000000043d8cb <runtime.lastcontinuehandler+571> 000000c042034780
00000000018eeed0: 00000000018efef0 0000000000000000
00000000018eeee0: 000000c042034780 0000000002880d45 <runtime.asmcgocall+113>
00000000018eeef0: ffffffffffffffff 0000000002880d45 <runtime.asmcgocall+113>
00000000018eef00: 00000000c0000005 000000c042034780
00000000018eef10: 0000000000095090 00000000004579f8 <runtime.sigtramp+184>
00000000018eef20: <00000000018efc30 !00000000018ef740
00000000018eef30: >000000c042034780 0000000000000000
00000000018eef40: 0000000000095080 0000000000283000
00000000018eef50: 0000000000000003 0000000000457a70 <runtime.lastcontinuetramp+0>
00000000018eef60: 0000000000095090 0000000000000000
00000000018eef70: 0000000000000000 0000000000095080
00000000018eef80: 000000c042034780 00000000018eef20
00000000018eef90: 0000000000000246 00007ffa5f465678
00000000018eefa0: 0000000000000000 0000000000000000
00000000018eefb0: 0000000000000000 00000000018ef610
00000000018eefc0: 0000000000000000 00000000018ef098
00000000018eefd0: 0000000000000003 0000000000283000
00000000018eefe0: 00000000018efc30 00000000018ef740
00000000018eeff0: 00000000018ef610 0000000000000000
00000000018ef000: 00000000018ef610 00000000018efc30
00000000018ef010: 0000000000000000 0000000000000000
00000000018ef020: 00000000018ef740 00000000018ef140
runtime.sigtramp()
C:/Go/src/runtime/sys_windows_amd64.s:175 +0xb8
Now I understand that reading the runtime with it might be a very bad idea, as you'd kind of create a new runtime, so I tried not reading the runtime, but re-using the current by registering the types. I got the following exceptions/errors.
Exceptions/errors without runtime read
unresolve external: $f64.3fe4000000000000
unresolve external: runtime.selectnbrecv
unresolve external: runtime.newselect
unresolve external: runtime.selectrecv
unresolve external: runtime.selectgo
unresolve external: runtime.selectsend
unresolve external: sync.runtime_notifyListNotifyAll
unresolve external: sync.runtime_notifyListNotifyOne
unresolve external: sync.runtime_notifyListAdd
unresolve external: sync.runtime_notifyListWait
unresolve external: syscall.Getpagesize
unresolve external: syscall.compileCallback
unresolve external: internal/poll.runtime_pollServerDescriptor
unresolve external: runtime.selectnbsend
unresolve external: runtime.convT2Istring
unresolve external: reflect.ismapkey
unresolve external: reflect.typedslicecopy
unresolve external: reflect.rselect
unresolve external: reflect.makemap
Exception 0xc0000005 0x0 0xffffffffffffffff 0x2870d62
PC=0x2870d62
panic: (runtime.errorString) (0x5a8120,0x6e7300)
fatal error: panic on system stack
runtime stack:
runtime: unexpected return pc for runtime.sigtramp called from 0xc043f7d540
stack: frame={sp:0x1c1feb8, fp:0x1c1fec8} stack=[0x1c0ff58,0x1c1ff58)
0000000001c1fdb8: 00000000005e1092 0000000000000001
0000000001c1fdc8: 0000000000000001 0000000001c1fe47
0000000001c1fdd8: 0000000000000009 0000000001c1fe30
0000000001c1fde8: 000000000042cd14 <runtime.printstring+132> 00000000005e1092
0000000001c1fdf8: 0000000000000001 0000000000000001
0000000001c1fe08: 00000000005e1092 0000000000000001
0000000001c1fe18: 0000000001c1fe50 000000000044d159 <runtime.tracebacktrap+89>
0000000001c1fe28: 0000000002870d62 <sync.(*Pool).pinSlow+371> 000000c043f7dcc8
0000000001c1fe38: 0000000000000000 000000c042034c00
0000000001c1fe48: 0000000000000002 0000000001c1fea8
0000000001c1fe58: 000000000043d8bd <runtime.lastcontinuehandler+557> 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe68: 000000c043f7dcc8 0000000000000000
0000000001c1fe78: 000000c042034c00 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe88: ffffffffffffffff 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe98: 00000000c0000005 000000c042035980
0000000001c1fea8: 000000c04203f858 00000000004579f8 <runtime.sigtramp+184>
0000000001c1feb8: <000000c043f7da30 !000000c043f7d540
0000000001c1fec8: >000000c042034c00 000000c000000000
0000000001c1fed8: 000000c04203f800 000000c04203fb58
0000000001c1fee8: 0000000000455783 <runtime.asmcgocall+115> 00000000004510dc <runtime.persistentalloc.func1+76>
0000000001c1fef8: 0000000000000020 0000000000000000
0000000001c1ff08: 00000000007496c0 00000000027ca6f8
0000000001c1ff18: 0000000000000438 000000c043f7cd20
0000000001c1ff28: 0000000000453f2e <runtime.systemstack+126> 00000000004301c0 <runtime.mstart+0>
0000000001c1ff38: 0000000000000000 0000000000000000
0000000001c1ff48: 0000000000000000 0000000000457bc4 <runtime.tstart_stdcall+68>
runtime.throw(0x5f3db7, 0x15)
C:/Go/src/runtime/panic.go:616 +0x88
panic(0x5a8120, 0x6e7300)
C:/Go/src/runtime/panic.go:431 +0x6a4
runtime.panicindex()
C:/Go/src/runtime/panic.go:28 +0x65
runtime.funcline1(0xc0445cef31, 0xc04462a000, 0x2870d62, 0x444d01, 0xc0445a041f, 0x14, 0xc0445a041f)
C:/Go/src/runtime/symtab.go:833 +0x184
runtime.funcline(0xc0445cef31, 0xc04462a000, 0x2870d62, 0x1, 0x1, 0x10)
C:/Go/src/runtime/symtab.go:838 +0x4b
runtime.gentraceback(0x2870d62, 0xc043f7dcc8, 0x0, 0xc042034c00, 0x0, 0x0, 0x64, 0x0, 0x0, 0x2, ...)
C:/Go/src/runtime/traceback.go:378 +0x891
runtime.traceback1(0x2870d62, 0xc043f7dcc8, 0x0, 0xc042034c00, 0x2)
C:/Go/src/runtime/traceback.go:684 +0x100
runtime.tracebacktrap(0x2870d62, 0xc043f7dcc8, 0x0, 0xc042034c00)
C:/Go/src/runtime/traceback.go:655 +0x59
runtime.lastcontinuehandler(0xc043f7da30, 0xc043f7d540, 0xc042034c00, 0xc000000000)
C:/Go/src/runtime/signal_windows.go:145 +0x22d
runtime: unexpected return pc for runtime.sigtramp called from 0xc043f7d540
stack: frame={sp:0x1c1feb8, fp:0x1c1fec8} stack=[0x1c0ff58,0x1c1ff58)
0000000001c1fdb8: 00000000005e1092 0000000000000001
0000000001c1fdc8: 0000000000000001 0000000001c1fe47
0000000001c1fdd8: 0000000000000009 0000000001c1fe30
0000000001c1fde8: 000000000042cd14 <runtime.printstring+132> 00000000005e1092
0000000001c1fdf8: 0000000000000001 0000000000000001
0000000001c1fe08: 00000000005e1092 0000000000000001
0000000001c1fe18: 0000000001c1fe50 000000000044d159 <runtime.tracebacktrap+89>
0000000001c1fe28: 0000000002870d62 <sync.(*Pool).pinSlow+371> 000000c043f7dcc8
0000000001c1fe38: 0000000000000000 000000c042034c00
0000000001c1fe48: 0000000000000002 0000000001c1fea8
0000000001c1fe58: 000000000043d8bd <runtime.lastcontinuehandler+557> 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe68: 000000c043f7dcc8 0000000000000000
0000000001c1fe78: 000000c042034c00 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe88: ffffffffffffffff 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe98: 00000000c0000005 000000c042035980
0000000001c1fea8: 000000c04203f858 00000000004579f8 <runtime.sigtramp+184>
0000000001c1feb8: <000000c043f7da30 !000000c043f7d540
0000000001c1fec8: >000000c042034c00 000000c000000000
0000000001c1fed8: 000000c04203f800 000000c04203fb58
0000000001c1fee8: 0000000000455783 <runtime.asmcgocall+115> 00000000004510dc <runtime.persistentalloc.func1+76>
0000000001c1fef8: 0000000000000020 0000000000000000
0000000001c1ff08: 00000000007496c0 00000000027ca6f8
0000000001c1ff18: 0000000000000438 000000c043f7cd20
0000000001c1ff28: 0000000000453f2e <runtime.systemstack+126> 00000000004301c0 <runtime.mstart+0>
0000000001c1ff38: 0000000000000000 0000000000000000
0000000001c1ff48: 0000000000000000 0000000000457bc4 <runtime.tstart_stdcall+68>
runtime.sigtramp()
C:/Go/src/runtime/sys_windows_amd64.s:175 +0xb8
goroutine 5 [running]:
runtime.asmcgocall(0x0, 0x5fb8e0)
C:/Go/src/runtime/asm_amd64.s:673 +0x47 fp=0xc043f7dbd0 sp=0xc043f7dbc8 pc=0x455757
runtime.cgocall(0x457840, 0xc04203fb58, 0x0)
C:/Go/src/runtime/cgocall.go:137 +0xa7 fp=0xc043f7dc08 sp=0xc043f7dbd0 pc=0x4023b7
syscall.Syscall6(0x7ffa5e140db0, 0xc042034c00, 0xc0433d6000, 0xc04462f800, 0x3635, 0xc043f7dd0c, 0x0, 0x0, 0x1, 0x3, ...)
C:/Go/src/runtime/syscall_windows.go:185 +0x12e fp=0xc043f7dc38 sp=0xc043f7dc08 pc=0x445d6e
syscall.WriteFile(0x5, 0x28ee906, 0x28fe498, 0x3800, 0xc043f7dd10, 0x475ae9, 0xc04206e280, 0x0)
C:/Go/src/syscall/zsyscall_windows.go:328 +0xe0 fp=0xc043f7dcc8 sp=0xc043f7dc38 pc=0x4628d0
fatal error: index out of range
panic during panic
runtime stack:
runtime: unexpected return pc for runtime.sigtramp called from 0xc043f7d540
stack: frame={sp:0x1c1feb8, fp:0x1c1fec8} stack=[0x1c0ff58,0x1c1ff58)
0000000001c1fdb8: 00000000005e1092 0000000000000001
0000000001c1fdc8: 0000000000000001 0000000001c1fe47
0000000001c1fdd8: 0000000000000009 0000000001c1fe30
0000000001c1fde8: 000000000042cd14 <runtime.printstring+132> 00000000005e1092
0000000001c1fdf8: 0000000000000001 0000000000000001
0000000001c1fe08: 00000000005e1092 0000000000000001
0000000001c1fe18: 0000000001c1fe50 000000000044d159 <runtime.tracebacktrap+89>
0000000001c1fe28: 0000000002870d62 <sync.(*Pool).pinSlow+371> 000000c043f7dcc8
0000000001c1fe38: 0000000000000000 000000c042034c00
0000000001c1fe48: 0000000000000002 0000000001c1fea8
0000000001c1fe58: 000000000043d8bd <runtime.lastcontinuehandler+557> 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe68: 000000c043f7dcc8 0000000000000000
0000000001c1fe78: 000000c042034c00 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe88: ffffffffffffffff 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe98: 00000000c0000005 000000c042035980
0000000001c1fea8: 000000c04203f858 00000000004579f8 <runtime.sigtramp+184>
0000000001c1feb8: <000000c043f7da30 !000000c043f7d540
0000000001c1fec8: >000000c042034c00 000000c000000000
0000000001c1fed8: 000000c04203f800 000000c04203fb58
0000000001c1fee8: 0000000000455783 <runtime.asmcgocall+115> 00000000004510dc <runtime.persistentalloc.func1+76>
0000000001c1fef8: 0000000000000020 0000000000000000
0000000001c1ff08: 00000000007496c0 00000000027ca6f8
0000000001c1ff18: 0000000000000438 000000c043f7cd20
0000000001c1ff28: 0000000000453f2e <runtime.systemstack+126> 00000000004301c0 <runtime.mstart+0>
0000000001c1ff38: 0000000000000000 0000000000000000
0000000001c1ff48: 0000000000000000 0000000000457bc4 <runtime.tstart_stdcall+68>
runtime.startpanic_m()
C:/Go/src/runtime/panic.go:690 +0x187
runtime.startpanic()
C:/Go/src/runtime/panic.go:589 +0x1e
runtime.throw(0x5f2c98, 0x12)
C:/Go/src/runtime/panic.go:615 +0x7b
runtime.panicCheckMalloc(0x612e80, 0x6e7300)
C:/Go/src/runtime/panic.go:20 +0x85
runtime.panicindex()
C:/Go/src/runtime/panic.go:27 +0x40
runtime.funcline1(0xc0445cef31, 0xc04462a000, 0x2870c65, 0x444d01, 0xc0445a041f, 0xc0445a041f, 0x14)
C:/Go/src/runtime/symtab.go:833 +0x184
runtime.funcline(0xc0445cef31, 0xc04462a000, 0x2870c65, 0x100, 0x1, 0x10)
C:/Go/src/runtime/symtab.go:838 +0x4b
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042034c00, 0x0, 0x0, 0x64, 0x0, 0x0, 0x0, ...)
C:/Go/src/runtime/traceback.go:378 +0x891
runtime.traceback1(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042034c00, 0x0)
C:/Go/src/runtime/traceback.go:684 +0x100
runtime.traceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc042034c00)
C:/Go/src/runtime/traceback.go:645 +0x59
runtime.tracebackothers(0xc042035980)
C:/Go/src/runtime/traceback.go:816 +0x24c
runtime.dopanic_m(0xc042035980, 0x42ba78, 0x1c1f838)
C:/Go/src/runtime/panic.go:736 +0x19d
runtime.dopanic.func1()
C:/Go/src/runtime/panic.go:598 +0x43
runtime.dopanic(0x0)
C:/Go/src/runtime/panic.go:597 +0x51
runtime.throw(0x5f3db7, 0x15)
C:/Go/src/runtime/panic.go:616 +0x88
panic(0x5a8120, 0x6e7300)
C:/Go/src/runtime/panic.go:431 +0x6a4
runtime.panicindex()
C:/Go/src/runtime/panic.go:28 +0x65
runtime.funcline1(0xc0445cef31, 0xc04462a000, 0x2870d62, 0x444d01, 0xc0445a041f, 0x14, 0xc0445a041f)
C:/Go/src/runtime/symtab.go:833 +0x184
runtime.funcline(0xc0445cef31, 0xc04462a000, 0x2870d62, 0x1, 0x1, 0x10)
C:/Go/src/runtime/symtab.go:838 +0x4b
runtime.gentraceback(0x2870d62, 0xc043f7dcc8, 0x0, 0xc042034c00, 0x0, 0x0, 0x64, 0x0, 0x0, 0x2, ...)
C:/Go/src/runtime/traceback.go:378 +0x891
runtime.traceback1(0x2870d62, 0xc043f7dcc8, 0x0, 0xc042034c00, 0x2)
C:/Go/src/runtime/traceback.go:684 +0x100
runtime.tracebacktrap(0x2870d62, 0xc043f7dcc8, 0x0, 0xc042034c00)
C:/Go/src/runtime/traceback.go:655 +0x59
runtime.lastcontinuehandler(0xc043f7da30, 0xc043f7d540, 0xc042034c00, 0xc000000000)
C:/Go/src/runtime/signal_windows.go:145 +0x22d
runtime: unexpected return pc for runtime.sigtramp called from 0xc043f7d540
stack: frame={sp:0x1c1feb8, fp:0x1c1fec8} stack=[0x1c0ff58,0x1c1ff58)
0000000001c1fdb8: 00000000005e1092 0000000000000001
0000000001c1fdc8: 0000000000000001 0000000001c1fe47
0000000001c1fdd8: 0000000000000009 0000000001c1fe30
0000000001c1fde8: 000000000042cd14 <runtime.printstring+132> 00000000005e1092
0000000001c1fdf8: 0000000000000001 0000000000000001
0000000001c1fe08: 00000000005e1092 0000000000000001
0000000001c1fe18: 0000000001c1fe50 000000000044d159 <runtime.tracebacktrap+89>
0000000001c1fe28: 0000000002870d62 <sync.(*Pool).pinSlow+371> 000000c043f7dcc8
0000000001c1fe38: 0000000000000000 000000c042034c00
0000000001c1fe48: 0000000000000002 0000000001c1fea8
0000000001c1fe58: 000000000043d8bd <runtime.lastcontinuehandler+557> 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe68: 000000c043f7dcc8 0000000000000000
0000000001c1fe78: 000000c042034c00 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe88: ffffffffffffffff 0000000002870d62 <sync.(*Pool).pinSlow+371>
0000000001c1fe98: 00000000c0000005 000000c042035980
0000000001c1fea8: 000000c04203f858 00000000004579f8 <runtime.sigtramp+184>
0000000001c1feb8: <000000c043f7da30 !000000c043f7d540
0000000001c1fec8: >000000c042034c00 000000c000000000
0000000001c1fed8: 000000c04203f800 000000c04203fb58
0000000001c1fee8: 0000000000455783 <runtime.asmcgocall+115> 00000000004510dc <runtime.persistentalloc.func1+76>
0000000001c1fef8: 0000000000000020 0000000000000000
0000000001c1ff08: 00000000007496c0 00000000027ca6f8
0000000001c1ff18: 0000000000000438 000000c043f7cd20
0000000001c1ff28: 0000000000453f2e <runtime.systemstack+126> 00000000004301c0 <runtime.mstart+0>
0000000001c1ff38: 0000000000000000 0000000000000000
0000000001c1ff48: 0000000000000000 0000000000457bc4 <runtime.tstart_stdcall+68>
runtime.sigtramp()
C:/Go/src/runtime/sys_windows_amd64.s:175 +0xb8
Aside from this, regardless of what I did, I also got a bunch of these:
filetab overflow!
And also these:
unresolve external: $f64.428a3185c5000000
unresolve external: $f64.422bf08eb0000000
If you're not sure how to fix those, that's no problem either. If I can help with anything, just mention me. 👍
show me your loader and how you load it.. I really don't know how to reproduction your problem.
~~I actually found a fix for the runtime related errors. I'll create a pull request and you can decide if you want that.~~ (Nevermind, this breaks existing examples)
This is my code for loading and 'linking':
package main
import (
"os"
"runtime"
"unsafe"
"cmd/objfile/goobj"
"strings"
"fmt"
"github.com/dearplain/goloader"
)
func main() {
symPtr := make(map[string]uintptr)
goloader.RegSymbol(symPtr)
f, _ := os.Open(os.Getenv("GOPATH") + "/src/github.com/dearplain/goloader/plugin/plugin.a")
reloc, err := goloader.ReadObjs(FindFilesAndPackages(f, "plugin"))
if err != nil {
fmt.Println(err)
}
module, err := goloader.Load(reloc, symPtr)
if err != nil {
fmt.Println(err)
}
runFuncPtr, ok := module.Syms["plugin.main"]
if !ok {
panic("no function with that name")
}
funcPtrContainer := (uintptr)(unsafe.Pointer(&runFuncPtr))
runFunc := *(*func())(unsafe.Pointer(&funcPtrContainer))
runFunc()
module.Unload()
}
var parsedImports = map[string]uintptr{}
func FindFilesAndPackages(file *os.File, packagePath string) (filePaths []string, packagePaths []string) {
g := os.Getenv("GOPATH") + "/pkg/windows_amd64/"
r := runtime.GOROOT() + "/pkg/windows_amd64/"
packagePaths = append(packagePaths, packagePath)
fmt.Println(file.Name())
filePaths = append(filePaths, file.Name())
obj, _ := goobj.Parse(file, packagePath)
for _, imp := range obj.Imports {
// Don't duplicate imported packages.
if _, ok := parsedImports[imp]; ok {
continue
}
var f *os.File
var err error
var p string
if strings.HasSuffix(imp, ".a") {
imp = strings.TrimRight(imp, ".a")
}
f, err = os.Open(g + imp + ".a")
p = g + imp + ".a"
if err != nil {
f, err = os.Open(r + imp + ".a")
p = r + imp + ".a"
}
if err != nil {
fmt.Println("unresolved import", r + imp, "Skipping...", err)
continue
}
packagePaths = append(packagePaths, imp)
filePaths = append(filePaths, p)
parsedImports[imp] = 0
fPaths, pPaths := FindFilesAndPackages(f, imp)
filePaths = append(filePaths, fPaths...)
packagePaths = append(packagePaths, pPaths...)
}
return filePaths, packagePaths
}
I placed my plugin in goloader/plugin.go
I now seem to get this:
panic: runtime error: index out of range
goroutine 1 [running]:
github.com/dearplain/goloader.Load(0xc042333880, 0xc0420837d0, 0x100, 0xc0422b1000, 0xef)
C:/Users/Sander/go/src/github.com/dearplain/goloader/dymcode.go:580 +0x33b7
main.main()
C:/Users/Sander/go/src/github.com/dearplain/goloader/cmd/main.go:24 +0x188
when attempting to Load.
Import path should like this:
github.com/vmihailenco/msgpack
An example:
./loader -o codes.a:github.com/vmihailenco/msgpack/codes -o \
msgpack.a:github.com/vmihailenco/msgpack -o mobjs.o -run main.main
It's not documented because I think there are still some problems.
I got something that works! Only the interfaces don't work yet in 1.10 like you said :)
Hi! Is there any progress on this? Will it work with 1.11 that was just released?
Thanks!
- with some dirty code, the interface method problem can be partially solved, but not fully, it makes me feel disappointed.
- I'm not test on 1.11, but it should works because the moduledata struct is not modified.