From owner-freebsd-hackers@freebsd.org Mon Nov 13 13:15:50 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2A0E8DBA30A for ; Mon, 13 Nov 2017 13:15:50 +0000 (UTC) (envelope-from teemperor@gmail.com) Received: from mail-lf0-x243.google.com (mail-lf0-x243.google.com [IPv6:2a00:1450:4010:c07::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A55896DDEF for ; Mon, 13 Nov 2017 13:15:49 +0000 (UTC) (envelope-from teemperor@gmail.com) Received: by mail-lf0-x243.google.com with SMTP id m1so2297006lfj.9 for ; Mon, 13 Nov 2017 05:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=rDbY5SNHESG6EUyxNcPmwB8IfOQWmDQG3RajmntRhj4=; b=oCsQfP+iTmzBPJHShhI+COeNpNEkoWhn3OkHWmQKfyexzf0yDt5g6n+pojycYxUo4i b9QNBBDZUds492NCMc22mTLYfYToNyBkQ1ETkhBH3Est7Ty/K1E2bPtEqyz0goAplmTw REsltwXNDk65HxMSAavI4hSTHh+21qpr2YEBYSjFb+Z62/IjV4v3aCMZxRFpUIFmX74L EzHzlG8xywZ3sc+eAPSskMmFLPbltceUXJxRWp6BRm3l/FXeRBUAs7Pe6+hYLhRGTgUG 29ksXCt+3LMSne8bqzBOGy9CHJI6n/Qrv0jUlcA19/YNncOS7vrgjsJNJsdk4772+8U7 3UlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rDbY5SNHESG6EUyxNcPmwB8IfOQWmDQG3RajmntRhj4=; b=WOJp4zuuydw20D8C3suG+miArpWh34hWtR/eShslvVR+DFobDp65DJvtAwypyn/zWx LPHNvsW0RUp6LLQN8/NstQEwhxoiYxxmLXQ/7f6WwHzSlwxVuZIkYvJVUrHfSTRTlIkB crnVIP8TSxInMwpkkrtJqOzBa+SUEuShn4Smnl6pYCjMR6wl7Be8GBpWbk8nU91wnH7M cc+lWJiGHHzBM/a9DYXFTy4O0w9TJAYDi2pgg+83HbyYo+v5n8KpNei8bBqt0SLv6nCy hjCjM+9WwF40l/MrYC7jkr5dFoPV/kLpI3kYE7MVdLFdkPcrs1ziZHcOT1Yocivkz1xj sHDQ== X-Gm-Message-State: AJaThX7qS4vp0SVCm2hiv8HnayvpTGWy95lYLTy2OEv7vBVbuyVkGHOm Ebi8emzAIUwyk+/UjoI/DcMQjwpUn7eVS0B5g9mFj/x0 X-Google-Smtp-Source: AGs4zMbWFsCXtIKMQINm7qywV9AIxSVlTnsxeembwaj3nhKRKS01/Uw9LXapR4EwHhVXHocrFGBC2EzdqKl52O71yYY= X-Received: by 10.25.204.22 with SMTP id c22mr1017392lfg.36.1510578945299; Mon, 13 Nov 2017 05:15:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.109.12 with HTTP; Mon, 13 Nov 2017 05:15:04 -0800 (PST) From: Raphael Isemann Date: Mon, 13 Nov 2017 14:15:04 +0100 Message-ID: Subject: Linking error: undefined reference to `__progname' from libc when creating shared library To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Nov 2017 13:15:50 -0000 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 $ 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