[virglrenderer-devel] [PATCH] fix symbol `util_cpu_caps' can not be used when making a shared object
Lepton Wu
lepton at chromium.org
Mon Jun 22 06:39:14 UTC 2020
On Sun, Jun 21, 2020 at 10:57 PM Hongxu Jia <hongxu.jia at windriver.com> wrote:
>
> Extern global variable `util_cpu_caps' to multiple C source files is
> not a good habit, it caused linking failure when making a shard object
> in some cross compiling circumstance
Thanks for patch. Virgl now is using gitlab to do development. Would you mind to
send your patch as a gitlab merge request here:
https://gitlab.freedesktop.org/virgl/virglrenderer
> ...
> |ld: gallium/auxiliary/.libs/libgallium.a(u_cpu_detect.o): relocation
> R_386_GOTOFF against undefined symbol `util_cpu_caps' can not be used
> when making a shared object
> |ld: final link failed: bad value
> ...
>
> Covert global variable to static and assign it only in one C source file,
> provide get function for other C source files
>
> Signed-off-by: Hongxu Jia <hongxu.jia at windriver.com>
> ---
> src/gallium/auxiliary/util/u_cpu_detect.c | 6 +++++-
> src/gallium/auxiliary/util/u_cpu_detect.h | 3 +--
> src/gallium/auxiliary/util/u_math.c | 8 ++++----
> 3 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c
> index 0b4b83a..be0cedd 100644
> --- a/src/gallium/auxiliary/util/u_cpu_detect.c
> +++ b/src/gallium/auxiliary/util/u_cpu_detect.c
> @@ -78,7 +78,11 @@ DEBUG_GET_ONCE_BOOL_OPTION(dump_cpu, "GALLIUM_DUMP_CPU", FALSE)
> #endif
>
>
> -struct util_cpu_caps util_cpu_caps;
> +static struct util_cpu_caps util_cpu_caps;
> +struct util_cpu_caps* get_util_cpu_caps(void)
> +{
> + return &util_cpu_caps;
> +}
>
> #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
> static int has_cpuid(void);
> diff --git a/src/gallium/auxiliary/util/u_cpu_detect.h b/src/gallium/auxiliary/util/u_cpu_detect.h
> index 01f3896..58134ab 100644
> --- a/src/gallium/auxiliary/util/u_cpu_detect.h
> +++ b/src/gallium/auxiliary/util/u_cpu_detect.h
> @@ -73,8 +73,7 @@ struct util_cpu_caps {
> unsigned has_daz:1;
> };
>
> -extern struct util_cpu_caps
> -util_cpu_caps;
> +struct util_cpu_caps* get_util_cpu_caps(void);
>
> void util_cpu_detect(void);
>
> diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c
> index e574153..c08ed3b 100644
> --- a/src/gallium/auxiliary/util/u_math.c
> +++ b/src/gallium/auxiliary/util/u_math.c
> @@ -90,7 +90,7 @@ util_fpstate_get(void)
> unsigned mxcsr = 0;
>
> #if defined(PIPE_ARCH_SSE)
> - if (util_cpu_caps.has_sse) {
> + if (get_util_cpu_caps()->has_sse) {
> mxcsr = _mm_getcsr();
> }
> #endif
> @@ -108,10 +108,10 @@ unsigned
> util_fpstate_set_denorms_to_zero(unsigned current_mxcsr)
> {
> #if defined(PIPE_ARCH_SSE)
> - if (util_cpu_caps.has_sse) {
> + if (get_util_cpu_caps()->has_sse) {
> /* Enable flush to zero mode */
> current_mxcsr |= _MM_FLUSH_ZERO_MASK;
> - if (util_cpu_caps.has_daz) {
> + if (get_util_cpu_caps()->has_daz) {
> /* Enable denormals are zero mode */
> current_mxcsr |= _MM_DENORMALS_ZERO_MASK;
> }
> @@ -130,7 +130,7 @@ void
> util_fpstate_set(unsigned mxcsr)
> {
> #if defined(PIPE_ARCH_SSE)
> - if (util_cpu_caps.has_sse) {
> + if (get_util_cpu_caps()->has_sse) {
> _mm_setcsr(mxcsr);
> }
> #endif
> --
> 2.8.1
>
> _______________________________________________
> virglrenderer-devel mailing list
> virglrenderer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/virglrenderer-devel
More information about the virglrenderer-devel
mailing list