From: Pierre-Eric Pelloux-Prayer Date: Mon, 10 Aug 2020 08:16:39 +0000 (+0200) Subject: ac/llvm: handle static/shared llvm init separately X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=b7c04b1790fb69e2f0f942a286c76b3efef85eab ac/llvm: handle static/shared llvm init separately Having a single init function works as expected for shared llvm, but when using a static llvm only one llvm will get initialized. This commit introduces 2 separate init function: - shared llvm = single public init function - static llvm = one init function for each module using llvm Fixes: 50d20dc055d ("ac/llvm: export ac_init_llvm_once in targets") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3376 Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Marek Olšák Part-of: --- diff --git a/Android.mk b/Android.mk index 6181bbe8f31..aa2e7f7610e 100644 --- a/Android.mk +++ b/Android.mk @@ -97,7 +97,7 @@ endif define mesa-build-with-llvm $(if $(filter $(MESA_ANDROID_MAJOR_VERSION), 4 5 6 7), \ $(warning Unsupported LLVM version in Android $(MESA_ANDROID_MAJOR_VERSION)),) \ - $(eval LOCAL_CFLAGS += -DLLVM_AVAILABLE -DMESA_LLVM_VERSION_STRING=\"3.9\") \ + $(eval LOCAL_CFLAGS += -DLLVM_AVAILABLE -DLLVM_IS_SHARED=1 -DMESA_LLVM_VERSION_STRING=\"3.9\") \ $(eval LOCAL_SHARED_LIBRARIES += libLLVM) endef diff --git a/meson.build b/meson.build index c3511c9652c..db4f8fc551b 100644 --- a/meson.build +++ b/meson.build @@ -1513,6 +1513,7 @@ endif if with_llvm pre_args += '-DLLVM_AVAILABLE' pre_args += '-DMESA_LLVM_VERSION_STRING="@0@"'.format(dep_llvm.version()) + pre_args += '-DLLVM_IS_SHARED=@0@'.format(_shared_llvm.to_int()) # LLVM can be built without rtti, turning off rtti changes the ABI of C++ # programs, so we need to build all C++ code in mesa without rtti as well to diff --git a/src/amd/llvm/ac_llvm_util.c b/src/amd/llvm/ac_llvm_util.c index 29f9352b886..c7c8b991756 100644 --- a/src/amd/llvm/ac_llvm_util.c +++ b/src/amd/llvm/ac_llvm_util.c @@ -78,12 +78,29 @@ static void ac_init_llvm_target() LLVMParseCommandLineOptions(ARRAY_SIZE(argv), argv, NULL); } -PUBLIC void ac_init_llvm_once(void) +PUBLIC void ac_init_shared_llvm_once(void) { static once_flag ac_init_llvm_target_once_flag = ONCE_FLAG_INIT; call_once(&ac_init_llvm_target_once_flag, ac_init_llvm_target); } +#if !LLVM_IS_SHARED +static once_flag ac_init_static_llvm_target_once_flag = ONCE_FLAG_INIT; +static void ac_init_static_llvm_once(void) +{ + call_once(&ac_init_static_llvm_target_once_flag, ac_init_llvm_target); +} +#endif + +void ac_init_llvm_once(void) +{ +#if LLVM_IS_SHARED + ac_init_shared_llvm_once(); +#else + ac_init_static_llvm_once(); +#endif +} + static LLVMTargetRef ac_get_llvm_target(const char *triple) { LLVMTargetRef target = NULL; diff --git a/src/amd/llvm/ac_llvm_util.h b/src/amd/llvm/ac_llvm_util.h index 4a01eceadec..622196081b4 100644 --- a/src/amd/llvm/ac_llvm_util.h +++ b/src/amd/llvm/ac_llvm_util.h @@ -131,6 +131,7 @@ ac_count_scratch_private_memory(LLVMValueRef function); LLVMTargetLibraryInfoRef ac_create_target_library_info(const char *triple); void ac_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info); +void ac_init_shared_llvm_once(void); /* Do not use directly, use ac_init_llvm_once */ void ac_init_llvm_once(void); diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index ba3a9e53b84..907e45cc0e7 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -176,7 +176,7 @@ if with_symbols_check args : [ '--lib', libvulkan_radeon, '--symbols-file', vulkan_icd_symbols, - '--ignore-symbol', 'ac_init_llvm_once', + '--ignore-symbol', 'ac_init_shared_llvm_once', symbols_check_args, ], suite : ['amd'], diff --git a/src/gallium/targets/dri-vdpau.dyn b/src/gallium/targets/dri-vdpau.dyn index d37123a8659..91988b49720 100644 --- a/src/gallium/targets/dri-vdpau.dyn +++ b/src/gallium/targets/dri-vdpau.dyn @@ -2,5 +2,5 @@ nouveau_drm_screen_create; radeon_drm_winsys_create; amdgpu_winsys_create; - ac_init_llvm_once; + ac_init_shared_llvm_once; }; diff --git a/src/gallium/targets/dri/dri.sym b/src/gallium/targets/dri/dri.sym index 83914c60cf3..7f7a93b02ff 100644 --- a/src/gallium/targets/dri/dri.sym +++ b/src/gallium/targets/dri/dri.sym @@ -6,7 +6,7 @@ radeon_drm_winsys_create; amdgpu_winsys_create; fd_drm_screen_create; - ac_init_llvm_once; + ac_init_shared_llvm_once; local: *; }; diff --git a/src/gallium/targets/omx/omx.sym b/src/gallium/targets/omx/omx.sym index 1cca4645bbb..8508b473c9a 100644 --- a/src/gallium/targets/omx/omx.sym +++ b/src/gallium/targets/omx/omx.sym @@ -7,7 +7,7 @@ # due to LLVM being initialized multiple times. radeon_drm_winsys_create; amdgpu_winsys_create; - ac_init_llvm_once; + ac_init_shared_llvm_once; local: *; }; diff --git a/src/gallium/targets/pipe-loader/pipe.sym b/src/gallium/targets/pipe-loader/pipe.sym index 8054e11ae18..3e5ef52b8d1 100644 --- a/src/gallium/targets/pipe-loader/pipe.sym +++ b/src/gallium/targets/pipe-loader/pipe.sym @@ -7,7 +7,7 @@ # due to LLVM being initialized multiple times. radeon_drm_winsys_create; amdgpu_winsys_create; - ac_init_llvm_once; + ac_init_shared_llvm_once; local: *; }; diff --git a/src/gallium/targets/va/va.sym b/src/gallium/targets/va/va.sym index 3f48ab61e98..76c19879074 100644 --- a/src/gallium/targets/va/va.sym +++ b/src/gallium/targets/va/va.sym @@ -6,7 +6,7 @@ # due to LLVM being initialized multiple times. radeon_drm_winsys_create; amdgpu_winsys_create; - ac_init_llvm_once; + ac_init_shared_llvm_once; local: *; }; diff --git a/src/gallium/targets/vdpau/vdpau.sym b/src/gallium/targets/vdpau/vdpau.sym index 36935e9e14d..928c55b4385 100644 --- a/src/gallium/targets/vdpau/vdpau.sym +++ b/src/gallium/targets/vdpau/vdpau.sym @@ -4,7 +4,7 @@ nouveau_drm_screen_create; radeon_drm_winsys_create; amdgpu_winsys_create; - ac_init_llvm_once; + ac_init_shared_llvm_once; local: *; };