Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 830185

Summary: media-libs/opencv-4.5.5 fails to build due to "error: ‘_mm_insert_epi64’ was not declared in this scope; did you mean ‘_mm_insert_epi8’?"
Product: Gentoo Linux Reporter: Iade Gesso <iade.gesso>
Component: Current packagesAssignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it <maintainer-needed>
Status: RESOLVED FIXED    
Severity: normal CC: espinafre, feinorgh, jstein, leonchik1976, rich, sam, scott, sven.eden
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
URL: https://github.com/opencv/opencv/issues/21597
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: build.log and the emerge --info output
Fix missing ‘_mm_insert_epi64’ function in 32bit build

Description Iade Gesso 2021-12-28 20:12:43 UTC
When I try to build the latest 4.5.5 version I get an error that tells me about an undeclared function. In particular I get this message:
  error: ‘_mm_insert_epi64’ was not declared in this scope; did you mean ‘_mm_insert_epi8’?

In the attachments the build.log and the emerge --info output.


Iade

Reproducible: Always

Steps to Reproduce:
1. Build opencv 4.5.5
2.
3.
Actual Results:  
Build process fails.
Comment 1 Iade Gesso 2021-12-28 20:13:14 UTC
Created attachment 760683 [details]
build.log and the emerge --info output
Comment 2 Sven Eden 2021-12-29 15:45:59 UTC
In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:

    429 #ifdef __x86_64__
    430 #define _mm_insert_epi64(D, S, N)                                       \
    431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),         \
    432                                           (long long)(S), (int)(N)))
    433 #endif

And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so the function really isn't there.
Comment 3 Iade Gesso 2021-12-29 15:48:22 UTC
(In reply to Sven Eden from comment #2)
> In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:
> 
>     429 #ifdef __x86_64__
>     430 #define _mm_insert_epi64(D, S, N)                                   
> \
>     431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),     
> \
>     432                                           (long long)(S), (int)(N)))
>     433 #endif
> 
> And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so
> the function really isn't there.

So... the issue can be in the GCC 11.2.1 package... but it appeared just now because previous OpenCV versions doesn't need that function?


Iade
Comment 4 Iade Gesso 2021-12-29 16:42:54 UTC
(In reply to Sven Eden from comment #2)
> In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:
> 
>     429 #ifdef __x86_64__
>     430 #define _mm_insert_epi64(D, S, N)                                   
> \
>     431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),     
> \
>     432                                           (long long)(S), (int)(N)))
>     433 #endif
> 
> And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so
> the function really isn't there.

Anyway... the same problem appears even if I build OpenCV 4.5.5 using the old GCC 8.5.x...


Iade
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-12-29 20:19:40 UTC
Such errors are usually nothing to do with gcc version and are to do with the package forcing extensions you don't have.
Comment 6 Sven Eden 2021-12-31 09:07:28 UTC
(In reply to Iade Gesso from comment #3)
> (In reply to Sven Eden from comment #2)
> > In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:
> > 
> >     429 #ifdef __x86_64__
> >     430 #define _mm_insert_epi64(D, S, N)                                   
> > \
> >     431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),     
> > \
> >     432                                           (long long)(S), (int)(N)))
> >     433 #endif
> > 
> > And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so
> > the function really isn't there.
> 
> So... the issue can be in the GCC 11.2.1 package... but it appeared just now
> because previous OpenCV versions doesn't need that function?

No. It is, because 'modules/gapi/src/backends/fluid/gfluidcore_simd_sse41.hpp checks against __i386__ only at one point (line 238), and at the other parts where '_mm_insert_epi64()' is used, it is done so without any checks.

opencv-4.5.4 build for ABI_X86_32 without any issues, so the problem is in gfluidcore_simd_sse41.hpp.
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-12-31 09:36:01 UTC
(In reply to Sven Eden from comment #6)
> No. It is, because
> 'modules/gapi/src/backends/fluid/gfluidcore_simd_sse41.hpp checks against
> __i386__ only at one point (line 238), and at the other parts where
> '_mm_insert_epi64()' is used, it is done so without any checks.
> 
> opencv-4.5.4 build for ABI_X86_32 without any issues, so the problem is in
> gfluidcore_simd_sse41.hpp.

Thanks. Can you report it upstream?
Comment 8 Iade Gesso 2022-01-08 22:19:15 UTC
(In reply to Sven Eden from comment #6)
> (In reply to Iade Gesso from comment #3)
> > (In reply to Sven Eden from comment #2)
> > > In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:
> > > 
> > >     429 #ifdef __x86_64__
> > >     430 #define _mm_insert_epi64(D, S, N)                                   
> > > \
> > >     431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),     
> > > \
> > >     432                                           (long long)(S), (int)(N)))
> > >     433 #endif
> > > 
> > > And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so
> > > the function really isn't there.
> > 
> > So... the issue can be in the GCC 11.2.1 package... but it appeared just now
> > because previous OpenCV versions doesn't need that function?
> 
> No. It is, because
> 'modules/gapi/src/backends/fluid/gfluidcore_simd_sse41.hpp checks against
> __i386__ only at one point (line 238), and at the other parts where
> '_mm_insert_epi64()' is used, it is done so without any checks.
> 
> opencv-4.5.4 build for ABI_X86_32 without any issues, so the problem is in
> gfluidcore_simd_sse41.hpp.

I found a solution here https://lists.freebsd.org/pipermail/p4-projects/2014-December/039272.html

Il tryed adding the definition of ‘_mm_insert_epi64’ for i386 as suggested in the link, and now opencv-4.5.5 builds fine.
I will provide a patch in the attachments.

Let me know if it works :)


Iade
Comment 9 Iade Gesso 2022-01-08 22:20:10 UTC
Created attachment 761664 [details, diff]
Fix missing ‘_mm_insert_epi64’ function in 32bit build
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-01-09 06:32:33 UTC
(In reply to Iade Gesso from comment #8)
> (In reply to Sven Eden from comment #6)
> > (In reply to Iade Gesso from comment #3)
> > > (In reply to Sven Eden from comment #2)
> > > > In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:
> > > > 
> > > >     429 #ifdef __x86_64__
> > > >     430 #define _mm_insert_epi64(D, S, N)                                   
> > > > \
> > > >     431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),     
> > > > \
> > > >     432                                           (long long)(S), (int)(N)))
> > > >     433 #endif
> > > > 
> > > > And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so
> > > > the function really isn't there.
> > > 
> > > So... the issue can be in the GCC 11.2.1 package... but it appeared just now
> > > because previous OpenCV versions doesn't need that function?
> > 
> > No. It is, because
> > 'modules/gapi/src/backends/fluid/gfluidcore_simd_sse41.hpp checks against
> > __i386__ only at one point (line 238), and at the other parts where
> > '_mm_insert_epi64()' is used, it is done so without any checks.
> > 
> > opencv-4.5.4 build for ABI_X86_32 without any issues, so the problem is in
> > gfluidcore_simd_sse41.hpp.
> 
> I found a solution here
> https://lists.freebsd.org/pipermail/p4-projects/2014-December/039272.html
> 
> Il tryed adding the definition of ‘_mm_insert_epi64’ for i386 as suggested
> in the link, and now opencv-4.5.5 builds fine.
> I will provide a patch in the attachments.
> 
> Let me know if it works :)
> 
> 
> Iade

I thikn you've misunderstood Sven's comment. Copying/pasting this definition is wrong; the usage of the instrinsics should instead be guarded with another define (like it is in other places).
Comment 11 Iade Gesso 2022-01-09 12:17:58 UTC
(In reply to Sam James from comment #10)
> (In reply to Iade Gesso from comment #8)
> > (In reply to Sven Eden from comment #6)
> > > (In reply to Iade Gesso from comment #3)
> > > > (In reply to Sven Eden from comment #2)
> > > > > In '/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/include/smmintrin.h' there is:
> > > > > 
> > > > >     429 #ifdef __x86_64__
> > > > >     430 #define _mm_insert_epi64(D, S, N)                                   
> > > > > \
> > > > >     431   ((__m128i) __builtin_ia32_vec_set_v2di ((__v2di)(__m128i)(D),     
> > > > > \
> > > > >     432                                           (long long)(S), (int)(N)))
> > > > >     433 #endif
> > > > > 
> > > > > And the error happens while building 'opencv-4.5.5_build-abi_x86_32.x86', so
> > > > > the function really isn't there.
> > > > 
> > > > So... the issue can be in the GCC 11.2.1 package... but it appeared just now
> > > > because previous OpenCV versions doesn't need that function?
> > > 
> > > No. It is, because
> > > 'modules/gapi/src/backends/fluid/gfluidcore_simd_sse41.hpp checks against
> > > __i386__ only at one point (line 238), and at the other parts where
> > > '_mm_insert_epi64()' is used, it is done so without any checks.
> > > 
> > > opencv-4.5.4 build for ABI_X86_32 without any issues, so the problem is in
> > > gfluidcore_simd_sse41.hpp.
> > 
> > I found a solution here
> > https://lists.freebsd.org/pipermail/p4-projects/2014-December/039272.html
> > 
> > Il tryed adding the definition of ‘_mm_insert_epi64’ for i386 as suggested
> > in the link, and now opencv-4.5.5 builds fine.
> > I will provide a patch in the attachments.
> > 
> > Let me know if it works :)
> > 
> > 
> > Iade
> 
> I thikn you've misunderstood Sven's comment. Copying/pasting this definition
> is wrong; the usage of the instrinsics should instead be guarded with
> another define (like it is in other places).

No, I understood what Sven told and I tryed to apply his suggestion but I fell down into a cast hell (I didn't find good documentation about the sse4.2 API)... so I proposed my patch as a sort of workaround... Hope someone can fix it in the right way!!!

Iade
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-01-10 01:01:14 UTC
(In reply to Iade Gesso from comment #11)
> No, I understood what Sven told and I tryed to apply his suggestion but I
> fell down into a cast hell (I didn't find good documentation about the
> sse4.2 API)... so I proposed my patch as a sort of workaround... Hope
> someone can fix it in the right way!!!
> 
> Iade

Would you mind reporting the issue upstream then as you can reproduce it?

Just attach the log and explain that one of the uses is unguarded.

For now, you can try -mno-sse4.1 for the 32 bit build I guess.
Comment 13 Sven Eden 2022-02-15 07:30:55 UTC
Changed URL to upstream bug with this exact issue (Using "_mm_insert_epi64" on 32bit builds)
Comment 14 Richard Ostrow 2022-04-22 02:24:49 UTC
Upstream appears to have a PR that got merged to address this issue (PR#21628 - GAPI Fluid Resize: Fix for 32bit build issue). I was unsuccessful at using the PR patch against the 4.5.5 sources, however... maybe I'm just not doing it right.
Comment 15 Richard Ostrow 2022-04-27 00:58:48 UTC
(In reply to Richard Ostrow from comment #14)
> Upstream appears to have a PR that got merged to address this issue
> (PR#21628 - GAPI Fluid Resize: Fix for 32bit build issue). I was
> unsuccessful at using the PR patch against the 4.5.5 sources, however...
> maybe I'm just not doing it right.

On a side note, I can confirm that the upstream merge has fixed the isssue - I was able to modify this ebuild to a "9999" git version using the head and it built and installed without issue. It's an ugly hack, though, so I don't think I'll submit a 9999 ebuild here (lots of things forced to version "4.5.5" with the contrib stuff rather than "${PV}", had to add a custom src_unpack() function to handle both git and downloaded stuff normally associated with the src_uri build, etc).

Really, only thing of worth noting is that it's fixed upstream and it's worth attempting to make a patch to make 4.5.5 compile/install - I don't know how long I've been staring at failed world updates due to opencv not compiling. I don't know what the release cycle is like, so I have no idea how long we'd have to wait for 4.5.6.

Alternatively, maybe we can bring back a previously working version? 4.5.5 is definitely broken for multilib builds.
Comment 16 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-04-27 01:03:46 UTC
(In reply to Richard Ostrow from comment #15)
> (In reply to Richard Ostrow from comment #14)
> > Upstream appears to have a PR that got merged to address this issue
> > (PR#21628 - GAPI Fluid Resize: Fix for 32bit build issue). I was
> > unsuccessful at using the PR patch against the 4.5.5 sources, however...
> > maybe I'm just not doing it right.
> 
> On a side note, I can confirm that the upstream merge has fixed the isssue -
> I was able to modify this ebuild to a "9999" git version using the head and
> it built and installed without issue. It's an ugly hack, though, so I don't
> think I'll submit a 9999 ebuild here (lots of things forced to version
> "4.5.5" with the contrib stuff rather than "${PV}", had to add a custom
> src_unpack() function to handle both git and downloaded stuff normally
> associated with the src_uri build, etc).
> 
> Really, only thing of worth noting is that it's fixed upstream and it's
> worth attempting to make a patch to make 4.5.5 compile/install - I don't
> know how long I've been staring at failed world updates due to opencv not
> compiling. I don't know what the release cycle is like, so I have no idea
> how long we'd have to wait for 4.5.6.
> 
> Alternatively, maybe we can bring back a previously working version? 4.5.5
> is definitely broken for multilib builds.

It didn't apply cleanly so I was hoping for a new release soon.
Comment 17 Larry the Git Cow gentoo-dev 2022-06-07 04:36:59 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2d5e4062df38b6faa35d2d2c1f785bc2f138a548

commit 2d5e4062df38b6faa35d2d2c1f785bc2f138a548
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-06-07 04:34:48 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-06-07 04:36:52 +0000

    media-libs/opencv: add 4.6.0
    
    Bug: https://bugs.gentoo.org/834092
    Closes: https://bugs.gentoo.org/830185
    Signed-off-by: Sam James <sam@gentoo.org>

 media-libs/opencv/Manifest            |   2 +
 media-libs/opencv/opencv-4.6.0.ebuild | 580 ++++++++++++++++++++++++++++++++++
 2 files changed, 582 insertions(+)