glibc: backport an patch to fix [BZ 19329]

This backports a pending CL from
https://sourceware.org/bugzilla/show_bug.cgi?id=19329
to fix the issue.

The commit message is
This fixes a subset of the issues described in
https://sourceware.org/ml/libc-alpha/2016-11/msg01026.html
without adding locks to pthread_create.

Only races between dlopen and pthread_create were considered,
and the asserts got removed that tried to check for concurrency
issues.

The patch is incomplete because dlclose, tls access and
dl_iterate_phdr related code paths are not modified.

dlclose should be updated in a similar fashion to dlopen
to make the patch complete alternatively pthread_create
may take the GL(dl_load_write_lock) to sync with dlclose
or the GL(dl_load_lock) to sync with dlopen and dlclose
(that would simplify the concurrency design, but increase
lock contention on the locks).

2016-11-30  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	[BZ #19329]
	* elf/dl-open.c (dl_open_worker): Write GL(dl_tls_generation)
	atomically.
	* elf/dl-tls.c (_dl_allocate_tls_init): Read GL(dl_tls_generation),
	GL(dl_tls_max_dtv_idx), slotinfo entries and listp->next atomically.
	Remove assertions that cannot be guaranteed.
	(_dl_add_to_slotinfo): Write the slotinfo entries and listp->next
	atomically.

BUG=chromium:783832
TEST=cbuildbot chromiuos-sdk falco-llvm-toolchain
     kevin-llvm-toolchain caroline-llvm-toolchain
     daisy-llvm-toolchain

Change-Id: I5f929f3e9bc2a4e1733907745e24e47aa92d1156
Reviewed-on: https://chromium-review.googlesource.com/883568
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
2 files changed