This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug dynamic-link/22634] New: Missing IFUNC support is not detected for gcc --enable-default-pie, breaks at least ia64 target


https://sourceware.org/bugzilla/show_bug.cgi?id=22634

            Bug ID: 22634
           Summary: Missing IFUNC support is not detected for gcc
                    --enable-default-pie, breaks at least ia64 target
           Product: glibc
           Version: 2.27
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: slyfox at inbox dot ru
  Target Milestone: ---

Original bug report:
    https://bugs.gentoo.org/641216

On ia64 glibc's ./configure (false) detects IFUNC support on gcc built as
--enable-default-pie. This manifests as crashes when calling IFUNC-resolved
functions from librt:

    $ cat a.c
    #include <time.h>
    #include <stdio.h>

    int main() {
        struct timespec t;
        int r = clock_getres(CLOCK_REALTIME, &t);
        printf ("r=%i; tv_sec=%llu, tv_nsec=%llu\n", r, (unsigned long
long)t.tv_sec, (unsigned long long)t.tv_nsec);
    }

    $ gcc -Wall a.c -o a
    $ ./a
    r=0; tv_sec=0, tv_nsec=4000000
    # ok

    $ gcc -Wall a.c -o a -lrt
    $ ./a
    SIGSEGV (core dumped)
    # crash

    $ LD_BIND_NOW=1 ./a
    r=339656; tv_sec=0, tv_nsec=0
    # garbage data


Relevant log snippet from config.log:

  configure:3948: checking for assembler and linker STT_GNU_IFUNC support

  Relocation section '.rela.dyn' at offset 0x1b0 contains 1 entries:
    Offset          Info           Type           Sym. Value    Sym. Name +
Addend
0000000102e8  00000000006f R_IA64_REL64LSB                      1d0
  configure:3979: result: yes

It should be an _IRELATIVE relocation to declare ifunc support. This is
unrelated relocation.

Instead glibc checks for any relocations and gets tricked by unrelated
relocation:
   
https://sourceware.org/git/?p=glibc.git;a=blob;f=configure.ac;h=ca1282a6b3f8c5369c133a47f5c8239c3f2d32b5;hb=HEAD#l597

Building glibc with libc_cv_ld_gnu_indirect_function=no restores librt.so
calls.

Basically this test is too weak to detect ifunc support:

 619   LC_ALL=C $READELF -r conftest | grep 'no relocations' >/dev/null || {
 620     libc_cv_ld_gnu_indirect_function=yes
 621   }

One of the solutions would be to build final binary with -no-pie / -nopie
(depends on gcc version).
Another would be to grep specifically for R_.+_IRELATIVE (repends on reloaction
names).

List of likely unaffected targets (given new enough binutils):
  #define R_386_IRELATIVE    42
  #define R_SPARC_IRELATIVE       249
  #define R_PPC_IRELATIVE         248
  #define R_PPC64_IRELATIVE       248
  #define R_AARCH64_P32_IRELATIVE
  #define R_AARCH64_IRELATIVE     1032
  #define R_ARM_IRELATIVE         160
  #define R_390_IRELATIVE         61
  #define R_X86_64_IRELATIVE      37

List of likely affected targets (don't know how many of those are linux/pie
capable):
    #define R_68K_
    #define R_MIPS_
    #define R_PARISC_
    #define R_ALPHA_
    #define R_IA64_
    #define R_SH_
    #define R_CRIS_
    #define R_MN10300_
    #define R_M32R_
    #define R_MICROBLAZE_
    #define R_MICROBLAZE_64_
    #define R_NIOS2_
    #define R_TILEPRO_
    #define R_TILEGX_
    #define R_BPF_
    #define R_METAG_

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]