All of lore.kernel.org
 help / color / mirror / Atom feed
* gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined'
@ 2022-04-11 21:08 ` Sergei Trofimovich
  0 siblings, 0 replies; 6+ messages in thread
From: Sergei Trofimovich @ 2022-04-11 21:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: amd-gfx, Joe Perches, linux-kbuild, Jakub Jelinek,
	Segher Boessenkool, Thomas Gleixner, Peter Zijlstra,
	Andy Lutomirski

Current linux-5.17.1 on fresh gcc-12 fails to build with errors like:

    ERROR: modpost: "__popcountdi2" [drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko] undefined!
    ERROR: modpost: "__popcountdi2" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

It is occasionally seen by others on previous gcc versions as well:

    https://lkml.org/lkml/2021/7/11/261
    https://lkml.org/lkml/2018/10/24/403

'__popcountdi2' are inserted by gcc for code like the following
from 'drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c':

    static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
    {
        uint64_t n = 0;
        uint8_t count = 0;
        u8 bksv[sizeof(n)] = { };

        memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
        n = *(uint64_t *)bksv;

        /* Here gcc inserts 'count = __builtin_popcount(n);' */
        while (n) {
                count++;
                n &= (n - 1);
        }

        return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
                               MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
    }

Note that gcc can insert it regardless of -mno-* options.

How should linux.git handle it? A few options come to mind:

- Perhaps use libgcc.a directly.
- Just implement '__popcountdi2'. Example definition from libgcc:
  https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcc2.c;hb=HEAD#l846
- Or workaround it with -fno-builtin-popcount in Makefiles.

CCing people who can help routing it and/or deciding on the fix:
amd-gfx@lists.freedesktop.org, Joe Perches, linux-kbuild@vger.kernel.org,
Jakub Jelinek, Segher Boessenkool, Thomas Gleixner,Peter Zijlstra, Andy
Lutomirski.

WDYT?

Thanks!

-- 

  Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined'
@ 2022-04-11 21:08 ` Sergei Trofimovich
  0 siblings, 0 replies; 6+ messages in thread
From: Sergei Trofimovich @ 2022-04-11 21:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jakub Jelinek, Segher Boessenkool, linux-kbuild, Peter Zijlstra,
	amd-gfx, Andy Lutomirski, Joe Perches, Thomas Gleixner

Current linux-5.17.1 on fresh gcc-12 fails to build with errors like:

    ERROR: modpost: "__popcountdi2" [drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko] undefined!
    ERROR: modpost: "__popcountdi2" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!

It is occasionally seen by others on previous gcc versions as well:

    https://lkml.org/lkml/2021/7/11/261
    https://lkml.org/lkml/2018/10/24/403

'__popcountdi2' are inserted by gcc for code like the following
from 'drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c':

    static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
    {
        uint64_t n = 0;
        uint8_t count = 0;
        u8 bksv[sizeof(n)] = { };

        memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
        n = *(uint64_t *)bksv;

        /* Here gcc inserts 'count = __builtin_popcount(n);' */
        while (n) {
                count++;
                n &= (n - 1);
        }

        return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
                               MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
    }

Note that gcc can insert it regardless of -mno-* options.

How should linux.git handle it? A few options come to mind:

- Perhaps use libgcc.a directly.
- Just implement '__popcountdi2'. Example definition from libgcc:
  https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcc2.c;hb=HEAD#l846
- Or workaround it with -fno-builtin-popcount in Makefiles.

CCing people who can help routing it and/or deciding on the fix:
amd-gfx@lists.freedesktop.org, Joe Perches, linux-kbuild@vger.kernel.org,
Jakub Jelinek, Segher Boessenkool, Thomas Gleixner,Peter Zijlstra, Andy
Lutomirski.

WDYT?

Thanks!

-- 

  Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined'
  2022-04-11 21:08 ` Sergei Trofimovich
@ 2022-04-11 21:21   ` Jakub Jelinek
  -1 siblings, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2022-04-11 21:21 UTC (permalink / raw)
  To: Sergei Trofimovich
  Cc: linux-kernel, amd-gfx, Joe Perches, linux-kbuild,
	Segher Boessenkool, Thomas Gleixner, Peter Zijlstra,
	Andy Lutomirski

