llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[libc][riscv] Fatal error: glibc detected an invalid stdio handle

Open mikhailramalho opened this issue 1 year ago • 1 comments

I started to get the following error when testing the latest ToT libc in a VisionFive 2 board:

$ valgrind ./libc.test.src.stdio.ungetc_test.__build__
==51691== Memcheck, a memory error detector
==51691== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==51691== Using Valgrind-3.21.0.GIT and LibVEX; rerun with -h for copyright info
==51691== Command: ./libc.test.src.stdio.ungetc_test.__build__
==51691== 
[ RUN      ] LlvmLibcUngetcTest.UngetAndReadBack
[       OK ] LlvmLibcUngetcTest.UngetAndReadBack (took 218 ms)
Ran 1 tests.  PASS: 1  FAIL: 0
Fatal error: glibc detected an invalid stdio handle
==51691== 
==51691== Process terminating with default action of signal 6 (SIGABRT)
==51691==    at 0x4B4CC54: __pthread_kill_implementation (pthread_kill.c:44)
==51691==    by 0x4B17B89: raise (raise.c:26)
==51691==    by 0x4B08047: abort (abort.c:79)
==51691==    by 0x4B4438B: __libc_message (libc_fatal.c:150)
==51691==    by 0x4B4439D: __libc_fatal (libc_fatal.c:159)
==51691==    by 0x4B446B5: _IO_vtable_check (vtables.c:67)
==51691==    by 0x4B446B5: _IO_vtable_check (vtables.c:37)
==51691==    by 0x4B3CB91: fflush (libioP.h:945)
==51691==    by 0x494E2B9: std::ostream::flush() (in /usr/lib/riscv64-linux-gnu/libstdc++.so.6.0.31)
==51691==    by 0x48F0AF3: std::ios_base::Init::~Init() (in /usr/lib/riscv64-linux-gnu/libstdc++.so.6.0.31)
==51691==    by 0x4B19265: __cxa_finalize (cxa_finalize.c:82)
==51691==    by 0x48DF975: ??? (in /usr/lib/riscv64-linux-gnu/libstdc++.so.6.0.31)
==51691==    by 0x4000E45: _dl_call_fini (dl-call_fini.c:43)
==51691== 
==51691== HEAP SUMMARY:
==51691==     in use at exit: 73,728 bytes in 1 blocks
==51691==   total heap usage: 10 allocs, 9 frees, 76,108 bytes allocated
==51691== 
==51691== LEAK SUMMARY:
==51691==    definitely lost: 0 bytes in 0 blocks
==51691==    indirectly lost: 0 bytes in 0 blocks
==51691==      possibly lost: 0 bytes in 0 blocks
==51691==    still reachable: 73,728 bytes in 1 blocks
==51691==         suppressed: 0 bytes in 0 blocks
==51691== Rerun with --leak-check=full to see details of leaked memory
==51691== 
==51691== For lists of detected and suppressed errors, rerun with: -s
==51691== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Aborted (core dumped)

libc built with:

$ clang -v
Ubuntu clang version 15.0.7
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/riscv64-linux-gnu/12

on:

$ uname -a
Linux ubuntu 6.2.0-23-generic #23.1-Ubuntu SMP Sat Jun  3 08:01:11 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux

mikhailramalho avatar Jun 27 '23 17:06 mikhailramalho

@llvm/issue-subscribers-libc

llvmbot avatar Jun 27 '23 18:06 llvmbot

Hi,

Sorry it's taken a while to get back to you. I have a theory as to what the problem is. My guess is that valgrind is expecting all ::FILE objects to be glibc files, and when our FILE object is created it interprets it as an invalid file. Is the crash happening when you don't run valgrind on the test?

michaelrj-google avatar Jul 10 '23 21:07 michaelrj-google

Hi,

Sorry it's taken a while to get back to you. I have a theory as to what the problem is. My guess is that valgrind is expecting all ::FILE objects to be glibc files, and when our FILE object is created it interprets it as an invalid file. Is the crash happening when you don't run valgrind on the test?

yes, and this also seems to be related to glibc 2.37.

mikhailramalho avatar Aug 16 '23 16:08 mikhailramalho

https://github.com/llvm/llvm-project/commit/0f6ef9bc2a14be0a5fdb0d05fc6bb2d5474bf0c6

jhuber6 avatar Aug 17 '23 20:08 jhuber6