Stephen Hemminger <step...@networkplumber.org> writes:

> On Wed, 6 Jan 2021 10:42:35 +0200
> Roi Dayan <r...@nvidia.com> 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...

Reply via email to