Skip to content
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

Static linking on arm but dynamic on x86 #232

Closed
jhiemstrawisc opened this issue Apr 10, 2024 · 8 comments
Closed

Static linking on arm but dynamic on x86 #232

jhiemstrawisc opened this issue Apr 10, 2024 · 8 comments

Comments

@jhiemstrawisc
Copy link

jhiemstrawisc commented Apr 10, 2024

I noticed recently that compiling your libc example has different behavior on arm64 than it does on x86 -- on arm, it produces a static binary, but on x86 it's dynamically linked, even with CGO_ENABLED=0.

Is this intended? I initially observed similar behavior after using purego in another project, where my x86 go binaries broke because they switched from static to dynamic.

@TotallyGamerJet
Copy link
Collaborator

TotallyGamerJet commented Apr 10, 2024

Which OS, go version, purego version are you using?

Amd64, and arm64 should be dynamically linked. How are you determining they are static?

@TotallyGamerJet
Copy link
Collaborator

@jhiemstrawisc is this still an issue? If not, I'd like to close it.

@TotallyGamerJet
Copy link
Collaborator

Closing as there hasn't been a response and this doesn't appear to actually be an issue.

@TotallyGamerJet TotallyGamerJet closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
@zhangyongding
Copy link

I also noticed this issue. Using the ldd command, it can be seen that dynamic libraries are linked in amd64, while this situation does not exist in arm64

@TotallyGamerJet
Copy link
Collaborator

Can you provide a minimal reproducible code? Both architectures should be dynamically linked.

@zhangyongding
Copy link

zhangyongding commented Sep 13, 2024

I am cross compiling linux/arm64 on linux/amd64, do I don‘t know if it is related to this?

@zhangyongding
Copy link

main.go

package main

import (
	"github.com/ebitengine/purego"
)

func openLibrary(name string) (uintptr, error) {
	return purego.Dlopen(name, purego.RTLD_NOW|purego.RTLD_GLOBAL)
}

// CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o puts_amd64 main.go
// CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o puts_arm64 main.go
func main() {
	libc, err := openLibrary("libc.so.6")
	if err != nil {
		panic(err)
	}
	var puts func(string)
	purego.RegisterLibFunc(&puts, libc, "puts")
	puts("Calling C from Go without Cgo!")
}

go build

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o puts_amd64 main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o puts_arm64 main.go

result

puts_amd64:
        linux-vdso.so.1 (0x00007ffc642cd000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f629ad48000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f629a957000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f629a738000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f629af4c000)
puts_arm64:
        not a dynamic executable

@TotallyGamerJet
Copy link
Collaborator

I don't have an amd64 computer but on my arm64 linux it was amd64 that gave a not a dynamic executable. I think it's a limitation of the natively installed version of ldd that only supports whatever architecture the system is.

desktop:~/purego/examples/libc$ CGO_ENABLED=0 GOARCH=arm64 go build -o libc_arm64
desktop:~/purego/examples/libc$ CGO_ENABLED=0 GOARCH=amd64 go build -o libc_amd64
desktop:~/purego/examples/libc$ ldd libc_arm64
	linux-vdso.so.1 (0x0000ffffa0d00000)
	libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffffa0ca0000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffffa0af0000)
	libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffffa0ad0000)
	/lib/ld-linux-aarch64.so.1 (0x0000ffffa0cc7000)
desktop:~/purego/examples/libc$ ldd libc_amd64
	not a dynamic executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants