MantisBT - CMake
View Issue Details
0015325CMakeCMakepublic2014-12-22 16:272015-06-01 08:38
David Coppa 
Brad King 
normalcrashalways
closedfixed 
x86_64Linux
CMake 3.1 
CMake 3.1.1CMake 3.1.1 
0015325: Regression building x265 using CMake 3.1 (Segmentation fault)
CMake 3.1 segfaults while building x265 using the ninja generator, "Unix Makefiles" generator is not affected.
This crash didn't happen with cmake-3.0.2 (same version of x265).

I have the same segfault on both Arch Linux and OpenBSD-current.

I've attached two files with the gdb output for both systems.

You can have a look at the source code for x265 here:
https://github.com/videolan/x265/tree/master/source/cmake [^]

$ cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr ../source/
-- cmake version 3.1.0
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detected x86 target processor
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Performing Test CC_HAS_NO_NARROWING
-- Performing Test CC_HAS_NO_NARROWING - Success
-- Performing Test CC_HAS_NO_ARRAY_BOUNDS
-- Performing Test CC_HAS_NO_ARRAY_BOUNDS - Success
-- Performing Test CC_HAS_FAST_MATH
-- Performing Test CC_HAS_FAST_MATH - Success
-- Performing Test CC_HAS_STACK_REALIGN
-- Performing Test CC_HAS_STACK_REALIGN - Success
-- Performing Test CC_HAS_FNO_EXCEPTIONS_FLAG
-- Performing Test CC_HAS_FNO_EXCEPTIONS_FLAG - Success
-- Found yasm: /usr/bin/yasm (found version "1.3.0")
-- Found Yasm 1.3.0 to build assembly primitives
-- x265 version 1.4
-- The ASM_YASM compiler identification is unknown
-- Found assembler: /usr/bin/yasm
-- Looking for strtok_r
-- Looking for strtok_r - found
-- Looking for include file getopt.h
-- Looking for include file getopt.h - found
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_ASM_YASM_COMPILE_OBJECT
Segmentation fault (core dumped)
Try building x265 using the ninja generator of CMake 3.1.0.
No tags attached.
? cmake31-x265-openbsd.out (32,623) 2014-12-22 16:27
https://public.kitware.com/Bug/file/5329/cmake31-x265-openbsd.out
? cmake31-x265-arch-linux.out (25,475) 2014-12-22 16:29
https://public.kitware.com/Bug/file/5330/cmake31-x265-arch-linux.out
log trace.log (2,469,776) 2014-12-22 17:56
https://public.kitware.com/Bug/file/5331/trace.log
Issue History
2014-12-22 16:27David CoppaNew Issue
2014-12-22 16:27David CoppaFile Added: cmake31-x265-openbsd.out
2014-12-22 16:29David CoppaFile Added: cmake31-x265-arch-linux.out
2014-12-22 17:56David CoppaFile Added: trace.log
2014-12-22 17:57David CoppaNote Added: 0037514
2014-12-22 18:25Brad KingStatusnew => acknowledged
2014-12-22 18:25Brad KingTarget Version => CMake 3.1.1
2014-12-22 18:25Brad KingDescription Updatedbug_revision_view_page.php?rev_id=1654#r1654
2014-12-22 18:32Brad KingNote Added: 0037515
2014-12-22 18:38Brad KingNote Added: 0037516
2014-12-22 18:42Brad KingNote Added: 0037517
2014-12-22 19:06Brad KingNote Added: 0037518
2014-12-23 08:19Brad KingNote Added: 0037521
2014-12-23 08:19Brad KingAssigned To => Brad King
2014-12-23 08:19Brad KingStatusacknowledged => resolved
2014-12-23 08:19Brad KingResolutionopen => fixed
2014-12-23 08:19Brad KingFixed in Version => CMake 3.1.1
2015-06-01 08:38Robert MaynardNote Added: 0038828
2015-06-01 08:38Robert MaynardStatusresolved => closed

Notes
(0037514)
David Coppa   
2014-12-22 17:57   
Also added log for cmake in trace mode.
(0037515)
Brad King   
2014-12-22 18:32   
Git bisects to:

 cmTarget: Compute languages from object libraries on demand.
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=042c1c83 [^]
(0037516)
Brad King   
2014-12-22 18:38   
Here is a fix to the crash:

 Ninja: Do not crash when CMAKE_<LANG>_COMPILE_OBJECT is empty
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9a13fcbf [^]

The error message about CMAKE_ASM_YASM_COMPILE_OBJECT not being available still appears with Ninja but not Makefiles.
(0037517)
Brad King   
2014-12-22 18:42   
Side note: I noticed x265's CMakeLists.txt file has:

if(POLICY CMP0025)
    cmake_policy(SET CMP0025 OLD) # report Apple's Clang as just Clang
endif()


Policies should never be set to OLD except in maintenance branches for existing project releases. The development branches should be fixed to deal with the policy's NEW behavior.
(0037518)
Brad King   
2014-12-22 19:06   
The x265 project should be fixed to enable ASM_YASM at the top level. Here is why:

The "x265-shared" target specifies "$<TARGET_OBJECTS:common>", and the "common" object library uses the ASM_YASM language. This means the "x265-shared" target uses the ASM_YASM language. This is not defined behavior because the ASM_YASM language is not enabled in the top-level directory containing the "x265-shared" target. This worked in earlier versions of CMake only by accident.

For reference, consider the case of enabling C at the top level and CXX in a subdirectory defining an object library. If a target in the top level uses objects from a C++ object library in the subdirectory then the C++ compiler front-end would be chosen to drive linking of the target. However, the CXX language is not enabled at the top level so no information is available to construct the link rule.
(0037521)
Brad King   
2014-12-23 08:19   
While x265 should still be fixed, we can make the existing case continue to work:

 Ninja: Generate rules only for languages compiled in a target
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fdbfcfdf [^]

 Tests: Test using objects from a language enabled in a subdirectory
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=07fc7b75 [^]
(0038828)
Robert Maynard   
2015-06-01 08:38   
Closing resolved issues that have not been updated in more than 4 months.