postgres.git / summary / log / commit / refs

commit    e6b2f7c2b41d6261dac15825dede55e94ca35614
Author:   Andres Freund <andres@anarazel.de>
Date:     Sat Nov 07 00:56:22 2026 +0000
First released in: 17.12, 18.7

    Exclude the variables in llvmjit_types.c from AddressSanitizer
    
    If address sanitizer is enabled, types of global variables are changed
    to a container type, to include space for a red zone after each global
    variable. Unfortunately, that causes mismatches with the generated code,
    which in turn causes crashes when JIT is combined with ASAN.
    
    This does not normally present a problem with autoconf builds, as we do
    not pass CFLAGS on to bitcode generation, so in autoconf builds the
    bitcode generation never sees sanitizer flags.  Somewhat similarly, in
    meson builds, c_args were not passed on to bitcode generation, but that
    was changed with 1039352e1 in 17.
    
    For now, just use #pragma to exclude global variables in llvmjit_types.c
    from address sanitizer.
    
    That might not be the best fix medium term, but we need a short-term
    fix, due to an upcoming fix's tests hitting this issue.
    
    We did not notice this historically as with cirrus-ci address sanitizer
    was tested with autoconf, which does not have this specific issue. The
    GHA based CI was only added after JIT was disabled by default.
    
    For now this is just backpatched to 17, as earlier branches
    a) don't have pg_attribute_no_sanitize_address()
    b) don't currently need it, due to 1039352e1 only being in >= 17
    
    Author: Henson Choi <assam258@gmail.com>
    Discussion: https://postgr.es/m/CAAAe_zA49cHXJ7J4hmeuSa75s+eSgCOnK_9Uvq6wUEJ2Bgvdfg@mail.gmail.com
    Backpatch-through: 17


src/backend/jit/llvm/llvmjit_types.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/backend/jit/llvm/llvmjit_types.c b/src/backend/jit/llvm/llvmjit_types.c index f93c383fd52..f0e4b8eea5d 100644 --- a/src/backend/jit/llvm/llvmjit_types.c +++ b/src/backend/jit/llvm/llvmjit_types.c @@ -44,7 +44,15 @@ * List of types needed for JITing. These have to be non-static, otherwise * clang/LLVM will omit them. As this file will never be linked into * anything, that's harmless. + * + * They are also excluded from AddressSanitizer instrumentation, so that they + * keep the types they are declared with (clang adds a wrapper struct with a + * redzone when using address sanitizer). This file is only ever compiled by + * clang, so a clang pragma is fine here. */ +#pragma clang attribute push (pg_attribute_no_sanitize_address(), \ + apply_to = variable(is_global)) + PGFunction TypePGFunction; size_t TypeSizeT; bool TypeStorageBool; @@ -70,6 +78,8 @@ TupleDescData StructTupleDescData; PlanState StructPlanState; MinimalTupleData StructMinimalTupleData; +#pragma clang attribute pop + /* * To determine which attributes functions need to have (depends e.g. on [parent: b2b1910d9ab3]