From patchwork Wed Sep 22 07:51:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 45280 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19F243858425 for ; Wed, 22 Sep 2021 07:52:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19F243858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632297136; bh=cRcQaC90n4Z+/1IfKmLQEkKnBYVmOgPRnO3qYmvGp3E=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BD09VZ5foaf7CzEVt1gVW3SrJErLLMnCnS0kmbvsUyBiKGUYICb0I1JcZrV3Jya30 icjnrDQFNxfet4sUMeA0KM2uEefi4aT+dlneRpoapOLOyV/mEr1RVqHrJeTuB08pgK osFaeZOSqAEE31SS8/orW9rMFtohl9NMqguPlo8w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) by sourceware.org (Postfix) with ESMTPS id AD197385842B for ; Wed, 22 Sep 2021 07:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD197385842B Received: from AM6PR10CA0012.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:89::25) by VI1PR08MB3037.eurprd08.prod.outlook.com (2603:10a6:803:42::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Wed, 22 Sep 2021 07:51:37 +0000 Received: from AM5EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:89:cafe::b5) by AM6PR10CA0012.outlook.office365.com (2603:10a6:209:89::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14 via Frontend Transport; Wed, 22 Sep 2021 07:51:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.33.187.114) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.33.187.114 as permitted sender) receiver=protection.outlook.com; client-ip=63.33.187.114; helo=64aa7808-outbound-2.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-2.mta.getcheckrecipient.com (63.33.187.114) by AM5EUR03FT046.mail.protection.outlook.com (10.152.16.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13 via Frontend Transport; Wed, 22 Sep 2021 07:51:37 +0000 Received: ("Tessian outbound ac52c8afb262:v103"); Wed, 22 Sep 2021 07:51:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f59a88c1453ce653 X-CR-MTA-TID: 64aa7808 Received: from 5cc0b9e831cb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id CDE436A9-D3AF-4313-AC66-4AC5C1E6E44A.1; Wed, 22 Sep 2021 07:51:24 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5cc0b9e831cb.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 22 Sep 2021 07:51:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G75Sc3hvylMfDAgYRE14ia5M7yu8K6MDNUY4c5VIs1SAXyU54zh1AyWKx1weI8vrMVkRKN8J/TMvVLlM62lFk5W5FpZDFZColrsfyQF91PBWrux/Tw4PQJYo1l9s+NKP56WcnFlB9c60XB97xv6NzyGYakk1lr7KI1fx/x/Tyxlx5yHrjhRGMnE9FN/weU7vx+Pj102tGEGBp+8kU/cDfTPOdi0lt7u2MBModbQ4xh0/VU5Bjxql5pvepL1l/oXaSx90XaVO172/7/U8yecfkoN4zN1k4+UFc6EujOruzsfsIb3dX5ef+nk8XVJfoznfuuURjS3xsXhh2t42RQoPmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cRcQaC90n4Z+/1IfKmLQEkKnBYVmOgPRnO3qYmvGp3E=; b=oGHP5CG/vbiJIY5YvqUUI6/7T8yV0c8nLxXCMrzkXw5jAFNzy5x39hqVDzv9ad3mD97cgd/0iSMKGZFaWE1qTLXBn4GVpxkU4hVuvOgHGjPT0rWbxXiexYUfS0akEyYLsARGYTSQMp4SvE++n6DP3KO5uh8ozfAEI34jgBB+BdmUMup3pSoAM9t4o1FS9VKcd5N96CFQichli0Vez4U/oHEcZoYK8+VsRY8rf6LYPKjrOLXRQT9AjLCS/hu43kGVQ4JRh+Qd1C+qk5uNpDhDiErLzl98I/biCvoPIrBFdFQmmDjvVHERLQhpRjxKFc1qBymNbe69GRsfGx2ruvzatA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PR2PR08MB4875.eurprd08.prod.outlook.com (2603:10a6:101:27::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Wed, 22 Sep 2021 07:51:22 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::118b:49d3:ac4a:966f]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::118b:49d3:ac4a:966f%8]) with mapi id 15.20.4544.013; Wed, 22 Sep 2021 07:51:22 +0000 To: libc-alpha@sourceware.org Subject: [PATCH 2/2] Add a pthread_create deadlock test [BZ #28357] Date: Wed, 22 Sep 2021 08:51:10 +0100 Message-Id: <20210922075110.5050-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SN4PR0201CA0064.namprd02.prod.outlook.com (2603:10b6:803:20::26) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 Received: from localhost.localdomain (217.140.106.55) by SN4PR0201CA0064.namprd02.prod.outlook.com (2603:10b6:803:20::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13 via Frontend Transport; Wed, 22 Sep 2021 07:51:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 912d9ef8-61e0-4df0-f878-08d97d9dce3c X-MS-TrafficTypeDiagnostic: PR2PR08MB4875:|VI1PR08MB3037: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7691;OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: VlVme8M6j/3j3aPRjjHfO3IGUINNoT8hhS0gHW0+ZykQ3yWI8fXq4ur0kq5c2MZ1qWi9gbid1ATWCz8K9wqAYThv8yLQb/gYtzezuzUBS74VYUczeWjGFfgbZSYe43QdvrWUMiCZLGLX14HBi0OSTTp+GruNATCU5AyujqmPWCTNPoRS5KfAVmQ65Pcyo494r7UoDk/OU/a2alummvCfAc9OJ48sRAOh8mfqpIFlYN3bVx9hwp+HQymTxRntm558ZV+qtMZ4Ij/gyFW3eAawgY0Tui7JvvZXeOD4fE90QGT/SJXc2p1ILXusCXk93EBNQ/KzgPTTUTbwLT4akdxTPhU4sKAYbnX4+4pQAaOuJygVuTuMiPQHul40rO3iDfhgQIIJhjEofTQBGNEA3WNFVbdc4+SYOAuE7M0X2Qj2uI1j7JQaZMmbaNlyZNeEYSQglTlp3rtS+MbOm/a0CzjcxGTpf1SAPUtgqmHR2Lx6YTMe/PnSeKGhHO/S2ZQuIUfaZtzRyqmh/n3NPXeVRg3hESd/AFEQ6BopxfJk57dT9v8PwtKADlwN2SV1pi4EFh3PO7fX3C0S25hnQ5UDOfqSMqM1mGQVUopCub5Ck/miq1oUumoT07dP101aQfMt06tMFpl7QxGW4+Wabt7EITd+njasvQzSBO1Sqef12PcQHA+vmdpixQ7eTr540kRUU9dyEO+IOVYUKZFm5YMxUFxpsHkXEj3EQeyHjmTG2U2ErpOHLQVIj82iLUGZoaLALTy3tB1SR8OQvFbcyPFey7tAiis/PQCrlUlmEPGyrDeDnSn/Cwy4zJXO/jjxZgKznOqxAUpEwy5MocFPmId53Oz4Xw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(44832011)(2616005)(6486002)(2906002)(6506007)(956004)(52116002)(6916009)(86362001)(36756003)(8936002)(6512007)(508600001)(316002)(6666004)(5660300002)(38350700002)(38100700002)(66476007)(66556008)(66946007)(8676002)(1076003)(186003)(26005)(83380400001)(2004002)(473944003); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4875 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: a3237526-852c-4a0b-8647-08d97d9dc535 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vg2Ft0Mqhkzj9cCcm3vKBf97rWa47WTjEFT1e9wKHRU2zPZbNn8tDvXuxxmvy8m9R49cMRi7ZTTiRfuKyA3+bBqOUqv5LoAh2VKbLj3ZPlFz+MR/mJPugrtS0SPPa+9708+e7rN5a895LlEboqy7YVRddjF2kbRst+OJnR274OcccIdxc1jZpVWWRlchRZr9xCD8p1+z/nZWAe1EaxJSzwZtjXR33XSdLQ8KxkLHxspynOzmNBi6rb8yJy0H3d8NFNf5mg6MZB37gTx4v+KB0Fh61yTqvU+kBKcQWg+V5q55+v0ftCCHdAtmp07MQQC3PUffR2lb/nzCyneXaWkBL9BRCYkHSBvpnUiLyYtzLV2cls3FAztieMTPtfLNn0XYECC1JvnEs05Clf+cJCj7e0X4SBLG8ykIEa4jSaxHV+P/hVCFufnHlV0eWrDAn5Y5I65nR81mNoh1PpA72P+2r6Z0CoN1Tycaq0T49uDYm5PhOWHiQkVBQOrmh8bkY8oHrBxDsXH1IHrDlVVUf1jQbh8CqSG4iWeHJ3oqECC7s+5P7bylW+o6cwZiDAxICkdULEaoSLuRiBhCk2VmeRzE/fztqU1xG48eDiZMVMljrjFbkEoYQH4VhpHgJZWT94Hf+VZIFjbsMxZS/LIuJZdpIlaOguJeLkElS3mi8G7xSC+CMJGjK4UebFCLcN0e9c0f8zQ+pLSYjiNRKATRwanEodQgaTgn3tqMRNnsWn9mFYj1/dUAVdQNxyklaI4WbjV8J3laSMRENkpQBY0zl94GSzdCRmjq+1AOVkokaW7vELQCeHQEH0/bBKkHfbqgExGiQPBDk2BbSISlbL1wuYCPCw== X-Forefront-Antispam-Report: CIP:63.33.187.114; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-2.mta.getcheckrecipient.com; PTR:ec2-63-33-187-114.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(956004)(356005)(2616005)(83380400001)(6486002)(70206006)(70586007)(44832011)(36756003)(508600001)(6512007)(82310400003)(2906002)(8676002)(6666004)(1076003)(336012)(86362001)(316002)(186003)(5660300002)(8936002)(6506007)(47076005)(6916009)(36860700001)(81166007)(26005)(2004002)(473944003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2021 07:51:37.2217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 912d9ef8-61e0-4df0-f878-08d97d9dce3c X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.33.187.114]; Helo=[64aa7808-outbound-2.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3037 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Check if locks in ctors or dtors can cause pthread_create to deadlock. Reviewed-by: Adhemerval Zanella --- sysdeps/pthread/Makefile | 10 ++- sysdeps/pthread/tst-create1.c | 120 +++++++++++++++++++++++++++++++ sysdeps/pthread/tst-create1mod.c | 41 +++++++++++ 3 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 sysdeps/pthread/tst-create1.c create mode 100644 sysdeps/pthread/tst-create1mod.c diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index 48dba717a1..4a21abdc38 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -150,15 +150,17 @@ tests += tst-cancelx2 tst-cancelx3 tst-cancelx6 tst-cancelx8 tst-cancelx9 \ tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3 ifeq ($(build-shared),yes) -tests += tst-atfork2 tst-pt-tls4 tst-_res1 tst-fini1 +tests += tst-atfork2 tst-pt-tls4 tst-_res1 tst-fini1 tst-create1 tests-nolibpthread += tst-fini1 endif modules-names += tst-atfork2mod tst-tls4moda tst-tls4modb \ - tst-_res1mod1 tst-_res1mod2 tst-fini1mod + tst-_res1mod1 tst-_res1mod2 tst-fini1mod \ + tst-create1mod test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names))) tst-atfork2mod.so-no-z-defs = yes +tst-create1mod.so-no-z-defs = yes ifeq ($(build-shared),yes) # Build all the modules even when not actually running test programs. @@ -277,4 +279,8 @@ LDFLAGS-tst-join7mod.so = -Wl,-soname,tst-join7mod.so CFLAGS-tst-unwind-thread.c += -funwind-tables +LDFLAGS-tst-create1 = -Wl,-export-dynamic +$(objpfx)tst-create1: $(shared-thread-library) +$(objpfx)tst-create1.out: $(objpfx)tst-create1mod.so + endif diff --git a/sysdeps/pthread/tst-create1.c b/sysdeps/pthread/tst-create1.c new file mode 100644 index 0000000000..44d1c0fc34 --- /dev/null +++ b/sysdeps/pthread/tst-create1.c @@ -0,0 +1,120 @@ +/* Verify that pthread_create does not deadlock when ctors take locks. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +/* +Check if ctor and pthread_create deadlocks in + +thread 1: dlopen -> ctor -> lock(user_lock) +thread 2: lock(user_lock) -> pthread_create + +or in + +thread 1: dlclose -> dtor -> lock(user_lock) +thread 2: lock(user_lock) -> pthread_create +*/ + +static pthread_barrier_t bar_ctor; +static pthread_barrier_t bar_dtor; +static pthread_mutex_t user_lock = PTHREAD_MUTEX_INITIALIZER; + +void +ctor (void) +{ + xpthread_barrier_wait (&bar_ctor); + dprintf (1, "thread 1: in ctor: started.\n"); + xpthread_mutex_lock (&user_lock); + dprintf (1, "thread 1: in ctor: locked user_lock.\n"); + xpthread_mutex_unlock (&user_lock); + dprintf (1, "thread 1: in ctor: unlocked user_lock.\n"); + dprintf (1, "thread 1: in ctor: done.\n"); +} + +void +dtor (void) +{ + xpthread_barrier_wait (&bar_dtor); + dprintf (1, "thread 1: in dtor: started.\n"); + xpthread_mutex_lock (&user_lock); + dprintf (1, "thread 1: in dtor: locked user_lock.\n"); + xpthread_mutex_unlock (&user_lock); + dprintf (1, "thread 1: in dtor: unlocked user_lock.\n"); + dprintf (1, "thread 1: in dtor: done.\n"); +} + +static void * +thread3 (void *a) +{ + dprintf (1, "thread 3: started.\n"); + dprintf (1, "thread 3: done.\n"); + return 0; +} + +static void * +thread2 (void *a) +{ + pthread_t t3; + dprintf (1, "thread 2: started.\n"); + + xpthread_mutex_lock (&user_lock); + dprintf (1, "thread 2: locked user_lock.\n"); + xpthread_barrier_wait (&bar_ctor); + t3 = xpthread_create (0, thread3, 0); + xpthread_mutex_unlock (&user_lock); + dprintf (1, "thread 2: unlocked user_lock.\n"); + xpthread_join (t3); + + xpthread_mutex_lock (&user_lock); + dprintf (1, "thread 2: locked user_lock.\n"); + xpthread_barrier_wait (&bar_dtor); + t3 = xpthread_create (0, thread3, 0); + xpthread_mutex_unlock (&user_lock); + dprintf (1, "thread 2: unlocked user_lock.\n"); + xpthread_join (t3); + + dprintf (1, "thread 2: done.\n"); + return 0; +} + +static void +thread1 (void) +{ + dprintf (1, "thread 1: started.\n"); + xpthread_barrier_init (&bar_ctor, NULL, 2); + xpthread_barrier_init (&bar_dtor, NULL, 2); + pthread_t t2 = xpthread_create (0, thread2, 0); + void *p = xdlopen ("tst-create1mod.so", RTLD_NOW | RTLD_GLOBAL); + dprintf (1, "thread 1: dlopen done.\n"); + xdlclose (p); + dprintf (1, "thread 1: dlclose done.\n"); + xpthread_join (t2); + dprintf (1, "thread 1: done.\n"); +} + +int +do_test (void) +{ + thread1 (); + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/sysdeps/pthread/tst-create1mod.c b/sysdeps/pthread/tst-create1mod.c new file mode 100644 index 0000000000..62c9006961 --- /dev/null +++ b/sysdeps/pthread/tst-create1mod.c @@ -0,0 +1,41 @@ +/* Verify that pthread_create does not deadlock when ctors take locks. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Require TLS setup for the module. */ +__thread int tlsvar; + +void ctor (void); +void dtor (void); + +static void __attribute__ ((constructor)) +do_init (void) +{ + dprintf (1, "constructor started: %d.\n", tlsvar++); + ctor (); + dprintf (1, "constructor done: %d.\n", tlsvar++); +} + +static void __attribute__ ((destructor)) +do_end (void) +{ + dprintf (1, "destructor started: %d.\n", tlsvar++); + dtor (); + dprintf (1, "destructor done: %d.\n", tlsvar++); +}