This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Disable single thread optimization for open_memstream
- From: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Cc: nd at arm dot com, Florian Weimer <fweimer at redhat dot com>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Date: Wed, 12 Jul 2017 15:09:40 +0100
- Subject: [PATCH] Disable single thread optimization for open_memstream
- Authentication-results: sourceware.org; auth=none
- Authentication-results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=arm.com;
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Single thread optimization is valid if at thread creation time the
optimization can be disabled. This is in principle true for all
stream objects that user code can access (and thus needs locking),
using the same internal list as fflush(0) uses. However in glibc
open_memstream is not on that list (BZ 21735) so the optimization
has to be disabled.
2017-07-12 Szabolcs Nagy <szabolcs.nagy@arm.com>
* libio/memstream.c (__open_memstream): Set _IO_FLAGS2_NEED_LOCK.
* libio/wmemstream.c (open_wmemstream): Likewise.
diff --git a/libio/memstream.c b/libio/memstream.c
index f83d4a5213..e391efd48a 100644
--- a/libio/memstream.c
+++ b/libio/memstream.c
@@ -96,6 +96,9 @@ __open_memstream (char **bufloc, _IO_size_t *sizeloc)
new_f->fp.bufloc = bufloc;
new_f->fp.sizeloc = sizeloc;
+ /* Disable single thread optimization. BZ 21735. */
+ new_f->fp._sf._sbf._f._flags2 |= _IO_FLAGS2_NEED_LOCK;
+
return (_IO_FILE *) &new_f->fp._sf._sbf;
}
libc_hidden_def (__open_memstream)
diff --git a/libio/wmemstream.c b/libio/wmemstream.c
index 5bc77f52ee..103a760bf5 100644
--- a/libio/wmemstream.c
+++ b/libio/wmemstream.c
@@ -98,6 +98,9 @@ open_wmemstream (wchar_t **bufloc, _IO_size_t *sizeloc)
new_f->fp.bufloc = bufloc;
new_f->fp.sizeloc = sizeloc;
+ /* Disable single thread optimization. BZ 21735. */
+ new_f->fp._sf._sbf._f._flags2 |= _IO_FLAGS2_NEED_LOCK;
+
return (_IO_FILE *) &new_f->fp._sf._sbf;
}