NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.32k stars 14.29k forks source link

Build failure: `opencv` with LTO #343123

Open ConnorBaker opened 2 months ago

ConnorBaker commented 2 months ago

Steps To Reproduce

Steps to reproduce the behavior:

  1. Correct the flag handling for enableLto, either manually or with #339619
  2. nix build -L .#opencv

Build log

Full log: https://gist.github.com/ConnorBaker/e48595af16c7c893a753ab625e5a78cd

Relevant snippet

[  7%] Linking CXX shared library ../../lib/libopencv_core.so
In member function 'allocate',
    inlined from 'allocate' at /build/source/modules/core/include/opencv2/core/utility.hpp:1013:1,
    inlined from '__ct ' at /build/source/modules/core/include/opencv2/core/utility.hpp:982:13,
    inlined from 'mixChannels' at /build/source/modules/core/src/channels.cpp:296:41:
/build/source/modules/core/include/opencv2/core/utility.hpp:1024:15: warning: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
 1024 |         ptr = new _Tp[_size];
      |               ^
/nix/store/x8rg4vhgd20i8vzykm1196f9qdb8klhh-gcc-13.3.0/include/c++/13.3.0/new: In function 'mixChannels':
/nix/store/x8rg4vhgd20i8vzykm1196f9qdb8klhh-gcc-13.3.0/include/c++/13.3.0/new:128:26: note: in a call to allocation function 'operator new []' declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^
In member function 'allocate',
    inlined from 'allocate' at /build/source/modules/core/include/opencv2/core/utility.hpp:1013:1,
    inlined from '__ct ' at /build/source/modules/core/include/opencv2/core/utility.hpp:982:13,
    inlined from 'mixChannels' at /build/source/modules/core/src/channels.cpp:329:41:
/build/source/modules/core/include/opencv2/core/utility.hpp:1024:15: warning: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
 1024 |         ptr = new _Tp[_size];
      |               ^
/nix/store/x8rg4vhgd20i8vzykm1196f9qdb8klhh-gcc-13.3.0/include/c++/13.3.0/new: In function 'mixChannels':
/nix/store/x8rg4vhgd20i8vzykm1196f9qdb8klhh-gcc-13.3.0/include/c++/13.3.0/new:128:26: note: in a call to allocation function 'operator new []' declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^
In member function 'allocate',
    inlined from 'allocate' at /build/source/modules/core/include/opencv2/core/utility.hpp:1013:1,
    inlined from '__ct ' at /build/source/modules/core/include/opencv2/core/utility.hpp:982:13,
    inlined from 'cvMixChannels' at /build/source/modules/core/src/convert_c.cpp:86:54:
/build/source/modules/core/include/opencv2/core/utility.hpp:1024:15: warning: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
 1024 |         ptr = new _Tp[_size];
      |               ^
/nix/store/x8rg4vhgd20i8vzykm1196f9qdb8klhh-gcc-13.3.0/include/c++/13.3.0/new: In function 'cvMixChannels':
/nix/store/x8rg4vhgd20i8vzykm1196f9qdb8klhh-gcc-13.3.0/include/c++/13.3.0/new:128:26: note: in a call to allocation function 'operator new []' declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans32.ltrans.o: in function `cv::(anonymous namespace)::ParallelLoopBodyWrapper::operator()(cv::Range const&) const':
<artificial>:(.text._ZNK2cv12_GLOBAL__N_123ParallelLoopBodyWrapperclERKNS_5RangeE+0x2bb): undefined reference to `__itt_relation_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::utils::trace::details::Region::Impl::~Impl()':
<artificial>:(.text._ZN2cv5utils5trace7details6Region4ImplD2Ev+0x33): undefined reference to `__itt_id_destroy_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::TLSData<cv::(anonymous namespace)::ThreadID>::createDataInstance() const':
<artificial>:(.text._ZNK2cv7TLSDataINS_12_GLOBAL__N_18ThreadIDEE18createDataInstanceEv+0x4b): undefined reference to `__itt_thread_set_name_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::utils::trace::details::isITTEnabled() [clone .lto_priv.0]':
<artificial>:(.text._ZN2cv5utils5trace7detailsL12isITTEnabledEv.lto_priv.0+0x62): undefined reference to `__itt_api_version_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7detailsL12isITTEnabledEv.lto_priv.0+0x7a): undefined reference to `__itt_domain_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::utils::trace::details::Region::Impl::enterRegion(cv::utils::trace::details::TraceManagerThreadLocal&)':
<artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl11enterRegionERNS2_23TraceManagerThreadLocalE+0x17b): undefined reference to `__itt_task_begin_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::utils::trace::details::Region::Impl::leaveRegion(cv::utils::trace::details::TraceManagerThreadLocal&)':
<artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl11leaveRegionERNS2_23TraceManagerThreadLocalE+0x7a): undefined reference to `__itt_metadata_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl11leaveRegionERNS2_23TraceManagerThreadLocalE+0x89): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl11leaveRegionERNS2_23TraceManagerThreadLocalE+0xe9): undefined reference to `__itt_task_end_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl11leaveRegionERNS2_23TraceManagerThreadLocalE+0x205): undefined reference to `__itt_metadata_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl11leaveRegionERNS2_23TraceManagerThreadLocalE+0x218): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::utils::trace::details::Region::LocationExtraData::LocationExtraData(cv::utils::trace::details::Region::LocationStaticStorage const&)':
<artificial>:(.text._ZN2cv5utils5trace7details6Region17LocationExtraDataC2ERKNS3_21LocationStaticStorageE+0x39): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region17LocationExtraDataC2ERKNS3_21LocationStaticStorageE+0xe5): undefined reference to `__itt_api_version_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region17LocationExtraDataC2ERKNS3_21LocationStaticStorageE+0xfd): undefined reference to `__itt_domain_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans40.ltrans.o: in function `cv::utils::trace::details::Region::Impl::registerRegion(cv::utils::trace::details::TraceManagerThreadLocal&)':
<artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl14registerRegionERNS2_23TraceManagerThreadLocalE+0x5f): undefined reference to `__itt_id_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl14registerRegionERNS2_23TraceManagerThreadLocalE+0xdd): undefined reference to `__itt_api_version_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details6Region4Impl14registerRegionERNS2_23TraceManagerThreadLocalE+0xf5): undefined reference to `__itt_domain_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans41.ltrans.o: in function `cv::utils::trace::details::TraceManager::TraceManager()':
<artificial>:(.text._ZN2cv5utils5trace7details12TraceManagerC2Ev+0x4eb): undefined reference to `__itt_region_begin_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details12TraceManagerC2Ev+0x4fd): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans41.ltrans.o: in function `cv::utils::trace::details::TraceManager::~TraceManager()':
<artificial>:(.text._ZN2cv5utils5trace7details12TraceManagerD2Ev+0x953): undefined reference to `__itt_region_end_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans41.ltrans.o: in function `cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, char const*)':
<artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEPKc+0x82): undefined reference to `__itt_metadata_str_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEPKc+0x14b): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans41.ltrans.o: in function `cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, int)':
<artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEi+0x6e): undefined reference to `__itt_metadata_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEi+0x139): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans41.ltrans.o: in function `cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, long)':
<artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEl+0x6f): undefined reference to `__itt_metadata_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEl+0x139): undefined reference to `__itt_string_handle_create_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: /build/ccn78tx5.ltrans41.ltrans.o: in function `cv::utils::trace::details::traceArg(cv::utils::trace::details::TraceArg const&, double)':
<artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEd+0x70): undefined reference to `__itt_metadata_add_ptr__3_0'
/nix/store/81xsp348yfgmaan9r5055mcdjfw7a8wc-binutils-2.42/bin/ld: <artificial>:(.text._ZN2cv5utils5trace7details8traceArgERKNS2_8TraceArgEd+0x139): undefined reference to `__itt_string_handle_create_ptr__3_0'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/build.make:1842: lib/libopencv_core.so.4.9.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:3363: modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

Additional context

Add any other context about the problem here.

Originally added in #221370, the ability to build OpenCV with LTO is controlled by the enableLto setting. However, the corresponding flag passed to CMake did not actually enable or disable LTO!

In #339619, the flag handling was reworked (moving away from a custom helper function and to the new cmake* family of functions in lib) and this issue was discovered.

Notify maintainers

@basvandijk

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[connorbaker@nixos-desktop:~/nixpkgs]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.12, NixOS, 24.11 (Vicuna), 24.11.20240703.9f4128e`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.23.1`
 - nixpkgs: `/nix/store/dk2rpyb6ndvfbf19bkb2plcz5y3k8i5v-source`

Add a :+1: reaction to issues you find important.

ConnorBaker commented 2 months ago

Relevant: https://github.com/NixOS/nixpkgs/pull/339619#issuecomment-2357541348