race condition with target_objects

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

race condition with target_objects

Juan E. Sanchez
Hi,

I am getting a race condition when I do a parallel build.

Having an OBJECT library in one directory:
ADD_LIBRARY(symdiff_objects OBJECT ${CXX_SRCS} ${MC_SRCS})
set_property(TARGET symdiff_objects PROPERTY POSITION_INDEPENDENT_CODE ON)

And then having that object library being used in another directory:
TARGET_LINK_LIBRARIES (symdiff_tcl $<TARGET_OBJECTS:symdiff_objects>
${TCL_ARCHIVE})

Results in this error with a parallel build:
  15%] Building CXX object
src/engine/CMakeFiles/symdiff_static.dir/EquationObject.o
make[2]: *** No rule to make target
`src/engine/CMakeFiles/symdiff_objects.dir/EquationObject.o', needed by
`src/tclcomp/libsymdifftcl.dylib'.  Stop.
make[2]: *** Waiting for unfinished jobs....

Serial builds work fine.  How do I tell cmake to wait?  This is cmake
3.9.0-rc4 running on os x with the makefile generator.

Regards,

Juan
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

race condition with target_objects

Brad King
On 06/25/2018 03:09 PM, Juan E. Sanchez wrote:
> ADD_LIBRARY(symdiff_objects OBJECT ${CXX_SRCS} ${MC_SRCS})
> set_property(TARGET symdiff_objects PROPERTY POSITION_INDEPENDENT_CODE ON)
> TARGET_LINK_LIBRARIES (symdiff_tcl $<TARGET_OBJECTS:symdiff_objects> ${TCL_ARCHIVE})
>
> How do I tell cmake to wait?

Strange, our test suite covers that and the dependency appears.
The TARGET_OBJECTS generator expression evaluation has special
logic to forward the target-level dependency.

> This is cmake 3.9.0-rc4

Please try a more recent version, perhaps an actual release.

-Brad
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: race condition with target_objects

Juan E. Sanchez
Hi,

The likely problem is that the symdiff_objects and the symdiff_tcl are
in side-by-side directories.  They are both added using ADD_SUBDIRECTORY
one level up.  If I put symdiff_python before symdiff_tcl, then that
target will fail.  Please fix your Makefile generator.

Regards,

Juan


On 6/26/18 10:58 AM, Brad King wrote:

> On 06/25/2018 03:09 PM, Juan E. Sanchez wrote:
>> ADD_LIBRARY(symdiff_objects OBJECT ${CXX_SRCS} ${MC_SRCS})
>> set_property(TARGET symdiff_objects PROPERTY POSITION_INDEPENDENT_CODE ON)
>> TARGET_LINK_LIBRARIES (symdiff_tcl $<TARGET_OBJECTS:symdiff_objects> ${TCL_ARCHIVE})
>>
>> How do I tell cmake to wait?
>
> Strange, our test suite covers that and the dependency appears.
> The TARGET_OBJECTS generator expression evaluation has special
> logic to forward the target-level dependency.
>
>> This is cmake 3.9.0-rc4
>
> Please try a more recent version, perhaps an actual release.
>
> -Brad
>

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: race condition with target_objects

Brad King
On 06/26/2018 01:32 PM, Juan E. Sanchez wrote:
> The likely problem is that the symdiff_objects and the symdiff_tcl are
> in side-by-side directories.  They are both added using ADD_SUBDIRECTORY
> one level up.  If I put symdiff_python before symdiff_tcl, then that
> target will fail.  Please fix your Makefile generator.

Target dependencies are agnostic to the directories.  The ordering at
most matters for serial builds of independent targets.

While trying to reproduce this in a simple example I found the problem:

```
TARGET_LINK_LIBRARIES (symdiff_tcl $<TARGET_OBJECTS:symdiff_objects> ${TCL_ARCHIVE})
```

That is not the way to reference an object library.

The documentation:

  https://cmake.org/cmake/help/v3.12/manual/cmake-buildsystem.7.html#object-libraries

shows that `$<TARGET_OBJECTS:...>` belongs in the list of *sources*,
not linked libraries.  You should be using:

```
add_library(symdiff_tcl SHARED ... $<TARGET_OBJECTS:symdiff_objects>)
```

-Brad
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: race condition with target_objects

Juan E. Sanchez
Hello Brad,

Thanks for finding the issue.  I had simply replaced the shared library
I was using with the name of the TARGET_OBJECTS generator.

The shared objects are great.  It helps me bypass Apple security issues
when a system interpreter loads a shared library, which loads another
shared library.

Regards,

Juan

On 6/26/18 1:34 PM, Brad King wrote:

> On 06/26/2018 01:32 PM, Juan E. Sanchez wrote:
>> The likely problem is that the symdiff_objects and the symdiff_tcl are
>> in side-by-side directories.  They are both added using ADD_SUBDIRECTORY
>> one level up.  If I put symdiff_python before symdiff_tcl, then that
>> target will fail.  Please fix your Makefile generator.
>
> Target dependencies are agnostic to the directories.  The ordering at
> most matters for serial builds of independent targets.
>
> While trying to reproduce this in a simple example I found the problem:
>
> ```
> TARGET_LINK_LIBRARIES (symdiff_tcl $<TARGET_OBJECTS:symdiff_objects> ${TCL_ARCHIVE})
> ```
>
> That is not the way to reference an object library.
>
> The documentation:
>
>    https://cmake.org/cmake/help/v3.12/manual/cmake-buildsystem.7.html#object-libraries
>
> shows that `$<TARGET_OBJECTS:...>` belongs in the list of *sources*,
> not linked libraries.  You should be using:
>
> ```
> add_library(symdiff_tcl SHARED ... $<TARGET_OBJECTS:symdiff_objects>)
> ```
>
> -Brad
>

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake