From 1fa97971e0ff25276f6e5d71ce145dc1904993c6 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 28 Nov 2025 14:19:09 +1300
Subject: [PATCH 2/6] jit: Fix jit_profiling_support when not available.

On LLVM libraries built without LLVM_USE_PERF, which probably means all
non-Linux systems, LLVMCreatePerfJITEventListener() is a dummy function
that returns NULL.  Silently ignore the option, avoiding an assertion
failure or segmentation fault inside LLVM.

LLVMCreateGDBRegistrationListener() is called similarly but is always
available so needs no guard.

Backpatch-through: 14
---
 src/backend/jit/llvm/llvmjit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 3d67bd6b9bc..0e67267e807 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -1191,7 +1191,8 @@ llvm_create_object_layer(void *Ctx, LLVMOrcExecutionSessionRef ES, const char *T
 	{
 		LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
 
-		LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l);
+		if (l)
+			LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l);
 	}
 
 	return objlayer;
-- 
2.51.2

