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

cmd/go: using -gccgo fails if .c file has same name as directory #8828

Closed
gopherbot opened this issue Sep 28, 2014 · 9 comments
Closed

cmd/go: using -gccgo fails if .c file has same name as directory #8828

gopherbot opened this issue Sep 28, 2014 · 9 comments
Milestone

Comments

@gopherbot
Copy link

by Snyh1010:

1. What is a short input program that triggers the error?

all the packages can compiled successfully, but they can't be used with an very trivial
code, like

package main
import _ "./failed1"
func main() {
} 

Use relative path package import for testing convenience, I have tested it under full
name import.
There has some summary comments in 1.go, 2.go and 3.go, respectively three different
error message.

2. What is the full compiler output?
/usr/bin/go build -compiler=gccgo 1.go
# command-line-arguments
./1.go:3:8: error: $WORK/gccgo/libfailed1.a exists but does not contain any Go export
data
 import _ "gccgo/failed1"
        ^
./1.go:3:8: error: import file ‘gccgo/failed1’ not found

--------------------------------------------------------------------------------
/usr/bin/go build -compiler=gccgo 2.go
# command-line-arguments
./2.go:3:17: error: redefinition of ‘failed2’
 import "./failed2"
                 ^
./2.go:3:17: note: previous definition of ‘failed2’ was here
make: *** [2] Error 2
------------------------------------------------------------------------------
/usr/bin/go build -compiler=gccgo 3.go
# command-line-arguments
/tmp/go-build220177682/_/run/shm/gccgo/failed-3.0/_obj/_cgo_export.c:6: error: undefined
reference to '__run_shm_gccgo_failed_3_0.Cgoexp_bar'
collect2: error: ld returned 1 exit status
make: *** [3] Error 2


3. What version of the compiler are you using?  (Run it with the -V flag.)
test with 
go version go1.3.1 linux/amd64 
and
go version devel +a622a4ff09da Fri Jul 18 13:05:21 2014 +0400 linux/amd64


--------------------------------------------------------------------------
all this code can compiled with go build (in attachment, make gc can verify it), but all
failed with go build -compiler=gccgo (in attachment, make 1; make 2 make 3 to test it)

Attachments:

  1. gccgo_failed.tar.gz (1243 bytes)
@gopherbot
Copy link
Author

Comment 1 by Snyh1010:

"2.go" will be compiled successfully if change the name of failed2/failed2.c to anything
other than the package name.
"3.go" will be compiled successfully in many way, include 
   * change the package name, remove the part of "3.0" or
   * remove any line in the failed-3.0/a.c or failed-3.0/a.go

@ianlancetaylor
Copy link
Contributor

Comment 2:

The problem is that failed1/empty.go is compiled to failed1.o, and failed1/failed1.c is
also compiled to failed1.o, and so one of them is lost.  This doesn't happen with gc
because failed1/empty.go is compiled to failed1.6, not failed1.o.
The work around for now is to not use the same name for the directory and the file.

Labels changed: added repo-main, release-go1.4maybe.

Status changed to Accepted.

@gopherbot
Copy link
Author

Comment 3 by Snyh1010:

Thanks for your explanation.
I can't describe it exactly.
But the "1.go" and "3.go" has the different error message, they both hasn't the same
source file as package name.
So the issues's title is not good
The trivial "1.go" was write only for test willfully, We can ignore it at this time.
The "3.go" is the problem I have encountered  and I can't find a work around now.

@ianlancetaylor
Copy link
Contributor

Comment 4:

You're right, the problem with 3.go is a different, unrelated, problem, and is
http://gcc.gnu.org/PR61880; there is a link to a possible patch there.

@rsc
Copy link
Contributor

rsc commented Sep 30, 2014

Comment 5:

Re #2, failed1/empty.go compiles to _go_.6, not failed1.6. I did this exactly to avoid
this kind of collision with C or assembly objects. It should be easy for the go command
to add a -o to the gccgo command line to write to _go_.o.

@gopherbot
Copy link
Author

Comment 6 by Snyh1010:

Re #4
 
I haven't test this patch yet,  but "failed3" has been solved in "gccgo (Ubuntu
4.9.1-15ubuntu1) 4.9.1"

@rsc
Copy link
Contributor

rsc commented Oct 15, 2014

Comment 7:

Chris, can you look at this? I think the fix could be as simple as modifying the first
line of gccgoToolchain.gc to read
    out := "_go_.o"
Can you check? If so, can we get this in? Thanks.

@gopherbot
Copy link
Author

Comment 8:

CL https://golang.org/cl/154410043 mentions this issue.

@paranoiacblack
Copy link
Contributor

Comment 9:

This issue was closed by revision 343d113.

Status changed to Fixed.

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
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

4 participants