Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#47494 closed defect (fixed)

root6: Undefined symbol "_environ" on Mac OS X 10.7

Reported by: mojca (Mojca Miklavec) Owned by: mojca (Mojca Miklavec)
Priority: Normal Milestone:
Component: ports Version:
Keywords: lion Cc: cjones051073 (Chris Jones), jeremyhu (Jeremy Huddleston Sequoia)
Port: root6

Description (last modified by mojca (Mojca Miklavec))

The update in r135166 broke the build on Lion:

[ 44%] Building CXX object core/meta/CMakeFiles/Cling.dir/__/metautils/src/TMetaUtils.cxx.o
cd /path/to/root6/work/build/core/meta && /opt/local/bin/clang++-mp-3.4   -DCling_EXPORTS -pipe -Os -arch x86_64 -stdlib=libc++  -m64 -pipe -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -Qunused-arguments -pthread -std=c++11 -Wno-deprecated-declarations -Wc++11-narrowing -Wsign-compare -Wsometimes-uninitialized -Wconditional-uninitialized -Wheader-guard -Warray-bounds -Wcomment -Wtautological-compare -Wstrncat-size -Wloop-analysis -Wbool-conversion -stdlib=libc++ -DR__HAVE_CONFIG -Wno-conditional-uninitialized -O2 -DNDEBUG -arch x86_64 -fPIC -I/path/to/root6/work/build/include/root -I/path/to/root6/work/build/include -I/path/to/root6/work/root-9ab0642adeca5d3703783bdbfeebfca86ea22af9/interpreter/llvm/src/include -I/path/to/root6/work/build/interpreter/llvm/src/include -I/path/to/root6/work/root-9ab0642adeca5d3703783bdbfeebfca86ea22af9/interpreter/llvm/src/tools/clang/include -I/path/to/root6/work/build/interpreter/llvm/src/tools/clang/include -I/path/to/root6/work/root-9ab0642adeca5d3703783bdbfeebfca86ea22af9/interpreter/cling/include -I/path/to/root6/work/root-9ab0642adeca5d3703783bdbfeebfca86ea22af9/io/io/inc    -fvisibility-inlines-hidden -fno-strict-aliasing -Wno-unused-parameter -Wwrite-strings -Wno-long-long -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -o CMakeFiles/Cling.dir/__/metautils/src/TMetaUtils.cxx.o -c /path/to/root6/work/root-9ab0642adeca5d3703783bdbfeebfca86ea22af9/core/metautils/src/TMetaUtils.cxx
Linking CXX shared library ../../lib/libCling.so
cd /path/to/root6/work/build/core/meta && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/Cling.dir/link.txt --verbose=ON
/opt/local/bin/clang++-mp-3.4  -pipe -Os -arch x86_64 -stdlib=libc++  -m64 -pipe -W -Wall -Woverloaded-virtual -fsigned-char -fno-common -Qunused-arguments -pthread -std=c++11 -Wno-deprecated-declarations -Wc++11-narrowing -Wsign-compare -Wsometimes-uninitialized -Wconditional-uninitialized -Wheader-guard -Warray-bounds -Wcomment -Wtautological-compare -Wstrncat-size -Wloop-analysis -Wbool-conversion -stdlib=libc++ -DR__HAVE_CONFIG -Wno-conditional-uninitialized -O2 -DNDEBUG -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -m64 -single_module -Wl,-dead_strip_dylibs  -L/opt/local/lib -Wl,-headerpad_max_install_names -arch x86_64 -compatibility_version 6.0.0 -current_version 6.3.3 -o ../../lib/libCling.6.03.03.so -install_name /opt/local/libexec/root6/lib/root/libCling.6.so CMakeFiles/Cling.dir/__/metautils/src/TMetaUtils.cxx.o CMakeFiles/MetaLLVM.dir/src/TCling.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingBaseClassInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingCallbacks.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingCallFunc.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingClassInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingDataMemberInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingMethodArgInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingMethodInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingTypedefInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingTypeInfo.cxx.o CMakeFiles/MetaLLVM.dir/src/TClingValue.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/BaseSelectionRule.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/ClassSelectionRule.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/VariableSelectionRule.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/RStl.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/Scanner.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/SelectionRules.cxx.o ../metautils/CMakeFiles/MetaUtilsLLVM.dir/src/XMLReader.cxx.o ../../interpreter/llvm/src/lib/libclingInterpreter.a ../../interpreter/llvm/src/lib/libclingMetaProcessor.a ../../interpreter/llvm/src/lib/libclingUtils.a /opt/local/lib/libncurses.dylib ../../lib/libRIO.6.03.03.so ../../interpreter/llvm/src/lib/libLLVMMCJIT.a ../../interpreter/llvm/src/lib/libLLVMOrcJIT.a ../../interpreter/llvm/src/lib/libLLVMExecutionEngine.a ../../interpreter/llvm/src/lib/libLLVMRuntimeDyld.a ../../interpreter/llvm/src/lib/libLLVMX86AsmParser.a ../../interpreter/llvm/src/lib/libLLVMX86CodeGen.a ../../interpreter/llvm/src/lib/libLLVMAsmPrinter.a ../../interpreter/llvm/src/lib/libLLVMSelectionDAG.a ../../interpreter/llvm/src/lib/libLLVMCodeGen.a ../../interpreter/llvm/src/lib/libLLVMTarget.a ../../interpreter/llvm/src/lib/libLLVMX86Desc.a ../../interpreter/llvm/src/lib/libLLVMX86AsmPrinter.a ../../interpreter/llvm/src/lib/libLLVMX86Utils.a ../../interpreter/llvm/src/lib/libLLVMX86Disassembler.a ../../interpreter/llvm/src/lib/libLLVMX86Info.a ../../interpreter/llvm/src/lib/libLLVMMCDisassembler.a ../../interpreter/llvm/src/lib/libclangCodeGen.a ../../interpreter/llvm/src/lib/libLLVMBitWriter.a ../../interpreter/llvm/src/lib/libLLVMipo.a ../../interpreter/llvm/src/lib/libLLVMVectorize.a ../../interpreter/llvm/src/lib/libLLVMInstrumentation.a ../../interpreter/llvm/src/lib/libLLVMObjCARCOpts.a ../../interpreter/llvm/src/lib/libLLVMScalarOpts.a ../../interpreter/llvm/src/lib/libLLVMInstCombine.a ../../interpreter/llvm/src/lib/libclangFrontend.a ../../interpreter/llvm/src/lib/libclangDriver.a ../../interpreter/llvm/src/lib/libLLVMOption.a ../../interpreter/llvm/src/lib/libclangParse.a ../../interpreter/llvm/src/lib/libclangSerialization.a ../../interpreter/llvm/src/lib/libclangSema.a ../../interpreter/llvm/src/lib/libclangEdit.a ../../interpreter/llvm/src/lib/libclangAnalysis.a ../../interpreter/llvm/src/lib/libclangAST.a ../../interpreter/llvm/src/lib/libclangLex.a ../../interpreter/llvm/src/lib/libclangBasic.a ../../interpreter/llvm/src/lib/libLLVMIRReader.a ../../interpreter/llvm/src/lib/libLLVMAsmParser.a ../../interpreter/llvm/src/lib/libLLVMLinker.a ../../interpreter/llvm/src/lib/libLLVMTransformUtils.a ../../interpreter/llvm/src/lib/libLLVMipa.a ../../interpreter/llvm/src/lib/libLLVMAnalysis.a ../../interpreter/llvm/src/lib/libLLVMProfileData.a ../../interpreter/llvm/src/lib/libLLVMObject.a ../../interpreter/llvm/src/lib/libLLVMMCParser.a ../../interpreter/llvm/src/lib/libLLVMMC.a ../../interpreter/llvm/src/lib/libLLVMBitReader.a ../../interpreter/llvm/src/lib/libLLVMCore.a ../../interpreter/llvm/src/lib/libLLVMSupport.a -lcurses -lpthread -lz -lm ../../lib/libThread.6.03.03.so ../../lib/libCore.6.03.03.so -Wl,-rpath,/opt/local/lib 
Undefined symbols for architecture x86_64:
  "_environ", referenced from:
      __ZL7ExecuteRN4llvm3sys11ProcessInfoENS_9StringRefEPPKcS6_PPKS3_jPNSt3__112basic_stringIcNSA_11char_traitsIcEENSA_9allocatorIcEEEE in libLLVMSupport.a(Program.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libCling.6.03.03.so] Error 1
