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

cgo: invalid reloc in gozk #1334

Closed
niemeyer opened this issue Dec 9, 2010 · 16 comments
Closed

cgo: invalid reloc in gozk #1334

niemeyer opened this issue Dec 9, 2010 · 16 comments

Comments

@niemeyer
Copy link
Contributor

niemeyer commented Dec 9, 2010

As posted to golang-dev:


Hey Russ,

> I pushed out the long-rumored new cgo.

Oh, exciting.

> Makefiles using Make.pkg to build cgo programs
> should need no changes.

To help test driving it, I've tried to recompile gozk[1] with the new
cgo on Ubuntu 10.10/amd64 since it has some reasonable testing, but it
doesn't look very happy.  The output is attached.

Is that a known issue?

[1] https://wiki.ubuntu.com/gozk

Attachments:

  1. err.txt (1724 bytes)
@rsc
Copy link
Contributor

rsc commented Dec 9, 2010

Comment 1:

One problem in the log (the nm errors) is a known problem
that keeps gotest from working on cgo packages.
http://golang.org/cl/3553041 should take care of that.
I'm not sure about the other errors.  It's possible that
the nm fix will fix them too.  Please try again after
the nm fix goes in.
(It should update this issue when I submit it.)

Labels changed: added cgo.

Owner changed to r...@golang.org.

Status changed to Accepted.

@niemeyer
Copy link
Contributor Author

Comment 2:

Noticed the patch went it (the issue didn't yet update for some reason).
You indeed got rid of those errors you mention, but there are still issues.
I'm attaching the new output.

Attachments:

  1. err2.txt (2644 bytes)

@rsc
Copy link
Contributor

rsc commented Dec 13, 2010

Comment 3:

Could you please upload the _test/gozk.a that is causing the problem?
Thanks.

@niemeyer
Copy link
Contributor Author

Comment 5:

Synced to tip, retried, and confirmed that the output is still the same as err2.txt.
Attaching _test/gozk.a.
Thanks for checking.

Attachments:

  1. gozk.a (414304 bytes)

@rsc
Copy link
Contributor

rsc commented Dec 16, 2010

Comment 6:

Please try CL 3710042 and see if it helps.

Status changed to WaitingForReply.

@niemeyer
Copy link
Contributor Author

Comment 7:

Synced to tip, applied the CL, and it's certainly looking better.  I'm now getting a
bunch of "not defined" errors, as per the attached output. Some data about the erroring
variables:
- In gozk.go they're used as e.g. C.ZOO_ASSOCIATING_STATE
- In zookeeper.h, they're defined as e.g. extern ZOOAPI const int ZOO_ASSOCIATING_STATE;
- In zookeeper.c, they're defined as e.g. const int ZOO_ASSOCIATING_STATE = 2;
Please let me know if I can help further.

Attachments:

  1. err3.txt (1396 bytes)

@rsc
Copy link
Contributor

rsc commented Dec 16, 2010

Comment 8:

Is zookeeper.c linked into your package or is it accessed via a shared library?
Does _cgo_import.c mention ZOO_ASSOCIATING_STATE ?

@niemeyer
Copy link
Contributor Author

Comment 9:

It's linked into the package as a shared library.  In the Makefile:
    CGO_LDFLAGS+=-lzookeeper_mt
_cgo_import.c does not mention ZOO_ASSOCIATING_STATE.
Attaching both the Makefile and _cgo_import.c.

Attachments:

  1. Makefile (150 bytes)
  2. _cgo_import.c (1485 bytes)

@rsc
Copy link
Contributor

rsc commented Dec 16, 2010

Comment 10:

Can reproduce this latest bug by changing stdio/file.go to say
package stdio
/*
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <resolv.h>
char* greeting = "hello, world";
*/
import "C"
import "unsafe"
type File C.FILE
var Stdout = (*File)(C.stdout)
var Stderr = (*File)(C.stderr)
var res = &C._res
The solution will be to make the generation of _cgo_main.c 
part of cgo instead of pushing it into the shell script where
it currently is.
For hello, something like
int main() { return 0; }
int crosscall2;
extern char __stderrp[];
void *mystderrp = __stderrp;
extern char _res[];
void *mystderrx = _res;
extern char greeting[];
void *mygreeting = greeting;
creates a working binary (refers to _res but not greeting,
which is internal).  
I am waiting for some other cgo changes to get reviewed
and submitted first but I think we're getting there.

@rsc
Copy link
Contributor

rsc commented Dec 16, 2010

Comment 11:

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Dec 17, 2010

Comment 12:

Please try CL 3746041.

@rsc
Copy link
Contributor

rsc commented Dec 17, 2010

Comment 13:

This issue was closed by revision 6c6d530.

Status changed to Fixed.

@niemeyer
Copy link
Contributor Author

Comment 14:

The build seems broken right now, due to this change:
[..pkg/runtime/cgo]% make
6g -o _go_.6 cgo.go 
6c -FVw iscgo.c
echo >_cgo_defun.c
gcc -m64 -g -fPIC -O2 -o _cgo_main.o -c  _cgo_main.c
gcc: _cgo_main.c: No such file or directory
gcc: no input files
make: *** [_cgo_main.o] Error 1

@niemeyer
Copy link
Contributor Author

Comment 15:

I've hacked together a _cgo_main.c to overcome the above issue, and all tests pass with
gozk:
gopack grc _test/gozk.a _gotest_.6  _cgo_defun.6 _cgo_import.6 gozk.cgo2.o _cgo_export.o
ZooKeeper test server directory: /tmp/gocheck-816681689/0
ZooKeeper test server port: 21812
OK: 34 passed
PASS
Thanks a lot for the awesome work on the new cgo Russ.

@rsc
Copy link
Contributor

rsc commented Jan 6, 2011

Comment 16:

Just want to confirm: gozk is working now, right?

@niemeyer
Copy link
Contributor Author

niemeyer commented Jan 6, 2011

Comment 17:

It is, all tests continue to pass. Thanks!

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants