Re: [go-nuts] External/internal linker and cgo packages

2020-04-29 Thread Ian Lance Taylor
On Wed, Apr 29, 2020 at 8:58 PM Vincent Blanchon
 wrote:
>
> Thank you again for your reply!
> I thought Go would compile all the C files in one .go, that makes sense.
>
> By the way, how Go would deal with those files if cgo is not enabled - 
> meaning the internal linker will do the job?
> How the internal linker can deal with that?

If you are using the internal linker, then you aren't using cgo, so
the linker won't see all those C files.

Ian


> Le jeudi 30 avril 2020 07:52:03 UTC+4, Ian Lance Taylor a écrit :
>>
>> On Tue, Apr 28, 2020 at 10:49 PM Vincent Blanchon
>>  wrote:
>> >
>> > I'm building a simple program that has a dependency to 
>> > github.com/DataDog/zstd, a wrapper of a C code.
>> > So by default, Go will use the external linker. When debugging with, I can 
>> > see
>> >
>> > host link: "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" 
>> > "-Wl,-pagezero_size,400" "-o" 
>> > "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-build122622791/b001/exe/a.out"
>> >  "-Qunused-arguments" 
>> > "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/go.o" 
>> > "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/00.o"
>> >  [...] 
>> > "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/53.o"
>> >  
>> > "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/54.o"
>> >  
>> > "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/55.o"
>> >  "-g" "-O2" "-g" "-O2" "-g" "-O2" "-lpthread" "-g" "-O2" "-framework" 
>> > "CoreFoundation" "-framework" "Security" "-no-pie"
>> >
>> > It links 55 files, from 00.o to 55.oIf I had more custom debug, I 
>> > can see than those files are mostly duplication:
>> >
>> > 04.o is 
>> > /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
>> >  github.com/DataDog/zstd 
>> > /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x005.o)
>> > 05.o is 
>> > /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
>> >  github.com/DataDog/zstd 
>> > /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x006.o)
>> >
>> > I can see 40 times this zstd package among the 55 files. Is it expected? 
>> > What is the difference between them?
>> >
>> > Also, what would happen to the non known cgo packages (not net, os/user or 
>> > runtime/cgo) if cgo is not enabled? How the internal linker will manage 
>> > this cgo package?
>>
>> I may be missing something, but that doesn't look like duplication to
>> me.  It looks like different files from an archive.  The first one is
>> _x005.o and the second one is _x006.o.
>>
>> You will get files like these for each .c file in a package that uses cgo.
>>
>> 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/38760d5d-b8e3-4a42-b087-8b81ab4ebd87%40googlegroups.com.

-- 
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/CAOyqgcUG8JOUNUovpJSnHzYaX9-x%3DRHqx4Dm5amW6AW61%3Dc7ZQ%40mail.gmail.com.


Re: [go-nuts] External/internal linker and cgo packages

2020-04-29 Thread Vincent Blanchon
Hello Ian,

Thank you again for your reply!
I thought Go would compile all the C files in one .go, that makes sense.

By the way, how Go would deal with those files if cgo is not enabled - 
meaning the internal linker will do the job?
How the internal linker can deal with that?


Le jeudi 30 avril 2020 07:52:03 UTC+4, Ian Lance Taylor a écrit :
>
> On Tue, Apr 28, 2020 at 10:49 PM Vincent Blanchon 
> > wrote: 
> > 
> > I'm building a simple program that has a dependency to 
> github.com/DataDog/zstd, a wrapper of a C code. 
> > So by default, Go will use the external linker. When debugging with, I 
> can see 
> > 
> > host link: "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" 
> "-Wl,-pagezero_size,400" "-o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-build122622791/b001/exe/a.out"
>  
> "-Qunused-arguments" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/go.o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/00.o" 
> [...] 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/53.o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/54.o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/55.o" 
> "-g" "-O2" "-g" "-O2" "-g" "-O2" "-lpthread" "-g" "-O2" "-framework" 
> "CoreFoundation" "-framework" "Security" "-no-pie" 
> > 
> > It links 55 files, from 00.o to 55.oIf I had more custom debug, 
> I can see than those files are mostly duplication: 
> > 
> > 04.o is 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
>  
> github.com/DataDog/zstd 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x005.o)
>  
>
> > 05.o is 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
>  
> github.com/DataDog/zstd 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x006.o)
>  
>
> > 
> > I can see 40 times this zstd package among the 55 files. Is it expected? 
> What is the difference between them? 
> > 
> > Also, what would happen to the non known cgo packages (not net, os/user 
> or runtime/cgo) if cgo is not enabled? How the internal linker will manage 
> this cgo package? 
>
> I may be missing something, but that doesn't look like duplication to 
> me.  It looks like different files from an archive.  The first one is 
> _x005.o and the second one is _x006.o. 
>
> You will get files like these for each .c file in a package that uses cgo. 
>
> 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/38760d5d-b8e3-4a42-b087-8b81ab4ebd87%40googlegroups.com.


Re: [go-nuts] External/internal linker and cgo packages

2020-04-29 Thread Ian Lance Taylor
On Tue, Apr 28, 2020 at 10:49 PM Vincent Blanchon
 wrote:
>
> I'm building a simple program that has a dependency to 
> github.com/DataDog/zstd, a wrapper of a C code.
> So by default, Go will use the external linker. When debugging with, I can see
>
> host link: "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" 
> "-Wl,-pagezero_size,400" "-o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-build122622791/b001/exe/a.out"
>  "-Qunused-arguments" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/go.o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/00.o" 
> [...] 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/53.o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/54.o" 
> "/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/55.o" 
> "-g" "-O2" "-g" "-O2" "-g" "-O2" "-lpthread" "-g" "-O2" "-framework" 
> "CoreFoundation" "-framework" "Security" "-no-pie"
>
> It links 55 files, from 00.o to 55.oIf I had more custom debug, I can 
> see than those files are mostly duplication:
>
> 04.o is 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
>  github.com/DataDog/zstd 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x005.o)
> 05.o is 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
>  github.com/DataDog/zstd 
> /path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x006.o)
>
> I can see 40 times this zstd package among the 55 files. Is it expected? What 
> is the difference between them?
>
> Also, what would happen to the non known cgo packages (not net, os/user or 
> runtime/cgo) if cgo is not enabled? How the internal linker will manage this 
> cgo package?

I may be missing something, but that doesn't look like duplication to
me.  It looks like different files from an archive.  The first one is
_x005.o and the second one is _x006.o.

You will get files like these for each .c file in a package that uses cgo.

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/CAOyqgcXfXPmA5YiVZ39JqvpgqZ7mAn84EYiO-ZUXrn9kqjbSMQ%40mail.gmail.com.


[go-nuts] External/internal linker and cgo packages

2020-04-28 Thread Vincent Blanchon
Hello,

I'm building a simple program that has a dependency to 
github.com/DataDog/zstd, a wrapper of a C code.
So by default, Go will use the external linker. When debugging with, I can 
see

host link: "clang" "-m64" "-Wl,-headerpad,1144" "-Wl,-no_pie" 
"-Wl,-pagezero_size,400" "-o" 
"/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-build122622791/b001/exe/a.out"
 "-Qunused-arguments" 
"/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/go.o" 
"/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/00.o" 
[...] 
"/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/53.o" 
"/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/54.o" 
"/var/folders/bb/w1lgkjdx47qd7695hb5r400hgn/T/go-link-023224426/55.o" 
"-g" "-O2" "-g" "-O2" "-g" "-O2" "-lpthread" "-g" "-O2" "-framework" 
"CoreFoundation" "-framework" "Security" "-no-pie"

It links 55 files, from 00.o to 55.oIf I had more custom debug, I 
can see than those files are mostly duplication:

04.o is 
/path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
 github.com/DataDog/zstd 
/path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x005.o)
05.o is 
/path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d
 github.com/DataDog/zstd 
/path/to/go-build/67/678a3a394ba4feae32a2ddb829ea65c1cf24be64248dcbcc3dae709b8e3b826d-d(_x006.o)

I can see 40 times this zstd package among the 55 files. Is it expected? 
What is the difference between them?

Also, what would happen to the non known cgo packages (not net, os/user or 
runtime/cgo) if cgo is not enabled? How the internal linker will manage 
this cgo package?

Thank you

-- 
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/db2d65de-8fc5-460e-b309-57f27cdf86cf%40googlegroups.com.