edisonwsk / golang-on-cygwin

Automatically exported from code.google.com/p/golang-on-cygwin
BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

underscoring causes link error on libcgo #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. From $GOROOT, "cd src/libcgo"
2. "make"

What is the expected output? What do you see instead?
Should compile, but it gets link error since it cannot find the symbol 
"_crosscall_386". The method "crosscall_386" is defined in 
"src/libcgo/386.S".

What version of the product are you using? On what operating system?
cygwin 1.7.1-1
gcc version 4.3.4 20090804 (release) 1 (GCC) i686-pc-cygwin

Please provide any additional information below.
1. cygwin's gcc WILL add an underscore before the link symbol (as if there 
is a "-fleading-underscore" flag set).

2. There's a bug in cygwin's gcc that ignores "-fno-leading-underscore". 
This bug seems not likely to be fixed before gcc 4.5.0. Refer to 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41692

Original issue reported on code.google.com by jeru.sh...@gmail.com on 28 Jan 2010 at 1:41

GoogleCodeExporter commented 9 years ago
3. even with gcc 4.5.0 it still occurs

a way to "get through" this fase is to change the name of the func in 386.S, 
adding a underscore to crosscall_386:

.globl EXT(_crosscall_386)
EXT(_crosscall_386):

instead of

.globl EXT(crosscall_386)
EXT(crosscall_386):

that way, when linking, gcc will find the symbol _crosscall_386
(the problem seems to be gcc is adding the leading underscore to the symbol 
table in linux_386.c where crosscall_386 is called. watch:

$ nm linux_386.o
00000000 b .bss
00000000 d .data
00000000 t .text
         U _crosscall_386
         U _free
00000060 T _initcgo
00000070 T _libcgo_sys_thread_start
         U _pthread_attr_getstacksize
         U _pthread_attr_init
         U _pthread_create
00000000 t _threadentry

(maybe it's supposed to do it)
and not doing the same to the func definition in 386.S (could it be the awkward 
definition using, it seems, machine instructions?)

#define EXT(s) s

.globl EXT(_crosscall_386)
EXT(_crosscall_386):
        pushl %ebp
        movl %esp, %ebp

anyway, changing there works.

Original comment by luis.agu...@gmail.com on 26 Dec 2010 at 9:59