ac/llvm: handle static/shared llvm init separately
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Mon, 10 Aug 2020 08:16:39 +0000 (10:16 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 17 Aug 2020 10:47:41 +0000 (10:47 +0000)
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 <bas@basnieuwenhuizen.nl>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6253>

Android.mk
meson.build
src/amd/llvm/ac_llvm_util.c
src/amd/llvm/ac_llvm_util.h
src/amd/vulkan/meson.build
src/gallium/targets/dri-vdpau.dyn
src/gallium/targets/dri/dri.sym
src/gallium/targets/omx/omx.sym
src/gallium/targets/pipe-loader/pipe.sym
src/gallium/targets/va/va.sym
src/gallium/targets/vdpau/vdpau.sym

index 6181bbe8f31a8a4d706ee0846927bb06b1e1c404..aa2e7f7610efa671a2d2cf8d93daf76031a0a806 100644 (file)
@@ -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
 
index c3511c9652c5ec70c814ca67f702ad787c11a2fa..db4f8fc551b82d3e8a025dd0d649a162f545cc65 100644 (file)
@@ -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
index 29f9352b886f9e0dbcf3614621c10c35e69431e7..c7c8b991756ef5c882a44e6c1848ca4ed061e56c 100644 (file)
@@ -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;
index 4a01eceadecaf67f3b6a45fadc23aaac15d44bd6..622196081b4b5e6563ec05183530587e7541a83f 100644 (file)
@@ -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);
 
 
index ba3a9e53b8401ddaba5bffecd2278724e3e52b46..907e45cc0e711a42e72002c7202982d12c18eea6 100644 (file)
@@ -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'],
index d37123a865945e3450ee793d66a6bfc41ef79e5b..91988b49720d9ab4970c1936a8ab654580c12154 100644 (file)
@@ -2,5 +2,5 @@
        nouveau_drm_screen_create;
        radeon_drm_winsys_create;
        amdgpu_winsys_create;
-       ac_init_llvm_once;
+       ac_init_shared_llvm_once;
 };
index 83914c60cf3d1a1f7f7777f477d08e470a9f2641..7f7a93b02ff311395f6cebaf3dd758882021a659 100644 (file)
@@ -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:
                *;
 };
index 1cca4645bbb331cce0266cb14dad2d0e53d6a266..8508b473c9a2721c5811151dd70cd17adc39e93a 100644 (file)
@@ -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:
                *;
 };
index 8054e11ae18bcf84b55b62a43839b77dbdfee960..3e5ef52b8d199e77e113d3ba75fd8f5357381476 100644 (file)
@@ -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:
                *;
 };
index 3f48ab61e98ddb570f1b6ea655b6ca96d26347f7..76c198790748e8762d4caeb9cf3fa7b1f855aab8 100644 (file)
@@ -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:
                *;
 };
index 36935e9e14dece7b057c4d3b114d35a9089c2cb0..928c55b43853999e57bbcbb88313580463cf128f 100644 (file)
@@ -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:
                *;
 };