LD_PRELOAD yet again

157 views
Skip to first unread message

Peter JIN

unread,
Aug 23, 2024, 8:21:15 PMAug 23
to golang-nuts
Hi all,

A continuation of the gccgo and LD_PRELOAD discussion (search for it in golang-dev).

As mentioned before, I have a bunch of LD_PRELOAD libraries written in C, and due to the static linking issue in Go, it would be difficult to use the libraries with Go programs.

I have considered several different methods to allow this to work:

* compile it with gccgo (go version too old)
* modify syscall function (a bit too hacky, requires CPU architecture specific assembler)
* compile to Windows target and run resulting binary under Wine (also a bit too hacky)
* compile Go to Node.js WASM, load WASM module in Node.js, then inject LD_PRELOAD into Node.js (main concern is standard library availability)

Would say a typical server application work with the WASM approach (such as one that calls http.ListenAndServe())? Or is that not supported with WASM?

Peter

Peter JIN

unread,
Aug 24, 2024, 8:17:40 PMAug 24
to golang-nuts
Some promising ideas…

If we can get the seccomp filter installed and identify where the Go code is beforehand (may be possible by placing two objects before and after a c-archive such that symbol values are set to indicate the start and end of the archive), and route the system call to the libc function in the signal handler, then we can very well achieve LD_PRELOAD support at least for system calls.

The main package would have to be changed slightly:

func main() {

becomes

func main() {}
//go:export Main
func Main() {

and in the C program, install the signal handler and then call the Main function.

Though the signal handler should be installed according to the guidance in https://pkg.go.dev/os/signal.

Hopefully the Go runtime does not make any conflicting use of SIGSYS…

Posting this information in case anyone else might want to figure out how to use LD_PRELOAD with Go.


Peter

Sent from my iPhone

On Aug 23, 2024, at 8:21 PM, Peter JIN <pjin...@gmail.com> wrote:


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/nPemezHF57s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c14d68da-a36b-4b82-9a74-89ad52895e62n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages