NetBSD Problem Report #47105

From kretschm@cs.uni-bonn.de  Mon Oct 22 09:35:07 2012
Return-Path: <kretschm@cs.uni-bonn.de>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 6E71763CA81
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 22 Oct 2012 09:35:07 +0000 (UTC)
Message-Id: <1350896581.988949.28717.nullmailer@jaguar-alpha.cs.uni-bonn.de>
Date: Mon, 22 Oct 2012 11:03:01 +0200
From: kretschm@cs.uni-bonn.de
Reply-To: kretschm@cs.uni-bonn.de
To: gnats-bugs@gnats.NetBSD.org
Subject: compiling with -pg, linking with -lpthread & without -pg -> core dump
X-Send-Pr-Version: 3.95

>Number:         47105
>Category:       toolchain
>Synopsis:       compiling with -pg, linking with -lpthread & without -pg -> core dump
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 22 09:40:00 +0000 2012
>Originator:     Matthias Kretschmer
>Release:        NetBSD 6.0_POST_RC1
>Organization:
>Environment:


System: NetBSD jaguar-gamma 6.0_POST_RC1 NetBSD 6.0_POST_RC1 (XEN3PAE_DOMU) #7: Mon Sep 10 10:53:12 CEST 2012 ignatios@random84.cs.uni-bonn.de:/var/itch/sources/6.0/oi386/sys/arch/i386/compile/XEN3PAE_DOMU i386
Architecture: i386
Machine: i386
>Description:
Compiling with -pg and then linking the result with -lpthread but
without -pg makes the resulting program sometimes crash in
pthread_mutex_lock() called by malloc().

>How-To-Repeat:
$ cat test.c
#include <pthread.h>
#include <stdlib.h>


int
main(int argc, char **argv)
{
    (void)malloc(10);

    return EXIT_SUCCESS;
}

$ gcc -c -g -pg test.c
$ gcc -o test test.o -lpthread
$ while true; do ./test; done
[1]   Segmentation fault (core dumped) ./test
[1]   Segmentation fault (core dumped) ./test
[1]   Segmentation fault (core dumped) ./test
...

$ gdb ./test -c test.core
(gdb) bt
#0  0xbb7deab2 in pthread_mutex_lock () from /usr/lib/libpthread.so.1
#1  0x00000050 in ?? ()
#2  0xbb7e9000 in ?? ()
#3  0xbb75da9f in malloc () from /usr/lib/libc.so.12
#4  0x080487ca in main (argc=1, argv=0xbf7feb54) at test.c:8
>Fix:
Link with -pg when compiled with -pg or don't use pthreads.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.