GoDynamic can load and run Golang dynamic library compiled by -buildmode=shared -linkshared

Related tags

Utilities godynamic
Overview

GoDynamic

Build Status

GoDynamic can load and run Golang dynamic library compiled by -buildmode=shared -linkshared

How does it work?

GoDynamic works like a dynamic linker: use dl loads an .so libraray and lookup symbol, can unload.

Please note that GoDynamic is not a scripting engine. All features of Go are supported, and run just as fast and lightweight as native Go code.

Comparison with plugin

GoDynamic reuses runtime by libstd.so, which makes it much smaller. And code loaded by GoDynamic is unloadable.

Build

Make sure you're using go >= 1.10.

Examples

export GO111MODULE=auto
go install -buildmode=shared std
go build -linkshared -v github.com/pkujhd/godynamic/examples/loader

go install -v -buildmode=shared -linkshared github.com/pkujhd/godynamic/examples/ubase
./loader -l $GOPATH/pkg/linux_`go env GOARCH`_dynlink/libgithub.com-pkujhd-godynamic-examples-ubase.so -p github.com/pkujhd/godynamic/examples/ubase.so -r github.com/pkujhd/godynamic/examples/ubase.Enter -times 10

go install -v -buildmode=shared -linkshared github.com/pkujhd/godynamic/examples/uschedule
./loader -l $GOPATH/pkg/linux_`go env GOARCH`_dynlink/libgithub.com-pkujhd-godynamic-examples-uschedule.so -p github.com/pkujhd/godynamic/examples/uschedule.so -r github.com/pkujhd/godynamic/examples/uschedule.Enter -times 10

go install -v -buildmode=shared -linkshared github.com/pkujhd/godynamic/examples/uhttp
./loader -l $GOPATH/pkg/linux_`go env GOARCH`_dynlink/libgithub.com-pkujhd-godynamic-examples-uhttp.so -p github.com/pkujhd/godynamic/examples/uhttp.so -r github.com/pkujhd/godynamic/examples/uhttp.Enter

Warning

golang buildmode(-buildmode=shared) will be not support after golang 1.18

This has currently only been tested and developed on: Golang 1.10-1.16 (x64/x86, linux)

Issues
  • Problems compiling example

    Problems compiling example

    Hello,

    I am running on Ubuntu 20.04 (64-bit) and have just tried to compile up your examples using both Go v1.16 and v1.17 but get the same errors:

    I get through these with no problems:

    export GO111MODULE=auto
    go install -buildmode=shared std
    go build -linkshared -v github.com/pkujhd/godynamic/examples/loader
    
    

    But then on the next step:

    go install -v -buildmode=shared -linkshared github.com/pkujhd/godynamic/examples/ubase
    

    Output:

    /test$ go install -v -buildmode=shared -linkshared github.com/pkujhd/godynamic/examples/ubase
    # /tmp/go-build180572587/b038/libgithub.com-pkujhd-godynamic-examples-ubase.so
    panic: runtime error: makeslice: cap out of range
    
    goroutine 1 [running]:
    cmd/link/internal/loader.(*Loader).LoadSyms(0xc00058c000, 0x66f793)
            /home/lonnie/.gvm/gos/go1.17/src/cmd/link/internal/loader/loader.go:2210 +0x9f
    cmd/link/internal/ld.(*Link).loadlib(0xc000140000)
            /home/lonnie/.gvm/gos/go1.17/src/cmd/link/internal/ld/lib.go:577 +0x46e
    cmd/link/internal/ld.Main(_, {0x20, 0x20, 0x1, 0x7, 0x10, 0x0, {0x0, 0x0}, {0x678977, ...}, ...})
            /home/lonnie/.gvm/gos/go1.17/src/cmd/link/internal/ld/main.go:249 +0xd8b
    main.main()
            /home/lonnie/.gvm/gos/go1.17/src/cmd/link/main.go:69 +0x1005
    

    Not really sure what is happening here.

    Can you please help?

    opened by lonnietc 3
  • golang1.17.2

    golang1.17.2 "fatal error: unreachable method called. linker bug?"

    [[email protected] plugin]$ ./loader -l /home/jhd/go/pkg/linux_amd64_dynlink/libgithub.com-pkujhd-godynamic-examples-ubase.so -p github.com/pkujhd/godynamic/examples/ubase.so -r github.com/pkujhd/godynamic/examples/ubase.Enter 
    fatal error: unreachable method called. linker bug?
    
    goroutine 1 [running]:
    runtime.throw({0x7fb946feb715, 0xc000012b30})
            /home/jhd/programs/go/src/runtime/panic.go:1198 +0x71 fp=0xc000373ab0 sp=0xc000373a80 pc=0x7fb9468bd671
    runtime.unreachableMethod()
            /home/jhd/programs/go/src/runtime/iface.go:561 +0x25 fp=0xc000373ad0 sp=0xc000373ab0 pc=0x7fb9468882c5
    fmt.(*pp).handleMethods(0xc0003a20d0, 0x0)
            /home/jhd/programs/go/src/fmt/print.go:620 +0x24c fp=0xc000373d80 sp=0xc000373ad0 pc=0x7fb9469d3c2c
    fmt.(*pp).printArg(0xc0003a20d0, {0x7fb9475bed40, 0xc000012b30}, 0x76)
            /home/jhd/programs/go/src/fmt/print.go:709 +0x6b3 fp=0xc000373e20 sp=0xc000373d80 pc=0x7fb9469d4953
    fmt.(*pp).doPrintln(0xc0003a20d0, {0xc000373f50, 0x1, 0x406b65})
            /home/jhd/programs/go/src/fmt/print.go:1169 +0x14f fp=0xc000373e90 sp=0xc000373e20 pc=0x7fb9469d83ef
    fmt.Fprintln({0x60d7a0, 0xc000010200}, {0xc000373f50, 0x1, 0x1})
            /home/jhd/programs/go/src/fmt/print.go:264 +0x4f fp=0xc000373ee0 sp=0xc000373e90 pc=0x7fb9469d164f
    fmt.Println(...)
            /home/jhd/programs/go/src/fmt/print.go:274
    main.main()
            /home/jhd/go/src/github.com/pkujhd/godynamic/examples/loader/loader.go:25 +0x248 fp=0xc000373f80 sp=0xc000373ee0 pc=0x409808
    runtime.main()
            /home/jhd/programs/go/src/runtime/proc.go:255 +0x282 fp=0xc000373fe0 sp=0xc000373f80 pc=0x7fb9468c0d22
    runtime.goexit()
            /home/jhd/programs/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000373fe8 sp=0xc000373fe0 pc=0x7fb9468f9801
    
    bug 
    opened by pkujhd 3
Owner
pkujhd
pkujhd
Little helper to create tar balls of an executable together with its ELF shared library dependencies.

Little helper to create tar balls of an executable together with its ELF shared library dependencies. This is useful for prototyping with gokrazy: htt

null 8 Jun 13, 2022
⚙️ Concept of Golang HTML render engine with frontend components and dynamic behavior

SSC Engine An HTML render engine concept that brings frontend-like components experience to the server side with native html/template on steroids. Sup

Yurii Zinets 535 Aug 6, 2022
Dynamic limit golang

uses channel and a timer goroutine to set a dynamic limit for a process (using timeout rather than hard limit)

Randy Anggadinata 0 Jan 30, 2022
Govalid is a data validation library that can validate most data types supported by golang

Govalid is a data validation library that can validate most data types supported by golang. Custom validators can be used where the supplied ones are not enough.

null 61 Apr 22, 2022
EGo lets you build, debug und run Go apps on Intel SGX - as simple as conventional Go programming!

EGo lets you build, debug und run Go apps on Intel SGX - as simple as conventional Go programming!

Edgeless Systems GmbH 322 Aug 1, 2022
To run a .go file use below syntax

To run a .go file use below syntax

PRADEEP KUMAR D 0 Nov 2, 2021
This Go package allows you to set handler functions that run when named events occur

This Go package allows you to set handler functions that run when named events occur

James 1 Feb 10, 2022
Clean-Swift source and test code auto-generator. It can save you time typing 500-600 lines of code.

Clean-Swift source & test code auto generator Overview Run Output Basic Usage make config.yaml target_project_name: Miro // target project name copyri

David Ha 20 Apr 13, 2022
With Pasteback you can store common terms and paste them back to clipboard

Pasteback With Pasteback you can store common terms and paste them back to clipboard when needed. There is one central spot to put every string into y

null 0 Nov 22, 2021
Otx - otx tool can scrap to find sensitive information and vulnerable endpoint urls.

otx Description This tool is base on AlienVault Open Threat Exchange (OTX)? and this tool can help you to extract all the urls endpoints which can be

ShaneKhant 4 Feb 9, 2022
libraries for various programming languages that make it easy to generate per-process trace files that can be loaded into chrome://tracing

chrometracing: chrome://tracing trace_event files The chrometracing directory contains libraries for various programming languages that make it easy t

Google 22 Jul 8, 2022
流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

netflix-verify 流媒体NetFlix解锁检测脚本,使用Go语言编写 在VPS网络正常的情况下,哪怕是双栈网络也可在几秒内快速完成IPv4/IPv6的解锁判断 鸣谢 感谢 @CoiaPrant 指出对于地域检测更简便的方法 感谢 @XmJwit 解决了IPV6 Only VPS无法下载脚

null 1.7k Aug 8, 2022
LogAnalyzer - Analyze logs with custom regex patterns.Can search for particular patterns on multiple files in a directory.

LogAnalyzer Analyze logs with custom regex patterns.Can search for particular patterns on multiple files in a directory

Johnson Simon 6 May 31, 2022
A fully Go userland with Linux bootloaders! u-root can create a one-binary root file system (initramfs) containing a busybox-like set of tools written in Go.

u-root Description u-root embodies four different projects. Go versions of many standard Linux tools, such as ls, cp, or shutdown. See cmds/core for m

null 2k Aug 11, 2022
This utility can be used for converting BSE Mutual fund scheme

go-mf-scheme-master-generator This utility can be used for converting BSE Mutual

null 0 Jan 21, 2022
JIN the coolest fighting game ever made that uses the M.U.G.E.N engine so heres how you can build it

JIN the coolest fighting game ever made that uses the M.U.G.E.N engine so heres how you can build it

Elijah Davis 1 Jan 24, 2022
Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package.

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with a minimal footprint, structures and []byte support.

Spiral Scout 1.1k Aug 5, 2022
A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

HashiCorp 1.2k Aug 8, 2022
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Montana Flynn 2.5k Aug 8, 2022