Bug 234775 - PTHREAD_STACK_MIN is too small on amd64
Summary: PTHREAD_STACK_MIN is too small on amd64
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-09 04:18 UTC by Mark Johnston
Modified: 2019-01-09 04:19 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Johnston freebsd_committer 2019-01-09 04:18:44 UTC
The following program segfaults on amd64:

#include <limits.h>
#include <pthread.h>

static void *
fn(void *arg __unused)
{

        return (NULL);
}

int
main(void)
{
        pthread_t t;
        pthread_attr_t attr;

        (void)pthread_attr_init(&attr);
        (void)pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);

        (void)pthread_create(&t, &attr, fn, NULL);
        (void)pthread_join(t, NULL);

        return (0);
}

We end up crashing when the thread exits:

(gdb) bt
#0  symlook_obj1_gnu (req=0x7fffdfffd070, obj=0x80022a000) at /home/mark/src/freebsd-dev/libexec/rtld-elf/rtld.c:4463
#1  symlook_obj (req=0x7fffdfffd070, obj=0x80022a000) at /home/mark/src/freebsd-dev/libexec/rtld-elf/rtld.c:4272
#2  0x0000000800214357 in symlook_list (req=<optimized out>, dlp=<optimized out>, objlist=<optimized out>)
    at /home/mark/src/freebsd-dev/libexec/rtld-elf/rtld.c:4197
#3  symlook_global (req=0x7fffdfffd6d0, donelist=0x7fffdfffd1c0) at /home/mark/src/freebsd-dev/libexec/rtld-elf/rtld.c:4091
#4  0x000000080020dd3c in symlook_default (req=0x7fffdfffd6d0, refobj=0x80022a800) at /home/mark/src/freebsd-dev/libexec/rtld-elf/rtld.c:4148
#5  0x000000080020ea73 in do_dlsym (handle=0xfffffffffffffffe, name=0x80025049b "_Unwind_ForcedUnwind", retaddr=0x800263dbe <_pthread_exit_mask+158>, 
    ve=0x0, flags=<error reading variable: Cannot access memory at address 0x2>) at /home/mark/src/freebsd-dev/libexec/rtld-elf/rtld.c:3503
#6  0x0000000800263dbe in thread_uw_init () at /home/mark/src/freebsd-dev/lib/libthr/thread/thr_exit.c:82
#7  _pthread_exit_mask (status=0x0, mask=0x0) at /home/mark/src/freebsd-dev/lib/libthr/thread/thr_exit.c:243
#8  0x0000000800263d1b in _pthread_exit (status=0x7fffdfffd070) at /home/mark/src/freebsd-dev/lib/libthr/thread/thr_exit.c:208
#9  0x000000080025675e in thread_start (curthread=0x80100a500) at /home/mark/src/freebsd-dev/lib/libthr/thread/thr_create.c:291
#10 0x0000000000000000 in ?? ()
Comment 1 Mark Johnston freebsd_committer 2019-01-09 04:19:48 UTC
PTHREAD_STACK_MIN is 2048 on amd64.  I'm not sure it makes much sense for it to be less than the page size.