make[2]: Leaving directory `/path/to/root6/work/build'
make[1]: *** [core/meta/CMakeFiles/Cling.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Linking CXX executable ../../bin/rootcling

Change History (6)

comment:1 Changed 9 years ago by mojca (Mojca Miklavec)

Description: modified (diff)

comment:2 Changed 9 years ago by mojca (Mojca Miklavec)

Cc: jeremyhu@… added

Dear Jeremy, I would like to ask for a bit of your help. Can you please look at the upstream bug report and see if you can clarify the situation? LLVM is part of ROOT 6 and it seems that I needed a patch of LLVM to make it compile.

(I also noticed that clang-3.7 recently failed to compile.)

comment:3 Changed 9 years ago by mojca (Mojca Miklavec)

Resolution: fixed
Status: newclosed

I now committed a naive patch in r135179 in order to get a working binary. I assume that ROOT developers will release a fix soon, then we can simply switch to a different commit.

I also noticed that the problem has already been fixed upstream as clarified on ROOT's bug tracker, so there's no need to do anything else.

comment:4 Changed 9 years ago by jeremyhu (Jeremy Huddleston Sequoia)

You can't use environ directly in libraries on OS X. See environ(7):

     Shared libraries and bundles don't have direct access to environ, which is only available to the
     loader ld(1) when a complete program is being linked.  The environment routines can still be used,
     but if direct access to environ is needed, the _NSGetEnviron() routine, defined in
     <crt_externs.h>, can be used to retrieve the address of environ at runtime.

comment:5 Changed 9 years ago by jeremyhu (Jeremy Huddleston Sequoia)

The || TARGET_OS_IPHONE should be removed in general.

Last edited 9 years ago by jeremyhu (Jeremy Huddleston Sequoia) (previous) (diff)

comment:6 in reply to:  5 Changed 9 years ago by mojca (Mojca Miklavec)

Jeremy, we now found the source of the problem (old LLVM version) and worked around the problem for now, with r135179.

Replying to jeremyhu@…:

The || TARGET_OS_IPHONE should be removed in general.

Can you please elaborate? Who should remove it and from where? Do you mean from our local MacPorts patch where I used #if !defined(__APPLE__) || TARGET_OS_IPHONE?

I can change

#if !defined(__APPLE__) || defined(TARGET_OS_IPHONE)

into

#if !defined(__APPLE__)

or even into

#if 0

given that we don't need to support iOS.

But this code is from LLVM: http://llvm.org/svn/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc

This is how it has been rewritten upstream (probably not that long ago):

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

#if defined(__APPLE__) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#define USE_NSGETENVIRON 1
#else
#define USE_NSGETENVIRON 0
#endif

#if !USE_NSGETENVIRON
  extern char **environ;
#else
#include <crt_externs.h> // _NSGetEnviron
#endif
#endif

Is that what you would expect or are there any problems left with that approach?

(I hope that ROOT developers will soon sync with the "latest" version of LLVM, so that the problem will no longer exist and we will no longer need to patch anything.)

Note: See TracTickets for help on using tickets.