[Bug 1757517] [NEW] An unused thread-local memory allocation can cause library calls to segfault.

2018-03-21 Thread Moosfet
Public bug reported:

I've discovered that adding "static __thread anything[8 * 1048576]" to
otherwise working programs will cause them to segfault.  I've attached a
short example that demonstrates the problem.

Compile the attached program like this:  gcc -o test test.c -lpthread
-lasound

When running it, it will display this:

Spawning thread...
Joining thread...
I'm a thread!
Segmentation fault

Unfortunately I haven't been able to figure out how to reproduce it
without using libasound, except that I can use libjack to trigger it
instead, but since that makes two independent libraries that have this
problem, I assume it is caused by something common between them, like
pthreads, GCC, or the Linux kernel.

FWIW, with the Jack version of the bug, I've seen it do two things.
With a larger allocation it displays messages about being unable to
create threads before failing to connect to its server.  With a smaller
allocation, it connects to its server, but then segfaults later in a
different call to libjack.

In all cases, merely removing the "static __thread anything[8 *
1048576]" from the program causes the libraries to work correctly.
Since the variable is never accessed by anything, adding it to the
programs should have no effect.

** Affects: glibc (Ubuntu)
 Importance: Undecided
 Status: New

** Attachment added: "Short example demonstrating the problem."
   https://bugs.launchpad.net/bugs/1757517/+attachment/5086214/+files/test.c

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1757517

Title:
  An unused thread-local memory allocation can cause library calls to
  segfault.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1757517/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

[Bug 1757517] Re: An unused thread-local memory allocation can cause library calls to segfault.

2018-03-21 Thread Moosfet
To see the problem in Jack, this example from the Jack project can do
it:

https://github.com/jackaudio/example-clients/blob/master/simple_client.c

Just add the "static __thread anything[8 * 1048576]" to it and
previously-working code begins doing this instead:

Cannot create thread res = 22
JackMessageBuffer::Create cannot start thread
Cannot create message buffer
Cannot create thread res = 22
Cannot start Jack client listener
Cannot start channel
JackShmReadWritePtr1::~JackShmReadWritePtr1 - Init not done for 4294967295, 
skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, 
skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, 
skipping unlock
jack_client_open() failed, status = 0x21

At least on my system, to get that output, the size of the allocation
must be at least 514025 bytes.  Using one byte less, it successfully
connects, but then segfaults later in a call to jack_activate();

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1757517

Title:
  An unused thread-local memory allocation can cause library calls to
  segfault.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1757517/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs