URL:
  <https://savannah.gnu.org/support/?111193>

                 Summary: libtool misses adding
`libclang_rt.builtins-x86_64.a` to c++ shared libraries
                   Group: GNU Libtool
               Submitter: slyfox
               Submitted: Sun 23 Feb 2025 10:41:26 AM UTC
                Category: None
                Priority: 5 - Normal
                Severity: 3 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Any
        Operating System: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Sun 23 Feb 2025 10:41:26 AM UTC By: Sergei Trofimovich <slyfox>
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?







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/support/?111193>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to