public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* How does ld and gold deal with C++ duplicate templates?
@ 2020-09-16  9:26 sotrdg sotrdg
  2020-09-16 19:23 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: sotrdg sotrdg @ 2020-09-16  9:26 UTC (permalink / raw)
  To: binutils@sourceware.org 

Like the bug I reported a month ago.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96577



https://godbolt.org/z/haG4E7

https://godbolt.org/z/M8e7Kb



First:



#include<vector>

#include<array>

#include<algorithm>



template<std::contiguous_iterator Iter>

void f(Iter a,Iter b)

{

    std::sort(a,b);

}



void g(std::vector<int>::iterator b,std::vector<int>::iterator e)

{

    f(b,e);

}



void h(int* b,int* e)

{

    f(b,e);

}



Second:





#include<vector>

#include<array>

#include<algorithm>



template<std::contiguous_iterator Iter>

void f(Iter a,Iter b)

{

    std::sort(a,b);

}



void g(std::vector<int>::iterator b,std::vector<int>::iterator e)

{

    f(std::to_address(b),std::to_address(e));

}



void h(int* b,int* e)

{

    f(b,e);

}





The two sort function should generate exactly the same binary. However the first which is none to_address version generates twice as much as code as the second one.

Will the GNU ld remove the duplication definitions?
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How does ld and gold deal with C++ duplicate templates?
  2020-09-16  9:26 How does ld and gold deal with C++ duplicate templates? sotrdg sotrdg
@ 2020-09-16 19:23 ` Ian Lance Taylor
  2020-09-16 19:38   ` sotrdg sotrdg
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2020-09-16 19:23 UTC (permalink / raw)
  To: sotrdg sotrdg; +Cc: binutils

On Wed, Sep 16, 2020 at 2:26 AM sotrdg sotrdg via Binutils
<binutils@sourceware.org> wrote:
>
> Like the bug I reported a month ago.
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96577
>
>
>
> https://godbolt.org/z/haG4E7
>
> https://godbolt.org/z/M8e7Kb
>
>
>
> First:
>
>
>
> #include<vector>
>
> #include<array>
>
> #include<algorithm>
>
>
>
> template<std::contiguous_iterator Iter>
>
> void f(Iter a,Iter b)
>
> {
>
>     std::sort(a,b);
>
> }
>
>
>
> void g(std::vector<int>::iterator b,std::vector<int>::iterator e)
>
> {
>
>     f(b,e);
>
> }
>
>
>
> void h(int* b,int* e)
>
> {
>
>     f(b,e);
>
> }
>
>
>
> Second:
>
>
>
>
>
> #include<vector>
>
> #include<array>
>
> #include<algorithm>
>
>
>
> template<std::contiguous_iterator Iter>
>
> void f(Iter a,Iter b)
>
> {
>
>     std::sort(a,b);
>
> }
>
>
>
> void g(std::vector<int>::iterator b,std::vector<int>::iterator e)
>
> {
>
>     f(std::to_address(b),std::to_address(e));
>
> }
>
>
>
> void h(int* b,int* e)
>
> {
>
>     f(b,e);
>
> }
>
>
>
>
>
> The two sort function should generate exactly the same binary. However the first which is none to_address version generates twice as much as code as the second one.
>
> Will the GNU ld remove the duplication definitions?


For gold, see the --icf option.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: How does ld and gold deal with C++ duplicate templates?
  2020-09-16 19:23 ` Ian Lance Taylor
@ 2020-09-16 19:38   ` sotrdg sotrdg
  2020-09-16 20:56     ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: sotrdg sotrdg @ 2020-09-16 19:38 UTC (permalink / raw)
  To: Ian Lance Taylor, binutils

But gold linker is said to be removed in the future since no one is willing to maintain it any more. BTW, I am using MinGW on Windows where gold does not seem to be available.

Does ld provide the same options?

And why these optimizations are not applied by default?

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

From: Ian Lance Taylor<mailto:iant@google.com>
Sent: Wednesday, September 16, 2020 15:23
To: sotrdg sotrdg<mailto:euloanty@live.com>
Cc: binutils@sourceware.org<mailto:binutils@sourceware.org>
Subject: Re: How does ld and gold deal with C++ duplicate templates?

On Wed, Sep 16, 2020 at 2:26 AM sotrdg sotrdg via Binutils
<binutils@sourceware.org> wrote:
>
> Like the bug I reported a month ago.
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96577
>
>
>
> https://godbolt.org/z/haG4E7
>
> https://godbolt.org/z/M8e7Kb
>
>
>
> First:
>
>
>
> #include<vector>
>
> #include<array>
>
> #include<algorithm>
>
>
>
> template<std::contiguous_iterator Iter>
>
> void f(Iter a,Iter b)
>
> {
>
>     std::sort(a,b);
>
> }
>
>
>
> void g(std::vector<int>::iterator b,std::vector<int>::iterator e)
>
> {
>
>     f(b,e);
>
> }
>
>
>
> void h(int* b,int* e)
>
> {
>
>     f(b,e);
>
> }
>
>
>
> Second:
>
>
>
>
>
> #include<vector>
>
> #include<array>
>
> #include<algorithm>
>
>
>
> template<std::contiguous_iterator Iter>
>
> void f(Iter a,Iter b)
>
> {
>
>     std::sort(a,b);
>
> }
>
>
>
> void g(std::vector<int>::iterator b,std::vector<int>::iterator e)
>
> {
>
>     f(std::to_address(b),std::to_address(e));
>
> }
>
>
>
> void h(int* b,int* e)
>
> {
>
>     f(b,e);
>
> }
>
>
>
>
>
> The two sort function should generate exactly the same binary. However the first which is none to_address version generates twice as much as code as the second one.
>
> Will the GNU ld remove the duplication definitions?


For gold, see the --icf option.

Ian


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How does ld and gold deal with C++ duplicate templates?
  2020-09-16 19:38   ` sotrdg sotrdg
@ 2020-09-16 20:56     ` Ian Lance Taylor
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2020-09-16 20:56 UTC (permalink / raw)
  To: sotrdg sotrdg; +Cc: binutils

On Wed, Sep 16, 2020 at 12:38 PM sotrdg sotrdg <euloanty@live.com> wrote:
>
> But gold linker is said to be removed in the future since no one is willing to maintain it any more. BTW, I am using MinGW on Windows where gold does not seem to be available.

Seems a pity, but OK.  It's true that I don't have time to maintain
it.  And it's true that it doesn't work on Windows.

> Does ld provide the same options?

Not to my knowledge.

> And why these optimizations are not applied by default?

Because they measurably increase link times.

Ian


> From: Ian Lance Taylor
> Sent: Wednesday, September 16, 2020 15:23
> To: sotrdg sotrdg
> Cc: binutils@sourceware.org
> Subject: Re: How does ld and gold deal with C++ duplicate templates?
>
>
>
> On Wed, Sep 16, 2020 at 2:26 AM sotrdg sotrdg via Binutils
> <binutils@sourceware.org> wrote:
> >
> > Like the bug I reported a month ago.
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96577
> >
> >
> >
> > https://godbolt.org/z/haG4E7
> >
> > https://godbolt.org/z/M8e7Kb
> >
> >
> >
> > First:
> >
> >
> >
> > #include<vector>
> >
> > #include<array>
> >
> > #include<algorithm>
> >
> >
> >
> > template<std::contiguous_iterator Iter>
> >
> > void f(Iter a,Iter b)
> >
> > {
> >
> >     std::sort(a,b);
> >
> > }
> >
> >
> >
> > void g(std::vector<int>::iterator b,std::vector<int>::iterator e)
> >
> > {
> >
> >     f(b,e);
> >
> > }
> >
> >
> >
> > void h(int* b,int* e)
> >
> > {
> >
> >     f(b,e);
> >
> > }
> >
> >
> >
> > Second:
> >
> >
> >
> >
> >
> > #include<vector>
> >
> > #include<array>
> >
> > #include<algorithm>
> >
> >
> >
> > template<std::contiguous_iterator Iter>
> >
> > void f(Iter a,Iter b)
> >
> > {
> >
> >     std::sort(a,b);
> >
> > }
> >
> >
> >
> > void g(std::vector<int>::iterator b,std::vector<int>::iterator e)
> >
> > {
> >
> >     f(std::to_address(b),std::to_address(e));
> >
> > }
> >
> >
> >
> > void h(int* b,int* e)
> >
> > {
> >
> >     f(b,e);
> >
> > }
> >
> >
> >
> >
> >
> > The two sort function should generate exactly the same binary. However the first which is none to_address version generates twice as much as code as the second one.
> >
> > Will the GNU ld remove the duplication definitions?
>
>
> For gold, see the --icf option.
>
> Ian
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-16 20:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16  9:26 How does ld and gold deal with C++ duplicate templates? sotrdg sotrdg
2020-09-16 19:23 ` Ian Lance Taylor
2020-09-16 19:38   ` sotrdg sotrdg
2020-09-16 20:56     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).