llvm-project/llvm/test
Fangrui Song a0c0389ffb [SimplifyLibcalls] Don't replace locked IO (fgetc/fgets/fputc/fputs/fread/fwrite) with unlocked IO (*_unlocked)
This essentially reverts some of the SimplifyLibcalls part changes of D45736 [SimplifyLibcalls] Replace locked IO with unlocked IO.

C11 7.21.5.2 The fflush function

> If stream is a null pointer, the fflush function performs this flushing action on all streams for which the behavior is defined above.

i.e. fopen'ed FILE* is inherently captured.

POSIX.1-2017 getc_unlocked, getchar_unlocked, putc_unlocked, putchar_unlocked - stdio with explicit client locking

> These functions can safely be used in a multi-threaded program if and only if they are called while the invoking thread owns the ( FILE *) object, as is the case after a successful call to the flockfile() or ftrylockfile() functions.

After a thread fopen'ed a FILE*, when it is calling foobar() which is now replaced by foobar_unlocked(),
if another thread is concurrently calling fflush(0), the behavior is undefined.

C11 7.22.4.4 The exit function

> Next, all open streams with unwritten buffered data are flushed, all open streams are closed, and all files created by the tmpfile function are removed.

The replacement is only feasible if the program is single threaded, or exit or fflush(0) is never called.
See also http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20180528/556615.html
for how the replacement makes libc interceptors difficult to implement.

dalias: in a worst case, it's unbounded data corruption because of concurrent access to pointers
without synchronization.  f->wpos or rpos could get outside of the buffer, thread A could do
f->wpos += j after knowing j is in bounds, while thread B also changes it concurrently.

This can produce exploitable conditions depending on libc internals.

Revert the SimplifyLibcalls part change because the cons obviously
overweigh the pros.  Even when the replacement is feasible, the benefit
is indemonstrable, more so in an application instead of an artificial
glibc benchmark.  Theoretically the replacement could be beneficial when
calling getc_unlocked/putc_unlocked in a loop, but then it is better
using a blocked IO operation and the user is likely aware of that.

The function attribute inference is still useful and thus kept.

Reviewed By: xbolva00

Differential Revision: https://reviews.llvm.org/D75933
2020-03-10 11:11:58 -07:00
..
Analysis [X86][SSE] Add more accurate costs for fmaxnum/fminnum codegen 2020-03-10 11:59:40 +00:00
Assembler Reland "[DebugInfo][clang][DWARF5]: Added support for debuginfo generation for defaulted parameters 2020-03-02 16:45:48 +05:30
Bindings Revert "Rework go bindings so that validation works fine" 2020-02-24 09:20:08 -08:00
Bitcode Revert "Restore "[WPD/LowerTypeTests] Delay lowering/removal of type tests until after ICP"" 2020-03-02 14:02:13 -08:00
BugPoint
CodeGen ARM: Fixup some tests using denormal-fp-math attribute 2020-03-10 14:02:06 -04:00
DebugInfo Reland "[DebugInfo] Enable the debug entry values feature by default" 2020-03-10 09:15:06 +01:00
Demangle
Examples
ExecutionEngine [JITLink] Add a -slab-address option to llvm-jitlink. 2020-03-03 14:25:51 -08:00
Feature Remove no un-necessary require for load_extension.ll 2020-02-26 08:29:09 +01:00
FileCheck
IR Fixed [AssumeBundles] Move to IR so it can be used by Analysis 2020-03-10 18:02:39 +01:00
Instrumentation Reland: [Coverage] Revise format to reduce binary size 2020-02-28 18:12:04 -08:00
Integer
JitListener
LTO ThinLTOBitcodeWriter: drop dso_local when a GlobalVariable is converted to a declaration 2020-03-05 18:09:33 -08:00
Linker
MC [tests] Add long nop test coverage for intel platforms 2020-03-09 15:29:04 -07:00
MachineVerifier
Object [lib/ObjectYAML] - Make `ELFYAML::Relocation::Offset` optional. 2020-03-06 13:59:58 +03:00
ObjectYAML
Other [SLP] Support vectorizing functions provided by vector libs. 2020-03-10 13:10:50 +00:00
Reduce
SafepointIRVerifier
Support
SymbolRewriter
TableGen TableGen: Fix logic for default operands 2020-02-19 23:41:07 -05:00
ThinLTO/X86 [WPD] Provide a way to prevent functions from being devirtualized 2020-03-09 14:05:15 +03:00
Transforms [SimplifyLibcalls] Don't replace locked IO (fgetc/fgets/fputc/fputs/fread/fwrite) with unlocked IO (*_unlocked) 2020-03-10 11:11:58 -07:00
Unit
Verifier More principled implementation of DISubprogram::describes() 2020-03-02 10:03:14 -08:00
YAMLParser
tools Reland "[DebugInfo] Enable the debug entry values feature by default" 2020-03-10 09:15:06 +01:00
.clang-format
CMakeLists.txt Revert abb00753 "build: reduce CMake handling for zlib" (PR44780) 2020-03-03 11:03:09 +01:00
TestRunner.sh
lit.cfg.py Revert "Rework go bindings so that validation works fine" 2020-02-24 09:20:08 -08:00
lit.site.cfg.py.in Revert abb00753 "build: reduce CMake handling for zlib" (PR44780) 2020-03-03 11:03:09 +01:00