Re: util-linux-2.41 breaks static build of btrfs-progs

Karel Zak <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <vy5gwsr6al5wl7nlksaq6orzkhhp4tog7gxtsjchl76ess5rtc@tmkazaywmvgv>
On Sun, Apr 20, 2025 at 09:24:43PM +0200, Stanislav Brabec wrote:
> Static build of btrfs-progs fails with util-linux-2.41 with a simple
> problem:
> Symbol parse_range becomes visible in libblkid.a, breaking parse-utils.c in
> btrfs-progs, using the same symbol.
> 
> The question is:
> Should be this fixed by util-linux by prefixing of ul_ to all symbols that
> are not declared as static?

I think the ul_ prefix should be used for all generic names like
parse_range(). I'm not sure if I want to use it strictly for all
functions, as the set of functions is large and such conflicts are
very rare.

ChatGPT has an interesting suggestion: add the prefix to the .a
library using "objcopy --redefine-syms" for all non-API and non-static
functions.

        #!/bin/bash
        PREFIX=foo_

        # Extract all global (non-static) function symbols from the .a file
        nm -g --defined-only libmylib.a | awk '{print $3}' | grep -v "^$PREFIX" | sort -u > tmp.syms

        # Generate rename list: <old> <new>
        awk -v pfx="$PREFIX" '{print $1 " " pfx $1}' tmp.syms > rename.syms

        # Apply symbol renaming
        objcopy --redefine-syms=rename.syms libmylib.a libmylib_prefixed.a


Maybe it's elegant way to go. Not sure, not tested :-)

    Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.