On Mon, Apr 11, 2022 at 10:08:15PM +0100, Sergei Trofimovich wrote:
> Current linux-5.17.1 on fresh gcc-12 fails to build with errors like:
> 
>     ERROR: modpost: "__popcountdi2" [drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko] undefined!
>     ERROR: modpost: "__popcountdi2" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
> 
> It is occasionally seen by others on previous gcc versions as well:
> 
>     https://lkml.org/lkml/2021/7/11/261
>     https://lkml.org/lkml/2018/10/24/403
> 
> '__popcountdi2' are inserted by gcc for code like the following
> from 'drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c':
> 
>     static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
>     {
>         uint64_t n = 0;
>         uint8_t count = 0;
>         u8 bksv[sizeof(n)] = { };
> 
>         memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
>         n = *(uint64_t *)bksv;
> 
>         /* Here gcc inserts 'count = __builtin_popcount(n);' */
>         while (n) {
>                 count++;
>                 n &= (n - 1);
>         }
> 
>         return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
>                                MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
>     }
> 
> Note that gcc can insert it regardless of -mno-* options.

Just FYI, this has been added in GCC 9 for https://gcc.gnu.org/PR82479
If the kernel implements its own __popcount?i2, it can perhaps with
runtime patching use hw instructions when those are available and
fallback to the generic version.

	Jakub


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined'
@ 2022-04-11 21:21   ` Jakub Jelinek
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2022-04-11 21:21 UTC (permalink / raw)
  To: Sergei Trofimovich
  Cc: Segher Boessenkool, linux-kbuild, Peter Zijlstra, linux-kernel,
	amd-gfx, Andy Lutomirski, Joe Perches, Thomas Gleixner

On Mon, Apr 11, 2022 at 10:08:15PM +0100, Sergei Trofimovich wrote:
> Current linux-5.17.1 on fresh gcc-12 fails to build with errors like:
> 
>     ERROR: modpost: "__popcountdi2" [drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko] undefined!
>     ERROR: modpost: "__popcountdi2" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
> 
> It is occasionally seen by others on previous gcc versions as well:
> 
>     https://lkml.org/lkml/2021/7/11/261
>     https://lkml.org/lkml/2018/10/24/403
> 
> '__popcountdi2' are inserted by gcc for code like the following
> from 'drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c':
> 
>     static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
>     {
>         uint64_t n = 0;
>         uint8_t count = 0;
>         u8 bksv[sizeof(n)] = { };
> 
>         memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
>         n = *(uint64_t *)bksv;
> 
>         /* Here gcc inserts 'count = __builtin_popcount(n);' */
>         while (n) {
>                 count++;
>                 n &= (n - 1);
>         }
> 
>         return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
>                                MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
>     }
> 
> Note that gcc can insert it regardless of -mno-* options.

Just FYI, this has been added in GCC 9 for https://gcc.gnu.org/PR82479
If the kernel implements its own __popcount?i2, it can perhaps with
runtime patching use hw instructions when those are available and
fallback to the generic version.

	Jakub


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined'
  2022-04-11 21:08 ` Sergei Trofimovich
@ 2022-04-13 13:07   ` Sergei Trofimovich
  -1 siblings, 0 replies; 6+ messages in thread
From: Sergei Trofimovich @ 2022-04-13 13:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: amd-gfx, Joe Perches, linux-kbuild, Jakub Jelinek,
	Segher Boessenkool, Thomas Gleixner, Peter Zijlstra,
	Andy Lutomirski

On Mon, Apr 11, 2022 at 10:08:15PM +0100, Sergei Trofimovich wrote:
> Current linux-5.17.1 on fresh gcc-12 fails to build with errors like:
> 
>     ERROR: modpost: "__popcountdi2" [drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko] undefined!
>     ERROR: modpost: "__popcountdi2" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
> 
> It is occasionally seen by others on previous gcc versions as well:
> 
>     https://lkml.org/lkml/2021/7/11/261
>     https://lkml.org/lkml/2018/10/24/403
> 
> '__popcountdi2' are inserted by gcc for code like the following
> from 'drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c':
> 
>     static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
>     {
>         uint64_t n = 0;
>         uint8_t count = 0;
>         u8 bksv[sizeof(n)] = { };
> 
>         memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
>         n = *(uint64_t *)bksv;
> 
>         /* Here gcc inserts 'count = __builtin_popcount(n);' */
>         while (n) {
>                 count++;
>                 n &= (n - 1);
>         }
> 
>         return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
>                                MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
>     }
> 
> Note that gcc can insert it regardless of -mno-* options.
> 
> How should linux.git handle it? A few options come to mind:
> 
> - Perhaps use libgcc.a directly.
> - Just implement '__popcountdi2'. Example definition from libgcc:
>   https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcc2.c;hb=HEAD#l846
> - Or workaround it with -fno-builtin-popcount in Makefiles.
> 
> CCing people who can help routing it and/or deciding on the fix:
> amd-gfx@lists.freedesktop.org, Joe Perches, linux-kbuild@vger.kernel.org,
> Jakub Jelinek, Segher Boessenkool, Thomas Gleixner,Peter Zijlstra, Andy
> Lutomirski.

There is now a discussion in gcc bugzilla:

    https://gcc.gnu.org/PR105253

-- 

  Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined'
@ 2022-04-13 13:07   ` Sergei Trofimovich
  0 siblings, 0 replies; 6+ messages in thread
From: Sergei Trofimovich @ 2022-04-13 13:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jakub Jelinek, Segher Boessenkool, linux-kbuild, Peter Zijlstra,
	amd-gfx, Andy Lutomirski, Joe Perches, Thomas Gleixner

On Mon, Apr 11, 2022 at 10:08:15PM +0100, Sergei Trofimovich wrote:
> Current linux-5.17.1 on fresh gcc-12 fails to build with errors like:
> 
>     ERROR: modpost: "__popcountdi2" [drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko] undefined!
>     ERROR: modpost: "__popcountdi2" [drivers/gpu/drm/amd/amdgpu/amdgpu.ko] undefined!
> 
> It is occasionally seen by others on previous gcc versions as well:
> 
>     https://lkml.org/lkml/2021/7/11/261
>     https://lkml.org/lkml/2018/10/24/403
> 
> '__popcountdi2' are inserted by gcc for code like the following
> from 'drivers/gpu/drm/amd/display/modules/hdcp/hdcp1_execution.c':
> 
>     static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
>     {
>         uint64_t n = 0;
>         uint8_t count = 0;
>         u8 bksv[sizeof(n)] = { };
> 
>         memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
>         n = *(uint64_t *)bksv;
> 
>         /* Here gcc inserts 'count = __builtin_popcount(n);' */
>         while (n) {
>                 count++;
>                 n &= (n - 1);
>         }
> 
>         return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
>                                MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
>     }
> 
> Note that gcc can insert it regardless of -mno-* options.
> 
> How should linux.git handle it? A few options come to mind:
> 
> - Perhaps use libgcc.a directly.
> - Just implement '__popcountdi2'. Example definition from libgcc:
>   https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcc2.c;hb=HEAD#l846
> - Or workaround it with -fno-builtin-popcount in Makefiles.
> 
> CCing people who can help routing it and/or deciding on the fix:
> amd-gfx@lists.freedesktop.org, Joe Perches, linux-kbuild@vger.kernel.org,
> Jakub Jelinek, Segher Boessenkool, Thomas Gleixner,Peter Zijlstra, Andy
> Lutomirski.

There is now a discussion in gcc bugzilla:

    https://gcc.gnu.org/PR105253

-- 

  Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-13 13:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11 21:08 gcc inserts __builtin_popcount, causes 'modpost: "__popcountdi2" ... amdgpu.ko] undefined' Sergei Trofimovich
2022-04-11 21:08 ` Sergei Trofimovich
2022-04-11 21:21 ` Jakub Jelinek
2022-04-11 21:21   ` Jakub Jelinek
2022-04-13 13:07 ` Sergei Trofimovich
2022-04-13 13:07   ` Sergei Trofimovich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.