Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a9a515

Browse files
committed
jit: Use -mno-outline-atomics for bitcode on ARM.
If the executable's .o files were produced by a compiler (probably gcc)not using -moutline-atomics, and the corresponding .bc files wereproduced by clang using -moutline-atomics (probably by default), thenthe generated bitcode functions would have the target attribute"+outline-atomics", and could fail at runtime when inlined. If thetarget ISA at bitcode generation time was armv8-a (the most conservativeaarch64 target, no LSE), then LLVM IR atomic instructions would generatecalls to functions in libgcc.a or libclang_rt.*.a that switch betweenLL/SC and faster LSE instructions depending on a runtime AT_HWCAP check.Since the corresponding .o files didn't need those functions, theywouldn't have been included in the executable, and resolution wouldfail.At least Debian and Ubuntu are known to ship gcc and clang compilersthat target armv8-a but differ on the use of outline atomics by default.Fix, by suppressing the outline atomics attribute in bitcode explicitly.Inline LL/SC instructions will be generated for atomic operations inbitcode built for armv8-a. Only configure scripts are adjusted for now,because the meson build system doesn't generate bitcode yet.This doesn't seem to be a new phenomenon, so real cases of functionsusing atomics that are inlined by JIT must be rare in the wild given howlong it took for a bug report to arrive. The reported case could bereduced to:postgres=# set jit_inline_above_cost = 0;SETpostgres=# set jit_above_cost = 0;SETpostgres=# select pg_last_wal_receive_lsn();WARNING: failed to resolve name __aarch64_swp4_acq_relFATAL: fatal llvm error: Program used external function'__aarch64_swp4_acq_rel' which could not be resolved!The change doesn't affect non-ARM systems or later target ISAs.Back-patch to all supported releases.Reported-by: Alexander Kozhemyakin <a.kozhemyakin@postgrespro.ru>Discussion:https://postgr.es/m/18610-37bf303f904fede3%40postgresql.org
1 parent2fb3919 commit8a9a515

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

‎configure

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7379,6 +7379,111 @@ if test x"$pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" = x"yes";
73797379
fi
73807380

73817381

7382+
# Ideally bitcode should perhaps match $CC's use, or not, of outline atomic
7383+
# functions, but for now we err on the side of suppressing them in bitcode,
7384+
# because we can't assume they're available at runtime. This affects aarch64
7385+
# builds using the basic armv8-a ISA without LSE support.
7386+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -mno-outline-atomics, for BITCODE_CFLAGS" >&5
7387+
$as_echo_n "checking whether ${CLANG} supports -mno-outline-atomics, for BITCODE_CFLAGS... " >&6; }
7388+
if ${pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics+:} false; then :
7389+
$as_echo_n "(cached) " >&6
7390+
else
7391+
pgac_save_CXXFLAGS=$CXXFLAGS
7392+
pgac_save_CXX=$CXX
7393+
CXX=${CLANG}
7394+
CXXFLAGS="${BITCODE_CFLAGS} -mno-outline-atomics"
7395+
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
7396+
ac_cxx_werror_flag=yes
7397+
ac_ext=cpp
7398+
ac_cpp='$CXXCPP $CPPFLAGS'
7399+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
7400+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
7401+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
7402+
7403+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7404+
/* end confdefs.h. */
7405+
7406+
int
7407+
main ()
7408+
{
7409+
7410+
;
7411+
return 0;
7412+
}
7413+
_ACEOF
7414+
if ac_fn_cxx_try_compile "$LINENO"; then :
7415+
pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics=yes
7416+
else
7417+
pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics=no
7418+
fi
7419+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7420+
ac_ext=c
7421+
ac_cpp='$CPP $CPPFLAGS'
7422+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
7423+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
7424+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
7425+
7426+
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
7427+
CXXFLAGS="$pgac_save_CXXFLAGS"
7428+
CXX="$pgac_save_CXX"
7429+
fi
7430+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics" >&5
7431+
$as_echo "$pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics" >&6; }
7432+
if test x"$pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics" = x"yes"; then
7433+
BITCODE_CFLAGS="${BITCODE_CFLAGS} -mno-outline-atomics"
7434+
fi
7435+
7436+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -mno-outline-atomics, for BITCODE_CXXFLAGS" >&5
7437+
$as_echo_n "checking whether ${CLANG} supports -mno-outline-atomics, for BITCODE_CXXFLAGS... " >&6; }
7438+
if ${pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics+:} false; then :
7439+
$as_echo_n "(cached) " >&6
7440+
else
7441+
pgac_save_CXXFLAGS=$CXXFLAGS
7442+
pgac_save_CXX=$CXX
7443+
CXX=${CLANG}
7444+
CXXFLAGS="${BITCODE_CXXFLAGS} -mno-outline-atomics"
7445+
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
7446+
ac_cxx_werror_flag=yes
7447+
ac_ext=cpp
7448+
ac_cpp='$CXXCPP $CPPFLAGS'
7449+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
7450+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
7451+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
7452+
7453+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7454+
/* end confdefs.h. */
7455+
7456+
int
7457+
main ()
7458+
{
7459+
7460+
;
7461+
return 0;
7462+
}
7463+
_ACEOF
7464+
if ac_fn_cxx_try_compile "$LINENO"; then :
7465+
pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics=yes
7466+
else
7467+
pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics=no
7468+
fi
7469+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7470+
ac_ext=c
7471+
ac_cpp='$CPP $CPPFLAGS'
7472+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
7473+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
7474+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
7475+
7476+
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
7477+
CXXFLAGS="$pgac_save_CXXFLAGS"
7478+
CXX="$pgac_save_CXX"
7479+
fi
7480+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics" >&5
7481+
$as_echo "$pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics" >&6; }
7482+
if test x"$pgac_cv_prog_CLANG_cxxflags__mno_outline_atomics" = x"yes"; then
7483+
BITCODE_CXXFLAGS="${BITCODE_CXXFLAGS} -mno-outline-atomics"
7484+
fi
7485+
7486+
73827487
NOT_THE_CFLAGS=""
73837488
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
73847489
$as_echo_n "checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }

‎configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,13 @@ if test "$with_llvm" = yes ; then
637637
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS,[-Xclang -no-opaque-pointers])
638638
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS,[-Xclang -no-opaque-pointers])
639639

640+
# Ideally bitcode should perhaps match $CC's use, or not, of outline atomic
641+
# functions, but for now we err on the side of suppressing them in bitcode,
642+
# because we can't assume they're available at runtime. This affects aarch64
643+
# builds using the basic armv8-a ISA without LSE support.
644+
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS,[-mno-outline-atomics])
645+
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANG, BITCODE_CXXFLAGS,[-mno-outline-atomics])
646+
640647
NOT_THE_CFLAGS=""
641648
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS,[-Wunused-command-line-argument])
642649
if test -n "$NOT_THE_CFLAGS"; then

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp