Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drd/tests/dlopen is failing #57

Closed
paulfloyd opened this issue Apr 23, 2020 · 4 comments
Closed

drd/tests/dlopen is failing #57

paulfloyd opened this issue Apr 23, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@paulfloyd
Copy link
Owner

In main: creating thread 1

drd: drd_thread.c:611 (vgDrd_thread_set_pthreadid): Assertion 'DRD_(g_threadinfo)[tid].pt_threadid == INVALID_POSIX_THREADID || DRD_(g_threadinfo)[tid].pt_threadid == ptid' failed.

host stacktrace:
==38047== at 0x3802761C: ??? (in /usr/home/paulf/scratch/valgrind/drd/drd-amd64-freebsd)
==38047== by 0x380AE026: ??? (in /usr/home/paulf/scratch/valgrind/drd/drd-amd64-freebsd)
==38047== by 0xDEADBEEFDEADBEEE: ???

sched status:
running_tid=1

Thread 1: status = VgTs_Runnable (lwpid 101560)
==38047== at 0x4A5128B: vgDrd_set_pthread_id (drd_pthread_intercepts.c:526)
==38047== by 0x4A513D4: pthread_create_intercept (drd_pthread_intercepts.c:584)
==38047== by 0x4A513D4: pthread_create (drd_pthread_intercepts.c:602)
==38047== by 0x58006A1: foo (dlopen_lib.c:22)
==38047== by 0x4009EA: main (dlopen_main.c:26)
client stack range: [0x7FEFFD000 0x7FF000FFF] client SP: 0x7FF0001F0
valgrind stack range: [0x40298E000 0x402A8DFFF] top usage: 12620 of 1048576

Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.

If that doesn't help, please report this bug to: www.valgrind.org

In the bug report, send all the above text, the valgrind
version, and what OS and version you are using. Thanks.

@paulfloyd paulfloyd added the bug Something isn't working label Apr 23, 2020
@paulfloyd paulfloyd self-assigned this Apr 23, 2020
@paulfloyd
Copy link
Owner Author

paulfloyd commented May 1, 2020

The assert is firing whilst servicing a client request, VG_USERREQ__SET_PTHREADID

It fires because the threadid is neither new nor equal to the existing one.

This can be either from
DRD_(set_pthread_id)
or
DRD_(thread_wrapper)

In reverse order
DRD_(thread_wrapper) called from pthread_create_intercept, the pthread_create wrapper

DRD_(set_pthread_id) has two callers, pthread_create_intercept again with a note to see B.Z. 356374. and also

/**
 * Shared library initialization function. The function init() is called after
 * dlopen() has loaded the shared library with DRD client intercepts because
 * the constructor attribute was specified in the declaration of this function.
 * Note: do specify the -nostdlib option to gcc when linking this code into a
 * shared library because doing so would cancel the effect of the constructor
 * attribute ! Using the gcc option -nodefaultlibs is fine because this last
 * option preserves the shared library initialization code that calls
 * constructor and destructor functions.
 */
static void DRD_(init)(void)
{
   DRD_(check_threading_library)();
   DRD_(set_pthread_id)();

Looks like we're on to something there

@paulfloyd
Copy link
Owner Author

There are 2 calls to DRD_(thread_set_pthreadid) with the second one failing. This first has pid 1 and ptid 80165632.

(gdb) p vgPlain_get_and_pp_StackTrace(1, 6)
==44351== at 0x485F662: vgDrd_set_pthread_id (drd_pthread_intercepts.c:518)
==44351== by 0x485F662: vgDrd_init (drd_pthread_intercepts.c:256)
==44351== by 0x400D2FC: ??? (in /libexec/ld-elf.so.1)
==44351== by 0x400C03C: ??? (in /libexec/ld-elf.so.1)
==44351== by 0x40098C8: ??? (in /libexec/ld-elf.so.1)

(gdb) p *vgDrd_g_threadinfo

$11 = {sg_first = 0x0, sg_last = 0x0, vg_threadid = 0, pt_threadid = 0, stack_min_min = 0, stack_min = 0, stack_startup = 0, stack_max = 0, stack_size = 0, name = '\000' <repeats 63 times>, on_alt_stack = 0 '\000', valid = 0 '\000', vg_thread_exists = 0 '\000',
posix_thread_exists = 0 '\000', detached_posix_thread = 0 '\000', is_recording_loads = 0 '\000', is_recording_stores = 0 '\000', pthread_create_nesting_level = 0, synchr_nesting = 0, deletion_seq = 0, creator_thread = 0}

so the assert is OK

This one is called because void DRD_(init) is marked with attribute constructor. It makes a call to VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__SET_PTHREADID, with pthread_self()

The above is executing as client code afaict, so not easy to debug the pid that it gets

tl_assert(DRD_(g_threadinfo)[tid].pt_threadid == INVALID_POSIX_THREADID
|| DRD_(g_threadinfo)[tid].pt_threadid == ptid);

because DRD_(g_threadinfo)[tid].pt_threadid == INVALID_POSIX_THREADID is true

Second time round, pid is still 1 and ptid is 88080432

(gdb) p vgPlain_get_and_pp_StackTrace(1, 6)
==44351== at 0x485FBDE: vgDrd_set_pthread_id (drd_pthread_intercepts.c:518)
==44351== by 0x485FBDE: pthread_create_intercept (drd_pthread_intercepts.c:576)
==44351== by 0x485FBDE: pthread_create (drd_pthread_intercepts.c:594)
==44351== by 0x4C7E7AC: foo (in /usr/home/paulf/scratch/valgrind/drd/tests/dlopen_lib.so)
==44351== by 0x201B38: main (dlopen_main.c:26)

But now g_threadinfo)[tid].pt_threadid has the value from the first call.

But, the threadid is different.

Could hack this by not doing that 1st call. Perhaps some init is bad, and the 1st is wrong?

@paulfloyd
Copy link
Owner Author

Workaround:

LD_PRELOAD=/lib/libthr.so.3

@paulfloyd
Copy link
Owner Author

Fixed with

To github.com:paulfloyd/freebsd_valgrind.git
e21eaa0..06b1017 freebsd -> freebsd

Hooray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant