mainGNU Libtool - Support: sr #111193, libtool misses adding...

 
 

sr #111193: libtool misses adding `libclang_rt.builtins-x86_64.a` to c++ shared libraries

Submitter:  Sergei Trofimovich <slyfox>
Submitted:  Sun 23 Feb 2025 10:41:26 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 15 Apr 2025 02:02:42 PM UTC, comment #5: 

comment #4:

> I tried on `libtool` from development branch at 409501b0a717552624707708adf5e7fd7c872ca3. I tested it on a real `soundtouch` project and it worked as expected. Yay!
>
> I had to configure `soundtouch` itself with `--enable-cxx-stdlib` (and not just `libtool` as I initially thought).

Thank you for testing, and I am happy it worked! The feature is currently on master [1], but I will update NEWS to specify the types of bugs that are fixed by using the new configuration options.

[1]https://git.savannah.gnu.org/cgit/libtool.git/commit/?id=9bc7536bd8755f3b63118613496a89671512f2db

Ileana Dumitrescu <ildumi>
Group administrator
Fri 11 Apr 2025 10:06:19 PM UTC, comment #4: 

comment #3:

> The patch has been committed to the development branch for disabling the use '-nostdlib' to let the compiler frontend decide what standard libraries to link when building C++ shared libraries and modules. Could you test if using '--enable-cxx-stdlib' helps fix the issue with 'libclang_rt.builtins-x86_64.a'?
>
> https://git.savannah.gnu.org/cgit/libtool.git/commit/?h=development&id=a390f27ff13fd8bca3f43ab4721d8dc56c476acb


I tried on `libtool` from development branch at 409501b0a717552624707708adf5e7fd7c872ca3. I tested it on a real `soundtouch` project and it worked as expected. Yay!

I had to configure `soundtouch` itself with `--enable-cxx-stdlib` (and not just `libtool` as I initially thought).

Sergei Trofimovich <slyfox>
Fri 28 Mar 2025 04:53:51 PM UTC, comment #3: 

The patch has been committed to the development branch for disabling the use '-nostdlib' to let the compiler frontend decide what standard libraries to link when building C++ shared libraries and modules. Could you test if using '--enable-cxx-stdlib' helps fix the issue with 'libclang_rt.builtins-x86_64.a'?

https://git.savannah.gnu.org/cgit/libtool.git/commit/?h=development&id=a390f27ff13fd8bca3f43ab4721d8dc56c476acb

Ileana Dumitrescu <ildumi>
Group administrator
Wed 26 Mar 2025 06:05:46 PM UTC, comment #2: 

While patching a different issue, I generated the attached patch to add a configuration option for libtool to avoid the usage of '-nostdlib' when linking C++ modules. I think this might be a good alternative solution for your issue.

(file #57070)

Ileana Dumitrescu <ildumi>
Group administrator
Tue 18 Mar 2025 06:08:56 PM UTC, comment #1: 

Thank you for your bug report. The following patch may fix this:

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 434f9ba7..33383e9d 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -7748,7 +7748,7 @@ if AC_TRY_EVAL(ac_compile); then
   for p in `eval "$output_verbose_link_cmd"`; do
     case $prev$p in

-    -L* | -R* | -l*)
+    -L* | -R* | -l* | */libclang_rt*.a)
        # Some compilers place space between "-{L,R,l}" and the path.
        # Remove the space.
        if test x-L = x"$p" ||

It is similar to one of the patches discussed in this open bug report:
  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27866

The other linked MSYS2 patch might also be necessary, but I need to look at it more.

Ileana Dumitrescu <ildumi>
Group administrator
Sun 23 Feb 2025 10:41:26 AM UTC, original submission:  

The downstream issue is `soundtouch` build failure on `clang` with `compiler-rt` as a compiler runtime implementation: https://codeberg.org/soundtouch/soundtouch/issues/47#issuecomment-2867506

Minimal reproducer is 3 files: configure.ac, Makefile.am, bug.cc.

configure.ac:

# cat configure.ac
AC_INIT([rt-bug], [1.0])

AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_MACRO_DIRS([m4])

LT_INIT

AC_PROG_CXX
AC_LANG([C++])

AC_CONFIG_FILES([Makefile])

AC_OUTPUT


Makefile.am:

ACLOCAL_AMFLAGS = -I m4

lib_LTLIBRARIES = libbug.la
libbug_la_SOURCES = bug.cc
libbug_la_LDFLAGS = -Wl,--no-undefined


bug.cc:

// to break:
// $ autoreconf -ivf && ./configure CC=x86_64-pc-linux-gnu-clang CXX=x86_64-pc-linux-gnu-clang++ && make clean && make

double bug(double a, int b) {
    // explicitly call the function from libgcc.a / libclang-builtins:
    return __builtin_powi(a,b);
}


Triggering the failure:


$ autoreconf -ivf && ./configure CC=x86_64-pc-linux-gnu-clang CXX=x86_64-pc-linux-gnu-clang++ && make clean && make
...
/bin/sh ./libtool  --tag=CXX   --mode=compile x86_64-pc-linux-gnu-clang++ -DPACKAGE_NAME=\"rt-bug\" -DPACKAGE_TARNAME=\"rt-bug\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"rt-bug\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"rt-bug\" -DVERSION=\"1.0\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I.     -g -O2 -MT bug.lo -MD -MP -MF .deps/bug.Tpo -c -o bug.lo bug.cc
libtool: compile:  x86_64-pc-linux-gnu-clang++ -DPACKAGE_NAME=\"rt-bug\" -DPACKAGE_TARNAME=\"rt-bug\" -DPACKAGE_VERSION=\"1.0\" "-DPACKAGE_STRING=\"rt-bug 1.0\"" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"rt-bug\" -DVERSION=\"1.0\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -g -O2 -MT bug.lo -MD -MP -MF .deps/bug.Tpo -c bug.cc  -fPIC -DPIC -o .libs/bug.o
libtool: compile:  x86_64-pc-linux-gnu-clang++ -DPACKAGE_NAME=\"rt-bug\" -DPACKAGE_TARNAME=\"rt-bug\" -DPACKAGE_VERSION=\"1.0\" "-DPACKAGE_STRING=\"rt-bug 1.0\"" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"rt-bug\" -DVERSION=\"1.0\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -g -O2 -MT bug.lo -MD -MP -MF .deps/bug.Tpo -c bug.cc -o bug.o >/dev/null 2>&1
mv -f .deps/bug.Tpo .deps/bug.Plo
/bin/sh ./libtool  --tag=CXX   --mode=link x86_64-pc-linux-gnu-clang++  -g -O2 -Wl,--no-undefined  -o libbug.la -rpath /usr/local/lib bug.lo
libtool: link: x86_64-pc-linux-gnu-clang++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o /usr/lib/llvm/17/bin/../../../../lib/clang/17/lib/linux/clang_rt.crtbegin-x86_64.o  .libs/bug.o   -L/usr/lib/gcc/x86_64-pc-linux-gnu/14 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/lib -L/lib -L/usr/lib -lc++ -lm -lc -lunwind /usr/lib/llvm/17/bin/../../../../lib/clang/17/lib/linux/clang_rt.crtend-x86_64.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o  -g -O2 -Wl,--no-undefined   -Wl,-soname -Wl,libbug.so.0 -o .libs/libbug.so.0.0.0
ld.lld: error: undefined symbol: __powidf2
>>> referenced by bug.cc:6 (/root/libtool-missing-runtime/bug.cc:6)
>>>               .libs/bug.o:(bug(double, int))
x86_64-pc-linux-gnu-clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:431: libbug.la] Error 1


Note: the problem here is that `libtool` uses `clang++` to link a shared library with `-nostdlib` but it lacks bits that define an implementation of `__powidf2`.

Here for comparison how `clang++` without `libtool` pulls in needed runtime bits:


$ x86_64-pc-linux-gnu-clang++ bug.cc -o libbug.so -shared -Wl,--no-undefined -Wl,-t
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o
/usr/lib/llvm/17/bin/../../../../lib/clang/17/lib/linux/clang_rt.crtbegin-x86_64.o
/tmp/bug-15776c.o
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/libc++_shared.so
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/libc++abi.so
/lib64/libm.so.6
/lib64/libmvec.so.1
/usr/lib/llvm/17/bin/../../../../lib/clang/17/lib/linux/libclang_rt.builtins-x86_64.a(powidf2.c.o)
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/libunwind.so
/lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/libunwind.so
/usr/lib/llvm/17/bin/../../../../lib/clang/17/lib/linux/clang_rt.crtend-x86_64.o
/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o


Note how `/usr/lib/llvm/17/bin/../../../../lib/clang/17/lib/linux/libclang_rt.builtins-x86_64.a(powidf2.c.o)` is pulled in for missing bits.

If I change C++ to C the above `libtool` example will just work. `-Wl,--no-undefined` is just a convenient way to detect that final shared library does not have it's all symbols satisfied.

If I look at a successful `gcc` `libtool` based build `gcc_s` is pulled in as expected:


$ autoreconf -ivf && ./configure CC=gcc CXX=g++ && make clean && make
...
/bin/sh ./libtool  --tag=CXX   --mode=compile g++ -DPACKAGE_NAME=\"rt-bug\" -DPACKAGE_TARNAME=\"rt-bug\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"rt-bug\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"rt-bug\" -DVERSION=\"1.0\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I.     -g -O2 -MT bug.lo -MD -MP -MF .deps/bug.Tpo -c -o bug.lo bug.cc
libtool: compile:  g++ -DPACKAGE_NAME=\"rt-bug\" -DPACKAGE_TARNAME=\"rt-bug\" -DPACKAGE_VERSION=\"1.0\" "-DPACKAGE_STRING=\"rt-bug 1.0\"" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"rt-bug\" -DVERSION=\"1.0\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -g -O2 -MT bug.lo -MD -MP -MF .deps/bug.Tpo -c bug.cc  -fPIC -DPIC -o .libs/bug.o
libtool: compile:  g++ -DPACKAGE_NAME=\"rt-bug\" -DPACKAGE_TARNAME=\"rt-bug\" -DPACKAGE_VERSION=\"1.0\" "-DPACKAGE_STRING=\"rt-bug 1.0\"" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"rt-bug\" -DVERSION=\"1.0\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -g -O2 -MT bug.lo -MD -MP -MF .deps/bug.Tpo -c bug.cc -o bug.o >/dev/null 2>&1
mv -f .deps/bug.Tpo .deps/bug.Plo
/bin/sh ./libtool  --tag=CXX   --mode=link g++  -g -O2 -Wl,--no-undefined  -o libbug.la -rpath /usr/local/lib bug.lo
libtool: link: g++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/crtbeginS.o  .libs/bug.o   -L/usr/lib/gcc/x86_64-pc-linux-gnu/14 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/14/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o  -g -O2 -Wl,--no-undefined   -Wl,-soname -Wl,libbug.so.0 -o .libs/libbug.so.0.0.0
libtool: link: (cd ".libs" && rm -f "libbug.so.0" && ln -s "libbug.so.0.0.0" "libbug.so.0")
libtool: link: (cd ".libs" && rm -f "libbug.so" && ln -s "libbug.so.0.0.0" "libbug.so")
libtool: link: ar cr .libs/libbug.a  bug.o
libtool: link: ranlib .libs/libbug.a
libtool: link: ( cd ".libs" && rm -f "libbug.la" && ln -s "../libbug.la" "libbug.la" )


Should `libtool` be amended to discover `libclang_rt.builtins-x86_64.a`? Or maybe avoid use of `-nostdlib` for this case?

Sergei Trofimovich <slyfox>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ildumi (Posted a comment)
  • -email is unavailable- added by slyfox (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-04-15 ildumi StatusReady For Test Done
        Open/ClosedOpen Closed
    2025-04-11 ildumi StatusNone Ready For Test
    2025-03-26 ildumi Attached File- Added 0001-libtool-Add-configuration-options-for-CXX-linking.patch, #57070

    Back to the top

    Powered by Savane 3.14-962f.
    Corresponding source code