Opened 7 years ago

Closed 6 years ago

#54242 closed defect (wontfix)

clang-3.8 build fails on 10.5 PPC due to fatal error: lipo: specifed architecture in libclang_rt.10.4.a does not match its cputype -- and workaround that allows build to succeed

Reported by: kencu (Ken) Owned by: jeremyhu (Jeremy Huddleston Sequoia)
Priority: Normal Milestone:
Component: ports Version:
Keywords: powerpc Cc: larryv (Lawrence Velázquez)
Port: clang-3.8

Description

During the build of clang-3.8 on 10.5 PPC, the following error is noted:

[ 14%] Generating ../../../../lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a
cd /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/projects/compiler-rt/lib/builtins && /opt/local/bin/cmake -E make_directory /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/./lib/clang/3.8.1/lib/darwin
cd /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/projects/compiler-rt/lib/builtins && lipo -output /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/./lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a -create -arch i386 /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_i386_10.4.a -arch x86_64 /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_x86_64_10.4.a
fatal error: lipo: specifed architecture type (i386) for file (/opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_i386_10.4.a) does not match its cputype (18) and cpusubtype (0) (should be cputype (7) and cpusubtype (3))

This appears to be due to an error in the cmake build script for this library. See below for more analysis and a workaround that allows the build to succeed.

Attachments (3)

clang_rt on PPC fails to configure -- CMakeError.log (73.1 KB) - added by kencu (Ken) 7 years ago.
error log when cmake tries to test-compile ppc code during configuration
proj-compilerrt-lib-builtins- alternate incomplete CMakeLists.txt (2.5 KB) - added by kencu (Ken) 7 years ago.
alternate cmake build script for compiler_rt-lib-builtins that builds single-arch library
error in clang-3.8 cmake configure (959 bytes) - added by kencu (Ken) 7 years ago.
error noted during configuration of clang-3.8

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 years ago by kencu (Ken)

First of all, for anyone who would like to duplicate this build, to get to this point, a few preliminary steps are needed, as outlined here 53184. Also, if I can fix this one last issue, I'll make available a port file that installs llvm-3.8 and clang-3.8 automatically on 10.5 PPC, as there are a few tiny adjustments needed during the PPC build. If you want to see the current Portfile and patch tree, it is in <http://github.com/kencu/LeopardPorts>

During configuration, this is noted:

CMake Warning at projects/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake:33 (message):
  Detecting supported architectures from 'ld -v' failed.  Returning default
  set.
Call Stack (most recent call first):
  projects/compiler-rt/cmake/config-ix.cmake:347 (darwin_get_toolchain_supported_archs)
  projects/compiler-rt/CMakeLists.txt:206 (include)


-- Toolchain supported arches: i386;x86_64;ppc;ppc64;armv7;armv7s;arm64
-- Finding valid architectures for osx...
-- OSX supported arches: 
-- Finding valid architectures for 10.4...
-- OSX 10.4 supported arches: i386;x86_64;ppc;ppc64
-- Compiler-RT supported architectures: 
CMake Warning at projects/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake:216 (message):
  Not generating lipo target for clang_rt.cc_kext because no input libraries
  exist.
Call Stack (most recent call first):
  projects/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake:334 (darwin_lipo_libs)
  projects/compiler-rt/lib/builtins/CMakeLists.txt:364 (darwin_add_builtin_libraries)


CMake Warning at projects/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake:216 (message):
  Not generating lipo target for clang_rt.osx because no input libraries
  exist.

And this generated file from cmake: ./build/projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.10.4.dir/build.make contains references to i386 and x86_64:

lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a: lib/libclang_rt.builtins_i386_10.4.a
lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a: lib/libclang_rt.builtins_x86_64_10.4.a
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating ../../../../lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a"
	cd /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/projects/compiler-rt/lib/builtins && /opt/local/bin/cmake -E make_directory /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/./lib/clang/3.8.1/lib/darwin
	cd /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/projects/compiler-rt/lib/builtins && lipo -output /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/./lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a -create -arch i386 /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_i386_10.4.a -arch x86_64 /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_x86_64_10.4.a

which leads to the failure line noted above.

