AnacondaRecipes / aggregate

BSD 3-Clause "New" or "Revised" License
32 stars 43 forks source link

building llvm compilers on mac #10

Closed loriab closed 7 years ago

loriab commented 7 years ago

I'm attempting to build the clang toolchain in an effort to add omp.h (at @msarahan's advice). A couple issues so far:

  1. I had to change the hash for the main llvm download as below. There's some support for the new hash at here, but I'm worried that I'm building from different source than the recipe is expecting
-{% set clang_llvm_bin_sha256 = '5ef4f1f72d0fe4cf03d8eaefb972b4d24219da67124a869ae75e3a6aeb1578f6' %}
+#{% set clang_llvm_bin_sha256 = '5ef4f1f72d0fe4cf03d8eaefb972b4d24219da67124a869ae75e3a6aeb1578f6' %}
+{% set clang_llvm_bin_sha256 = '5f697801a46239c04251730b7ccccd3ebbacb9043ad381a061ae6812409e9eae' %}
  1. (the blocking problem) In a link line I get some unresolved symbols. Full cmake error log (~/toolchainconda/conda-bld/llvm-suite_1507343700837/work/llvm_tapi_build/CMakeFiles/CMakeError.log) is here. I'm not requesting any grand investigation, just wondering if this error rings any bells or even if my conda-build command (further below) is wrong. Thanks for any help!
/usr/bin/clang++ --sysroot /Users/loriab/linux/toolchainconda/conda-bld/llvm-suite_1507395752745/work/bootstrap/MacOSX10.9.sdk -std=c++11 -o ld src/ld/ld.o src/ld/Options.o src/ld/InputFiles.o src/ld/Snapshot.o src/ld/SymbolTable.o src/ld/Resolver.o src/ld/OutputFile.o src/ld/passes/branch_island.o src/ld/passes/branch_shim.o src/ld/passes/code_dedup.o src/ld/passes/compact_unwind.o src/ld/passes/dtrace_dof.o src/ld/passes/dylibs.o src/ld/passes/got.o src/ld/passes/huge.o src/ld/passes/objc.o src/ld/passes/order.o src/ld/passes/bitcode_bundle.o src/ld/passes/stubs/stubs.o src/ld/passes/tlvp.o src/ld/parsers/archive_file.o src/ld/parsers/lto_file.o src/ld/parsers/macho_dylib_file.o src/ld/parsers/macho_relocatable_file.o src/ld/parsers/opaque_section_file.o src/ld/parsers/textstub_dylib_file.o src/ld/debugline.o -L/Users/loriab/linux/toolchainconda/conda-bld/llvm-suite_1507395752745/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib -L/Users/loriab/linux/toolchainconda/conda-bld/llvm-suite_1507395752745/work/prefix/lib -multiply_defined suppress -Wl,-rpath,@loader_path/../lib/ -L../libstuff -lstuff   -lpthread -lLTO -ltapi -lxar /usr/lib/libcrypto.dylib
Undefined symbols for architecture x86_64:
  "_UCNV_FROM_U_CALLBACK_STOP_58", referenced from:
      _openIcuConverter in libxar.a(encoding.o)
  "_UCNV_TO_U_CALLBACK_STOP_58", referenced from:
      _openIcuConverter in libxar.a(encoding.o)
  "_ucnv_close_58", referenced from:
      _xmlFindCharEncodingHandler in libxar.a(encoding.o)
      _openIcuConverter in libxar.a(encoding.o)
      _xmlCharEncCloseFunc in libxar.a(encoding.o)
  "_ucnv_convertEx_58", referenced from:
      _xmlCharEncFirstLineInt in libxar.a(encoding.o)
      _xmlCharEncFirstLineInput in libxar.a(encoding.o)
      _xmlCharEncInput in libxar.a(encoding.o)
      _xmlCharEncInFunc in libxar.a(encoding.o)
      _xmlCharEncOutput in libxar.a(encoding.o)
      _xmlCharEncOutFunc in libxar.a(encoding.o)
      _xmlByteConsumed in libxar.a(encoding.o)
      ...
  "_ucnv_open_58", referenced from:
      _openIcuConverter in libxar.a(encoding.o)
  "_ucnv_setFromUCallBack_58", referenced from:
      _openIcuConverter in libxar.a(encoding.o)
  "_ucnv_setToUCallBack_58", referenced from:
      _openIcuConverter in libxar.a(encoding.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[1]: *** [ld] Error 1

General conditions:

msarahan commented 7 years ago

Do you have the 10.9 sdk installed in /opt?

See CONDA_BUILD_SYSROOT in conda _build_config.yaml for the exact location. You can get this from many different places. One is https://github.com/phracker/MacOSX-SDKs

We currently can't just provide packages due to licensing concerns. Thanks Apple.

loriab commented 7 years ago

You're right, I didn't have the sdk installed. Did so, and adjusted conda_build_config.yaml location accordingly. Incidentally, there was a full 10.9 sdk installed to miniconda/conda-bld/llvm-suite_1507415239196/work/bootstrap/MacOSX10.9.sdk/System at conda-build time that file-structure-wise is identical to the github sdk 10.9 repo.

Unfortunately, error was still the same. "Fixed" it by adding an extra library to cctools_build/ld64/Makefile LTO_LIBS = -lxml2 -lpthread -lLTO. Also had to edit cctools_build_libtool/ld64/Makefile to add $(top_srcdir)/../prefix to MYINCLUDES & MYLDFLAGS so that it could find tapi/tapi.h and ltapi (though this was during a hand-makeing jaunt and hasn't been confirmed in a linear compilation sequence).

The next blocking error is the signature problem below. In occurs in cctools_build_final and at that time, it has already successfully built the file twice (immediately below). The patch that toggles qsort_r signatures is present in the source, so this is clearly an issue that's being managed by the build. Any notion why macho_relocatable_file.cpp could be failing to build only for "_final" (of "", "_libtool", & "_final")?

>>> cctools_build_final/ld64$ find ../../ -name "macho_relocatable_file*"
../..//cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp
../..//cctools/ld64/src/ld/parsers/macho_relocatable_file.h
../..//cctools_build/ld64/src/ld/parsers/macho_relocatable_file.o
../..//cctools_build_libtool/ld64/src/ld/parsers/macho_relocatable_file.o
/Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/work/prefix/bin/clang++ --sysroot /Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/work/bootstrap/MacOSX10.9.sdk   -DHAVE_CONFIG_H  -DDEBUG -DBINDIR="\"/Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/work/prefix/bin\"" -DLDPROG="\"x86_64-apple-darwin13.4.0-ld_classic\"" -DASPROG="\"x86_64-apple-darwin13.4.0-as\"" -DLTO_SUPPORT -DALL_SUPPORTED_ARCHS="\"armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)\"" -DBITCODE_XAR_VERSION="\"1.0\"" -DSUPPORT_APPLE_TV=1 -DSUPPORT_ARCH_x86_64=1 -DSUPPORT_ARCH_x86_64h=1 -DSUPPORT_ARCH_i386=1 -DSUPPORT_ARCH_armv4t=1 -DSUPPORT_ARCH_armv5=1 -DSUPPORT_ARCH_armv6=1 -DSUPPORT_ARCH_armv7=1 -DSUPPORT_ARCH_armv7f=1 -DSUPPORT_ARCH_armv7k=1 -DSUPPORT_ARCH_armv7s=1 -DSUPPORT_ARCH_armv6m=1 -DSUPPORT_ARCH_armv7m=1 -DSUPPORT_ARCH_armv7em=1 -DSUPPORT_ARCH_armv8=1 -DSUPPORT_ARCH_arm64=1 -DSUPPORT_ARCH_arm64v8=1  -I../../cctools/ld64/include -I../../cctools/ld64/Readers -I../../cctools/ld64/Writers -I../include -I../../cctools/include -I../../cctools/ld64/src/ld -I../../cctools/ld64/src/abstraction -I../../cctools/ld64/src/ld/parsers  -include ../include/config.h  -I/Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/include -mmacosx-version-min=10.9 -D__DARWIN_UNIX03 -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/work/prefix/include -fno-builtin-round -fno-builtin-trunc -mdynamic-no-pic -I/Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/include -mmacosx-version-min=10.9 -D__DARWIN_UNIX03 -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS  -std=c++11 -c -o src/ld/parsers/macho_relocatable_file.o ../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp
clang-4.0: warning: argument unused during compilation: '--sysroot=/Users/github/toolchainconda/conda-bld/llvm-suite_1507415239196/work/bootstrap/MacOSX10.9.sdk' [-Wunused-command-line-argument]
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:2363:2: error: cannot initialize a parameter of type 'void *' with an rvalue of type 'int (*)(const void *, const void *, void *)'
        QSORT_R(array, _machOSectionsCount, sizeof(uint32_t), this, sectionIndexSorter);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:59:64: note: expanded from macro 'QSORT_R'
 #define QSORT_R(_a,_b,_c,_vp,_fn) ::qsort_r((_a), (_b), (_c), (int(*)(const void*, const void*, void*))(_fn), (_vp))
                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:1762:8: note: in instantiation of member function 'mach_o::relocatable::Parser<x86_64>::makeSortedSectionsArray' requested here
        this->makeSortedSectionsArray(sortedSectionIndexes);
              ^
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:1006:26: note: in instantiation of member function 'mach_o::relocatable::Parser<x86_64>::parse' requested here
                                                                                                                                return p.parse(opts);
                                                                                                                                         ^
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:7841:49: note: in instantiation of member function 'mach_o::relocatable::Parser<x86_64>::parse' requested here
                                return mach_o::relocatable::Parser<x86_64>::parse(fileContent, fileLength, path, modTime, ordinal, opts);
                                                                            ^
/Users/github/Git/MacOSX-SDKs/MacOSX10.9.sdk/usr/include/stdlib.h:299:45: note: passing argument to parameter here
void     qsort_r(void *, size_t, size_t, void *,
                                               ^
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:2461:2: error: cannot initialize a parameter of type 'void *' with an rvalue of type 'int (*)(const void *, const void *, void *)'
        QSORT_R(array, _symbolsInSections, sizeof(uint32_t), &extra, &symbolIndexSorter);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../cctools/ld64/src/ld/parsers/macho_relocatable_file.cpp:59:64: note: expanded from macro 'QSORT_R'
 #define QSORT_R(_a,_b,_c,_vp,_fn) ::qsort_r((_a), (_b), (_c), (int(*)(const void*, const void*, void*))(_fn), (_vp))
                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mingwandroid commented 7 years ago

I probably would not attempt to build these compilers on any macOS other than 10.9. You'll be in for a tough time if you do. I did try once but it's kind of not worth it since you want to guarantee the compilers work on and generate code for 10.9 and building them on anything else risks breaking that guarantee (same as how the new gcc compilers were built on CentOS6).

The macOS compilers built with this recipe on conda defaults have omp.h (it is in the llvm-openmp package as is lib/libomp.dylib):

tar -tf /opt/conda/pkgs/llvm-openmp-4.0.1-hda82c8b_0.tar.bz2 
info/hash_input_files
info/files
info/index.json
info/paths.json
info/about.json
info/hash_input.json
info/LICENSE.txt
info/git
info/test/test_time_dependencies.json
info/recipe/install-openmp.sh
info/recipe/conda_build_config.yaml
info/recipe/meta.yaml
lib/clang/4.0.1/include/omp.h
info/recipe/build.sh
lib/libomp.dylib

I also tested these just now for building r-data.table which requires OpenMP (https://github.com/Rdatatable/data.table/wiki/Installation#openmp-enabled-compiler-for-mac)

in build.sh:

if [[ ${HOST} =~ .*darwin.* ]]; then
  echo "CC=${CC} -fopenmp" > ~/.R/Makevars
fi
$R CMD INSTALL --build .
if [[ ${HOST} =~ .*darwin.* ]]; then
  rm -rf ~/.R
fi
loriab commented 7 years ago

You did warn us :-)

Thanks very much, @mingwandroid. Added llvm-openmp to build and runtime, and my original package built like a charm. Now to impose -fopenmp=iomp5 ...

Warning to future thread readers: to build clang packages, really must be on 10.9. Even with 10.9 sdk, neither 10.10 nor 10.11 will do.

mingwandroid commented 7 years ago

I can probably fix that but perhaps only if these compilers are used as a build dependency and that's cyclic and that won't work either so we'd need a hack.

Or maybe I can fix it without needing these compilers but it's unlikely to be looked at any time soon.

loriab commented 7 years ago

No cause to "fix" them (allow compilation away from 10.9) on my part. I was only trying to build the compilers so that I could install an omp.h, and you solved that by alerting me to package llvm-openmp.

nehaljwani commented 6 years ago

All of the missing symbols that are being reported for libxar.a come from libicuuc.58 .

nehaljwani commented 6 years ago

And the requirement on libicuuc is coming from the statically linked libxml2.a in libxar.a

nehaljwani commented 6 years ago

If I make sure that the build uses https://repo.anaconda.com/pkgs/main/osx-64/xar-1.6.1-h50205bb_0.tar.bz2 , then the link error goes away.