From cfba0b9c19cc7e384697789be22b3fa141c09468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 15 Apr 2024 18:36:20 +0300 Subject: [PATCH] attempt to fix dynamic library build error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` /nix/store/mzrw2zphz9xx9s3qq8x5zpf18isp0jga-go-1.20.3/share/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /nix/store/ybw485608d7f1yv1v071j2052q64mvla-binutils-2.40/bin/ld: /build/go-link-2631521468/go.o: relocation R_X86_64_TPOFF32 against `runtime.tlsg' can not be used when making a shared object; recompile with -fPIC /nix/store/ybw485608d7f1yv1v071j2052q64mvla-binutils-2.40/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status ``` Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 2 +- default.nix | 3 +++ flake.nix | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 554461bd5..2e67cab95 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,7 @@ endif dynamic-library: @echo "Building shared library..." rm -f ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT)* - $(GOBIN_SHARED_LIB_CFLAGS) $(GOBIN_SHARED_LIB_CGO_LDFLAGS) ${GOBIN} build \ + ${GOBIN} $(GOBIN_SHARED_LIB_CGO_LDFLAGS) build \ -buildmode=c-shared \ -tags="${BUILD_TAGS} gowaku_no_rln" \ -o ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT) \ diff --git a/default.nix b/default.nix index 00a01af8c..978c5da05 100644 --- a/default.nix +++ b/default.nix @@ -3,6 +3,7 @@ self ? ./., subPkgs ? "cmd/waku", ldflags ? [], + cgoLdflags ? "", output ? null, commit ? builtins.substring 0 7 (self.rev or "dirty"), version ? builtins.readFile ./VERSION, @@ -18,6 +19,8 @@ pkgs.buildGo120Module { "-X github.com/waku-org/go-waku/waku/v2/node.GitCommit=${commit}" "-X github.com/waku-org/go-waku/waku/v2/node.Version=${version}" ] ++ ldflags; + CGO_LDFLAGS = cgoLdflags; + GOGCCFLAGS = "-fPIC"; doCheck = false; # Otherwise library would be just called bin/c. diff --git a/flake.nix b/flake.nix index e4cd6b46f..f7ba701ec 100644 --- a/flake.nix +++ b/flake.nix @@ -34,7 +34,8 @@ inherit self; subPkgs = ["library/c"]; ldflags = ["-buildmode=c-shared"]; - output = "libgowaku.a"; + cgoLdflags = "-Wl,-Bsymbolic,-soname,libgowaku.so.0"; + output = "libgowaku.so"; }; }); @@ -47,7 +48,9 @@ inputsFrom = [ packages.${system}.node ]; buildInputs = with pkgs; [ golangci-lint ]; nativeBuildInputs = lib.optional stdenv.isDarwin [ - (pkgs.xcodeenv.composeXcodeWrapper { version = "14.2"; allowHigher = true; }) + (pkgs.xcodeenv.composeXcodeWrapper { + version = "14.2"; allowHigher = true; + }) ]; };