-
Notifications
You must be signed in to change notification settings - Fork 70
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
purgo build fail at linux #189
Comments
Hey @Cyberhan123 👋 Can you also provide the output of go env (feel free to redact any value that you don't feel comfortable sharing)? |
In fact, there is in the log. |
DataDog/dd-trace-go#2504 (comment) @TotallyGamerJet Do you have any insights? |
I do not. Seems very strange since no changes to the dynamic linking have been made in quite a while |
@Cyberhan123 does it work if you set CGO_ENABLED=0? |
If I am not mistaken, if relocations happens during build process it means the library is being statically linked. Now the question is: why would anyone want to static link libdl? I believe this could be caused by another package somewhere in the dependency tree that added Adding |
Relocations happen for any symbol that is in a different object file. Even if that symbol is one that is dynamically linked it must be relocated to the GOT & POT at build time. However, I think you might be correct that there is something causing it to try and be statically linked which isn't possible with purego. Please do let me know what you find! |
I was able to confirm on Ubunutu arm64 that building with |
If it is pure go code, there is no problem,If cgo exists, the above error will be reported. |
I'm using |
My code below also causes this problem:
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
sd "github.com/seasonjs/stable-diffusion"
)
// #include <stdio.h>
// #include <stdlib.h>
//
// void __lsan_do_leak_check(void);
//
//#cgo CFLAGS: -fsanitize=address
//#cgo LDFLAGS: -fsanitize=address
import "C"
func MemoryLeakCheck() error {
diffusion, err := sd.NewCStableDiffusion("./deps/linux/lbsd-abi.so")
if err != nil {
return err
}
diffusion.SetLogCallBack(func(level sd.LogLevel, text string) {
fmt.Printf("%s", text)
})
ctx := diffusion.NewCtx("./models/miniSD.ckpt", "", "", "", false, false, true, 4, sd.F16, sd.CUDA_RNG, sd.DEFAULT)
defer diffusion.FreeCtx(ctx)
images := diffusion.PredictImage(ctx, "british short hair cat, high quality", "", 0, 7.0, 128, 128, sd.EULER_A, 10, 43, 1)
err = writeToFile(images[0].Data, int(images[0].Height), int(images[0].Width), "./assets/love_cat1.png")
if err != nil {
return err
}
C.__lsan_do_leak_check()
return nil
}
func writeToFile(byteData []byte, height int, width int, outputPath string) error {
img := image.NewRGBA(image.Rect(0, 0, width, height))
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
idx := (y*width + x) * 3
img.Set(x, y, color.RGBA{
R: byteData[idx],
G: byteData[idx+1],
B: byteData[idx+2],
A: 255,
})
}
}
file, err := os.Create(outputPath)
if err != nil {
return err
}
defer file.Close()
err = png.Encode(file, img)
if err != nil {
return err
}
return nil
}
func main() {
MemoryLeakCheck()
} |
There is definitely something going on with the connection between having package main
import (
_ "github.com/seasonjs/stable-diffusion"
)
import "C"
func main() {
} |
No cgo code is used in stable-diffusion |
The solution I am thinking of now is that if there is cgo, then my library needs to use cgo for compatibility, |
So I removed everything from stable-diffusion except |
Do you mean there are dependencies using cgo? |
No, I'm saying if a main.go imports "C" but also imports another package that imports purego then you get this error message. This is very strange. |
Forcing internal link mode with Cgo enabled works. |
@TotallyGamerJet When I try to build using the command you suggested on Linux, I get an error:
|
Right now my leading theory is that the external linker cannot handle the linker directives generated by Since it seems that we kinda have different errors than you. @Cyberhan123 Would you mind cloning my repo on my branch and connecting it with a |
@eliottness Thank you, I still have some questions to ask, which is the problem of struct transfer. When cgo is enabled, the memory of the struct cannot be aligned.
|
I think Elliottness is right about the cause. I just find it strange that reproducing only happens when another package imports a package with purego in it. Otherwise it does work. But if your fix solves this then that's great! |
Thank God, this fix seems to also fix the struct alignment issue? ? ? I'm really confused about the underlying logic. It would be great if someone from Golang official could explain it. |
Let me make a small attempt: @rsc |
It likely has to do with the fact that |
Use the standard Cgo import mechanism when CGO_ENABLED=1. This fixes an issue where sometimes the external linker would fail to add the dlfcn symbols causing a linker error. Closes #189
I'll tag v0.5.2 and v0.6.0-alpha.4 a few days later, if we don't find any other issues. |
Use the standard Cgo import mechanism when CGO_ENABLED=1. This fixes an issue where sometimes the external linker would fail to add the dlfcn symbols causing a linker error. Closes #189
Let me reopen this. We are not able to cherry-pick this to 0.5 yet. |
Use the standard Cgo import mechanism when CGO_ENABLED=1. This fixes an issue where sometimes the external linker would fail to add the dlfcn symbols causing a linker error. Closes #189
Use the standard Cgo import mechanism when CGO_ENABLED=1. This fixes an issue where sometimes the external linker would fail to add the dlfcn symbols causing a linker error. Closes #189
Done |
Upgrade to get fix ebitengine/purego#189 from upstream Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
I try to build an app using purego on ubuntu but it fails on linux
The following is the complete github action log:
App, linuxamd64, ubuntu-latest.txt
The text was updated successfully, but these errors were encountered: