1 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2 # Local configure fragment for sysdeps/loongarch/elf.
4 dnl It is always possible to access static and hidden symbols in an
5 dnl position independent way.
6 AC_DEFINE(HIDDEN_VAR_NEEDS_DYNAMIC_RELOC)
8 dnl Test if the toolchain is new enough for static PIE.
9 dnl We need a GAS supporting explicit reloc (older GAS produces stack-based
10 dnl reloc and triggers an internal error in the linker). And, we need GCC to
11 dnl pass the correct linker flags for static PIE. GCC >= 13 and GAS >= 2.40
12 dnl satisfy the requirement, but a distro may backport static PIE support into
13 dnl earlier GCC or Binutils releases as well.
14 AC_CACHE_CHECK([if the toolchain is sufficient to build static PIE on LoongArch],
15 libc_cv_static_pie_on_loongarch, [
16 cat > conftest1.S << EOF
18 .type _start, @function
21 /* This ensures the assembler supports explicit reloc. */
22 pcalau12i \$a0, %pc_hi20(x)
23 ld.w \$a0, \$a0, %pc_lo12(x)
29 /* This should produce an R_LARCH_RELATIVE in the static PIE. */
32 cat > conftest2.S << EOF
36 /* The linker should be able to handle this and produce a PLT entry. */
37 la.pcrel \$t0, \$t0, external_func
41 libc_cv_static_pie_on_loongarch=no
42 if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostdlib -fPIE -o conftest1 conftest1.S]) \
43 && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest1 | grep -q R_LARCH_RELATIVE]) \
44 && ! AC_TRY_COMMAND([LC_ALL=C $READELF -Wl conftest1 | grep -q INTERP]) \
45 && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -shared -fPIC -o conftest2.so conftest2.S]) \
46 && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest2.so | grep -q 'R_LARCH_JUMP_SLOT.*external_func'])
48 libc_cv_static_pie_on_loongarch=yes
52 if test "$libc_cv_static_pie_on_loongarch" = yes; then
53 AC_DEFINE(SUPPORT_STATIC_PIE)
56 # Check if gcc supports option -mcmodel=medium.
57 AC_CACHE_CHECK(whether $CC supports option -mcmodel=medium,
58 libc_cv_loongarch_cmodel_medium, [
59 if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS -mcmodel=medium /dev/null 1>&AS_MESSAGE_LOG_FD); then
60 libc_cv_loongarch_cmodel_medium=yes
62 libc_cv_loongarch_cmodel_medium=no
64 LIBC_CONFIG_VAR([have-cmodel-medium], [$libc_cv_loongarch_cmodel_medium])