Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Nov 2017 14:15:04 +0100
From:      Raphael Isemann <teemperor@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Linking error: undefined reference to `__progname' from libc when creating shared library
Message-ID:  <CADrqtg7bY%2B77PyKpT3=bLKhkH3nNimv-Nayg6d2CMxy6d6hLzw@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi all,

I'm trying to port CERN's ROOT framework ( https://root.cern.ch/ ) to
FreeBSD but I'm currently struggling with some linking error that is
resisting my attempts at debugging it.

The problem is that ROOT is trying to link one of its shared
libraries, but somehow libc.so starts looking for the `__progname`
symbol. Looking at the FreeBSD source, it seems we get this symbol
from crt1.o. And as I'm not linking against that (as I don't want to
create an executable, but an SO) I get an undefined reference.

Anyone has a hint why we see this behavior? Is it possible to
reference something in libc that requires `__progname` in return?

The linker invocation is below (I called clang and let it also print
the ld invocation on the way). The whole invocation including all the
LLVM libraries is here [1].

You can reproduce it by running this (and waiting a long time because
that first builds LLVM/clang from scratch):

$ git clone https://github.com/root-project/root
$ <apply this patch> https://pastebin.com/raw/THbJsffy
$ mkdir build
$ cd build
$ cmake -DCMAKE_EXE_LINKER_FLAGS:string="-lm -lcrypt" -Dcxx14:bool=ON
-$Dall=On -GNinja ../root/
$ ninja -j4 -l4 Cling

Cheers,

- Raphael Isemann

(Not sure if that's the right mailing list, but looking at the
handbook this seems to be the most appropriate list for such a generic
issue).

Linker invocation:
#############################################
root@roottest ~/build# uname -a
FreeBSD roottest 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul
21 02:08:28 UTC 2017
root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
#############################################
root@roottest ~/build# bash -c "/usr/bin/c++ -v -fPIC
-Wc++11-narrowing -Wsign-compare -Wsometimes-uninitialized
-Wconditional-uninitialized -Wheader-guard -Warray-bounds -Wcomment
-Wtautological-compare -Wstrncat-size -Wloop-analysis
-Wbool-conversion -pthread -std=c++14 -fvisibility=hidden -Wno-shadow
-fno-strict-aliasing -Wno-unused-parameter -Wwrite-strings
-Wno-long-long  -DLLVM_BUILD_GLOBAL_ISEL -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-Wno-conditional-uninitialized -O2 -g -DNDEBUG   -shared
-Wl,-soname,libCling.so -o lib/libCling.so
core/clingutils/CMakeFiles/ClingUtils.dir/src/RStl.cxx.o
core/clingutils/CMakeFiles/ClingUtils.dir/src/TClingUtils.cxx.o
core/metacling/src/CMakeFiles/MetaCling.dir/rootclingTCling.cxx.o
core/metacling/src/CMakeFiles/Cling.dir/dummy.cxx.o -L/usr/local/lib
-Wl,-rpath,/usr/local/lib:
interpreter/llvm/src/lib/libclingInterpreter.a
interpreter/llvm/src/lib/libclingMetaProcessor.a
interpreter/llvm/src/lib/libclingUtils.a -lelf
-Wl,--unresolved-symbols=ignore-in-object-files
interpreter/llvm/src/lib/libclingInterpreter.a
[stripped .so files]
interpreter/llvm/src/lib/libclangCodeGen.a
interpreter/llvm/src/lib/libclangFrontend.a
interpreter/llvm/src/lib/libclangDriver.a
interpreter/llvm/src/lib/libLLVMSupport.a -lrt /usr/lib/libexecinfo.so
-ltinfo -lpthread /usr/lib/libz.so -lm
interpreter/llvm/src/lib/libLLVMDemangle.a"
FreeBSD clang version 4.0.0 (tags/RELEASE_400/final 297347) (based on
LLVM 4.0.0)
Target: x86_64-unknown-freebsd11.1
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/ld" --eh-frame-hdr -Bshareable --hash-style=both
--enable-new-dtags -o lib/libCling.so /usr/lib/crti.o
/usr/lib/crtbeginS.o -L/usr/local/lib -L/usr/lib -soname libCling.so
core/clingutils/CMakeFiles/ClingUtils.dir/src/RStl.cxx.o
core/clingutils/CMakeFiles/ClingUtils.dir/src/TClingUtils.cxx.o
core/dictgen/CMakeFiles/Dictgen.dir/src/BaseSelectionRule.cxx.o
core/dictgen/CMakeFiles/Dictgen.dir/src/ClassSelectionRule.cxx.o
[stripped .so files]
interpreter/llvm/src/lib/libLLVMSupport.a -lrt /usr/lib/libexecinfo.so
-ltinfo -lpthread /usr/lib/libz.so -lm
interpreter/llvm/src/lib/libLLVMDemangle.a -lc++ -lm -lgcc --as-needed
-lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s
--no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o
/lib/libc.so.7: undefined reference to `__progname'
c++: error: linker command failed with exit code 1 (use -v to see invocation)
#############################################

[1] https://pastebin.com/raw/L6KtTaPK



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADrqtg7bY%2B77PyKpT3=bLKhkH3nNimv-Nayg6d2CMxy6d6hLzw>