The first issue is that both of the generated libclang_rt.builtins* files are ppc (neither is ppc64), and neither is the i386 or x86_64 code they are labelled as being, but that's not too important as for now we're only after ppc anyway.

$ cd `port work clang-3.8`
$ lipo -info ./build/lib/libclang_rt.builtins_i386_10.4.a
input file ./build/lib/libclang_rt.builtins_i386_10.4.a is not a fat file
Non-fat file: ./build/lib/libclang_rt.builtins_i386_10.4.a is architecture: ppc
$ lipo -info ./build/lib/libclang_rt.builtins_x86_64_10.4.a
input file ./build/lib/libclang_rt.builtins_x86_64_10.4.a is not a fat file
Non-fat file: ./build/lib/libclang_rt.builtins_x86_64_10.4.a is architecture: ppc

The second issue is that the -arch for the libclang_rt.builtins_i386_10.4.a has to be ppc.

To generate the libclang_rt.builtins library for ppc, edit the ./build/projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.10.4.dir/build.make

and change this line (note I'm in a custom repo here -- your file path will be a bit different):

cd /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/projects/compiler-rt/lib/builtins && lipo -output /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/./lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a -create -arch i386 /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_i386_10.4.a -arch x86_64 /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_x86_64_10.4.a

to this, updating the arch type from -create -arch i386 to -create -arch ppc (leave the file name alone, although it's incorrect), and deleting the second arch (as it is also ppc, and we only want one ppc architecture):

cd /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/projects/compiler-rt/lib/builtins && lipo -output /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/./lib/clang/3.8.1/lib/darwin/libclang_rt.10.4.a -create -arch ppc /opt/local/var/macports/build/_opt_LeopardPorts_lang_llvm-3.8/clang-3.8/work/build/lib/libclang_rt.builtins_i386_10.4.a
Version 5, edited 7 years ago by kencu (Ken) (previous) (next) (diff)

comment:2 Changed 7 years ago by mf2k (Frank Schima)

Cc: larryv added; jeremyhu removed
Owner: set to jeremyhu
Status: newassigned

comment:3 Changed 7 years ago by kencu (Ken)

The cmake logic in this file appears to contain the relevant code:

work/llvm-3.8.1.src/projects/compiler-rt/cmake/config-ix.cmake

It's quite a complex process for building a multi-arch runtime, and would not be trivial to fix. Far easier would be to just rewrite a new cmake script and use it for ppc to build the library.

Last edited 7 years ago by kencu (Ken) (previous) (diff)

comment:4 Changed 7 years ago by kencu (Ken)

-- this comment deleted as no longer helpful --

Last edited 7 years ago by kencu (Ken) (previous) (diff)

comment:5 Changed 7 years ago by kencu (Ken)

The cmake script that manages the building of libclang_rt.10.4.a looks at the supported arches to test

-- OSX 10.4 supported arches: i386;x86_64;ppc;ppc64

and then tries to run a test-compile with each using the build system. This build of clang-3.8 on 10.5 PPC is bootstrapping with gcc6 (no other choice). So with this gcc6 macports configuration, all the x86 code fails to build, and the system tries to build the ppc and ppc64 code. But all these test compiles fail to build as well for some reason (Cmake error log attached), soit defaults to i386 and x86_64. And herein comes the "lucky" quirk - when gcc6 on ppc gets asked to build -arch i386, it says it can't and then builds it -arch ppc instead. So that is how we wind up getting code out.

Last edited 7 years ago by kencu (Ken) (previous) (diff)

Changed 7 years ago by kencu (Ken)

error log when cmake tries to test-compile ppc code during configuration

Changed 7 years ago by kencu (Ken)

alternate cmake build script for compiler_rt-lib-builtins that builds single-arch library

Changed 7 years ago by kencu (Ken)

error noted during configuration of clang-3.8

comment:6 Changed 6 years ago by kencu (Ken)

Resolution: wontfix
Status: assignedclosed

closing this off, as it's not a fixable MacPorts item. For those interested, progress on clang-3.8+ on PPC is tracked here <https://trac.macports.org/ticket/53184>

Note: See TracTickets for help on using tickets.