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

Simple go program from the upstream repository fails to compile #25599

Closed
javgh opened this issue May 7, 2017 · 3 comments
Closed

Simple go program from the upstream repository fails to compile #25599

javgh opened this issue May 7, 2017 · 3 comments

Comments

@javgh
Copy link

javgh commented May 7, 2017

Issue description

A year ago an issue was filed for the Go compiler ( golang/go#14669 ) that showed that passing optimization flags to cgo would break it. This bug was fixed upstream and a test case has been added.

That same testcase does not seem to compile under NixOS however. I'm new to both NixOS and go, so I'm not quite sure what's going on.

Steps to reproduce

Test case from upstream:

wget https://raw.githubusercontent.com/golang/go/master/misc/cgo/errors/issue14669.go
cat issue14669.go
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Issue 14669: test that fails when build with CGO_CFLAGS selecting
// optimization.

package p

/*
const int E = 1;

typedef struct s {
	int       c;
} s;
*/
import "C"

func F() {
	_ = C.s{
		c: C.E,
	}
}

Attempt to build it:

nix-shell -p go gcc
go build -x issue14669.go 
warning: GOPATH set to GOROOT (/nix/store/k114bnw0gzag4b07492dgxi2gs858xrl-go-1.8/share/go) has no effect
WORK=/run/user/1000/go-build864270593
mkdir -p $WORK/command-line-arguments/_obj/
mkdir -p $WORK/
cd /tmp/g
CGO_LDFLAGS="-g" "-O2" /nix/store/k114bnw0gzag4b07492dgxi2gs858xrl-go-1.8/share/go/pkg/tool/linux_amd64/cgo -objdir $WORK/command-line-arguments/_obj/ -importpath command-line-arguments -- -I $WORK/command-line-arguments/_obj/ -g -O2 issue14669.go
# command-line-arguments
cgo-dwarf-inference:2:8: error: enumerator value for '__cgo_enum__0' is not an integer constant
cgo-dwarf-inference:5:8: error: enumerator value for '__cgo_enum__2' is not an integer constant
cgo-dwarf-inference:8:2: error: initializer element is not constant
cgo-dwarf-inference:8:2: note: (near initialization for '__cgodebug_data[0]')
cgo-dwarf-inference:10:2: error: initializer element is not constant
cgo-dwarf-inference:10:2: note: (near initialization for '__cgodebug_data[2]')

Technical details

  • System: 17.09pre106916.c5badb123a (Hummingbird)
  • Nix version: nix-env (Nix) 1.11.9
  • Nixpkgs version: 17.09pre106916.c5badb123a
  • Sandboxing enabled: false
@javgh
Copy link
Author

javgh commented May 8, 2017

Sorry, the referenced issue ( golang/go#14669 ) is a red herring. I now realized that it's not related at all.

The real problem is a mismatch between C compilers. The NixOS go package is built using clang, but I tried to use gcc while attempting to compile the small Go program. The problem goes away if I instead use clang.

It seems that the helper buildGoPackage also uses gcc by default, which then runs into the same problem for certain Go programs. I'll look into that some more and might then open a separate issue for it.

@javgh javgh closed this as completed May 8, 2017
@sergei-mironov
Copy link
Contributor

Wow, thank you! With this knowledge I was able to build the newest go-etherium using older expression. I didn't run any tests yet, but still its a ./result :) Below is the full 1.6.1 expression, for reference:

{ stdenv, fetchFromGitHub, go, gmp, leveldb, clang }:

stdenv.mkDerivation rec {
name = "geth-${version}";
version = "1.6.1";
buildInputs = [go gmp clang];

src = fetchFromGitHub {
owner = "ethereum";
repo = "go-ethereum";
rev = "021c3c281629baf2eae967dc2f0a7532ddfdc1fb";
sha256 = "02w5zjs40iznnph6c0kp34c84nrx3dkdarcpdyawkjpwjvxkw05g";
};

preBuild=''
export CC=clang
'';

installPhase = ''
mkdir -p "$out"
cp -r build/bin "$out/bin"
'';

meta = with stdenv.lib; {
description = "Ethereum blockchain client";
homepage = "https://ethereum.org/";
maintainers = with maintainers; [ dvc ];
license = licenses.gpl3;
};
}

@javgh
Copy link
Author

javgh commented May 8, 2017

Follow up issue regarding buildGoPackage: #25626

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

2 participants