bitcoinfuzz icon indicating copy to clipboard operation
bitcoinfuzz copied to clipboard

Multiple Definition Errors When Linking Both btcd and lnd Static Libraries

Open erickcestari opened this issue 9 months ago • 3 comments

When attempting to link both btcd and lnd modules (built as static libraries) into the same executable, the following linking errors occur:

/usr/bin/ld: modules/lnd/module.a(go.o): in function `_cgo_topofstack':
(.text+0x75ee0): multiple definition of `_cgo_topofstack'; modules/btcd/module.a(go.o):(.text+0x72160): first defined here
/usr/bin/ld: modules/lnd/module.a(go.o): in function `_cgo_panic':
/usr/lib/go/src/runtime/cgo/callbacks.go:46: multiple definition of `_cgo_panic'; modules/btcd/module.a(go.o):/usr/lib/go/src/runtime/cgo/callbacks.go:46: first defined here
/usr/bin/ld: modules/lnd/module.a(go.o): in function `crosscall2':
/usr/lib/go/src/runtime/cgo/asm_amd64.s:26: multiple definition of `crosscall2'; modules/btcd/module.a(go.o):/usr/lib/go/src/runtime/cgo/asm_amd64.s:26: first defined here

Similar to #90

erickcestari avatar Mar 12 '25 17:03 erickcestari

It seems that when building multiple modules we start to have a problem of shared dependencies between them. For instance the rustbitcoin and rustminiscript had a name conflict on rustsecp256k1. Now we got a problem with go modules. Maybe a solution would be to create shared objects of the common dependencies? Them adjust that in the linking stage?

luisfg30 avatar Mar 13 '25 00:03 luisfg30

I think in general you might have to look at what cargo does -- building every single dependency separately as a rlib (or something) and then linking them all at once.z

apoelstra avatar Mar 13 '25 03:03 apoelstra

We could consider accepting multiple definitions in the bitcoinfuzz Makefile. However, I'm uncertain about the potential consequences of implementing this approach.

ifeq ($(UNAME_S), Darwin)
    LDFLAGS = -framework CoreFoundation -Wl,-ld_classic -Wl,-allow_multiple_definition
else
    LDFLAGS = -Wl,-z,muldefs
endif

erickcestari avatar Mar 13 '25 15:03 erickcestari