-
Notifications
You must be signed in to change notification settings - Fork 4
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
CGo panic: linker failed to read symbols from dependency object files #21
Comments
The issue you're seeing is due to a type of CGo (native) ELF relocation which I haven't added support for yet. I could potentially add support for it, but unfortunately that SQLite package is a massive CGo user and links against libsqlite3 (a C library). Go normally uses the external system linker (gcc/ld) to resolve and load C libraries when building binaries which use CGo. I haven't yet added support for loading C library symbols from C archives or .so files in the same way that the native system linker does - my CGo support so far only includes C files compiled directly next to the Go files. I did have an idea a while ago about parsing the LDFLAGS and using libdl to dynamically load C library symbols to link against when loading a CGo package, but again I haven't implemented it yet, and have no idea if it will work, and whether dlclosing on unload would be safe. For now, unfortunately I'd say attempting to JIT load CGo packages which use external C libraries (via LDFLAGS) won't work, but I'd keep this issue open as a nudge for me to implement the 2 things I suggested above if I get a chance. Sorry I couldn't be of more help |
Ah that makes sense, thanks for explaining it. Unfortunate limitation but I'll figure something out. Thanks again, it is a great project. |
So I think I was a bit hasty in my conclusions in my last message. After a more detailed look at the Once I added in support for the missing relocation type, it loaded, but to my surprise I found that
To fix this, I'll probably need to change how native symbols are loaded so they're guaranteed to be contiguous per-translation unit, with any epilogues added to the end of each translation unit instead of the end of each function. The slightly more surprising thing is that I think this prevents unreachable symbols emitted between a hardcoded jump and its target being link-time eliminated - I'd be curious to see what gcc does in these cases |
I have similar error when trying to use go-etherum: The code that I am trying to make it work: package main
import (
"fmt"
"github.com/eh-steve/goloader/jit"
"math/big"
)
func main() {
conf := jit.BuildConfig{
KeepTempFiles: false, // Files are copied/written to a temp dir to ensure it is writable. This retains the temporary copies
ExtraBuildFlags: []string{"-x"}, // Flags passed to go build command
BuildEnv: nil, // Env vars to set for go build toolchain
TmpDir: "", // To control where temporary files are copied
DebugLog: true, //
}
loadable, err := jit.BuildGoPackageRemote(conf, "github.com/DanijelRadakovic/ethereum-plugin", "9eef6ae")
if err != nil {
panic(err)
}
module, err := loadable.Load()
if err != nil {
panic(err)
}
// module.SymbolsByPkg is a map[string]map[string]interface{} of all packages and their exported functions and global vars
symbols := module.SymbolsByPkg[loadable.ImportPath]
if err != nil {
panic(err)
}
defer func() {
err = module.Unload()
if err != nil {
panic(err)
}
}()
switch f := symbols["FetchData"].(type) {
case func() (*big.Int, error):
//result, errCall := f([]byte(`{"k":"v"}`))
result, errCall := f()
if errCall != nil {
panic(errCall)
}
fmt.Println(result)
default:
panic("Function signature was not what was expected")
}
} |
Would you mind trying against the branch eh-steve/issue-87? I've added a fallthrough for this case Line 335 in b041c77
Edit: Once you do that, I think it's a similar situation to the issue I described above, where gcc emits a hardcoded JMP to/from a Once I get around to implementing the fix I described above (load native CGo symbols contiguously),🤞🏻 it should fix both problems. |
I've done the following: go get github.com/eh-steve/goloader@issue-87 But now I am getting the following error:
|
Yeah that's what I'm saying is due to the non-PIC code emitted by gcc, and I hope to fix this by forcing native symbols to be laid out in full segments exactly as emitted by the compiler instead of what I currently do which is slice up each segment into different symbols and add them all separately (which breaks any hardcoded non-PIC JMP or CALL instructions). |
Getting this error after using the mattn/go-sqlite3 library
Works fine not in goloader so I'm thinking it must be an issue here, could you explain the reason? I tried researching the error but didn't come up with too much, is this library just incompatible?
Heres the full dump,
panic: linker failed to read symbols from dependency object files ([vendor/golang.org/x/net/dns/dnsmessage text/tabwriter sync runtime/internal/atomic runtime reflect os net/netip math/rand log io internal/singleflight internal/poll image golang.org/x/text/language github.com/yuin/gopher-lua github.com/sirupsen/logrus github.com/sandertv/gophertunnel/minecraft/protocol/packet github.com/sandertv/gophertunnel/minecraft/protocol/login github.com/sandertv/gophertunnel/minecraft/protocol github.com/sandertv/gophertunnel/minecraft github.com/mattn/go-sqlite3 github.com/google/uuid github.com/df-mc/dragonfly/server/world/sound github.com/df-mc/dragonfly/server/world/particle github.com/df-mc/dragonfly/server/world/mcdb github.com/df-mc/dragonfly/server/world/chunk github.com/df-mc/dragonfly/server/player/title github.com/df-mc/dragonfly/server/player/scoreboard github.com/df-mc/dragonfly/server/player/form github.com/df-mc/dragonfly/server/player/bossbar github.com/df-mc/dragonfly/server/item/recipe github.com/df-mc/dragonfly/server/item/potion github.com/df-mc/dragonfly/server/item/category github.com/df-mc/dragonfly/server/entity/effect github.com/df-mc/dragonfly/server/entity github.com/df-mc/dragonfly/server/block github.com/df-mc/dragonfly/server github.com/brentp/intintmap database/sql time sync/atomic net github.com/nnnnt21/drag/server github.com/nnnnt21/drag/resources/plugins/ranks github.com/go-gl/mathgl/mgl64 github.com/df-mc/dragonfly/server/world github.com/df-mc/dragonfly/server/session github.com/df-mc/dragonfly/server/player/skin github.com/df-mc/dragonfly/server/player github.com/df-mc/dragonfly/server/item/inventory github.com/df-mc/dragonfly/server/item github.com/df-mc/dragonfly/server/event github.com/df-mc/dragonfly/server/cmd github.com/df-mc/dragonfly/server/block/cube github.com/df-mc/atomic command-line-arguments]): read error: only a limited subset of elf relocations currently supported, got elf.R_X86_64_GOTPCREL for symbol sqlite3_overload_function reloc to sqlite3_free
The text was updated successfully, but these errors were encountered: