<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/98711>98711</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc] printf test no longer work after recent changes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          SchrodingerZhu
      </td>
    </tr>
</table>

<pre>
    After recent changes, printf family test no long work in full build mode.
In debug build, the program hang forever at the following scene:
```
❯ gdb /home/schrodinger/development/llvm-project/build-2/libc/test/src/stdio/libc.test.src.stdio.fprintf_test.__unit__.__build
__
GNU gdb (GDB; openSUSE Tumbleweed) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-suse-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.opensuse.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/schrodinger/development/llvm-project/build-2/libc/test/src/stdio/libc.test.src.stdio.fprintf_test.__unit__.__build__...
(gdb) r
Starting program: /home/schrodinger/development/llvm-project/build-2/libc/test/src/stdio/libc.test.src.stdio.fprintf_test.__unit__.__build__ 
Missing separate debuginfos, use: zypper install glibc-debuginfo-2.39-9.1.aarch64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFPrintfTest.WriteToFile
[       OK ] LlvmLibcFPrintfTest.WriteToFile (177 us)
Ran 1 tests.  PASS: 1  FAIL: 0
^C
Program received signal SIGINT, Interrupt.
0x0000fffff7ac7f58 in __lll_lock_wait_private () from /lib64/libc.so.6
Missing separate debuginfos, use: zypper install libgcc_s1-debuginfo-14.1.1+git10335-1.1.aarch64 libstdc++6-debuginfo-14.1.1+git10335-1.1.aarch64
(gdb) bt
#0  0x0000fffff7ac7f58 in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x0000fffff7ab4e04 in fflush () from /lib64/libc.so.6
#2  0x0000fffff7d4745c in std::basic_ostream<char, std::char_traits<char> >::flush() () from /lib64/libstdc++.so.6
#3  0x0000fffff7cc4004 in std::ios_base::Init::~Init() () from /lib64/libstdc++.so.6
#4  0x0000fffff7a83e58 in __cxa_finalize () from /lib64/libc.so.6
#5  0x0000fffff7cad9a0 in ?? () from /lib64/libstdc++.so.6
Backtrace 
```
In release build, I sometime get
```
[3128/4107] Running unit test libc.test.src.stdio.fprintf_test.__unit__
FAILED: libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fprintf_test.__unit__ /home/schrodinger/development/llvm-project/build-2/libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fprintf_test.__unit__ 
cd /home/schrodinger/development/llvm-project/build-2/libc/test/src/stdio && /home/schrodinger/development/llvm-project/build-2/libc/test/src/stdio/libc.test.src.stdio.fprintf_test.__unit__.__build__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFPrintfTest.WriteToFile
[       OK ] LlvmLibcFPrintfTest.WriteToFile (76 us)
Ran 1 tests.  PASS: 1  FAIL: 0
Fatal error: glibc detected an invalid stdio handle
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWNtu4zjSfhr6phBBouTThS_sOA6CP5MJkjQG_94IlFiSuE2TAknZ7bnYZ1-UJDuH6R1096KBXsOAJR6qPlZ9dTCF96o2iCs23bDpdiK60Fi3ei4bZ6UyNbp_NN2ksPK0WlcBHTgs0QQoG2Fq9IxfQ-uUCRVUYq_0CQL6AMaCtqaGo3WfQRmoOq2h6JSWsLcSIxZvWby-MyCx6OphhkSFBqF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