• Siddhesh Poyarekar's avatar
    kselftest: Minimise dependency of get_size on C library interfaces · 6b64a650
    Siddhesh Poyarekar authored
    It was observed[1] on arm64 that __builtin_strlen led to an infinite
    loop in the get_size selftest.  This is because __builtin_strlen (and
    other builtins) may sometimes result in a call to the C library
    function.  The C library implementation of strlen uses an IFUNC
    resolver to load the most efficient strlen implementation for the
    underlying machine and hence has a PLT indirection even for static
    binaries.  Because this binary avoids the C library startup routines,
    the PLT initialization never happens and hence the program gets stuck
    in an infinite loop.
    
    On x86_64 the __builtin_strlen just happens to expand inline and avoid
    the call but that is not always guaranteed.
    
    Further, while testing on x86_64 (Fedora 31), it was observed that the
    test also failed with a segfault inside write() because the generated
    code for the write function in glibc seems to access TLS before the
    syscall (probably due to the cancellation point check) and fails
    because TLS is not initialised.
    
    To mitigate these problems, this patch reduces the interface with the
    C library to just the syscall function.  The syscall function still
    sets errno on failure, which is undesirable but for now it only
    affects cases where syscalls fail.
    
    [1] https://bugs.linaro.org/show_bug.cgi?id=5479Signed-off-by: default avatarSiddhesh Poyarekar <siddhesh@gotplt.org>
    Reported-by: default avatarMasami Hiramatsu <masami.hiramatsu@linaro.org>
    Tested-by: default avatarMasami Hiramatsu <masami.hiramatsu@linaro.org>
    Reviewed-by: default avatarTim Bird <tim.bird@sony.com>
    Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
    6b64a650
get_size.c 2.82 KB