From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 7FBBD398B8A1 for ; Wed, 16 Sep 2020 19:23:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7FBBD398B8A1 Received: by mail-lj1-x22a.google.com with SMTP id k25so6950217ljk.0 for ; Wed, 16 Sep 2020 12:23:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BWpBYNKCaul8DNs/AeorF2cJugZVWK3vjwJ2BdBisNc=; b=KrOemW/kmpceTna1MbAy6IWBt8hfL6F3wx6cwTlRgrgVGe7LJbDuAYeWdo+ZWU6YPe +74eztmsDTeeb3vbNNXW374m8P7tQ6nztOQpl7n6/va1N+ME60QOaCA/1s6DBCwGknPV jY7SkzDq848qdTO73OOiIRTD12TjO9uYx2+BrGzTm1CpBw49WJA8HdEoMR+NiwUG29J1 l6quYSb8BTNTfAVdEhaZtEg8z24xLnuHUb9Wbr1S0lrKvhExMJJ86MCWstKUcr4pGAHv htwHZSCTBLu402xOcrBZjeyRPPVWv3A2Sui2WI9MGB1I0bs0vPIlSrP20meyzTVfmy3+ a5/g== X-Gm-Message-State: AOAM530hghKP/U2iroI2zleoIkVLADjj3TAFH3b0aF8cEJeyM9GUJA97 9tSu5R4bqfpdnylJkYRcWoD8xjOBrBp+owe+9d/pdg== X-Google-Smtp-Source: ABdhPJxPMJ5AxWae7oVIxvfjdLjVZUx2+HKWimhHhyQZZvBMXhXOhH4WmDcSnpou3phZtuDLigU0BkT5XBjgEPCt0DE= X-Received: by 2002:a2e:3013:: with SMTP id w19mr8568423ljw.339.1600284198072; Wed, 16 Sep 2020 12:23:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ian Lance Taylor Date: Wed, 16 Sep 2020 12:23:06 -0700 Message-ID: Subject: Re: How does ld and gold deal with C++ duplicate templates? To: sotrdg sotrdg Cc: "binutils@sourceware.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-18.9 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Sep 2020 19:23:21 -0000 On Wed, Sep 16, 2020 at 2:26 AM sotrdg sotrdg via Binutils 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 > > #include > > #include > > > > template > > void f(Iter a,Iter b) > > { > > std::sort(a,b); > > } > > > > void g(std::vector::iterator b,std::vector::iterator e) > > { > > f(b,e); > > } > > > > void h(int* b,int* e) > > { > > f(b,e); > > } > > > > Second: > > > > > > #include > > #include > > #include > > > > template > > void f(Iter a,Iter b) > > { > > std::sort(a,b); > > } > > > > void g(std::vector::iterator b,std::vector::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