From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6D4FC433E0 for ; Wed, 6 Jan 2021 16:08:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96EE32312F for ; Wed, 6 Jan 2021 16:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbhAFQIx (ORCPT ); Wed, 6 Jan 2021 11:08:53 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:19868 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbhAFQIx (ORCPT ); Wed, 6 Jan 2021 11:08:53 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Wed, 06 Jan 2021 08:08:13 -0800 Received: from yaviefel (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 6 Jan 2021 16:08:11 +0000 References: <1609355503-7981-1-git-send-email-roid@nvidia.com> <875z4cwus8.fsf@nvidia.com> <405e8cce-e2dd-891a-dc8a-7c8b0c77f4c6@nvidia.com> <20210106080020.44ffd4d9@hermes.local> User-agent: mu4e 1.4.10; emacs 27.1 From: Petr Machata To: Stephen Hemminger CC: Roi Dayan , Petr Machata , , David Ahern , Petr Machata Subject: Re: [PATCH iproute2] build: Fix link errors on some systems In-Reply-To: <20210106080020.44ffd4d9@hermes.local> Date: Wed, 6 Jan 2021 17:08:08 +0100 Message-ID: <87ft3eujyv.fsf@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1609949293; bh=gJ2dxGvktG6eLGaRh2LVAkdLeH96w4JzejfIYZizidk=; h=References:User-agent:From:To:CC:Subject:In-Reply-To:Date: Message-ID:MIME-Version:Content-Type:X-Originating-IP: X-ClientProxiedBy; b=deR0tS+5guv3nOAjWnuFdgzRTlc2AwD1dyFAaro76mDTln5lYtdXE5h2KY+HaRvmk Fc3aXSm3r8hXKklGumMm+3t3xKQkHBgRXlCrv3trZaYAlxTsLiKPioXet3MIaHO7gE h/QDvdbP9Al30Cjey7py/mSP5dNeUF5/ln/v9FlkHyobqcqTq3lRUqWGfkjol8Emdj nGN+GHtWv0/nIscWRd2qYGZBJ1xTEDaQ9aebPMXHpBh+uXdApUJ5Z0mq2BeJsIRUVn jdwAb7DDvGxFVN7V2MUNcyzAo1tDKLL8cA2kCTttnpV5iRIZ/boYhXwX1BS1hevQFC GnfW4Fyh93AMg== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Stephen Hemminger writes: > On Wed, 6 Jan 2021 10:42:35 +0200 > Roi Dayan wrote: > >> > >> > I think that just adding an unnecessary -lm is more of a tidiness issue >> > than anything else. One way to avoid it is to split the -lm deps out >> > from util.c / json_print.c to like util_math.c / json_print_math.c. That >> > way they will be in an .o of their own, and won't be linked in unless >> > the binary in question needs the code. Then the binaries that do call it >> > can keep on linking in -lm like they did so far. >> > >> > Thoughts? >> > > > Adding -lm to just some tools is not really required. > The linker will ignore the shared library if not used. I don't think that's true. $ echo 'int main() {}' | gcc -x c /dev/stdin -lm $ ldd a.out linux-vdso.so.1 (0x00007fff903e5000) libm.so.6 => /lib64/libm.so.6 (0x00007fa475d75000) libc.so.6 => /lib64/libc.so.6 (0x00007fa475bab000) /lib64/ld-linux-x86-64.so.2 (0x00007fa475ee4000) Anyway, without the split to math / non-math modules, the DSO will actually end up being necessary, because the undefined references to floor() etc. in util.o / json_print.o will bring it in. Except of course not everybody actually uses the code...