Thanks that was a valuable information. It might be the debugging flag that 
caused the issue. I debugged the cgo file and found that in char* mached 
with dwarf.UcharType instead of dwarf.chatType

On Monday, July 20, 2020 at 3:45:00 PM UTC-4, Ian Lance Taylor wrote:
>
> On Mon, Jul 20, 2020 at 12:28 PM Mahdi Hosseini <m.ho...@gmail.com 
> <javascript:>> wrote: 
> > 
> > Hi, 
> > I try to recompile Go for a new platform which is a s390x platform using 
> Clang instead of GCC. I can not work for C string in CGO. Apparently char 
> in unsigned by default on my platform and building even the simple CGO 
> program always fails with this error: 
> > 
> > /home/user/tmp/go-build468743286/b001/_cgo_gotypes.go:175:25: undefined: 
> _Ctype_char 
> > 
> > the code is: 
> > 
> > package main 
> > 
> > //#include <stdio.h> 
> > //char* callC() { 
> > // return "Calling C code!"; 
> > //} 
> > import "C" 
> > 
> > import "fmt" 
> > 
> > func main() { 
> >         fmt.Println("Convert C String to Go String") 
> >         str := C.GoString(C.callC()) 
> >         fmt.Println(str) 
> > } 
> > 
> > to overcome this I modified the gcc.go file in src/cmd/cgo and added 
> this: 
> > 
> > if s == "uchar" { 
> >                 s = "char" 
> >             } 
> >             name := c.Ident("_Ctype_" + s) 
> > I don't now how CGO always convert my char* to *_Ctype_uchar instead of 
> *_Ctype_char. 
> > Anyone have a clue on this? 
>
> cgo is just using the debug information generated by the C compiler. 
> It expects to see debug info for the type "char".  For example, if I 
> compile this C file 
>
> #include <stdio.h> 
> char* callC() { 
>  return "Calling C code!"; 
> } 
>
> with clang on my system and run "readelf --debug" on the resulting 
> object file, I see 
>
>  <1><48>: Abbrev Number: 4 (DW_TAG_base_type) 
>     <49>   DW_AT_name        : (indirect string, offset: 0x4c): char 
>     <4d>   DW_AT_encoding    : 6        (signed char) 
>     <4e>   DW_AT_byte_size   : 1 
>
> cgo will use this to define the type "C.char". 
>
> This is independent of whether char is signed or unsigned.  Given that 
> your code uses "char", it surprises me that there is no named entry 
> for it in the debug info. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f4a72340-018e-4172-b702-af4f03ad48f1o%40googlegroups.com.

Reply via email to