From patchwork Sun Mar 26 23:11:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Mezentsev X-Patchwork-Id: 75166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1165619vqo; Sun, 26 Mar 2023 16:11:49 -0700 (PDT) X-Google-Smtp-Source: AKy350Yimv+eH+S6e0zG9PxKMwFdSa+0Mgs42L3MJxEyn+O5n6zctbIgMMh8Vo7dS86RYAvLwjlO X-Received: by 2002:aa7:df84:0:b0:501:d532:d84e with SMTP id b4-20020aa7df84000000b00501d532d84emr8983492edy.39.1679872309146; Sun, 26 Mar 2023 16:11:49 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z10-20020aa7cf8a000000b0050220a6041asi8599547edx.311.2023.03.26.16.11.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 16:11:49 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XNnmULWW; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB7383858C2C for ; Sun, 26 Mar 2023 23:11:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB7383858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679872307; bh=Ips1PoVBxKzfJycPNm+T5oscxnsWze3DDArRxkF1pLE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XNnmULWW00hQ6Q1tteeo4HWtbHXHUCqB4khuLbbg8klgcPBeNdG8z5JTYYn63QCK4 DcEmb0aXPUnrYf0/s85hSOiyLPa/6/TApPVey3Z2pCSf8vY6mIp2lYbSzTeJu3KBXM zhQFOK39JNndHwSyTep9LhIOzfgocG9eecN658nU= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 098D43858D37 for ; Sun, 26 Mar 2023 23:11:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 098D43858D37 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32QNAUwJ029194 for ; Sun, 26 Mar 2023 23:11:28 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pjyg0g03d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 26 Mar 2023 23:11:27 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 32QJ1XcQ009243 for ; Sun, 26 Mar 2023 23:11:25 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3phqdahecm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 26 Mar 2023 23:11:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T/CbPSelogFs2lhycPCZLRcpU4P9McNcbbVzNo6mfL0FW4VE7gau/DxjUSRv4P9suaCzHJqWKXAr+vTRtxxbrYLdJUhBBl/g1diuJ108jNgXh1B6oo+CzFJ7DSNkMYmuL9UFeExkmRK/mOeehv6R92Uq/zKc6OH6zWf1vfQAzJUOf1Mp5BCXr4g8mvxtVaATh3D00t6biEDVzf6IjIsuud6RHIgUEL5CrZhLfiFchgFv12CQa7eNUc4ssSCVPbPkW7tWrNDWssgRuVIQwqI+zI3Uog4lXnaihjmiviuMU2NwZg/NFByNPpGNe3/3E8evELJeswFKc2uAXcrpcjOovw== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ips1PoVBxKzfJycPNm+T5oscxnsWze3DDArRxkF1pLE=; b=hTaR3K4f2CnAkd3IG0Ih5hj+wETjCgAYOb7h1FufGTY0EoREewjXHhPZlgV2/uB5ayZOqSxZMAwVuD+zTAvzf52ZufgaWz4OqI4LWII95AX1UagXD1Pgi+MjjdklRxl/2HufoEZblch93pWCmVVuyNH5iAfWuWffiEsPVasEueu2PyoXm1JtTaYXuHfUx59olG01OJRGLPzqXzYaiQUNqj0myLnu5Jfqlff7xFY/kdw2EFQM6Mp+hawTBFa8+4bvvpefErJBOx0lS0ql5attUI3pUTs0M29mVIvu8SQANP4j5qFXs48mEkL4/JriYoIAPak678cF58e5eg4a4jKH3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10) by PH0PR10MB5580.namprd10.prod.outlook.com (2603:10b6:510:ff::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Sun, 26 Mar 2023 23:11:16 +0000 Received: from SA2PR10MB4636.namprd10.prod.outlook.com ([fe80::534c:a39:4701:8319]) by SA2PR10MB4636.namprd10.prod.outlook.com ([fe80::534c:a39:4701:8319%4]) with mapi id 15.20.6178.038; Sun, 26 Mar 2023 23:11:16 +0000 To: binutils@sourceware.org Cc: Vladimir Mezentsev Subject: [Review is neded] gprofng: 30089 [display text] Invalid number of threads Date: Sun, 26 Mar 2023 16:11:11 -0700 Message-Id: <20230326231111.3207581-1-vladimir.mezentsev@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: SA9PR13CA0103.namprd13.prod.outlook.com (2603:10b6:806:24::18) To SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PR10MB4636:EE_|PH0PR10MB5580:EE_ X-MS-Office365-Filtering-Correlation-Id: ced9ca9a-2eb6-4f2c-08ee-08db2e4f6692 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oQYGq5HECJHIp+DPLVihk5qrWnCJJegIKJVVjsvSLyB6hc+rgAXzlql60f3tTfGn8RH7x1BWESe2aBuKN770oLg+8vz72KgfdLpyFWj12mZwf12l+M1ej5elsNmNOL7uYceM6Qm4ee2qHjCKNpk9q5pXg+7+CYaJiAyNO86EXs1HAXtDQkQnUchkXBV9JuUXWopE9AskKV7zFms6XNDPU5zMSRREozT5MnVO/zIwls2l2I5SwOVmApVFwib8A+M+/Ww1/FysP107lH4nerv9GA10voGV8Zy1ePbYQ3rBF2K9e43/W9WmEMdp8k209dPHCHgaRQqpzKpfPCogNWsDoGVnnjtINU+eew/i0afaZQv1iInngHAxrKCJ4iTRBeyQLSwbojDHUbT2+1LiqO8Iks1GAVN4r1dH2rifSfnrk+t3y18f3N2hCxUwpyeRcy03o3kcCW7fhPuXTd27kx1T1CyLrjACaq1acHps3HAmgGodLoe7ASsKZXhwXiK3M7aqaGwhW/tmqlIsw2Dc5RcvrT9N99Dg/nJ3SjWu5GmUT1+0D1d3nyZ20zvz7Vlt9Ovfc+ur27WPKIFo4+o7nG4jnA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA2PR10MB4636.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(5660300002)(2616005)(41300700001)(84970400001)(6916009)(186003)(8936002)(66476007)(66556008)(6506007)(4326008)(9686003)(107886003)(66946007)(38100700002)(6512007)(83380400001)(36756003)(1076003)(8676002)(26005)(30864003)(6486002)(478600001)(316002)(6666004)(2906002)(86362001)(2004002)(579004)(559001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WTk5/rS1vjrdLB0wacogpSC0S8b/aR+txIDZE6TVFnqfBHCdVU3b9AvCBrs/Ps6xELwEry0iWHt9WYMRnE5316gwa6gLg0ZVF7hfq/2AjWqFX7fKgH/LqextZ3YnsLy8EJyaryesK/gdaGSGMFNUP6Z20WCynFu/zky9XPs0vIyRL9fSAqseMAVx0NnOSDpPEl84WKPhbzZ0XgxBQTSNjcd4Fox6qoQUikjzAPlNFiIVasgkrOORJ0X8oKVnZ5amwW6C2+pajgEZKbobsakfwpD3fNiZeK7BVyPNxECzptjjcwtq4k7qMpSb7qUAwSayyM+s1G1xZvU8bYyQx48uXZSYMtXsNfY9nhZdZrGA/+OhpmagU5B7wDTW2IzWr2QoX2EjFDaUOmjHaD/Y9PXwWlpHlNfLtTSwr6VnBsW3lHMH4+UxFriCAsuuqCjxIB3/Yz0W52X/RBBjCeFwAip6SkRqOK+eV5mWAsbSxNWaCVF7ASLSOGng1X6WGZUGgYrrvTO9NangVc5A4wYJtScevJWanSQGYP8cKtXwyhAMYcwh8jXJl2P98hiVbNxaOoVYJGus8pauIIfMvpDjJQ05za3PgacFyNVy0u5ciPcZ9eQ4bW/eK6EVwnP8r/b9iBo5sNEOsEF8rT/slc2+BH8rOkNNs2fjRCEhuKo74f/VdVg0X9PLIZdaoNZixwyJtDyL6g2bky9hAMb0YZbuOBVyKJgZ0UOwik8Rj2gYRygtegAqfmaiXd6JPFmTGiKt4GTQWI0j9g+JruQuk3gGYJUR6QtSt3lzQ9l8fgfi57yHVx2qWLEKSygAY328SlQ3WwRtBPXT19SzZ2cn5V8xvR5gVzJcnKRpr9em1Rl+drTRp5uur1zdw10MTHxl+XnQSw4m73O+wqzMeNrVzMvdX1n7Wqa/PObFviPPVe7ya8a1YPKUq3YW0/NQqliJzRYpOVLS2NTVMtSV3lXutmQyvP2WWCUE7f1nxCoevaSGGN1dMGw06czozjUhxltXcXy0xI3uywbIZ6dxtDv7UpKnYbAVg3Qq/GNmfGpdfBwljVwYFfChYIY2LIkyXsWwwnam5VJABsJfk5aWVSxZ4IdCOVX+iG85okmBuHbjTGNMy7meeBvKLFBvS4sIR3QEXZqhCHgVh+tzXB6deRYfD1Tc0Qwmj3TV/50Yd3RwvW+0gwguYa8GVqFRz6k1udsUHv+GoEx8MUSu4nLUECLErhbfoEzGpQDYuGKpI/sPelA/HCdOlpb+x/L+ApM5ilAtevO5jXK3KG3xQcazleDC3rYwXLuLfbuXfT1cYF9pKzCbbNEXtPW6RbI3qGHYmOuG5KHdRNDm6RXZ9R+q1KcO1UmLeBVesA/Q/7OKtue4Fg5HjxNt4VdduJ1daKtDQPhn3O1oCAuM5biZDhjOJmrGGdqeZQWXNht4d1oPiMh8NU4faw3Oy0l+G8ZqjwkcrEEsfZvrjyMWLtFrm3H3BdZmEhzRDWD++XEPn/nVeUUruBPIsway/DMxrS+0p7pB7ANhCdV4HTgC9IqFIeTPfF4X02ztjgYgtBHKFA5lSka+ed7vKLqSaxAAqPn6WFtXQdTEojBAbE57a1XahEv4DuZ6EpWGwYX5aQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: jH96qJbXYkq9cKBfF3NhuJPpE3q6P9InuIJHDyHrdQCV0GrUsdhkI19vfxDSTZEK4E5eHAWMXe8BbQb5bYc6hGmOjlgEnOk9MS305bHGhpgazCUm1FaHtih0NMeo11xLPzPyoWgIDlQ2J32trZ9pAZgY4QhhLFg4uQmsM4AO85BkjTOTzlcQmBfLVvcb0T+ecpSB2Fc7a0mJaX8Pe5GUveSOWq2zmPKP68CNjIvGs8bAVw1+71moi6Pxzwy4H5U/9GOPeONNaOKaY5MaUzhoGqcfx73Uv8H7nwthOFEoiCk1ROqvJ1T3tD0fefKIlJmSqzcJs4F1KjoUWF2wnx008+tBvEarTR14ye5WV2PmHKNRjpcWdqAq67hEBuU73naR0Q2h/pbS8AR210EfZb1cDuuT5F/swbpItR5k5o/TXbGOoBzg29d5XZtRXfuVJ1cuRRmlZwQ3cK6GvQO7YBmtwyCd9M1MDNaWxJKgjMHdMSQu8ONq7z+luMIiZjCw13oqoyIE03lu9zptMEucTmGRLAR+3xTpUTEUnY6/CXW8KatFKCU+JwN2na6IdtXjNvOBdyXDjg4W/j9nEj9A0OSXJLmDTYk7w55cfEQXj3bKHHOtC5T5Ak4A72Ppb/bGyzE2DZJl7FC/ZYESejUjqUNWBoC/XSYRXz76wbw7fucjq3s09uHjlgoSten5rXsnwPpUarYHYNz5v0crl0S2/SJJvX4Gb/eXqZp5+dPNg2Fc6TVrY6e5/B1wyYd0pFRMd6+1vB9w2lZYWRVUihCvGCGxPw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ced9ca9a-2eb6-4f2c-08ee-08db2e4f6692 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4636.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2023 23:11:16.7615 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9pUSxnkFJPHdeUPkZtID63Ru4n3hAjyiYkXfE0HqpipSWNHwlSBGCLG+2/7ERblnC2s2VudeoQCapcRF7QJ2od2sWBJiyjeErntQbgFxGP0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5580 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303260183 X-Proofpoint-ORIG-GUID: LTji3KQ0nms7V7oOC10aWD75myEcTyxw X-Proofpoint-GUID: LTji3KQ0nms7V7oOC10aWD75myEcTyxw X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vladimir Mezentsev via Binutils From: Vladimir Mezentsev Reply-To: vladimir.mezentsev@oracle.com Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761473786091401465?= X-GMAIL-MSGID: =?utf-8?q?1761473786091401465?= From: Vladimir Mezentsev The real problem is that libcollector doesn't interpose thread_create@GLIBC_2.34 We interpose a lot of libC functions (dlopen, fork, pthread_create, etc.). Some of these functions have versions. For example, dlopen@GLIBC_2.34, dlopen@GLIBC_2.17, dlopen@GLIBC_2.2.5, etc. We have to interpose each of the functions because we don't know which version of libC will be used during profiling. Historically, we have used three versions of scripts (mapfile.aarch64-Linux, mapfile.amd64-Linux, mapfile.intel-Linux). Three are not needed. One is enough The fixes below include: - merged all version symbols into one version script. - added new version symbols which are defined in latest versions of libC. - removed unused defines and duplicated code. - added the DCL_FUNC_VER macro to define the version symbols. Tested on x86_64 and aarch64 (OL8/OL9). No regression. gprofng/ChangeLog 2023-03-23 Vladimir Mezentsev PR gprofng/30089 * libcollector/Makefile.am: Use libgprofng.ver instead of mapfile.* * libcollector/configure.ac: Delete GPROFNG_VARIANT. * src/collector_module.h: Move the SYMVER_ATTRIBUTE macro to collector.h * libcollector/collector.h: Add macros (SYMVER_ATTRIBUTE, DCL_FUNC_VER). Remove unused defines. * libcollector/dispatcher.c: Interpose functions from libC. Clean up the old code. * libcollector/iotrace.c: Likewise. * libcollector/libcol_util.c: Likewise. * libcollector/linetrace.c: Likewise. * libcollector/mmaptrace.c: Likewise. * libcollector/synctrace.c: Likewise. * libcollector/libgprofng.ver: New file. * libcollector/Makefile.in: Rebuild. * libcollector/configure: Rebuild. * libcollector/mapfile.aarch64-Linux: Removed. * libcollector/mapfile.amd64-Linux: Removed. * libcollector/mapfile.intel-Linux: Removed. * libcollector/mapfile.sparc-Linux: Removed. * libcollector/mapfile.sparcv9-Linux: Removed. --- gprofng/libcollector/Makefile.am | 4 +- gprofng/libcollector/Makefile.in | 3 +- gprofng/libcollector/collector.h | 80 +- gprofng/libcollector/configure | 22 +- gprofng/libcollector/configure.ac | 17 - gprofng/libcollector/dispatcher.c | 425 ++++---- gprofng/libcollector/iotrace.c | 1135 ++++++-------------- gprofng/libcollector/libcol_util.c | 77 +- gprofng/libcollector/libgprofng.ver | 125 +++ gprofng/libcollector/linetrace.c | 492 +++------ gprofng/libcollector/mapfile.aarch64-Linux | 40 - gprofng/libcollector/mapfile.amd64-Linux | 79 -- gprofng/libcollector/mapfile.intel-Linux | 81 -- gprofng/libcollector/mapfile.sparc-Linux | 40 - gprofng/libcollector/mapfile.sparcv9-Linux | 58 - gprofng/libcollector/mmaptrace.c | 183 ++-- gprofng/libcollector/synctrace.c | 696 ++++-------- gprofng/src/collector_module.h | 11 - 18 files changed, 1229 insertions(+), 2339 deletions(-) create mode 100644 gprofng/libcollector/libgprofng.ver delete mode 100644 gprofng/libcollector/mapfile.aarch64-Linux delete mode 100644 gprofng/libcollector/mapfile.amd64-Linux delete mode 100644 gprofng/libcollector/mapfile.intel-Linux delete mode 100644 gprofng/libcollector/mapfile.sparc-Linux delete mode 100644 gprofng/libcollector/mapfile.sparcv9-Linux diff --git a/gprofng/libcollector/Makefile.am b/gprofng/libcollector/Makefile.am index 9dd888864c1..0610fb00594 100644 --- a/gprofng/libcollector/Makefile.am +++ b/gprofng/libcollector/Makefile.am @@ -19,8 +19,6 @@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I . -I ../.. -GPROFNG_VARIANT = @GPROFNG_VARIANT@ - CSOURCES = \ gethrtime.c \ dispatcher.c \ @@ -46,7 +44,7 @@ AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -I.. -I$(srcdir) \ -I$(srcdir)/../common -I$(srcdir)/../src \ -I$(srcdir)/../../include AM_LDFLAGS = -module -avoid-version \ - -Wl,--version-script,$(srcdir)/mapfile.$(GPROFNG_VARIANT) \ + -Wl,--version-script,$(srcdir)/libgprofng.ver \ $(LD_NO_AS_NEEDED) -Wl,-lrt -Wl,-ldl myincludedir = @includedir@ diff --git a/gprofng/libcollector/Makefile.in b/gprofng/libcollector/Makefile.in index eef61ba85f7..dc76a76bd67 100644 --- a/gprofng/libcollector/Makefile.in +++ b/gprofng/libcollector/Makefile.in @@ -325,7 +325,6 @@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GPROFNG_NO_NONNULL_COMPARE_CFLAGS = @GPROFNG_NO_NONNULL_COMPARE_CFLAGS@ -GPROFNG_VARIANT = @GPROFNG_VARIANT@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ @@ -448,7 +447,7 @@ AM_CPPFLAGS = $(GPROFNG_CPPFLAGS) -I.. -I$(srcdir) \ -I$(srcdir)/../../include AM_LDFLAGS = -module -avoid-version \ - -Wl,--version-script,$(srcdir)/mapfile.$(GPROFNG_VARIANT) \ + -Wl,--version-script,$(srcdir)/libgprofng.ver \ $(LD_NO_AS_NEEDED) -Wl,-lrt -Wl,-ldl myincludedir = @includedir@ diff --git a/gprofng/libcollector/collector.h b/gprofng/libcollector/collector.h index 77957ec537d..12a6e15a733 100644 --- a/gprofng/libcollector/collector.h +++ b/gprofng/libcollector/collector.h @@ -32,9 +32,25 @@ #define CALL_REAL(x) (__real_##x) #define NULL_PTR(x) (__real_##x == NULL) +#define SYS_LIBC_NAME "libc.so.6" + +#ifdef __has_attribute +#if __has_attribute (__symver__) +#define SYMVER_ATTRIBUTE(sym, symver) __attribute__ ((__symver__ (#symver))) +#endif +#endif +#ifndef SYMVER_ATTRIBUTE +# define SYMVER_ATTRIBUTE(sym, symver) __asm__(".symver " #sym "," #symver); +#endif + #if defined(__MUSL_LIBC) #define dlvsym(f, nm, v) dlsym (f, nm) #define SIGEV_THREAD_ID 4 +#define DCL_FUNC_VER(REAL_DCL, sym, ver) +#else +#define DCL_FUNC_VER(REAL_DCL, sym, ver) \ + SYMVER_ATTRIBUTE (__collector_ ## sym, ver) \ + REAL_DCL (__collector_ ## sym, CALL_REAL (sym)) #endif extern hrtime_t __collector_start_time; @@ -51,7 +67,8 @@ extern int __collector_write_packet (struct DataHandle*, CM_Packet*); extern int __collector_write_string (struct DataHandle*, char*, int); extern FrameInfo __collector_get_frame_info (hrtime_t, int, void *); extern FrameInfo __collector_getUID (CM_Array *arg, FrameInfo uid); -extern int __collector_getStackTrace (void *buf, int size, void *bptr, void *eptr, void *arg); +extern int __collector_getStackTrace (void *buf, int size, void *bptr, + void *eptr, void *arg); extern void *__collector_ext_return_address (unsigned level); extern void __collector_mmap_fork_child_cleanup (); @@ -83,10 +100,8 @@ extern void __collector_ext_dispatcher_restart (); extern void __collector_ext_dispatcher_deinstall (); extern void __collector_ext_usage_sample (Smpl_type type, char *name); extern void __collector_ext_profile_handler (siginfo_t *, ucontext_t *); -extern int __collector_ext_clone_pthread (int (*fn)(void *), void *child_stack, int flags, void *arg, - va_list va /* pid_t *ptid, struct user_desc *tlspid_t *" ctid" */); - -/* D-light related functions */ +extern int __collector_ext_clone_pthread (int (*fn)(void *), void *child_stack, + int flags, void *arg, va_list va); extern int __collector_sigprof_install (); extern int __collector_ext_hwc_active (); extern void __collector_ext_hwc_check (siginfo_t *, ucontext_t *); @@ -98,7 +113,8 @@ extern int (*__collector_VM_ReadByteInstruction)(unsigned char *); extern int (*__collector_omp_stack_trace)(char*, int, hrtime_t, void*); extern hrtime_t (*__collector_gethrtime)(); extern int (*__collector_mpi_stack_trace)(char*, int, hrtime_t); -extern int __collector_open_experiment (const char *exp, const char *par, sp_origin_t origin); +extern int __collector_open_experiment (const char *exp, const char *par, + sp_origin_t origin); extern void __collector_suspend_experiment (char *why); extern void __collector_resume_experiment (); extern void __collector_clean_state (); @@ -198,56 +214,4 @@ enum #endif /* DEBUG */ -// To find the glibc version: -// objdump -T /lib*/*so /lib*/*/*.so | grep popen -// IMPORTANT: The GLIBC_* versions below must match those in mapfile. - #if ARCH(Aarch64) - #define SYS_LIBC_NAME "libc.so.6" - #define SYS_PTHREAD_CREATE_VERSION "GLIBC_2.17" - #define SYS_DLOPEN_VERSION "GLIBC_2.17" - #define SYS_POPEN_VERSION "GLIBC_2.17" - #define SYS_FOPEN_X_VERSION "GLIBC_2.17" - #define SYS_FGETPOS_X_VERSION "GLIBC_2.17" - -#elif ARCH(Intel) - #define SYS_LIBC_NAME "libc.so.6" - #define SYS_POSIX_SPAWN_VERSION "GLIBC_2.15" - #if WSIZE(32) - #define SYS_PTHREAD_CREATE_VERSION "GLIBC_2.1" - #define SYS_DLOPEN_VERSION "GLIBC_2.1" - #define SYS_POPEN_VERSION "GLIBC_2.1" - #define SYS_TIMER_X_VERSION "GLIBC_2.2" - #define SYS_FOPEN_X_VERSION "GLIBC_2.1" - #define SYS_FGETPOS_X_VERSION "GLIBC_2.2" - #define SYS_FGETPOS64_X_VERSION "GLIBC_2.2" - #define SYS_OPEN64_X_VERSION "GLIBC_2.2" - #define SYS_PREAD_X_VERSION "GLIBC_2.2" - #define SYS_PWRITE_X_VERSION "GLIBC_2.2" - #define SYS_PWRITE64_X_VERSION "GLIBC_2.2" - #else /* WSIZE(64) */ - #define SYS_PTHREAD_CREATE_VERSION "GLIBC_2.2.5" - #define SYS_DLOPEN_VERSION "GLIBC_2.2.5" - #define SYS_POPEN_VERSION "GLIBC_2.2.5" - #define SYS_TIMER_X_VERSION "GLIBC_2.3.3" - #define SYS_FOPEN_X_VERSION "GLIBC_2.2.5" - #define SYS_FGETPOS_X_VERSION "GLIBC_2.2.5" - #endif - - #elif ARCH(SPARC) - #define SYS_LIBC_NAME "libc.so.6" - #define SYS_DLOPEN_VERSION "GLIBC_2.1" - #if WSIZE(32) - #define SYS_PTHREAD_CREATE_VERSION "GLIBC_2.1" - #define SYS_POPEN_VERSION "GLIBC_2.1" - #define SYS_FOPEN_X_VERSION "GLIBC_2.1" - #define SYS_FGETPOS_X_VERSION "GLIBC_2.2" - #else /* WSIZE(64) */ - #define SYS_PTHREAD_CREATE_VERSION "GLIBC_2.2" - #define SYS_POPEN_VERSION "GLIBC_2.2" - #define SYS_TIMER_X_VERSION "GLIBC_2.3.3" - #define SYS_FOPEN_X_VERSION "GLIBC_2.2" - #define SYS_FGETPOS_X_VERSION "GLIBC_2.2" - #endif - #endif - #endif diff --git a/gprofng/libcollector/configure b/gprofng/libcollector/configure index 002f23ff2d5..18f2e449207 100755 --- a/gprofng/libcollector/configure +++ b/gprofng/libcollector/configure @@ -634,7 +634,6 @@ am__EXEEXT_TRUE LTLIBOBJS LIBOBJS GPROFNG_NO_NONNULL_COMPARE_CFLAGS -GPROFNG_VARIANT CXXCPP OTOOL64 OTOOL @@ -12064,7 +12063,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12067 "configure" +#line 12066 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -12170,7 +12169,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 12173 "configure" +#line 12172 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -15475,23 +15474,6 @@ if test "$enable_shared" != "yes"; then $as_echo "$as_me: WARNING: Cannot set --enable-shared for gprofng/libcollector. Profiling will be unavailable." >&2;} fi -GPROFNG_VARIANT=unknown -x=`echo | $CC $CFLAGS -dM -E - | grep -w __x86_64` -if test -n "$x"; then - GPROFNG_VARIANT=amd64-Linux -else - x=`echo | $CC $CFLAGS -dM -E - | grep -w __i386__` - if test -n "$x"; then - GPROFNG_VARIANT=intel-Linux - else - x=`echo | $CC $CFLAGS -dM -E - | grep -w __aarch64__` - if test -n "$x"; then - GPROFNG_VARIANT=aarch64-Linux - fi - fi -fi - - ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/gprofng/libcollector/configure.ac b/gprofng/libcollector/configure.ac index 495963c51e0..7af958145c7 100644 --- a/gprofng/libcollector/configure.ac +++ b/gprofng/libcollector/configure.ac @@ -41,23 +41,6 @@ if test "$enable_shared" != "yes"; then AC_MSG_WARN([Cannot set --enable-shared for gprofng/libcollector. Profiling will be unavailable.]) fi -GPROFNG_VARIANT=unknown -x=`echo | $CC $CFLAGS -dM -E - | grep -w __x86_64` -if test -n "$x"; then - GPROFNG_VARIANT=amd64-Linux -else - x=`echo | $CC $CFLAGS -dM -E - | grep -w __i386__` - if test -n "$x"; then - GPROFNG_VARIANT=intel-Linux - else - x=`echo | $CC $CFLAGS -dM -E - | grep -w __aarch64__` - if test -n "$x"; then - GPROFNG_VARIANT=aarch64-Linux - fi - fi -fi -AC_SUBST(GPROFNG_VARIANT) - ACX_PROG_CC_WARNING_OPTS([-Wno-nonnull-compare], [GPROFNG_NO_NONNULL_COMPARE_CFLAGS]) AC_SUBST(GPROFNG_NO_NONNULL_COMPARE_CFLAGS) diff --git a/gprofng/libcollector/dispatcher.c b/gprofng/libcollector/dispatcher.c index 5c5a06ec1b4..82c4bb7a533 100644 --- a/gprofng/libcollector/dispatcher.c +++ b/gprofng/libcollector/dispatcher.c @@ -63,19 +63,39 @@ static int (*__real_timer_settime) (timer_t timerid, int flags, static int (*__real_timer_delete) (timer_t timerid) = NULL; static int (*__real_timer_gettime) (timer_t timerid, struct itimerspec *curr_value) = NULL; -#if ARCH(Intel) && WSIZE(32) + +static int (*__real_pthread_create_2_34) (pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) = NULL; +static int (*__real_pthread_create_2_17) (pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) = NULL; +static int (*__real_pthread_create_2_2_5) (pthread_t *thread, + const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg) = NULL; static int (*__real_pthread_create_2_1) (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) = NULL; static int (*__real_pthread_create_2_0) (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) = NULL; -#elif ARCH(Intel) && WSIZE(64) + +static int (*__real_timer_create_2_34) (clockid_t clockid, + struct sigevent *sevp, timer_t *timerid) = NULL; +static int (*__real_timer_create_2_17) (clockid_t clockid, + struct sigevent *sevp, timer_t *timerid) = NULL; static int (*__real_timer_create_2_3_3) (clockid_t clockid, struct sigevent *sevp, timer_t *timerid) = NULL; static int (*__real_timer_create_2_2_5) (clockid_t clockid, struct sigevent *sevp, timer_t *timerid) = NULL; -#endif +static int (*__real_timer_create_2_2) (clockid_t clockid, + struct sigevent *sevp, timer_t *timerid) = NULL; + +int (*__real_pthread_sigmask_2_32) (int, const sigset_t *, sigset_t *) = NULL; +int (*__real_pthread_sigmask_2_17) (int, const sigset_t *, sigset_t *) = NULL; +int (*__real_pthread_sigmask_2_2_5) (int, const sigset_t *, sigset_t *) = NULL; +int (*__real_pthread_sigmask_2_0) (int, const sigset_t *, sigset_t *) = NULL; + /* Original SIGPROF handler which will be replaced with the dispatcher. Used * to properly interact with libaio, which uses SIGPROF as its SIGAIOCANCEL. */ @@ -637,12 +657,6 @@ protect_profiling_signals (sigset_t* lset) } } -#define SYS_SETITIMER_NAME "setitimer" -#define SYS_SIGACTION_NAME "sigaction" -#define SYS_SIGPROCMASK_NAME "sigprocmask" -#define SYS_PTHREAD_SIGMASK "pthread_sigmask" -#define SYS_THR_SIGSETMASK "thr_sigsetmask" - static int init_interposition_intf () { @@ -652,15 +666,10 @@ init_interposition_intf () /* Linux requires RTLD_LAZY, Solaris can do just RTLD_NOLOAD */ void *handle = dlopen (SYS_LIBC_NAME, RTLD_LAZY | RTLD_NOLOAD); -#if ARCH(SPARC) && WSIZE(64) - /* dlopen a bogus path to avoid CR 23608692 */ - dlopen ("/bogus_path_for_23608692_workaround/", RTLD_LAZY | RTLD_NOLOAD); -#endif - __real_setitimer = dlsym (RTLD_NEXT, SYS_SETITIMER_NAME); - + __real_setitimer = dlsym (RTLD_NEXT, "setitimer"); if (__real_setitimer == NULL) { - __real_setitimer = dlsym (RTLD_DEFAULT, SYS_SETITIMER_NAME); + __real_setitimer = dlsym (RTLD_DEFAULT, "setitimer"); if (__real_setitimer == NULL) { TprintfT (DBG_LT2, "init_interposition_intf() setitimer not found\n"); @@ -673,54 +682,127 @@ init_interposition_intf () TprintfT (DBG_LT2, "init_interposition_intf() using RTLD_%s\n", (dlflag == RTLD_DEFAULT) ? "DEFAULT" : "NEXT"); - TprintfT (DBG_LT2, "@%p __real_setitimer\n", __real_setitimer); - __real_sigaction = dlsym (dlflag, SYS_SIGACTION_NAME); - TprintfT (DBG_LT2, "@%p __real_sigaction\n", __real_sigaction); + __real_sigaction = dlsym (dlflag, "sigaction"); /* also explicitly get libc.so/setitimer (as a backup) */ - __real_libc_setitimer = dlsym (handle, SYS_SETITIMER_NAME); - TprintfT (DBG_LT2, "@%p __real_libc_setitimer\n", __real_libc_setitimer); - - __real_sigprocmask = dlsym (dlflag, SYS_SIGPROCMASK_NAME); - TprintfT (DBG_LT2, "@%p __real_sigprocmask\n", __real_sigprocmask); + __real_libc_setitimer = dlsym (handle, "setitimer"); - __real_thr_sigsetmask = dlsym (dlflag, SYS_THR_SIGSETMASK); - TprintfT (DBG_LT2, "@%p __real_thr_sigsetmask\n", __real_thr_sigsetmask); + __real_sigprocmask = dlsym (dlflag, "sigprocmask"); + __real_thr_sigsetmask = dlsym (dlflag, "thr_sigsetmask"); - __real_pthread_sigmask = dlsym (dlflag, SYS_PTHREAD_SIGMASK); - TprintfT (DBG_LT2, "@%p __real_pthread_sigmask\n", __real_pthread_sigmask); + __real_pthread_sigmask_2_32 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.32"); + __real_pthread_sigmask_2_17 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.17"); + __real_pthread_sigmask_2_2_5 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.2.5"); + __real_pthread_sigmask_2_0 = dlvsym (dlflag, "pthread_sigmask", "GLIBC_2.0"); + __real_pthread_sigmask = dlsym (dlflag, "pthread_sigmask"); -#if ARCH(Aarch64) - __real_pthread_create = dlvsym (dlflag, "pthread_create", SYS_PTHREAD_CREATE_VERSION); - __real_timer_create = dlsym (dlflag, "timer_create"); - __real_timer_settime = dlsym (dlflag, "timer_settime"); - __real_timer_delete = dlsym (dlflag, "timer_delete"); - __real_timer_gettime = dlsym (dlflag, "timer_gettime"); -#else - __real_pthread_create = dlvsym (dlflag, "pthread_create", SYS_PTHREAD_CREATE_VERSION); - TprintfT (DBG_LT2, "[%s] @%p __real_pthread_create\n", SYS_PTHREAD_CREATE_VERSION, __real_pthread_create); - __real_timer_create = dlvsym (dlflag, "timer_create", SYS_TIMER_X_VERSION); - TprintfT (DBG_LT2, "init_lineage_intf() [%s] @0x%p __real_timer_create\n", SYS_TIMER_X_VERSION, __real_timer_create); - __real_timer_settime = dlvsym (dlflag, "timer_settime", SYS_TIMER_X_VERSION); - TprintfT (DBG_LT2, "init_lineage_intf() [%s] @0x%p __real_timer_settime\n", SYS_TIMER_X_VERSION, __real_timer_settime); - __real_timer_delete = dlvsym (dlflag, "timer_delete", SYS_TIMER_X_VERSION); - TprintfT (DBG_LT2, "init_lineage_intf() [%s] @0x%p __real_timer_delete\n", SYS_TIMER_X_VERSION, __real_timer_delete); - __real_timer_gettime = dlvsym (dlflag, "timer_gettime", SYS_TIMER_X_VERSION); - TprintfT (DBG_LT2, "init_lineage_intf() [%s] @0x%p __real_timer_gettime\n", SYS_TIMER_X_VERSION, __real_timer_gettime); - __real_clone = dlsym (dlflag, "clone"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_clone\n", __real_clone); -#if ARCH(Intel) && WSIZE(32) - __real_pthread_create_2_1 = __real_pthread_create; + __real_pthread_create_2_34 = dlvsym (dlflag, "pthread_create", "GLIBC_2.34"); + __real_pthread_create_2_17 = dlvsym (dlflag, "pthread_create", "GLIBC_2.17"); + __real_pthread_create_2_2_5 = dlvsym (dlflag, "pthread_create", "GLIBC_2.2.5"); + __real_pthread_create_2_1 = dlvsym (dlflag, "pthread_create", "GLIBC_2.1"); __real_pthread_create_2_0 = dlvsym (dlflag, "pthread_create", "GLIBC_2.0"); -#elif ARCH(Intel) && WSIZE(64) - __real_timer_create_2_3_3 = __real_timer_create; + if (__real_pthread_create_2_34) + __real_pthread_create = __real_pthread_create_2_34; + else if (__real_pthread_create_2_17) + __real_pthread_create = __real_pthread_create_2_17; + else if (__real_pthread_create_2_2_5) + __real_pthread_create = __real_pthread_create_2_2_5; + else if (__real_pthread_create_2_1) + __real_pthread_create = __real_pthread_create_2_1; + else if (__real_pthread_create_2_0) + __real_pthread_create = __real_pthread_create_2_0; + else + __real_pthread_create = dlsym (dlflag, "pthread_create"); + + __real_timer_create_2_34 = dlvsym (dlflag, "timer_create", "GLIBC_2.34"); + __real_timer_create_2_17 = dlvsym (dlflag, "timer_create", "GLIBC_2.17"); + __real_timer_create_2_3_3 = dlvsym (dlflag, "timer_create", "GLIBC_2.3.3"); __real_timer_create_2_2_5 = dlvsym (dlflag, "timer_create", "GLIBC_2.2.5"); -#elif ARCH(SPARC) && WSIZE(64) - __real_timer_create_2_3_3 = __real_timer_create; __real_timer_create_2_2 = dlvsym (dlflag, "timer_create", "GLIBC_2.2"); -#endif /* ARCH() && SIZE() */ -#endif + if (__real_timer_create_2_34) + __real_timer_create = __real_timer_create_2_34; + else if (__real_timer_create_2_17) + __real_timer_create = __real_timer_create_2_17; + else if (__real_timer_create_2_3_3) + __real_timer_create = __real_timer_create_2_3_3; + else if (__real_timer_create_2_2_5) + __real_timer_create = __real_timer_create_2_2_5; + else if (__real_timer_create_2_2) + __real_timer_create = __real_timer_create_2_2; + else + __real_timer_create = dlsym (dlflag, "timer_create"); + + void *t; + if ((t = dlvsym (dlflag, "timer_settime", "GLIBC_2.34")) != NULL) + __real_timer_settime = t; + else if ((t = dlvsym (dlflag, "timer_settime", "GLIBC_2.17")) != NULL) + __real_timer_settime = t; + else if ((t = dlvsym (dlflag, "timer_settime", "GLIBC_2.3.3")) != NULL) + __real_timer_settime = t; + else if ((t = dlvsym (dlflag, "timer_settime", "GLIBC_2.2.5")) != NULL) + __real_timer_settime = t; + else if ((t = dlvsym (dlflag, "timer_settime", "GLIBC_2.0")) != NULL) + __real_timer_settime = t; + else + __real_timer_settime = dlsym (dlflag, "timer_settime"); + + if ((t = dlvsym (dlflag, "timer_delete", "GLIBC_2.34")) != NULL) + __real_timer_delete = t; + else if ((t = dlvsym (dlflag, "timer_delete", "GLIBC_2.17")) != NULL) + __real_timer_delete = t; + else if ((t = dlvsym (dlflag, "timer_delete", "GLIBC_2.3.3")) != NULL) + __real_timer_delete = t; + else if ((t = dlvsym (dlflag, "timer_delete", "GLIBC_2.2.5")) != NULL) + __real_timer_delete = t; + else if ((t = dlvsym (dlflag, "timer_delete", "GLIBC_2.2")) != NULL) + __real_timer_delete = t; + else + __real_timer_delete = dlsym (dlflag, "timer_delete"); + + if ((t = dlvsym (dlflag, "timer_gettime", "GLIBC_2.34")) != NULL) + __real_timer_gettime = t; + else if ((t = dlvsym (dlflag, "timer_gettime", "GLIBC_2.17")) != NULL) + __real_timer_gettime = t; + else if ((t = dlvsym (dlflag, "timer_gettime", "GLIBC_2.3.3")) != NULL) + __real_timer_gettime = t; + else if ((t = dlvsym (dlflag, "timer_gettime", "GLIBC_2.2.5")) != NULL) + __real_timer_gettime = t; + else if ((t = dlvsym (dlflag, "timer_gettime", "GLIBC_2.0")) != NULL) + __real_timer_gettime = t; + else + __real_timer_gettime = dlsym (dlflag, "timer_gettime"); + + __real_clone = dlsym (dlflag, "clone"); + +#define PR_FUNC(f) TprintfT (DBG_LT2, " dispetcher.c: " #f ": @%p\n", f) + PR_FUNC (__real_clone); + PR_FUNC (__real_libc_setitimer); + PR_FUNC (__real_pthread_create); + PR_FUNC (__real_pthread_create_2_0); + PR_FUNC (__real_pthread_create_2_1); + PR_FUNC (__real_pthread_create_2_17); + PR_FUNC (__real_pthread_create_2_2_5); + PR_FUNC (__real_pthread_create_2_34); + PR_FUNC (__real_pthread_sigmask); + PR_FUNC (__real_pthread_sigmask_2_0); + PR_FUNC (__real_pthread_sigmask_2_2_5); + PR_FUNC (__real_pthread_sigmask_2_17); + PR_FUNC (__real_pthread_sigmask_2_32); + PR_FUNC (__real_setitimer); + PR_FUNC (__real_sigaction); + PR_FUNC (__real_sigprocmask); + PR_FUNC (__real_thr_sigsetmask); + PR_FUNC (__real_timer_create); + PR_FUNC (__real_timer_create_2_17); + PR_FUNC (__real_timer_create_2_2); + PR_FUNC (__real_timer_create_2_2_5); + PR_FUNC (__real_timer_create_2_3_3); + PR_FUNC (__real_timer_create_2_34); + PR_FUNC (__real_timer_delete); + PR_FUNC (__real_timer_gettime); + PR_FUNC (__real_timer_settime); + return 0; } @@ -817,88 +899,44 @@ sigset (int sig, sighandler_t handler) /*------------------------------------------------------------- timer_create */ // map interposed symbol versions -#if WSIZE(64) -#if ARCH(SPARC) || ARCH(Intel) -static int -__collector_timer_create_symver (int(real_timer_create) (), clockid_t clockid, struct sigevent *sevp, - timer_t *timerid); - -SYMVER_ATTRIBUTE (__collector_timer_create_2_3_3, timer_create@GLIBC_2.3.3) -int -__collector_timer_create_2_3_3 (clockid_t clockid, struct sigevent *sevp, - timer_t *timerid) -{ - if (NULL_PTR (timer_create)) - init_interposition_intf (); - TprintfT (DBG_LTT, "dispatcher: GLIBC: __collector_timer_create_2_3_3@%p\n", CALL_REAL (timer_create_2_3_3)); - return __collector_timer_create_symver (CALL_REAL (timer_create_2_3_3), clockid, sevp, timerid); -} -#endif /* ARCH(SPARC) || ARCH(Intel)*/ - -#if ARCH(SPARC) - -SYMVER_ATTRIBUTE (__collector_timer_create_2_2, timer_create@GLIBC_2.2) -int -__collector_timer_create_2_2 (clockid_t clockid, struct sigevent *sevp, - timer_t *timerid) -{ - if (NULL_PTR (timer_create)) - init_interposition_intf (); - TprintfT (DBG_LTT, "dispatcher: GLIBC: __collector_timer_create_2_2@%p\n", CALL_REAL (timer_create_2_2)); - return __collector_timer_create_symver (CALL_REAL (timer_create_2_2), clockid, sevp, timerid); -} - -#elif ARCH(Intel) - -SYMVER_ATTRIBUTE (__collector_timer_create_2_2_5, timer_create@GLIBC_2.2.5) -int -__collector_timer_create_2_2_5 (clockid_t clockid, struct sigevent *sevp, - timer_t *timerid) -{ - if (NULL_PTR (timer_create)) - init_interposition_intf (); - TprintfT (DBG_LTT, "dispatcher: GLIBC: __collector_timer_create_2_2_5@%p\n", CALL_REAL (timer_create_2_2_5)); - return __collector_timer_create_symver (CALL_REAL (timer_create_2_2_5), clockid, sevp, timerid); -} -#endif /* ARCH() */ -#endif /* WSIZE(64) */ - -#if ARCH(Aarch64) || (ARCH(Intel) && WSIZE(32)) -int timer_create (clockid_t clockid, struct sigevent *sevp, timer_t *timerid) -#else static int -__collector_timer_create_symver (int(real_timer_create) (), clockid_t clockid, - struct sigevent *sevp, timer_t *timerid) -#endif +gprofng_timer_create (int (real_func) (), clockid_t clockid, + struct sigevent *sevp, timer_t *timerid) { - int ret; - - if (NULL_PTR (timer_create)) - init_interposition_intf (); - - /* collector reserves SIGPROF - */ - if (sevp == NULL || sevp->sigev_notify != SIGEV_SIGNAL - || sevp->sigev_signo != SIGPROF) + // collector reserves SIGPROF + if (sevp == NULL || sevp->sigev_notify != SIGEV_SIGNAL || + sevp->sigev_signo != SIGPROF) { -#if ARCH(Aarch64) || (ARCH(Intel) && WSIZE(32)) - ret = CALL_REAL (timer_create)(clockid, sevp, timerid); -#else - ret = (real_timer_create) (clockid, sevp, timerid); -#endif - TprintfT (DBG_LT2, "Real timer_create(%d) returned %d\n", - clockid, ret); + int ret = real_func (clockid, sevp, timerid); + TprintfT (DBG_LT2, "timer_create @%p (%d) ret=%d\n", real_func, + (int) clockid, ret); return ret; } /* log that application's timer_create request is overridden */ (void) __collector_log_write ("%d\n", SP_JCMD_CWARN, COL_WARN_ITMROVR, -1); - ret = -1; errno = EBUSY; - TprintfT (DBG_LT2, "timer_create() returning %d\n", ret); - return ret; + TprintfT (DBG_LT2, "timer_create @%p (%d) ret=%d\n", real_func, + (int) clockid, -1); \ + return -1; } + +#define DCL_TIMER_CREATE(dcl_f, real_f) \ + int dcl_f (clockid_t clockid, struct sigevent *sevp, timer_t *timerid) \ + { \ + if ((real_f) == NULL) \ + init_interposition_intf (); \ + return gprofng_timer_create (real_f, clockid, sevp, timerid); \ + } + +DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_34, timer_create@GLIBC_2.34) +DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_17, timer_create@GLIBC_2.17) +DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_3_3, timer_create@GLIBC_2.3.3) +DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_2_5, timer_create@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_TIMER_CREATE, timer_create_2_2, timer_create@GLIBC_2.2) +DCL_TIMER_CREATE (timer_create, CALL_REAL (timer_create)) + /*------------------------------------------------------------- setitimer */ int _setitimer (int which, const struct itimerval *nval, @@ -995,26 +1033,42 @@ __collector_thr_sigsetmask (int how, const sigset_t* iset, sigset_t* oset) } /*----------------------------------------------------------- pthread_sigmask */ +// map interposed symbol versions -int -pthread_sigmask (int how, const sigset_t* iset, sigset_t* oset) +static int +gprofng_pthread_sigmask (int (real_func) (), + int how, const sigset_t *iset, sigset_t* oset) { - if (NULL_PTR (pthread_sigmask)) - init_interposition_intf (); - TprintfT (DBG_LT1, "__collector_pthread_sigmask(%d) interposing\n", how); sigset_t lsigset; sigset_t* lset = NULL; if (iset) { lsigset = *iset; lset = &lsigset; - if ((how == SIG_BLOCK) || (how == SIG_SETMASK)) - protect_profiling_signals (lset); + if (how == SIG_BLOCK || how == SIG_SETMASK) + protect_profiling_signals (lset); } - int ret = CALL_REAL (pthread_sigmask)(how, lset, oset); - TprintfT (DBG_LT1, "__collector_pthread_sigmask(%d) returning %d\n", how, ret); + int ret = (real_func) (how, lset, oset); + TprintfT (DBG_LT1, "real_pthread_sigmask @%p (%d) ret=%d\n", + real_func, how, ret); return ret; + } + +#define DCL_PTHREAD_SIGMASK(dcl_f, real_f) \ + int dcl_f (int how, const sigset_t *iset, sigset_t* oset) \ + { \ + if ((real_f) == NULL) \ + init_interposition_intf (); \ + return gprofng_pthread_sigmask (real_f, how, iset, oset); \ + } + +DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_32, pthread_sigmask@GLIBC_2.32) +DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_17, pthread_sigmask@GLIBC_2.17) +DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_2_5, pthread_sigmask@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_PTHREAD_SIGMASK, pthread_sigmask_2_0, pthread_sigmask@GLIBC_2.0) +DCL_PTHREAD_SIGMASK (pthread_sigmask, CALL_REAL(pthread_sigmask)) + /*----------------------------------------------------------- pthread_create */ typedef struct _CollectorArgs { @@ -1075,94 +1129,47 @@ collector_root (void *cargs) } // map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) -static int -__collector_pthread_create_symver (int(real_pthread_create) (), - pthread_t *thread, - const pthread_attr_t *attr, - void *(*func)(void*), - void *arg); - -SYMVER_ATTRIBUTE (__collector_pthread_create_2_1, pthread_create@GLIBC_2.1) -int -__collector_pthread_create_2_1 (pthread_t *thread, - const pthread_attr_t *attr, - void *(*func)(void*), - void *arg) -{ - if (NULL_PTR (pthread_create)) - init_interposition_intf (); - TprintfT (DBG_LTT, "dispatcher: GLIBC: __collector_pthread_create_2_1@%p\n", CALL_REAL (pthread_create_2_1)); - return __collector_pthread_create_symver (CALL_REAL (pthread_create_2_1), thread, attr, func, arg); -} - -SYMVER_ATTRIBUTE (__collector_pthread_create_2_0, pthread_create@GLIBC_2.0) -int -__collector_pthread_create_2_0 (pthread_t *thread, - const pthread_attr_t *attr, - void *(*func)(void*), - void *arg) -{ - if (NULL_PTR (pthread_create)) - init_interposition_intf (); - TprintfT (DBG_LTT, "dispatcher: GLIBC: __collector_pthread_create_2_0@%p\n", CALL_REAL (pthread_create_2_0)); - return __collector_pthread_create_symver (CALL_REAL (pthread_create_2_0), thread, attr, func, arg); -} - -#endif -#if ARCH(Intel) && WSIZE(32) static int -__collector_pthread_create_symver (int(real_pthread_create) (), - pthread_t *thread, - const pthread_attr_t *attr, - void *(*func)(void*), - void *arg) -#else -int -pthread_create (pthread_t *thread, const pthread_attr_t *attr, - void *(*func)(void*), void *arg) -#endif +gprofng_pthread_create (int (real_func) (), pthread_t *thread, + const pthread_attr_t *attr, + void *(*func)(void*), void *arg) { - if (NULL_PTR (pthread_create)) - init_interposition_intf (); - - TprintfT (DBG_LT1, "pthread_create interposition called\n"); - + TprintfT (DBG_LTT, "gprofng_pthread_create @%p\n", real_func); if (dispatch_mode != DISPATCH_ON) - { -#if ARCH(Intel) && WSIZE(32) - return (real_pthread_create) (thread, attr, func, arg); -#else - return CALL_REAL (pthread_create)(thread, attr, func, arg); -#endif - } - CollectorArgs *cargs = __collector_allocCSize (__collector_heap, sizeof (CollectorArgs), 1); - + return (real_func) (thread, attr, func, arg); + CollectorArgs *cargs = __collector_allocCSize (__collector_heap, + sizeof (CollectorArgs), 1); if (cargs == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_pthread_create) (thread, attr, func, arg); -#else - return CALL_REAL (pthread_create)(thread, attr, func, arg); -#endif - } + return (real_func) (thread, attr, func, arg); cargs->func = func; cargs->arg = arg; cargs->stack = NULL; cargs->isPthread = 1; - int ret = -1; -#if ARCH(Intel) && WSIZE(32) - ret = (real_pthread_create) (thread, attr, &collector_root, cargs); -#else - ret = CALL_REAL (pthread_create)(thread, attr, &collector_root, cargs); -#endif + int ret = (real_func) (thread, attr, &collector_root, cargs); if (ret) __collector_freeCSize (__collector_heap, cargs, sizeof (CollectorArgs)); - TprintfT (DBG_LT1, "pthread_create returning %d\n", ret); + TprintfT (DBG_LT1, "gprofng_pthread_create @%p returns %d\n", real_func, ret); return ret; } + +#define DCL_PTHREAD_CREATE(dcl_f, real_f) \ + int dcl_f (pthread_t *thread, const pthread_attr_t *attr, \ + void *(*func)(void*), void *arg) \ + { \ + if ((real_f) == NULL) \ + init_interposition_intf (); \ + return gprofng_pthread_create (real_f, thread, attr, func, arg); \ + } + +DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_34, pthread_create@GLIBC_2.34) +DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_17, pthread_create@GLIBC_2.17) +DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_2_5, pthread_create@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_1, pthread_create@GLIBC_2.1) +DCL_FUNC_VER (DCL_PTHREAD_CREATE, pthread_create_2_0, pthread_create@GLIBC_2.0) +DCL_PTHREAD_CREATE (pthread_create, CALL_REAL (pthread_create)) + int __collector_ext_clone_pthread (int (*fn)(void *), void *child_stack, int flags, void *arg, va_list va /* pid_t *ptid, struct user_desc *tls, pid_t *" ctid" */) diff --git a/gprofng/libcollector/iotrace.c b/gprofng/libcollector/iotrace.c index 303e755df6e..d27f8524d7d 100644 --- a/gprofng/libcollector/iotrace.c +++ b/gprofng/libcollector/iotrace.c @@ -36,7 +36,6 @@ #include "gp-defs.h" #include "collector.h" #include "gp-experiment.h" -#include "data_pckts.h" #include "tsd.h" @@ -132,38 +131,42 @@ static struct dirent *(*__real_readdir)(DIR *dirp) = NULL; static int (*__real_flock)(int fd, int operation) = NULL; static int (*__real_lockf)(int fildes, int function, off_t size) = NULL; static int (*__real_fflush)(FILE *stream) = NULL; - -#if WSIZE(32) static int (*__real_open64)(const char *path, int oflag, ...) = NULL; +static int (*__real_open64_2_2)(const char *path, int oflag, ...) = NULL; static int (*__real_creat64)(const char *path, mode_t mode) = NULL; static int (*__real_fgetpos64)(FILE *stream, fpos64_t *pos) = NULL; static int (*__real_fsetpos64)(FILE *stream, const fpos64_t *pos) = NULL; - -#if ARCH(Intel) +static FILE *(*__real_fopen_2_17)(const char *filename, const char *mode) = NULL; +static FILE *(*__real_fopen_2_2_5)(const char *filename, const char *mode) = NULL; static FILE *(*__real_fopen_2_1)(const char *filename, const char *mode) = NULL; +static FILE *(*__real_fopen_2_0)(const char *filename, const char *mode) = NULL; +static int (*__real_fclose_2_17)(FILE *stream) = NULL; +static int (*__real_fclose_2_2_5)(FILE *stream) = NULL; static int (*__real_fclose_2_1)(FILE *stream) = NULL; +static int (*__real_fclose_2_0)(FILE *stream) = NULL; +static FILE *(*__real_fdopen_2_17)(int fildes, const char *mode) = NULL; +static FILE *(*__real_fdopen_2_2_5)(int fildes, const char *mode) = NULL; static FILE *(*__real_fdopen_2_1)(int fildes, const char *mode) = NULL; +static FILE *(*__real_fdopen_2_0)(int fildes, const char *mode) = NULL; +static int (*__real_fgetpos_2_17)(FILE *stream, fpos_t *pos) = NULL; +static int (*__real_fgetpos_2_2_5)(FILE *stream, fpos_t *pos) = NULL; static int (*__real_fgetpos_2_2)(FILE *stream, fpos_t *pos) = NULL; +static int (*__real_fgetpos_2_0)(FILE *stream, fpos_t *pos) = NULL; +static int (*__real_fsetpos_2_17)(FILE *stream, const fpos_t *pos) = NULL; +static int (*__real_fsetpos_2_2_5)(FILE *stream, const fpos_t *pos) = NULL; static int (*__real_fsetpos_2_2)(FILE *stream, const fpos_t *pos) = NULL; -static int (*__real_fgetpos64_2_2)(FILE *stream, fpos64_t *pos) = NULL; -static int (*__real_fsetpos64_2_2)(FILE *stream, const fpos64_t *pos) = NULL; -static int (*__real_open64_2_2)(const char *path, int oflag, ...) = NULL; +static int (*__real_fsetpos_2_0)(FILE *stream, const fpos_t *pos) = NULL; static ssize_t (*__real_pread_2_2)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL; static ssize_t (*__real_pwrite_2_2)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL; -static ssize_t (*__real_pwrite64_2_2)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL; -static FILE *(*__real_fopen_2_0)(const char *filename, const char *mode) = NULL; -static int (*__real_fclose_2_0)(FILE *stream) = NULL; -static FILE *(*__real_fdopen_2_0)(int fildes, const char *mode) = NULL; -static int (*__real_fgetpos_2_0)(FILE *stream, fpos_t *pos) = NULL; -static int (*__real_fsetpos_2_0)(FILE *stream, const fpos_t *pos) = NULL; +static int (*__real_fgetpos64_2_17)(FILE *stream, fpos64_t *pos) = NULL; +static int (*__real_fgetpos64_2_2_5)(FILE *stream, fpos64_t *pos) = NULL; +static int (*__real_fgetpos64_2_2)(FILE *stream, fpos64_t *pos) = NULL; static int (*__real_fgetpos64_2_1)(FILE *stream, fpos64_t *pos) = NULL; +static int (*__real_fsetpos64_2_17)(FILE *stream, const fpos64_t *pos) = NULL; +static int (*__real_fsetpos64_2_2_5)(FILE *stream, const fpos64_t *pos) = NULL; +static int (*__real_fsetpos64_2_2)(FILE *stream, const fpos64_t *pos) = NULL; static int (*__real_fsetpos64_2_1)(FILE *stream, const fpos64_t *pos) = NULL; -static int (*__real_open64_2_1)(const char *path, int oflag, ...) = NULL; -static ssize_t (*__real_pread_2_1)(int fildes, void *buf, size_t nbyte, off_t offset) = NULL; -static ssize_t (*__real_pwrite_2_1)(int fildes, const void *buf, size_t nbyte, off_t offset) = NULL; -static ssize_t (*__real_pwrite64_2_1)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL; -#endif /* ARCH() */ -#endif /* WSIZE(32) */ +static ssize_t (*__real_pwrite64_2_2)(int fildes, const void *buf, size_t nbyte, off64_t offset) = NULL; static int collector_align_pktsize (int sz) @@ -378,6 +381,26 @@ detach_experiment (void) return 0; } +static int +init_fopen (void *dlflag) +{ + __real_fopen_2_17 = dlvsym (dlflag, "fopen", "GLIBC_2.17"); + __real_fopen_2_2_5 = dlvsym (dlflag, "fopen", "GLIBC_2.2.5"); + __real_fopen_2_1 = dlvsym (dlflag, "fopen", "GLIBC_2.1"); + __real_fopen_2_0 = dlvsym (dlflag, "fopen", "GLIBC_2.0"); + if (__real_fopen_2_17) + __real_fopen = __real_fopen_2_17; + else if (__real_fopen_2_2_5) + __real_fopen = __real_fopen_2_2_5; + else if (__real_fopen_2_1) + __real_fopen = __real_fopen_2_1; + else if (__real_fopen_2_0) + __real_fopen = __real_fopen_2_0; + else + __real_fopen = dlsym (dlflag, "fopen"); + return __real_fopen ? 1 : 0; +} + static int init_io_intf () { @@ -400,46 +423,11 @@ init_io_intf () else abort (); -#if ARCH(Intel) -#if WSIZE(32) -#define SYS_FOPEN_X_VERSION "GLIBC_2.1" -#define SYS_FGETPOS_X_VERSION "GLIBC_2.2" -#define SYS_FGETPOS64_X_VERSION "GLIBC_2.2" -#define SYS_OPEN64_X_VERSION "GLIBC_2.2" -#define SYS_PREAD_X_VERSION "GLIBC_2.2" -#define SYS_PWRITE_X_VERSION "GLIBC_2.2" -#define SYS_PWRITE64_X_VERSION "GLIBC_2.2" -#else /* WSIZE(64) */ -#define SYS_FOPEN_X_VERSION "GLIBC_2.2.5" -#define SYS_FGETPOS_X_VERSION "GLIBC_2.2.5" -#endif -#elif ARCH(SPARC) -#if WSIZE(32) -#define SYS_FOPEN_X_VERSION "GLIBC_2.1" -#define SYS_FGETPOS_X_VERSION "GLIBC_2.2" -#else /* WSIZE(64) */ -#define SYS_FOPEN_X_VERSION "GLIBC_2.2" -#define SYS_FGETPOS_X_VERSION "GLIBC_2.2" -#endif -#elif ARCH(Aarch64) -#define SYS_FOPEN_X_VERSION "GLIBC_2.17" -#define SYS_FGETPOS_X_VERSION "GLIBC_2.17" -#endif /* ARCH() */ - -#if WSIZE(32) dlflag = RTLD_NEXT; - __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION); - if (__real_fopen == NULL) - { - /* We are probably dlopened after libc, - * try to search in the previously loaded objects - */ - __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION); - if (__real_fopen != NULL) - { - Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n"); - dlflag = RTLD_DEFAULT; - } + if (init_fopen (dlflag) == 0) + { + if (init_fopen (RTLD_DEFAULT)) + dlflag = RTLD_DEFAULT; else { CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n"); @@ -447,212 +435,129 @@ init_io_intf () } } - __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION); - if (__real_fclose == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION); - if (__real_fdopen == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION); - if (__real_fgetpos == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION); - if (__real_fsetpos == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n"); - rc = COL_ERROR_IOINIT; - } - - -#if ARCH(Intel) - __real_fopen_2_1 = __real_fopen; - __real_fclose_2_1 = __real_fclose; - __real_fdopen_2_1 = __real_fdopen; - __real_fgetpos_2_2 = __real_fgetpos; - __real_fsetpos_2_2 = __real_fsetpos; - - __real_fopen_2_0 = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", "GLIBC_2.0"); - if (__real_fopen_2_0 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen_2_0\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fclose_2_0 = (int (*)(FILE*))dlvsym (dlflag, "fclose", "GLIBC_2.0"); - if (__real_fclose_2_0 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose_2_0\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fdopen_2_0 = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", "GLIBC_2.0"); - if (__real_fdopen_2_0 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen_2_0\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fgetpos_2_0 = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", "GLIBC_2.0"); - if (__real_fgetpos_2_0 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos_2_0\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fsetpos_2_0 = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", "GLIBC_2.0"); - if (__real_fsetpos_2_0 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos_2_0\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fgetpos64_2_1 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", "GLIBC_2.1"); - if (__real_fgetpos64_2_1 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_1\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fsetpos64_2_1 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", "GLIBC_2.1"); - if (__real_fsetpos64_2_1 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_1\n"); - rc = COL_ERROR_IOINIT; - } - - __real_open64_2_1 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", "GLIBC_2.1"); - if (__real_open64_2_1 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_1\n"); - rc = COL_ERROR_IOINIT; - } - - __real_pread_2_1 = (int (*)(int fildes, void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pread", "GLIBC_2.1"); - if (__real_pread_2_1 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_1\n"); - rc = COL_ERROR_IOINIT; - } - - __real_pwrite_2_1 = (int (*)(int fildes, const void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pwrite", "GLIBC_2.1"); - if (__real_pwrite_2_1 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_1\n"); - rc = COL_ERROR_IOINIT; - } - - __real_pwrite64_2_1 = (int (*)(int fildes, const void *buf, size_t nbyte, off64_t offset))dlvsym (dlflag, "pwrite64", "GLIBC_2.1"); - if (__real_pwrite64_2_1 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_1\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fgetpos64_2_2 = (int (*)(FILE*, fpos64_t*))dlvsym (dlflag, "fgetpos64", SYS_FGETPOS64_X_VERSION); - if (__real_fgetpos64_2_2 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64_2_2\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fsetpos64_2_2 = (int (*)(FILE*, const fpos64_t*))dlvsym (dlflag, "fsetpos64", SYS_FGETPOS64_X_VERSION); - if (__real_fsetpos64_2_2 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64_2_2\n"); - rc = COL_ERROR_IOINIT; - } - - __real_open64_2_2 = (int (*)(const char*, int, ...))dlvsym (dlflag, "open64", SYS_OPEN64_X_VERSION); - if (__real_open64_2_2 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64_2_2\n"); - rc = COL_ERROR_IOINIT; - } - - __real_pread_2_2 = (int (*)(int fildes, void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pread", SYS_PREAD_X_VERSION); - if (__real_pread_2_2 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread_2_2\n"); - rc = COL_ERROR_IOINIT; - } + __real_fgetpos64_2_17 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.17"); + __real_fgetpos64_2_2_5 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.2.5"); + __real_fgetpos64_2_2 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.2"); + __real_fgetpos64_2_1 = dlvsym (dlflag, "fgetpos64", "GLIBC_2.1"); + if (__real_fgetpos64_2_17) + __real_fgetpos64 = __real_fgetpos64_2_17; + else if (__real_fgetpos64_2_2_5) + __real_fgetpos64 = __real_fgetpos64_2_2_5; + else if (__real_fgetpos64_2_2) + __real_fgetpos64 = __real_fgetpos64_2_2; + else if (__real_fgetpos64_2_1) + __real_fgetpos64 = __real_fgetpos64_2_1; + else + __real_fgetpos64 = dlsym (dlflag, "fgetpos64"); - __real_pwrite_2_2 = (int (*)(int fildes, const void *buf, size_t nbyte, off_t offset))dlvsym (dlflag, "pwrite", SYS_PWRITE_X_VERSION); - if (__real_pwrite_2_2 == NULL) + __real_pread_2_2 = dlvsym (dlflag, "pread", "GLIBC_2.2"); + if (__real_pread_2_2) + __real_pread = __real_pread_2_2; + else + __real_pread = dlsym (dlflag, "pread"); + if (__real_pread == NULL) { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite_2_2\n"); + CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pread\n"); rc = COL_ERROR_IOINIT; } - __real_pwrite64_2_2 = (int (*)(int fildes, const void *buf, size_t nbyte, off64_t offset))dlvsym (dlflag, "pwrite64", SYS_PWRITE64_X_VERSION); - if (__real_pwrite64_2_2 == NULL) + __real_pwrite_2_2 = dlvsym (dlflag, "pwrite", "GLIBC_2.2"); + if (__real_pwrite_2_2) + __real_pwrite = __real_pwrite_2_2; + else + __real_pwrite = dlsym (dlflag, "pwrite"); + if (__real_pwrite == NULL) { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite64_2_2\n"); + CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT pwrite\n"); rc = COL_ERROR_IOINIT; } -#endif -#else /* WSIZE(64) */ - dlflag = RTLD_NEXT; - __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (dlflag, "fopen", SYS_FOPEN_X_VERSION); - if (__real_fopen == NULL) - { - /* We are probably dlopened after libc, - * try to search in the previously loaded objects - */ - __real_fopen = (FILE * (*)(const char*, const char*))dlvsym (RTLD_DEFAULT, "fopen", SYS_FOPEN_X_VERSION); - if (__real_fopen != NULL) - { - Tprintf (0, "iotrace: WARNING: init_io_intf() using RTLD_DEFAULT for Linux io routines\n"); - dlflag = RTLD_DEFAULT; - } - else - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fopen\n"); - rc = COL_ERROR_IOINIT; - } - } - - __real_fclose = (int (*)(FILE*))dlvsym (dlflag, "fclose", SYS_FOPEN_X_VERSION); + __real_pwrite64_2_2 = dlvsym (dlflag, "pwrite64", "GLIBC_2.2"); + if (__real_pwrite64_2_2) + __real_pwrite64 = __real_pwrite64_2_2; + else + __real_pwrite64 = dlsym (dlflag, "pwrite64"); + + __real_fclose_2_17 = dlvsym (dlflag, "fclose", "GLIBC_2.17"); + __real_fclose_2_2_5 = dlvsym (dlflag, "fclose", "GLIBC_2.2.5"); + __real_fclose_2_1 = dlvsym (dlflag, "fclose", "GLIBC_2.1"); + __real_fclose_2_0 = dlvsym (dlflag, "fclose", "GLIBC_2.0"); + if (__real_fclose_2_17) + __real_fclose = __real_fclose_2_17; + else if (__real_fclose_2_2_5) + __real_fclose = __real_fclose_2_2_5; + else if (__real_fclose_2_1) + __real_fclose = __real_fclose_2_1; + else if (__real_fclose_2_0) + __real_fclose = __real_fclose_2_0; + else + __real_fclose = dlsym (dlflag, "fclose"); if (__real_fclose == NULL) { CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fclose\n"); rc = COL_ERROR_IOINIT; } - __real_fdopen = (FILE * (*)(int, const char*))dlvsym (dlflag, "fdopen", SYS_FOPEN_X_VERSION); + __real_fdopen_2_17 = dlvsym (dlflag, "fdopen", "GLIBC_2.17"); + __real_fdopen_2_2_5 = dlvsym (dlflag, "fdopen", "GLIBC_2.2.5"); + __real_fdopen_2_1 = dlvsym (dlflag, "fdopen", "GLIBC_2.1"); + __real_fdopen_2_0 = dlvsym (dlflag, "fdopen", "GLIBC_2.0"); + if (__real_fdopen_2_17) + __real_fdopen = __real_fdopen_2_17; + else if (__real_fdopen_2_2_5) + __real_fdopen = __real_fdopen_2_2_5; + else if (__real_fdopen_2_1) + __real_fdopen = __real_fdopen_2_1; + else if (__real_fdopen_2_0) + __real_fdopen = __real_fdopen_2_0; + else + __real_fdopen = dlsym (dlflag, "fdopen"); if (__real_fdopen == NULL) { CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fdopen\n"); rc = COL_ERROR_IOINIT; } - __real_fgetpos = (int (*)(FILE*, fpos_t*))dlvsym (dlflag, "fgetpos", SYS_FGETPOS_X_VERSION); + __real_fgetpos_2_17 = dlvsym (dlflag, "fgetpos", "GLIBC_2.17"); + __real_fgetpos_2_2_5 = dlvsym (dlflag, "fgetpos", "GLIBC_2.2.5"); + __real_fgetpos_2_2 = dlvsym (dlflag, "fgetpos", "GLIBC_2.2"); + __real_fgetpos_2_0 = dlvsym (dlflag, "fgetpos", "GLIBC_2.0"); + if (__real_fgetpos_2_17) + __real_fgetpos = __real_fgetpos_2_17; + else if (__real_fgetpos_2_2_5) + __real_fgetpos = __real_fgetpos_2_2_5; + else if (__real_fgetpos_2_2) + __real_fgetpos = __real_fgetpos_2_2; + else if (__real_fgetpos_2_0) + __real_fgetpos = __real_fgetpos_2_0; + else + __real_fgetpos = dlsym (dlflag, "fgetpos"); if (__real_fgetpos == NULL) { CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos\n"); rc = COL_ERROR_IOINIT; } - __real_fsetpos = (int (*)(FILE*, const fpos_t*))dlvsym (dlflag, "fsetpos", SYS_FGETPOS_X_VERSION); + __real_fsetpos_2_17 = dlvsym (dlflag, "fsetpos", "GLIBC_2.17"); + __real_fsetpos_2_2_5 = dlvsym (dlflag, "fsetpos", "GLIBC_2.2.5"); + __real_fsetpos_2_2 = dlvsym (dlflag, "fsetpos", "GLIBC_2.2"); + __real_fsetpos_2_0 = dlvsym (dlflag, "fsetpos", "GLIBC_2.0"); + if (__real_fsetpos_2_17) + __real_fsetpos = __real_fsetpos_2_17; + else if (__real_fsetpos_2_2_5) + __real_fsetpos = __real_fsetpos_2_2_5; + else if (__real_fsetpos_2_2) + __real_fsetpos = __real_fsetpos_2_2; + else if (__real_fsetpos_2_0) + __real_fsetpos = __real_fsetpos_2_0; + else + __real_fsetpos = dlsym (dlflag, "fsetpos"); if (__real_fsetpos == NULL) { CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos\n"); rc = COL_ERROR_IOINIT; } -#endif /* WSIZE(32) */ __real_open = (int (*)(const char*, int, ...))dlsym (dlflag, "open"); if (__real_open == NULL) @@ -661,14 +566,11 @@ init_io_intf () rc = COL_ERROR_IOINIT; } -#if WSIZE(32) - __real_open64 = (int (*)(const char*, int, ...))dlsym (dlflag, "open64"); - if (__real_open64 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT open64\n"); - rc = COL_ERROR_IOINIT; - } -#endif + __real_open64_2_2 = dlvsym (dlflag, "open64", "GLIBC_2.2"); + if (__real_open64_2_2) + __real_open64 = __real_open64_2_2; + else + __real_open64 = dlsym (dlflag, "open64"); __real_fcntl = (int (*)(int, int, ...))dlsym (dlflag, "fcntl"); if (__real_fcntl == NULL) @@ -748,14 +650,12 @@ init_io_intf () rc = COL_ERROR_IOINIT; } -#if WSIZE(32) __real_creat64 = (int (*)(const char*, mode_t))dlsym (dlflag, "creat64"); if (__real_creat64 == NULL) { CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT creat64\n"); rc = COL_ERROR_IOINIT; } -#endif __real_read = (ssize_t (*)(int, void*, size_t))dlsym (dlflag, "read"); if (__real_read == NULL) @@ -963,21 +863,6 @@ init_io_intf () rc = COL_ERROR_IOINIT; } -#if WSIZE(32) - __real_fgetpos64 = (int (*)(FILE*, fpos64_t*))dlsym (dlflag, "fgetpos64"); - if (__real_fgetpos64 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fgetpos64\n"); - rc = COL_ERROR_IOINIT; - } - - __real_fsetpos64 = (int (*)(FILE*, const fpos64_t*))dlsym (dlflag, "fsetpos64"); - if (__real_fsetpos64 == NULL) - { - CALL_REAL (fprintf)(stderr, "iotrace_init COL_ERROR_IOINIT fsetpos64\n"); - rc = COL_ERROR_IOINIT; - } -#endif init_io_intf_finished++; return rc; } @@ -1062,53 +947,9 @@ open (const char *path, int oflag, ...) } /*------------------------------------------------------------- open64 */ -#if ARCH(Intel) && WSIZE(32) -// map interposed symbol versions static int -__collector_open64_symver (int(real_open64) (const char *, int, ...), - const char *path, int oflag, mode_t mode); - -SYMVER_ATTRIBUTE (__collector_open64_2_2, open64@GLIBC_2.2) -int -__collector_open64_2_2 (const char *path, int oflag, ...) -{ - mode_t mode; - va_list ap; - va_start (ap, oflag); - mode = va_arg (ap, mode_t); - va_end (ap); - TprintfT (DBG_LTT, - "iotrace: __collector_open64_2_2@%p(path=%s, oflag=0%o, mode=0%o\n", - CALL_REAL (open64_2_2), path ? path : "NULL", oflag, mode); - if (NULL_PTR (open64)) - init_io_intf (); - return __collector_open64_symver (CALL_REAL (open64_2_2), path, oflag, mode); -} - -SYMVER_ATTRIBUTE (__collector_open64_2_1, open64@GLIBC_2.1) -int -__collector_open64_2_1 (const char *path, int oflag, ...) -{ - mode_t mode; - va_list ap; - va_start (ap, oflag); - mode = va_arg (ap, mode_t); - va_end (ap); - TprintfT (DBG_LTT, - "iotrace: __collector_open64_2_1@%p(path=%s, oflag=0%o, mode=0%o\n", - CALL_REAL (open64_2_1), path ? path : "NULL", oflag, mode); - if (NULL_PTR (open64)) - init_io_intf (); - return __collector_open64_symver (CALL_REAL (open64_2_1), path, oflag, mode); -} - -#endif /* ARCH(Intel) && WSIZE(32) */ -#if WSIZE(32) -#if ARCH(Intel) && WSIZE(32) - -static int -__collector_open64_symver (int(real_open64) (const char *, int, ...), - const char *path, int oflag, mode_t mode) +gprofng_open64 (int(real_open64) (const char *, int, ...), + const char *path, int oflag, mode_t mode) { int *guard; int fd; @@ -1116,39 +957,11 @@ __collector_open64_symver (int(real_open64) (const char *, int, ...), IOTrace_packet *iopkt; size_t sz; unsigned pktSize; - if (NULL_PTR (open64)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || path == NULL) - return (real_open64) (path, oflag, mode); + return real_open64 (path, oflag, mode); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); fd = real_open64 (path, oflag, mode); -#else /* ^ARCH(Intel) && WSIZE(32) */ - -int -open64 (const char *path, int oflag, ...) -{ - int *guard; - int fd; - void *packet; - IOTrace_packet *iopkt; - mode_t mode; - va_list ap; - size_t sz; - unsigned pktSize; - - va_start (ap, oflag); - mode = va_arg (ap, mode_t); - va_end (ap); - if (NULL_PTR (open64)) - init_io_intf (); - if (CHCK_REENTRANCE (guard) || path == NULL) - return CALL_REAL (open64)(path, oflag, mode); - PUSH_REENTRANCE (guard); - hrtime_t reqt = gethrtime (); - fd = CALL_REAL (open64)(path, oflag, mode); -#endif /* ^ARCH(Intel) && WSIZE(32) */ - if (RECHCK_REENTRANCE (guard) || path == NULL) { POP_REENTRANCE (guard); @@ -1174,7 +987,8 @@ open64 (const char *path, int oflag, ...) iopkt->fd = fd; iopkt->fstype = collector_fstype (path); collector_strncpy (&(iopkt->fname), path, sz); - iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt); + iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt); collector_interface->freeCSize (io_heap, packet, pktSize); } @@ -1186,7 +1000,23 @@ open64 (const char *path, int oflag, ...) POP_REENTRANCE (guard); return fd; } -#endif + +#define DCL_OPEN64(dcl_f, real_f) \ + int dcl_f (const char *path, int oflag, ...) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + mode_t mode; \ + va_list ap; \ + va_start (ap, oflag); \ + mode = va_arg (ap, mode_t); \ + va_end (ap); \ + return gprofng_open64 (real_f, path, oflag, mode); \ + } + +DCL_FUNC_VER (DCL_OPEN64, open64_2_2, open64@GLIBC_2.2) +DCL_OPEN64 (open64, CALL_REAL(open64)) + #define F_ERROR_ARG 0 #define F_INT_ARG 1 @@ -1627,69 +1457,21 @@ close (int fildes) } /*------------------------------------------------------------- fopen */ -// map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) - static FILE* -__collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode); - -SYMVER_ATTRIBUTE (__collector_fopen_2_1, fopen@GLIBC_2.1) -FILE* -__collector_fopen_2_1 (const char *filename, const char *mode) -{ - if (NULL_PTR (fopen)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_1@%p\n", CALL_REAL (fopen_2_1)); - return __collector_fopen_symver (CALL_REAL (fopen_2_1), filename, mode); -} - -SYMVER_ATTRIBUTE (__collector_fopen_2_0, fopen@GLIBC_2.0) -FILE* -__collector_fopen_2_0 (const char *filename, const char *mode) -{ - if (NULL_PTR (fopen)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fopen_2_0@%p\n", CALL_REAL (fopen_2_0)); - return __collector_fopen_symver (CALL_REAL (fopen_2_0), filename, mode); -} - -#endif - -#if ARCH(Intel) && WSIZE(32) - -static FILE* -__collector_fopen_symver (FILE*(real_fopen) (), const char *filename, const char *mode) -{ -#else - -FILE* -fopen (const char *filename, const char *mode) +gprofng_fopen (FILE*(real_fopen) (), const char *filename, const char *mode) { -#endif int *guard; FILE *fp = NULL; void *packet; IOTrace_packet *iopkt; size_t sz; unsigned pktSize; - if (NULL_PTR (fopen)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || filename == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_fopen) (filename, mode); -#else - return CALL_REAL (fopen)(filename, mode); -#endif - } + return real_fopen (filename, mode); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - fp = (real_fopen) (filename, mode); -#else - fp = CALL_REAL (fopen)(filename, mode); -#endif + fp = real_fopen (filename, mode); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -1720,12 +1502,8 @@ fopen (const char *filename, const char *mode) } iopkt->fstype = collector_fstype (filename); collector_strncpy (&(iopkt->fname), filename, sz); - -#if ARCH(Intel) && WSIZE(32) - iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt->comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif + iopkt->comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt->comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); collector_interface->writeDataRecord (io_hndl, (Common_packet*) iopkt); collector_interface->freeCSize (io_heap, packet, pktSize); } @@ -1738,66 +1516,32 @@ fopen (const char *filename, const char *mode) return fp; } -/*------------------------------------------------------------- fclose */ -// map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) - -static int -__collector_fclose_symver (int(real_fclose) (), FILE *stream); - -SYMVER_ATTRIBUTE (__collector_fclose_2_1, fclose@GLIBC_2.1) -int -__collector_fclose_2_1 (FILE *stream) -{ - if (NULL_PTR (fclose)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_1@%p\n", CALL_REAL (fclose_2_1)); - return __collector_fclose_symver (CALL_REAL (fclose_2_1), stream); -} - -SYMVER_ATTRIBUTE (__collector_fclose_2_0, fclose@GLIBC_2.0) -int -__collector_fclose_2_0 (FILE *stream) -{ - if (NULL_PTR (fclose)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fclose_2_0@%p\n", CALL_REAL (fclose_2_0)); - return __collector_fclose_symver (CALL_REAL (fclose_2_0), stream); -} - -#endif +#define DCL_FOPEN(dcl_f, real_f) \ + FILE *dcl_f (const char *filename, const char *mode) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fopen (real_f, filename, mode); \ + } -#if ARCH(Intel) && WSIZE(32) +DCL_FUNC_VER (DCL_FOPEN, fopen_2_17, fopen@GLIBC_2.17) +DCL_FUNC_VER (DCL_FOPEN, fopen_2_2_5, fopen@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FOPEN, fopen_2_1, fopen@GLIBC_2.1) +DCL_FUNC_VER (DCL_FOPEN, fopen_2_0, fopen@GLIBC_2.0) +DCL_FOPEN (fopen, CALL_REAL(fopen)) +/*------------------------------------------------------------- fclose */ static int -__collector_fclose_symver (int(real_fclose) (), FILE *stream) -{ -#else - -int -fclose (FILE *stream) +gprofng_fclose (int(real_fclose) (), FILE *stream) { -#endif int *guard; int stat; IOTrace_packet iopkt; - if (NULL_PTR (fclose)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || stream == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_fclose) (stream); -#else - return CALL_REAL (fclose)(stream); -#endif - } + return real_fclose (stream); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - stat = (real_fclose) (stream); -#else - stat = CALL_REAL (fclose)(stream); -#endif + stat = real_fclose (stream); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -1813,17 +1557,27 @@ fclose (FILE *stream) else iopkt.iotype = CLOSE_TRACE_ERROR; iopkt.fd = fileno (stream); - -#if ARCH(Intel) && WSIZE(32) - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); POP_REENTRANCE (guard); return stat; } +#define DCL_FCLOSE(dcl_f, real_f) \ + int dcl_f (FILE *stream) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fclose (real_f, stream); \ + } + +DCL_FUNC_VER (DCL_FCLOSE, fclose_2_17, fclose@GLIBC_2.17) +DCL_FUNC_VER (DCL_FCLOSE, fclose_2_2_5, fclose@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FCLOSE, fclose_2_1, fclose@GLIBC_2.1) +DCL_FUNC_VER (DCL_FCLOSE, fclose_2_0, fclose@GLIBC_2.0) +DCL_FCLOSE (fclose, CALL_REAL(fclose)) + /*------------------------------------------------------------- fflush */ int fflush (FILE *stream) @@ -1863,63 +1617,19 @@ fflush (FILE *stream) } /*------------------------------------------------------------- fdopen */ -// map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) - static FILE* -__collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode); - -SYMVER_ATTRIBUTE (__collector_fdopen_2_1, fdopen@GLIBC_2.1) -FILE* -__collector_fdopen_2_1 (int fildes, const char *mode) +gprofng_fdopen (FILE*(real_fdopen) (), int fildes, const char *mode) { - if (NULL_PTR (fdopen)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_1@%p\n", CALL_REAL (fdopen_2_1)); - return __collector_fdopen_symver (CALL_REAL (fdopen_2_1), fildes, mode); -} - -SYMVER_ATTRIBUTE (__collector_fdopen_2_0, fdopen@GLIBC_2.0) -FILE* -__collector_fdopen_2_0 (int fildes, const char *mode) -{ - if (NULL_PTR (fdopen)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fdopen_2_0@%p\n", CALL_REAL (fdopen_2_0)); - return __collector_fdopen_symver (CALL_REAL (fdopen_2_0), fildes, mode); -} - -#endif - -#if ARCH(Intel) && WSIZE(32) -static FILE* -__collector_fdopen_symver (FILE*(real_fdopen) (), int fildes, const char *mode) -{ -#else -FILE* -fdopen (int fildes, const char *mode) -{ -#endif int *guard; FILE *fp = NULL; IOTrace_packet iopkt; if (NULL_PTR (fdopen)) init_io_intf (); if (CHCK_REENTRANCE (guard)) - { -#if ARCH(Intel) && WSIZE(32) - return (real_fdopen) (fildes, mode); -#else - return CALL_REAL (fdopen)(fildes, mode); -#endif - } + return real_fdopen (fildes, mode); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - fp = (real_fdopen) (fildes, mode); -#else - fp = CALL_REAL (fdopen)(fildes, mode); -#endif + fp = real_fdopen (fildes, mode); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -1936,16 +1646,27 @@ fdopen (int fildes, const char *mode) iopkt.iotype = OPEN_TRACE_ERROR; iopkt.fd = fildes; iopkt.fstype = UNKNOWNFS_TYPE; -#if ARCH(Intel) && WSIZE(32) - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); POP_REENTRANCE (guard); return fp; } +#define DCL_FDOPEN(dcl_f, real_f) \ + FILE *dcl_f (int fildes, const char *mode) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fdopen (real_f, fildes, mode); \ + } + +DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_17, fdopen@GLIBC_2.17) +DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_2_5, fdopen@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_1, fdopen@GLIBC_2.1) +DCL_FUNC_VER (DCL_FDOPEN, fdopen_2_0, fdopen@GLIBC_2.0) +DCL_FDOPEN (fdopen, CALL_REAL(fdopen)) + /*------------------------------------------------------------- dup */ int dup (int fildes) @@ -2332,62 +2053,18 @@ fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream) } /*------------------------------------------------------------- pread */ -#if ARCH(Intel) && WSIZE(32) -// map interposed symbol versions -static int -__collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset); - -SYMVER_ATTRIBUTE (__collector_pread_2_2, pread@GLIBC_2.2) -int -__collector_pread_2_2 (int fildes, void *buf, size_t nbyte, off_t offset) +static ssize_t +gprofng_pread (ssize_t(real_pread) (int, void *, size_t, off_t), + int fildes, void *buf, size_t nbyte, off_t offset) { - TprintfT (DBG_LTT, "iotrace: __collector_pread_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n", - CALL_REAL (pread_2_2), fildes, buf, (long long) nbyte, (long long) offset); - if (NULL_PTR (pread)) - init_io_intf (); - return __collector_pread_symver (CALL_REAL (pread_2_2), fildes, buf, nbyte, offset); -} - -SYMVER_ATTRIBUTE (__collector_pread_2_1, pread@GLIBC_2.1) -int -__collector_pread_2_1 (int fildes, void *buf, size_t nbyte, off_t offset) -{ - TprintfT (DBG_LTT, "iotrace: __collector_pread_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n", - CALL_REAL (pread_2_1), fildes, buf, (long long) nbyte, (long long) offset); - if (NULL_PTR (pread)) - init_io_intf (); - return __collector_pread_symver (CALL_REAL (pread_2_1), fildes, buf, nbyte, offset); -} - -static int -__collector_pread_symver (int(real_pread) (), int fildes, void *buf, size_t nbyte, off_t offset) -{ -#else /* ^ARCH(Intel) && WSIZE(32) */ - -ssize_t -pread (int fildes, void *buf, size_t nbyte, off_t offset) -{ -#endif int *guard; ssize_t ret; IOTrace_packet iopkt; - if (NULL_PTR (pread)) - init_io_intf (); if (CHCK_REENTRANCE (guard)) - { -#if ARCH(Intel) && WSIZE(32) - return (real_pread) (fildes, buf, nbyte, offset); -#else - return CALL_REAL (pread)(fildes, buf, nbyte, offset); -#endif - } + return real_pread (fildes, buf, nbyte, offset); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - ret = (real_pread) (fildes, buf, nbyte, offset); -#else - ret = CALL_REAL (pread)(fildes, buf, nbyte, offset); -#endif + ret = real_pread (fildes, buf, nbyte, offset); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -2404,15 +2081,27 @@ pread (int fildes, void *buf, size_t nbyte, off_t offset) iopkt.iotype = READ_TRACE_ERROR; iopkt.fd = fildes; iopkt.nbyte = ret; - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); - collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); + collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt); POP_REENTRANCE (guard); return ret; } +#define DCL_PREAD(dcl_f, real_f) \ + ssize_t dcl_f (int fildes, void *buf, size_t nbyte, off_t offset) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_pread (real_f, fildes, buf, nbyte, offset); \ + } + +DCL_FUNC_VER (DCL_PREAD, pread_2_2, pread@GLIBC_2.2) +DCL_PREAD (pread, CALL_REAL(pread)) + /*------------------------------------------------------------- pwrite */ -#if !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32) +#if !defined(__MUSL_LIBC) // map interposed symbol versions SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@GLIBC_2.2) @@ -2437,28 +2126,6 @@ __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset) return ret; } -SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1) -int -__collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t offset) -{ - int *guard; - if (NULL_PTR (pwrite_2_1)) - init_io_intf (); - if (CHCK_REENTRANCE (guard)) - return CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset); - PUSH_REENTRANCE (guard); - hrtime_t reqt = gethrtime (); - ssize_t ret = CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset); - if (RECHCK_REENTRANCE (guard)) - { - POP_REENTRANCE (guard); - return ret; - } - write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); - POP_REENTRANCE (guard); - return ret; -} - #endif ssize_t pwrite (int fildes, const void *buf, size_t nbyte, off_t offset) @@ -2482,7 +2149,7 @@ pwrite (int fildes, const void *buf, size_t nbyte, off_t offset) } /*------------------------------------------------------------- pwrite64 */ -#if WSIZE(32) && ARCH(Intel) +#if WSIZE(32) && !defined(__USE_FILE_OFFSET64) #if !defined(__MUSL_LIBC) // map interposed symbol versions @@ -2507,31 +2174,8 @@ __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t off POP_REENTRANCE (guard); return ret; } - -SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1) -int -__collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64_t offset) -{ - int *guard; - if (NULL_PTR (pwrite64_2_1)) - init_io_intf (); - if (CHCK_REENTRANCE (guard)) - return CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset); - PUSH_REENTRANCE (guard); - hrtime_t reqt = gethrtime (); - ssize_t ret = CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset); - if (RECHCK_REENTRANCE (guard)) - { - POP_REENTRANCE (guard); - return ret; - } - write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); - POP_REENTRANCE (guard); - return ret; -} #endif -#if !defined(__USE_FILE_OFFSET64) ssize_t pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset) { @@ -2554,8 +2198,6 @@ pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset) } #endif -#endif /* SIZE(32) && ARCH(Intel) */ - /*------------------------------------------------------------- fgets */ char* fgets (char *s, int n, FILE *stream) @@ -3238,62 +2880,18 @@ ftell (FILE *stream) } /*------------------------------------------------------------- fgetpos */ -// map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) static int -__collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos); - -SYMVER_ATTRIBUTE (__collector_fgetpos_2_2, fgetpos@GLIBC_2.2) -int -__collector_fgetpos_2_2 (FILE *stream, fpos_t *pos) +gprofng_fgetpos (int(real_fgetpos) (FILE *stream, fpos_t *pos), + FILE *stream, fpos_t *pos) { - if (NULL_PTR (fgetpos)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_2@%p\n", CALL_REAL (fgetpos_2_2)); - return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_2), stream, pos); -} - -SYMVER_ATTRIBUTE (__collector_fgetpos_2_0, fgetpos@GLIBC_2.0) -int -__collector_fgetpos_2_0 (FILE *stream, fpos_t *pos) -{ - if (NULL_PTR (fgetpos)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fgetpos_2_0@%p\n", CALL_REAL (fgetpos_2_0)); - return __collector_fgetpos_symver (CALL_REAL (fgetpos_2_0), stream, pos); -} -#endif - -#if ARCH(Intel) && WSIZE(32) - -static int -__collector_fgetpos_symver (int(real_fgetpos) (), FILE *stream, fpos_t *pos) -{ -#else -int -fgetpos (FILE *stream, fpos_t *pos) -{ -#endif int *guard; int ret; IOTrace_packet iopkt; - if (NULL_PTR (fgetpos)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || stream == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_fgetpos) (stream, pos); -#else - return CALL_REAL (fgetpos)(stream, pos); -#endif - } + return real_fgetpos (stream, pos); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - ret = (real_fgetpos) (stream, pos); -#else - ret = CALL_REAL (fgetpos)(stream, pos); -#endif + ret = real_fgetpos (stream, pos); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -3309,75 +2907,39 @@ fgetpos (FILE *stream, fpos_t *pos) else iopkt.iotype = OTHERIO_TRACE_ERROR; iopkt.fd = fileno (stream); - -#if ARCH(Intel) && WSIZE(32) - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif - collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); + collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt); POP_REENTRANCE (guard); return ret; } -#if WSIZE(32) -/*------------------------------------------------------------- fgetpos64 */ -#if ARCH(Intel) -// map interposed symbol versions +#define DCL_FGETPOS(dcl_f, real_f) \ + int dcl_f (FILE *stream, fpos_t *pos) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fgetpos (real_f, stream, pos); \ + } -static int -__collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos); - -SYMVER_ATTRIBUTE (__collector_fgetpos64_2_2, fgetpos64@GLIBC_2.2) -int -__collector_fgetpos64_2_2 (FILE *stream, fpos64_t *pos) -{ - TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_2@%p(stream=%p, pos=%p)\n", - CALL_REAL (fgetpos64_2_2), stream, pos); - if (NULL_PTR (fgetpos64)) - init_io_intf (); - return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_2), stream, pos); -} - -SYMVER_ATTRIBUTE (__collector_fgetpos64_2_1, fgetpos64@GLIBC_2.1) -int -__collector_fgetpos64_2_1 (FILE *stream, fpos64_t *pos) -{ - TprintfT (DBG_LTT, "iotrace: __collector_fgetpos64_2_1@%p(stream=%p, pos=%p)\n", - CALL_REAL (fgetpos64_2_1), stream, pos); - if (NULL_PTR (fgetpos64)) - init_io_intf (); - return __collector_fgetpos64_symver (CALL_REAL (fgetpos64_2_1), stream, pos); -} +DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_17, fgetpos@GLIBC_2.17) +DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_2_5, fgetpos@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_2, fgetpos@GLIBC_2.2) +DCL_FUNC_VER (DCL_FGETPOS, fgetpos_2_0, fgetpos@GLIBC_2.0) +DCL_FGETPOS (fgetpos, CALL_REAL(fgetpos)) +/*------------------------------------------------------------- fgetpos64 */ static int -__collector_fgetpos64_symver (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos) +gprofng_fgetpos64 (int(real_fgetpos64) (), FILE *stream, fpos64_t *pos) { -#else -int -fgetpos64 (FILE *stream, fpos64_t *pos) -{ -#endif int *guard; int ret; IOTrace_packet iopkt; - if (NULL_PTR (fgetpos64)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || stream == NULL) - { -#if ARCH(Intel) - return (real_fgetpos64) (stream, pos); -#else - return CALL_REAL (fgetpos64)(stream, pos); -#endif - } + return real_fgetpos64 (stream, pos); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) - ret = (real_fgetpos64) (stream, pos); -#else - ret = CALL_REAL (fgetpos64)(stream, pos); -#endif + ret = real_fgetpos64 (stream, pos); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -3393,74 +2955,40 @@ fgetpos64 (FILE *stream, fpos64_t *pos) else iopkt.iotype = OTHERIO_TRACE_ERROR; iopkt.fd = fileno (stream); -#if ARCH(Intel) - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif - collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); + collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt); POP_REENTRANCE (guard); return ret; } -#endif -/*------------------------------------------------------------- fsetpos */ -// map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) -static int -__collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos); +#define DCL_FGETPOS64(dcl_f, real_f) \ + int dcl_f (FILE *stream, fpos64_t *pos) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fgetpos64 (real_f, stream, pos); \ + } -SYMVER_ATTRIBUTE (__collector_fsetpos_2_2, fsetpos@GLIBC_2.2) -int -__collector_fsetpos_2_2 (FILE *stream, const fpos_t *pos) -{ - if (NULL_PTR (fsetpos)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_2@%p\n", CALL_REAL (fsetpos_2_2)); - return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_2), stream, pos); -} - -SYMVER_ATTRIBUTE (__collector_fsetpos_2_0, fsetpos@GLIBC_2.0) -int -__collector_fsetpos_2_0 (FILE *stream, const fpos_t *pos) -{ - if (NULL_PTR (fsetpos)) - init_io_intf (); - TprintfT (DBG_LTT, "iotrace: __collector_fsetpos_2_0@%p\n", CALL_REAL (fsetpos_2_0)); - return __collector_fsetpos_symver (CALL_REAL (fsetpos_2_0), stream, pos); -} -#endif - -#if ARCH(Intel) && WSIZE(32) +DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_17, fgetpos64@GLIBC_2.17) +DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_2_5, fgetpos64@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_2, fgetpos64@GLIBC_2.2) +DCL_FUNC_VER (DCL_FGETPOS64, fgetpos64_2_1, fgetpos64@GLIBC_2.1) +DCL_FGETPOS64 (fgetpos64, CALL_REAL(fgetpos64)) +/*------------------------------------------------------------- fsetpos */ static int -__collector_fsetpos_symver (int(real_fsetpos) (), FILE *stream, const fpos_t *pos) +gprofng_fsetpos (int(real_fsetpos) (FILE *, const fpos_t *), + FILE *stream, const fpos_t *pos) { -#else -int -fsetpos (FILE *stream, const fpos_t *pos) -{ -#endif int *guard; int ret; IOTrace_packet iopkt; - if (NULL_PTR (fsetpos)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || stream == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_fsetpos) (stream, pos); -#else - return CALL_REAL (fsetpos)(stream, pos); -#endif - } + return real_fsetpos (stream, pos); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - ret = (real_fsetpos) (stream, pos); -#else - ret = CALL_REAL (fsetpos)(stream, pos); -#endif + ret = real_fsetpos (stream, pos); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -3476,73 +3004,40 @@ fsetpos (FILE *stream, const fpos_t *pos) else iopkt.iotype = OTHERIO_TRACE_ERROR; iopkt.fd = fileno (stream); -#if ARCH(Intel) && WSIZE(32) - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif - collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); + collector_interface->writeDataRecord (io_hndl, (Common_packet*) &iopkt); POP_REENTRANCE (guard); return ret; } -#if WSIZE(32) -/*------------------------------------------------------------- fsetpos64 */ -#if ARCH(Intel) -// map interposed symbol versions -static int -__collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos); - -SYMVER_ATTRIBUTE (__collector_fsetpos64_2_2, fsetpos64@GLIBC_2.2) -int -__collector_fsetpos64_2_2 (FILE *stream, const fpos64_t *pos) -{ - TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_2@%p(stream=%p, pos=%p)\n", - CALL_REAL (fsetpos64_2_2), stream, pos); - if (NULL_PTR (fsetpos64)) - init_io_intf (); - return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_2), stream, pos); -} +#define DCL_FSETPOS(dcl_f, real_f) \ + int dcl_f (FILE *stream, const fpos_t *pos) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fsetpos (real_f, stream, pos); \ + } -SYMVER_ATTRIBUTE (__collector_fsetpos64_2_1, fsetpos64@GLIBC_2.1) -int -__collector_fsetpos64_2_1 (FILE *stream, const fpos64_t *pos) -{ - TprintfT (DBG_LTT, "iotrace: __collector_fsetpos64_2_1@%p(stream=%p, pos=%p)\n", - CALL_REAL (fsetpos64_2_1), stream, pos); - if (NULL_PTR (fsetpos64)) - init_io_intf (); - return __collector_fsetpos64_symver (CALL_REAL (fsetpos64_2_1), stream, pos); -} +DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_17, fsetpos@GLIBC_2.17) +DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_2_5, fsetpos@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_2, fsetpos@GLIBC_2.2) +DCL_FUNC_VER (DCL_FSETPOS, fsetpos_2_0, fsetpos@GLIBC_2.0) +DCL_FSETPOS (fsetpos, CALL_REAL(fsetpos)) +/*------------------------------------------------------------- fsetpos64 */ static int -__collector_fsetpos64_symver (int(real_fsetpos64) (), FILE *stream, const fpos64_t *pos) +gprofng_fsetpos64 (int(real_fsetpos64) (FILE *, const fpos64_t *), + FILE *stream, const fpos64_t *pos) { -#else -int -fsetpos64 (FILE *stream, const fpos64_t *pos) -{ -#endif int *guard; int ret; IOTrace_packet iopkt; - if (NULL_PTR (fsetpos64)) - init_io_intf (); if (CHCK_REENTRANCE (guard) || stream == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_fsetpos64) (stream, pos); -#else - return CALL_REAL (fsetpos64)(stream, pos); -#endif - } + return real_fsetpos64 (stream, pos); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); -#if ARCH(Intel) && WSIZE(32) - ret = (real_fsetpos64) (stream, pos); -#else - ret = CALL_REAL (fsetpos64)(stream, pos); -#endif + ret = real_fsetpos64 (stream, pos); if (RECHCK_REENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -3558,16 +3053,26 @@ fsetpos64 (FILE *stream, const fpos64_t *pos) else iopkt.iotype = OTHERIO_TRACE_ERROR; iopkt.fd = fileno (stream); -#if ARCH(Intel) - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); -#else - iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); -#endif + iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, + iopkt.comm.tstamp, FRINFO_FROM_STACK_ARG, &iopkt); collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); POP_REENTRANCE (guard); return ret; } -#endif + +#define DCL_FSETPOS64(dcl_f, real_f) \ + int dcl_f (FILE *stream, const fpos64_t *pos) \ + { \ + if ((real_f) == NULL) \ + init_io_intf (); \ + return gprofng_fsetpos64 (real_f, stream, pos); \ + } + +DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_17, fsetpos64@GLIBC_2.17) +DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_2_5, fsetpos64@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_2, fsetpos64@GLIBC_2.2) +DCL_FUNC_VER (DCL_FSETPOS64, fsetpos64_2_1, fsetpos64@GLIBC_2.1) +DCL_FSETPOS64 (fsetpos64, CALL_REAL(fsetpos64)) /*------------------------------------------------------------- fsync */ int diff --git a/gprofng/libcollector/libcol_util.c b/gprofng/libcollector/libcol_util.c index b1607333df1..a8802d4a9b0 100644 --- a/gprofng/libcollector/libcol_util.c +++ b/gprofng/libcollector/libcol_util.c @@ -40,12 +40,6 @@ #include "memmgr.h" // __collector_allocCSize, __collector_freeCSize #include "tsd.h" -/* TprintfT(,...) definitions. Adjust per module as needed */ -#define DBG_LT0 0 // for high-level configuration, unexpected errors/warnings -#define DBG_LT1 1 // for configuration details, warnings -#define DBG_LT2 2 -#define DBG_LT3 3 - /* * This file is intended for collector's own implementation of * various routines to avoid interaction with libc and other @@ -1456,54 +1450,53 @@ __collector_util_init () /* don't treat this as fatal, so that S10 could work */ } -#if ARCH(Intel) && WSIZE(32) - ptr = dlvsym (libc, "fopen", "GLIBC_2.1"); - if (ptr) - __collector_util_funcs.fopen = (FILE * (*)())ptr; + if ((ptr = dlvsym (libc, "fopen", "GLIBC_2.17")) != NULL) + __collector_util_funcs.fopen = ptr; + else if ((ptr = dlvsym (libc, "fopen", "GLIBC_2.2.5")) != NULL) + __collector_util_funcs.fopen = ptr; + else if ((ptr = dlvsym (libc, "fopen", "GLIBC_2.1")) != NULL) + __collector_util_funcs.fopen = ptr; + else if ((ptr = dlvsym (libc, "fopen", "GLIBC_2.0")) != NULL) + __collector_util_funcs.fopen = ptr; else + ptr = dlsym (libc, "fopen"); + if (__collector_util_funcs.fopen == NULL) { - Tprintf (DBG_LT0, "libcol_util: WARNING: dlvsym for %s@%s failed. Using dlsym() instead.", "fopen", "GLIBC_2.1"); -#endif /* ARCH(Intel) && WSIZE(32) */ - ptr = dlsym (libc, "fopen"); - if (ptr) - __collector_util_funcs.fopen = (FILE * (*)())ptr; - else - { - CALL_UTIL (fprintf)(stderr, "collector_util_init COL_ERROR_UTIL_INIT fopen: %s\n", dlerror ()); - err = COL_ERROR_UTIL_INIT; - } -#if ARCH(Intel) && WSIZE(32) + CALL_UTIL (fprintf)(stderr, "COL_ERROR_UTIL_INIT fopen: %s\n", dlerror ()); + err = COL_ERROR_UTIL_INIT; } -#endif - ptr = dlsym (libc, "popen"); - if (ptr) - __collector_util_funcs.popen = (FILE * (*)())ptr; + if ((ptr = dlvsym (libc, "popen", "GLIBC_2.17")) != NULL) + __collector_util_funcs.popen = ptr; + else if ((ptr = dlvsym (libc, "popen", "GLIBC_2.2.5")) != NULL) + __collector_util_funcs.popen = ptr; + else if ((ptr = dlvsym (libc, "popen", "GLIBC_2.1")) != NULL) + __collector_util_funcs.popen = ptr; + else if ((ptr = dlvsym (libc, "popen", "GLIBC_2.0")) != NULL) + __collector_util_funcs.popen = ptr; else + ptr = dlsym (libc, "popen"); + if (__collector_util_funcs.popen == NULL) { - CALL_UTIL (fprintf)(stderr, "collector_util_init COL_ERROR_UTIL_INIT popen: %s\n", dlerror ()); + CALL_UTIL (fprintf)(stderr, "COL_ERROR_UTIL_INIT popen: %s\n", dlerror ()); err = COL_ERROR_UTIL_INIT; } -#if ARCH(Intel) && WSIZE(32) - ptr = dlvsym (libc, "fclose", "GLIBC_2.1"); - if (ptr) - __collector_util_funcs.fclose = (int(*)())ptr; + if ((ptr = dlvsym (libc, "fclose", "GLIBC_2.17")) != NULL) + __collector_util_funcs.fclose = ptr; + else if ((ptr = dlvsym (libc, "fclose", "GLIBC_2.2.5")) != NULL) + __collector_util_funcs.fclose = ptr; + else if ((ptr = dlvsym (libc, "fclose", "GLIBC_2.1")) != NULL) + __collector_util_funcs.fclose = ptr; + else if ((ptr = dlvsym (libc, "fclose", "GLIBC_2.0")) != NULL) + __collector_util_funcs.fclose = ptr; else + ptr = dlsym (libc, "fclose"); + if (__collector_util_funcs.fclose == NULL) { - Tprintf (DBG_LT0, "libcol_util: WARNING: dlvsym for %s@%s failed. Using dlsym() instead.", "fclose", "GLIBC_2.1"); -#endif /* ARCH(Intel) && WSIZE(32) */ - ptr = dlsym (libc, "fclose"); - if (ptr) - __collector_util_funcs.fclose = (int(*)())ptr; - else - { - CALL_UTIL (fprintf)(stderr, "collector_util_init COL_ERROR_UTIL_INIT fclose: %s\n", dlerror ()); - err = COL_ERROR_UTIL_INIT; - } -#if ARCH(Intel) && WSIZE(32) + CALL_UTIL (fprintf)(stderr, "COL_ERROR_UTIL_INIT fclose: %s\n", dlerror ()); + err = COL_ERROR_UTIL_INIT; } -#endif ptr = dlsym (libc, "pclose"); if (ptr) diff --git a/gprofng/libcollector/libgprofng.ver b/gprofng/libcollector/libgprofng.ver new file mode 100644 index 00000000000..dbb3212aa1e --- /dev/null +++ b/gprofng/libcollector/libgprofng.ver @@ -0,0 +1,125 @@ +/* Copyright (C) 2021-2023 Free Software Foundation, Inc. + Contributed by Oracle. + + This file is part of GNU Binutils. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +GLIBC_2.0 { + global: + pthread_create; + pthread_mutex_lock; + pthread_mutex_unlock; + pthread_sigmask; + popen; +}; + +GLIBC_2.1 { + global: + pthread_create; + popen; +} GLIBC_2.0; + +GLIBC_2.2 { + global: + open64; + posix_spawn; + posix_spawnp; + pread; + pwrite; + pwrite64; + timer_create; + fgetpos; + fsetpos; + fgetpos64; + fsetpos64; +} GLIBC_2.1; + +GLIBC_2.2.5 { + global: + posix_spawn; + posix_spawnp; + pthread_mutex_lock; + pthread_mutex_unlock; + pthread_sigmask; + pthread_join; + sem_wait; + pthread_create; + dlopen; + popen; + timer_create; + pthread_cond_wait; + pthread_cond_timedwait; + fopen; + fclose; + fdopen; + fgetpos; + fsetpos; +} GLIBC_2.2 ; + +GLIBC_2.3.2 { + global: + pthread_cond_wait; + pthread_cond_timedwait; +} GLIBC_2.2.5; + +GLIBC_2.3.3 { + global: + timer_create; +} GLIBC_2.3.2; + +GLIBC_2.15 { + global: + posix_spawn; + posix_spawnp; +} GLIBC_2.3.3; + +GLIBC_2.17 { + global: + posix_spawn; + posix_spawnp; + pthread_mutex_lock; + pthread_mutex_unlock; + pthread_sigmask; + pthread_join; + sem_wait; + pthread_create; + dlopen; + popen; + timer_create; + pthread_cond_wait; + pthread_cond_timedwait; + fopen; + fclose; + fdopen; + fgetpos; + fsetpos; +} GLIBC_2.15; + +GLIBC_2.32 { + global: + pthread_sigmask; +} GLIBC_2.17; + +GLIBC_2.34 { + global: + pthread_join; + sem_wait; + pthread_create; + dlopen; + timer_create; +} GLIBC_2.32; + diff --git a/gprofng/libcollector/linetrace.c b/gprofng/libcollector/linetrace.c index fd8e54a7973..b29e0b93591 100644 --- a/gprofng/libcollector/linetrace.c +++ b/gprofng/libcollector/linetrace.c @@ -73,27 +73,15 @@ static int (*__real_grantpt) (int fd) = NULL; static char *(*__real_ptsname) (int fd) = NULL; static FILE *(*__real_popen) (const char *command, const char *type) = NULL; static int clone_linenum = 0; -#if ARCH(Intel) -#if WSIZE(32) +static FILE *(*__real_popen_2_17) (const char *command, const char *type) = NULL; +static FILE *(*__real_popen_2_2_5) (const char *command, const char *type) = NULL; static FILE *(*__real_popen_2_1) (const char *command, const char *type) = NULL; static FILE *(*__real_popen_2_0) (const char *command, const char *type) = NULL; -static int (*__real_posix_spawn_2_15) (pid_t *pid, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) = NULL; -static int (*__real_posix_spawn_2_2) (pid_t *pid, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) = NULL; -static int (*__real_posix_spawnp_2_15) (pid_t *pid, const char *file, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) = NULL; -static int (*__real_posix_spawnp_2_2) (pid_t *pid, const char *file, + +static int (*__real_posix_spawn_2_17) (pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]) = NULL; -#elif WSIZE(64) static int (*__real_posix_spawn_2_15) (pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, @@ -102,6 +90,15 @@ static int (*__real_posix_spawn_2_2_5) (pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]) = NULL; +static int (*__real_posix_spawn_2_2) (pid_t *pid, const char *path, + const posix_spawn_file_actions_t *file_actions, + const posix_spawnattr_t *attrp, + char *const argv[], char *const envp[]) = NULL; + +static int (*__real_posix_spawnp_2_17) (pid_t *pid, const char *file, + const posix_spawn_file_actions_t *file_actions, + const posix_spawnattr_t *attrp, + char *const argv[], char *const envp[]) = NULL; static int (*__real_posix_spawnp_2_15) (pid_t *pid, const char *file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, @@ -110,8 +107,10 @@ static int (*__real_posix_spawnp_2_2_5) (pid_t *pid, const char *file, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const argv[], char *const envp[]) = NULL; -#endif /* WSIZE() */ -#endif /* ARCH(Intel) */ +static int (*__real_posix_spawnp_2_2) (pid_t *pid, const char *file, + const posix_spawn_file_actions_t *file_actions, + const posix_spawnattr_t *attrp, + char *const argv[], char *const envp[]) = NULL; static int (*__real_system) (const char *command) = NULL; static int (*__real_posix_spawn) (pid_t *pid, const char *path, const posix_spawn_file_actions_t *file_actions, @@ -675,63 +674,87 @@ init_lineage_intf () dlflag = RTLD_NEXT; TprintfT (DBG_LT2, "init_lineage_intf() using RTLD_%s\n", dlflag == RTLD_DEFAULT ? "DEFAULT" : "NEXT"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_fork\n", __real_fork); __real_vfork = dlsym (dlflag, "vfork"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_vfork\n", __real_vfork); __real_execve = dlsym (dlflag, "execve"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_execve\n", __real_execve); __real_execvp = dlsym (dlflag, "execvp"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_execvp\n", __real_execvp); __real_execv = dlsym (dlflag, "execv"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_execv\n", __real_execv); __real_execle = dlsym (dlflag, "execle"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_execle\n", __real_execle); __real_execlp = dlsym (dlflag, "execlp"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_execlp\n", __real_execlp); __real_execl = dlsym (dlflag, "execl"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_execl\n", __real_execl); __real_clone = dlsym (dlflag, "clone"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_clone\n", __real_clone); __real_posix_spawn = dlsym (dlflag, "posix_spawn"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_posix_spawn\n", - __real_posix_spawn); __real_posix_spawnp = dlsym (dlflag, "posix_spawnp"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_posix_spawnp\n", - __real_posix_spawnp); - __real_popen = dlvsym (dlflag, "popen", SYS_POPEN_VERSION); - TprintfT (DBG_LT2, "init_lineage_intf()[%s] @0x%p __real_popen\n", - SYS_POPEN_VERSION, __real_popen); -#if ARCH(Intel) - __real_posix_spawn_2_15 = dlvsym (dlflag, "posix_spawn", SYS_POSIX_SPAWN_VERSION); - __real_posix_spawnp_2_15 = dlvsym (dlflag, "posix_spawnp", SYS_POSIX_SPAWN_VERSION); -#if WSIZE(32) - __real_popen_2_1 = __real_popen; + + __real_popen_2_17 = dlvsym (dlflag, "popen", "GLIBC_2.17"); + __real_popen_2_2_5 = dlvsym (dlflag, "popen", "GLIBC_2.2.5"); + __real_popen_2_1 = dlvsym (dlflag, "popen", "GLIBC_2.1"); __real_popen_2_0 = dlvsym (dlflag, "popen", "GLIBC_2.0"); - __real_posix_spawn_2_2 = dlvsym (dlflag, "posix_spawn", "GLIBC_2.2"); - __real_posix_spawnp_2_2 = dlvsym (dlflag, "posix_spawnp", "GLIBC_2.2"); -#elif WSIZE(64) + if (__real_popen_2_17) + __real_popen = __real_popen_2_17; + else if (__real_popen_2_2_5) + __real_popen = __real_popen_2_2_5; + else if (__real_popen_2_1) + __real_popen = __real_popen_2_1; + else if (__real_popen_2_0) + __real_popen = __real_popen_2_0; + else + __real_popen = dlsym (dlflag, "popen"); + + __real_posix_spawn_2_17 = dlvsym (dlflag, "posix_spawn", "GLIBC_2.17"); + __real_posix_spawn_2_15 = dlvsym (dlflag, "posix_spawn", "GLIBC_2.15"); __real_posix_spawn_2_2_5 = dlvsym (dlflag, "posix_spawn", "GLIBC_2.2.5"); + __real_posix_spawn_2_2 = dlvsym (dlflag, "posix_spawn", "GLIBC_2.2"); + + __real_posix_spawnp_2_17 = dlvsym (dlflag, "posix_spawnp", "GLIBC_2.17"); + __real_posix_spawnp_2_15 = dlvsym (dlflag, "posix_spawnp", "GLIBC_2.15"); __real_posix_spawnp_2_2_5 = dlvsym (dlflag, "posix_spawnp", "GLIBC_2.2.5"); -#endif /* WSIZE() */ -#endif /* ARCH(Intel) */ + __real_posix_spawnp_2_2 = dlvsym (dlflag, "posix_spawnp", "GLIBC_2.2"); + __real_grantpt = dlsym (dlflag, "grantpt"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_grantpt\n", __real_grantpt); __real_ptsname = dlsym (dlflag, "ptsname"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_ptsname\n", __real_ptsname); __real_system = dlsym (dlflag, "system"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_system\n", __real_system); __real_setuid = dlsym (dlflag, "setuid"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_setuid\n", __real_setuid); __real_seteuid = dlsym (dlflag, "seteuid"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_seteuid\n", __real_seteuid); __real_setreuid = dlsym (dlflag, "setreuid"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_setreuid\n", __real_setreuid); __real_setgid = dlsym (dlflag, "setgid"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_setgid\n", __real_setgid); __real_setegid = dlsym (dlflag, "setegid"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_setegid\n", __real_setegid); __real_setregid = dlsym (dlflag, "setregid"); - TprintfT (DBG_LT2, "init_lineage_intf() @0x%p __real_setregid\n", __real_setregid); + +#define PR_FUNC(f) TprintfT (DBG_LT2, "linetrace.c: " #f ": @%p\n", f) + PR_FUNC (__real_fork); + PR_FUNC (__real_vfork); + PR_FUNC (__real_execve); + PR_FUNC (__real_execvp); + PR_FUNC (__real_execv); + PR_FUNC (__real_execle); + PR_FUNC (__real_execlp); + PR_FUNC (__real_execl); + PR_FUNC (__real_clone); + PR_FUNC (__real_grantpt); + PR_FUNC (__real_ptsname); + PR_FUNC (__real_popen); + PR_FUNC (__real_popen_2_17); + PR_FUNC (__real_popen_2_2_5); + PR_FUNC (__real_popen_2_1); + PR_FUNC (__real_popen_2_0); + PR_FUNC (__real_posix_spawn_2_17); + PR_FUNC (__real_posix_spawn_2_15); + PR_FUNC (__real_posix_spawn_2_2_5); + PR_FUNC (__real_posix_spawn_2_2); + PR_FUNC (__real_posix_spawnp_2_17); + PR_FUNC (__real_posix_spawnp_2_15); + PR_FUNC (__real_posix_spawnp_2_2_5); + PR_FUNC (__real_posix_spawnp_2_2); + PR_FUNC (__real_system); + PR_FUNC (__real_posix_spawn); + PR_FUNC (__real_posix_spawnp); + PR_FUNC (__real_setuid); + PR_FUNC (__real_seteuid); + PR_FUNC (__real_setreuid); + PR_FUNC (__real_setgid); + PR_FUNC (__real_setegid); + PR_FUNC (__real_setregid); + return 0; } @@ -1365,226 +1388,120 @@ __collector_execl (const char* path, const char *arg0, ...) #include /*-------------------------------------------------------- posix_spawn */ -#if ARCH(Intel) // map interposed symbol versions static int -__collector_posix_spawn_symver (int(real_posix_spawn) (), - pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]); - -SYMVER_ATTRIBUTE (__collector_posix_spawn_2_15, posix_spawn@GLIBC_2.15) -int -__collector_posix_spawn_2_15 (pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) -{ - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_posix_spawn_2_15@%p(path=%s, argv[0]=%s, env[0]=%s)\n", - CALL_REAL (posix_spawn_2_15), path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL"); - if (NULL_PTR (posix_spawn)) - init_lineage_intf (); - return __collector_posix_spawn_symver (CALL_REAL (posix_spawn_2_15), pidp, - path, file_actions, attrp, argv, envp); -} - -#if WSIZE(32) -SYMVER_ATTRIBUTE (__collector_posix_spawn_2_2, posix_spawn@GLIBC_2.2) -int -__collector_posix_spawn_2_2 (pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) -{ - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_posix_spawn_2_2@%p(path=%s, argv[0]=%s, env[0]=%s)\n", - CALL_REAL (posix_spawn_2_2), path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL"); - if (NULL_PTR (posix_spawn)) - init_lineage_intf (); - return __collector_posix_spawn_symver (CALL_REAL (posix_spawn_2_2), pidp, - path, file_actions, attrp, argv, envp); -} - -#else /* ^WSIZE(32) */ -SYMVER_ATTRIBUTE (__collector_posix_spawn_2_2_5, posix_spawn@GLIBC_2.2.5) -int -__collector_posix_spawn_2_2_5 (pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) -{ - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_posix_spawn_2_2_5@%p(path=%s, argv[0]=%s, env[0]=%s)\n", - CALL_REAL (posix_spawn_2_2_5), path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL"); - if (NULL_PTR (posix_spawn)) - init_lineage_intf (); - return __collector_posix_spawn_symver (CALL_REAL (posix_spawn_2_2_5), pidp, - path, file_actions, attrp, argv, envp); -} -#endif /* ^WSIZE(32) */ - -static int -__collector_posix_spawn_symver (int(real_posix_spawn) (), -#else /* ^ARCH(Intel) */ -int -__collector_posix_spawn ( -#endif /* ARCH() */ - pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) +gprofng_posix_spawn (int(real_posix_spawn) (), + pid_t *pidp, const char *path, + const posix_spawn_file_actions_t *file_actions, + const posix_spawnattr_t *attrp, + char *const argv[], char *const envp[]) { int ret; static char **coll_env = NULL; /* environment for collection */ - if (NULL_PTR (posix_spawn)) - init_lineage_intf (); - if (NULL_PTR (posix_spawn)) + if (real_posix_spawn == NULL) { - TprintfT (DBG_LT0, "__collector_posix_spawn(path=%s) interposing: ERROR, posix_spawn() not found by dlsym\n", + TprintfT (DBG_LT0, "gprofng_posix_spawn (path=%s) interposin ERROR, posix_spawn() not found by dlsym\n", path ? path : "NULL"); return -1; /* probably should set errno */ } - int * guard = NULL; - int combo_flag = (line_mode == LM_TRACK_LINEAGE) ? ((CHCK_REENTRANCE (guard)) ? 1 : 0) : 0; - TprintfT (DBG_LT0, "__collector_posix_spawn(path=%s, argv[0]=%s, env[0]=%s) interposing: line_mode=%d combo=%d\n", - path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL", line_mode, combo_flag); + int *guard = NULL; + int combo_flag = (line_mode == LM_TRACK_LINEAGE && + CHCK_REENTRANCE (guard)) ? 1 : 0; + TprintfT (DBG_LT0, "gprofng_posix_spawn @%p (%s, argv[0]=%s, env[0]=%s)" + "line_mode=%d combo=%d\n", (real_posix_spawn), path ? path : "NULL", + (argv && argv[0]) ? argv[0] : "NULL", + (envp && envp[0]) ? envp[0] : "NULL", line_mode, combo_flag); if (line_mode == LM_CLOSED) /* ensure collection environment is sanitised */ __collector_env_unset ((char**) envp); - if ((line_mode != LM_TRACK_LINEAGE) || combo_flag) - { -#if ARCH(Intel) - return (real_posix_spawn) (pidp, path, file_actions, attrp, argv, envp); -#else - return CALL_REAL (posix_spawn)(pidp, path, file_actions, attrp, argv, envp); -#endif - } + if (line_mode != LM_TRACK_LINEAGE || combo_flag) + return (real_posix_spawn) (pidp, path, file_actions, attrp, argv, envp); int following_exec = 0; - coll_env = linetrace_ext_exec_prologue ("posix_spawn", path, argv, envp, &following_exec); - TprintfT (DBG_LT0, "__collector_posix_spawn(): coll_env=0x%p\n", coll_env); - __collector_env_printall ("__collector_posix_spawn", coll_env); + coll_env = linetrace_ext_exec_prologue ("posix_spawn", path, argv, envp, + &following_exec); + __collector_env_printall ("gprofng_posix_spawn", coll_env); PUSH_REENTRANCE (guard); -#if ARCH(Intel) - ret = (real_posix_spawn) (pidp, path, file_actions, attrp, argv, coll_env); -#else - ret = CALL_REAL (posix_spawn)(pidp, path, file_actions, attrp, argv, coll_env); -#endif + ret = real_posix_spawn (pidp, path, file_actions, attrp, argv, coll_env); POP_REENTRANCE (guard); linetrace_ext_exec_epilogue ("posix_spawn", envp, ret, &following_exec); return ret; } -/*-------------------------------------------------------- posix_spawnp */ -#if ARCH(Intel) -// map interposed symbol versions +#define DCL_POSIX_SPAWN(dcl_f, real_f) \ +int dcl_f (pid_t *pidp, const char *path, \ + const posix_spawn_file_actions_t *file_actions, \ + const posix_spawnattr_t *attrp, \ + char *const argv[], char *const envp[]) \ + { \ + if ((real_f) == NULL) \ + init_lineage_intf (); \ + return gprofng_posix_spawn (real_f, pidp, path, file_actions, attrp, \ + argv, envp); \ + } + + +DCL_FUNC_VER (DCL_POSIX_SPAWN, posix_spawn_2_17, posix_spawn@GLIBC_2.17) +DCL_FUNC_VER (DCL_POSIX_SPAWN, posix_spawn_2_15, posix_spawn@GLIBC_2.15) +DCL_FUNC_VER (DCL_POSIX_SPAWN, posix_spawn_2_2_5, posix_spawn@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_POSIX_SPAWN, posix_spawn_2_2, posix_spawn@GLIBC_2.2) +DCL_POSIX_SPAWN (posix_spawn, CALL_REAL (posix_spawn)) +/*-------------------------------------------------------- posix_spawnp */ static int -__collector_posix_spawnp_symver (int(real_posix_spawnp) (), pid_t *pidp, - const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]); - -SYMVER_ATTRIBUTE (__collector_posix_spawnp_2_15, posix_spawnp@GLIBC_2.15) -int // Common interposition -__collector_posix_spawnp_2_15 (pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) -{ - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_posix_spawnp_2_15@%p(path=%s, argv[0]=%s, env[0]=%s)\n", - CALL_REAL (posix_spawnp_2_15), path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL"); - if (NULL_PTR (posix_spawnp)) - init_lineage_intf (); - return __collector_posix_spawnp_symver (CALL_REAL (posix_spawnp_2_15), pidp, - path, file_actions, attrp, argv, envp); -} - -#if WSIZE(32) - -SYMVER_ATTRIBUTE (__collector_posix_spawnp_2_2, posix_spawnp@GLIBC_2.2) -int -__collector_posix_spawnp_2_2 (pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) -{ - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_posix_spawnp_2_2@%p(path=%s, argv[0]=%s, env[0]=%s)\n", - CALL_REAL (posix_spawnp_2_2), path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL"); - if (NULL_PTR (posix_spawnp)) - init_lineage_intf (); - return __collector_posix_spawnp_symver (CALL_REAL (posix_spawnp_2_2), pidp, - path, file_actions, attrp, argv, envp); -} - -#else /* ^WSIZE(32) */ -SYMVER_ATTRIBUTE (__collector_posix_spawnp_2_2_5, posix_spawnp@GLIBC_2.2.5) -int -__collector_posix_spawnp_2_2_5 (pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]) +gprofng_posix_spawnp (int (real_posix_spawnp) (), + pid_t *pidp, const char *path, + const posix_spawn_file_actions_t *file_actions, + const posix_spawnattr_t *attrp, + char *const argv[], char *const envp[]) { - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_posix_spawnp_2_2_5@%p(path=%s, argv[0]=%s, env[0]=%s)\n", - CALL_REAL (posix_spawnp_2_2_5), path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", envp ? (envp[0] ? envp[0] : "NULL") : "NULL"); - if (NULL_PTR (posix_spawnp)) - init_lineage_intf (); - return __collector_posix_spawnp_symver (CALL_REAL (posix_spawnp_2_2_5), pidp, - path, file_actions, attrp, argv, envp); -} - -#endif /* ^WSIZE(32) */ - -static int -__collector_posix_spawnp_symver (int(real_posix_spawnp) (), -#else /* ^ARCH(Intel) */ -int -__collector_posix_spawnp ( -#endif /* ARCH() */ - pid_t *pidp, const char *path, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, - char *const argv[], char *const envp[]){ - int ret; static char **coll_env = NULL; /* environment for collection */ - if (NULL_PTR (posix_spawnp)) - init_lineage_intf (); - if (NULL_PTR (posix_spawnp)) + + if (real_posix_spawnp == NULL) { - TprintfT (DBG_LT0, "__collector_posix_spawnp(path=%s) interposing: ERROR, posix_spawnp() not found by dlsym\n", + TprintfT (DBG_LT0, "gprofng_posix_spawnp (path=%s) interposin ERROR\n", path ? path : "NULL"); return -1; /* probably should set errno */ } - int * guard = NULL; + int *guard = NULL; int combo_flag = (line_mode == LM_TRACK_LINEAGE) ? ((CHCK_REENTRANCE (guard)) ? 1 : 0) : 0; - TprintfT (DBG_LT0, "__collector_posix_spawnp(path=%s, argv[0]=%s, env[0]=%s) interposing: line_mode=%d combo=%d\n", - path ? path : "NULL", argv ? (argv[0] ? argv[0] : "NULL") : "NULL", - envp ? (envp[0] ? envp[0] : "NULL") : "NULL", line_mode, combo_flag); + TprintfT (DBG_LT0, "gprofng_posix_spawnp @%p (path=%s, argv[0]=%s, env[0]=%s) line_mode=%d combo=%d\n", + real_posix_spawnp, path ? path : "NULL", + argv && argv[0] ? argv[0] : "NULL", + envp && envp[0] ? envp[0] : "NULL", line_mode, combo_flag); - if (line_mode == LM_CLOSED) /* ensure collection environment is sanitised */ + if (line_mode == LM_CLOSED) /* ensure collection environment is sanitized */ __collector_env_unset ((char**) envp); if (line_mode != LM_TRACK_LINEAGE || combo_flag) - { -#if ARCH(Intel) - return (real_posix_spawnp) (pidp, path, file_actions, attrp, argv, envp); -#else - return CALL_REAL (posix_spawnp)(pidp, path, file_actions, attrp, argv, envp); -#endif - } + return (real_posix_spawnp) (pidp, path, file_actions, attrp, argv, envp); int following_exec = 0; coll_env = linetrace_ext_exec_prologue ("posix_spawnp", path, argv, envp, &following_exec); TprintfT (DBG_LT0, "__collector_posix_spawnp(): coll_env=0x%p\n", coll_env); __collector_env_printall ("__collector_posix_spawnp", coll_env); PUSH_REENTRANCE (guard); -#if ARCH(Intel) - ret = (real_posix_spawnp) (pidp, path, file_actions, attrp, argv, coll_env); -#else - ret = CALL_REAL (posix_spawnp)(pidp, path, file_actions, attrp, argv, coll_env); -#endif + int ret = real_posix_spawnp (pidp, path, file_actions, attrp, argv, coll_env); POP_REENTRANCE (guard); linetrace_ext_exec_epilogue ("posix_spawnp", envp, ret, &following_exec); return ret; } +#define DCL_POSIX_SPAWNP(dcl_f, real_f) \ +int dcl_f (pid_t *pidp, const char *path, \ + const posix_spawn_file_actions_t *file_actions, \ + const posix_spawnattr_t *attrp, \ + char *const argv[], char *const envp[]) \ + { \ + if ((real_f) == NULL) \ + init_lineage_intf (); \ + return gprofng_posix_spawnp (real_f, pidp, path, \ + file_actions, attrp, argv, envp); \ + } + +DCL_FUNC_VER (DCL_POSIX_SPAWNP, posix_spawnp_2_17, posix_spawnp@GLIBC_2.17) +DCL_FUNC_VER (DCL_POSIX_SPAWNP, posix_spawnp_2_15, posix_spawnp@GLIBC_2.15) +DCL_FUNC_VER (DCL_POSIX_SPAWNP, posix_spawnp_2_2_5, posix_spawnp@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_POSIX_SPAWNP, posix_spawnp_2_2, posix_spawnp@GLIBC_2.2) +DCL_POSIX_SPAWNP (posix_spawnp, CALL_REAL (posix_spawnp)) + /*------------------------------------------------------------- system */ int system () __attribute__ ((weak, alias ("__collector_system"))); @@ -1612,90 +1529,33 @@ __collector_system (const char *cmd) /*------------------------------------------------------------- popen */ // map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) -static FILE * -__collector_popen_symver (FILE*(real_popen) (), const char *cmd, const char *mode); - -SYMVER_ATTRIBUTE (__collector_popen_2_1, popen@GLIBC_2.1) -FILE * -__collector_popen_2_1 (const char *cmd, const char *mode) -{ - if (NULL_PTR (popen)) - init_lineage_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_popen_2_1@%p\n", CALL_REAL (popen_2_1)); - return __collector_popen_symver (CALL_REAL (popen_2_1), cmd, mode); -} - -SYMVER_ATTRIBUTE (__collector_popen_2_0, popen@GLIBC_2.0) -FILE * -__collector_popen_2_0 (const char *cmd, const char *mode) -{ - if (NULL_PTR (popen)) - init_lineage_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_popen_2_0@%p\n", CALL_REAL (popen_2_0)); - return __collector_popen_symver (CALL_REAL (popen_2_0), cmd, mode); -} - -SYMVER_ATTRIBUTE (__collector__popen_2_1, _popen@GLIBC_2.1) -FILE * -__collector__popen_2_1 (const char *cmd, const char *mode) -{ - if (NULL_PTR (popen)) - init_lineage_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector__popen_2_1@%p\n", CALL_REAL (popen_2_1)); - return __collector_popen_symver (CALL_REAL (popen_2_1), cmd, mode); -} - -SYMVER_ATTRIBUTE (__collector__popen_2_0, _popen@GLIBC_2.0) -FILE * -__collector__popen_2_0 (const char *cmd, const char *mode) -{ - if (NULL_PTR (popen)) - init_lineage_intf (); - return __collector_popen_symver (CALL_REAL (popen_2_0), cmd, mode); -} -#else // WSIZE(64) -FILE * popen () __attribute__ ((weak, alias ("__collector_popen"))); -#endif - -#if ARCH(Intel) && WSIZE(32) -static FILE * -__collector_popen_symver (FILE*(real_popen) (), const char *cmd, const char *mode) -#else - -FILE * -__collector_popen (const char *cmd, const char *mode) -#endif -{ - FILE *ret; - if (NULL_PTR (popen)) - init_lineage_intf (); - TprintfT (DBG_LT0, - "__collector_popen(cmd=%s) interposing: line_mode=%d combo=%d\n", - cmd ? cmd : "NULL", line_mode, get_combo_flag ()); - int *guard = NULL; - if (line_mode == LM_TRACK_LINEAGE) - INIT_REENTRANCE (guard); - if (guard == NULL) - { -#if ARCH(Intel) && WSIZE(32) - return (real_popen) (cmd, mode); -#else - return CALL_REAL (popen)(cmd, mode); -#endif - } - int following_combo = 0; - linetrace_ext_combo_prologue ("popen", cmd, &following_combo); - PUSH_REENTRANCE (guard); -#if ARCH(Intel) && WSIZE(32) - ret = (real_popen) (cmd, mode); -#else - ret = CALL_REAL (popen)(cmd, mode); -#endif - POP_REENTRANCE (guard); - linetrace_ext_combo_epilogue ("popen", (ret == NULL) ? (-1) : 0, &following_combo); - return ret; -} +#define DCL_POPEN(dcl_f, real_f) \ + FILE *dcl_f (const char *cmd, const char *mode) \ + { \ + if ((real_f) == NULL) \ + init_lineage_intf (); \ + TprintfT (DBG_LT0, #dcl_f " (%s) interposing: line_mode=%d combo=%d\n", \ + cmd ? cmd : "NULL", line_mode, get_combo_flag ()); \ + int *guard = NULL; \ + if (line_mode == LM_TRACK_LINEAGE) \ + INIT_REENTRANCE (guard); \ + if (guard == NULL) \ + return (real_f) (cmd, mode); \ + int following_combo = 0; \ + linetrace_ext_combo_prologue ("popen", cmd, &following_combo); \ + PUSH_REENTRANCE (guard); \ + FILE *ret = (real_f) (cmd, mode); \ + POP_REENTRANCE (guard); \ + linetrace_ext_combo_epilogue ("popen", ret == NULL ? -1 : 0, \ + &following_combo); \ + return ret; \ + } + +DCL_FUNC_VER (DCL_POPEN, popen_2_17, popen@GLIBC_2.17) +DCL_FUNC_VER (DCL_POPEN, popen_2_2_5, popen@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_POPEN, popen_2_1, popen@GLIBC_2.1) +DCL_FUNC_VER (DCL_POPEN, popen_2_0, popen@GLIBC_2.0) +DCL_POPEN (popen, CALL_REAL (popen)) /*------------------------------------------------------------- grantpt */ int grantpt () __attribute__ ((weak, alias ("__collector_grantpt"))); diff --git a/gprofng/libcollector/mapfile.aarch64-Linux b/gprofng/libcollector/mapfile.aarch64-Linux deleted file mode 100644 index c03b2181eca..00000000000 --- a/gprofng/libcollector/mapfile.aarch64-Linux +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2021-2023 Free Software Foundation, Inc. - Contributed by Oracle. - - This file is part of GNU Binutils. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -GLIBC_2.17 { - global: - posix_spawn; - posix_spawnp; - pthread_mutex_lock; - pthread_mutex_unlock; - pthread_join; - sem_wait; - pthread_create; - dlopen; - popen; - timer_create; - pthread_cond_wait; - pthread_cond_timedwait; - fopen; - fclose; - fdopen; - fgetpos; - fsetpos; -}; diff --git a/gprofng/libcollector/mapfile.amd64-Linux b/gprofng/libcollector/mapfile.amd64-Linux deleted file mode 100644 index 0868308118c..00000000000 --- a/gprofng/libcollector/mapfile.amd64-Linux +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2021-2023 Free Software Foundation, Inc. - Contributed by Oracle. - - This file is part of GNU Binutils. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -GLIBC_2.2.5 { - global: - posix_spawn; - posix_spawnp; - pthread_mutex_lock; - pthread_mutex_unlock; - pthread_join; - sem_wait; - pthread_create; - dlopen; - popen; - timer_create; - pthread_cond_wait; - pthread_cond_timedwait; - fopen; - fclose; - fdopen; - fgetpos; - fsetpos; -}; - -GLIBC_2.3.2 { - global: - pthread_cond_wait; - pthread_cond_timedwait; -}; - -GLIBC_2.3.3 { - global: - timer_create; -}; - -GLIBC_2.15 { - global: - posix_spawn; - posix_spawnp; -}; - -GLIBC_2.17 { - global: - posix_spawn; - posix_spawnp; - pthread_mutex_lock; - pthread_mutex_unlock; - pthread_join; - sem_wait; - pthread_create; - dlopen; - popen; - timer_create; - pthread_cond_wait; - pthread_cond_timedwait; - fopen; - fclose; - fdopen; - fgetpos; - fsetpos; -}; - diff --git a/gprofng/libcollector/mapfile.intel-Linux b/gprofng/libcollector/mapfile.intel-Linux deleted file mode 100644 index b66292550a7..00000000000 --- a/gprofng/libcollector/mapfile.intel-Linux +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (C) 2021-2023 Free Software Foundation, Inc. - Contributed by Oracle. - - This file is part of GNU Binutils. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -GLIBC_2.0 { - global: - pthread_mutex_lock; - pthread_mutex_unlock; - pthread_join; - pthread_create; - dlopen; - popen; - sem_wait; - pthread_cond_wait; - pthread_cond_timedwait; - fopen; - fclose; - fdopen; - fgetpos; - fsetpos; -}; - -GLIBC_2.1 { - global: - sem_wait; - pthread_create; - dlopen; - open64; - pread; - pwrite; - pwrite64; - popen; - fopen; - fclose; - fdopen; - fgetpos64; - fsetpos64; -}; - -GLIBC_2.2 { - global: - open64; - posix_spawn; - posix_spawnp; - pread; - pwrite; - pwrite64; - timer_create; - fgetpos; - fsetpos; - fgetpos64; - fsetpos64; -}; - -GLIBC_2.3.2 { - global: - pthread_cond_wait; - pthread_cond_timedwait; -}; - -GLIBC_2.15 { - global: - posix_spawn; - posix_spawnp; -}; diff --git a/gprofng/libcollector/mapfile.sparc-Linux b/gprofng/libcollector/mapfile.sparc-Linux deleted file mode 100644 index a74c60fa978..00000000000 --- a/gprofng/libcollector/mapfile.sparc-Linux +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2021-2023 Free Software Foundation, Inc. - Contributed by Oracle. - - This file is part of GNU Binutils. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -GLIBC_2.0 { - global: - pthread_mutex_lock; - pthread_mutex_unlock; - pthread_join; -}; - -GLIBC_2.1 { - global: - sem_wait; - pthread_create; - dlopen; - popen; -}; - -GLIBC_2.3.2 { - global: - pthread_cond_wait; - pthread_cond_timedwait; -}; diff --git a/gprofng/libcollector/mapfile.sparcv9-Linux b/gprofng/libcollector/mapfile.sparcv9-Linux deleted file mode 100644 index c46214e26ed..00000000000 --- a/gprofng/libcollector/mapfile.sparcv9-Linux +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 2021-2023 Free Software Foundation, Inc. - Contributed by Oracle. - - This file is part of GNU Binutils. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street - Fifth Floor, Boston, - MA 02110-1301, USA. */ - -GLIBC_2.0 { - global: - dlopen; -}; - -GLIBC_2.1 { - global: - dlopen; -}; - -GLIBC_2.2 { - global: - pthread_create; - popen; - pthread_mutex_lock; - pthread_mutex_unlock; - pthread_join; - sem_wait; - pthread_cond_wait; - pthread_cond_timedwait; - timer_create; - fopen; - fclose; - fdopen; - fgetpos; - fsetpos; -}; - -GLIBC_2.3.2 { - global: - pthread_cond_wait; - pthread_cond_timedwait; -}; - -GLIBC_2.3.3 { - global: - timer_create; -}; diff --git a/gprofng/libcollector/mmaptrace.c b/gprofng/libcollector/mmaptrace.c index c46dac4e0aa..f81ff8db1df 100644 --- a/gprofng/libcollector/mmaptrace.c +++ b/gprofng/libcollector/mmaptrace.c @@ -61,12 +61,6 @@ typedef struct prmap_t int pr_pagesize; /* pagesize (bytes) for this mapping */ } prmap_t; -#define SYS_MMAP_NAME "mmap" -#define SYS_MMAP64_NAME "mmap64" -#define SYS_MUNMAP_NAME "munmap" -#define SYS_DLOPEN_NAME "dlopen" -#define SYS_DLCLOSE_NAME "dlclose" - typedef struct MapInfo { struct MapInfo *next; @@ -113,11 +107,17 @@ static void *(*__real_mmap64)(void* start, size_t length, int prot, int flags, int fd, off64_t offset) = NULL; static int (*__real_munmap)(void* start, size_t length) = NULL; static void *(*__real_dlopen)(const char* pathname, int mode) = NULL; -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) +static void *(*__real_dlopen_2_34)(const char* pathname, int mode) = NULL; +static void *(*__real_dlopen_2_17)(const char* pathname, int mode) = NULL; +static void *(*__real_dlopen_2_2_5)(const char* pathname, int mode) = NULL; static void *(*__real_dlopen_2_1)(const char* pathname, int mode) = NULL; static void *(*__real_dlopen_2_0)(const char* pathname, int mode) = NULL; -#endif + static int (*__real_dlclose)(void* handle) = NULL; +static int (*__real_dlclose_2_34)(void* handle) = NULL; +static int (*__real_dlclose_2_17)(void* handle) = NULL; +static int (*__real_dlclose_2_2_5)(void* handle) = NULL; +static int (*__real_dlclose_2_0)(void* handle) = NULL; static void (*collector_heap_record)(int, size_t, void*) = NULL; /* internal function prototypes */ @@ -1408,17 +1408,15 @@ init_mmap_intf () { if (__collector_dlsym_guard) return 1; - void *dlflag; - __real_mmap = (void*(*)(void* addr, size_t len, int prot, int flags, - int fildes, off_t off))dlsym (RTLD_NEXT, SYS_MMAP_NAME); + void *dlflag = RTLD_NEXT; + __real_mmap = dlsym (dlflag, "mmap"); if (__real_mmap == NULL) { /* We are probably dlopened after libthread/libc, * try to search in the previously loaded objects */ - __real_mmap = (void*(*)(void* addr, size_t len, int prot, int flags, - int fildes, off_t off))dlsym (RTLD_DEFAULT, SYS_MMAP_NAME); + __real_mmap = dlsym (RTLD_DEFAULT, "mmap"); if (__real_mmap == NULL) { TprintfT (0, "ERROR: collector real mmap not found\n"); @@ -1427,33 +1425,59 @@ init_mmap_intf () TprintfT (DBG_LT2, "collector real mmap found with RTLD_DEFAULT\n"); dlflag = RTLD_DEFAULT; } - else - { - TprintfT (DBG_LT2, "collector real mmap found with RTLD_NEXT\n"); - dlflag = RTLD_NEXT; - } - TprintfT (DBG_LT2, "init_mmap_intf() @%p __real_mmap\n", __real_mmap); - __real_mmap64 = (void*(*)(void *, size_t, int, int, int, off64_t)) - dlsym (dlflag, SYS_MMAP64_NAME); - TprintfT (DBG_LT2, "init_mmap_intf() @%p __real_mmap64\n", __real_mmap64); - __real_munmap = (int(*)(void *, size_t)) dlsym (dlflag, SYS_MUNMAP_NAME); - TprintfT (DBG_LT2, "init_mmap_intf() @%p __real_munmap\n", __real_munmap); + __real_mmap64 = dlsym (dlflag, "mmap64"); + __real_munmap = dlsym (dlflag, "munmap"); // dlopen/dlmopen/dlclose are in libdl.so - __real_dlopen = (void*(*)(const char *, int)) - dlvsym (dlflag, SYS_DLOPEN_NAME, SYS_DLOPEN_VERSION); - TprintfT (DBG_LT2, "init_mmap_intf() [%s] @%p __real_dlopen\n", - SYS_DLOPEN_VERSION, __real_dlopen); -#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) - __real_dlopen_2_1 = __real_dlopen; - __real_dlopen_2_0 = (void*(*)(const char *, int)) - dlvsym (dlflag, SYS_DLOPEN_NAME, "GLIBC_2.0"); -#endif - - __real_dlclose = (int(*)(void* handle))dlsym (dlflag, SYS_DLCLOSE_NAME); - TprintfT (DBG_LT2, "init_mmap_intf() @%p __real_dlclose\n", __real_dlclose); - TprintfT (DBG_LT2, "init_mmap_intf() done\n"); + __real_dlopen_2_34 = dlvsym (dlflag, "dlopen", "GLIBC_2.34"); + __real_dlopen_2_17 = dlvsym (dlflag, "dlopen", "GLIBC_2.17"); + __real_dlopen_2_2_5 = dlvsym (dlflag, "dlopen", "GLIBC_2.2.5"); + __real_dlopen_2_1 = dlvsym (dlflag, "dlopen", "GLIBC_2.1"); + __real_dlopen_2_0 = dlvsym (dlflag, "dlopen", "GLIBC_2.0"); + if (__real_dlopen_2_34) + __real_dlopen = __real_dlopen_2_34; + else if (__real_dlopen_2_17) + __real_dlopen = __real_dlopen_2_17; + else if (__real_dlopen_2_2_5) + __real_dlopen = __real_dlopen_2_2_5; + else if (__real_dlopen_2_1) + __real_dlopen = __real_dlopen_2_1; + else if (__real_dlopen_2_0) + __real_dlopen = __real_dlopen_2_0; + else + __real_dlopen = dlsym (dlflag, "dlopen"); + + __real_dlclose_2_34 = dlvsym (dlflag, "dlclose", "GLIBC_2.34"); + __real_dlclose_2_17 = dlvsym (dlflag, "dlclose", "GLIBC_2.17"); + __real_dlclose_2_2_5 = dlvsym (dlflag, "dlclose", "GLIBC_2.2.5"); + __real_dlclose_2_0 = dlvsym (dlflag, "dlclose", "GLIBC_2.0"); + if (__real_dlclose_2_34) + __real_dlclose = __real_dlclose_2_34; + else if (__real_dlclose_2_17) + __real_dlclose = __real_dlclose_2_17; + else if (__real_dlclose_2_2_5) + __real_dlclose = __real_dlclose_2_2_5; + else if (__real_dlclose_2_0) + __real_dlclose = __real_dlclose_2_0; + else + __real_dlclose = dlsym (dlflag, "dlclose"); + +#define PR_FUNC(f) TprintfT (DBG_LT2, " mmaptrace.c: " #f ": @%p\n", f) + PR_FUNC (__real_dlclose); + PR_FUNC (__real_dlclose_2_0); + PR_FUNC (__real_dlclose_2_17); + PR_FUNC (__real_dlclose_2_2_5); + PR_FUNC (__real_dlclose_2_34); + PR_FUNC (__real_dlopen); + PR_FUNC (__real_dlopen_2_0); + PR_FUNC (__real_dlopen_2_1); + PR_FUNC (__real_dlopen_2_17); + PR_FUNC (__real_dlopen_2_2_5); + PR_FUNC (__real_dlopen_2_34); + PR_FUNC (__real_mmap); + PR_FUNC (__real_mmap64); + PR_FUNC (__real_munmap); return 0; } @@ -1530,8 +1554,8 @@ munmap (void *start, size_t length) /*------------------------------------------------------------- dlopen */ static void * -__collector_dlopen_symver (void*(real_dlopen) (const char *, int), - void *caller, const char *pathname, int mode) +gprofng_dlopen (void*(real_dlopen) (const char *, int), + void *caller, const char *pathname, int mode) { const char * real_pathname = pathname; char new_pathname[MAXPATHLEN]; @@ -1552,15 +1576,15 @@ __collector_dlopen_symver (void*(real_dlopen) (const char *, int), const char *p = __collector_strrchr (dl_info.dli_fname, '/'); if (p) __collector_strlcpy (new_pathname, dl_info.dli_fname, - (p - dl_info.dli_fname + 2) < MAXPATHLEN ? (p - dl_info.dli_fname + 2) : MAXPATHLEN); - __collector_strlcat (new_pathname, pathname + origin_offset, MAXPATHLEN - CALL_UTIL (strlen)(new_pathname)); + (p - dl_info.dli_fname + 2) < MAXPATHLEN ? + (p - dl_info.dli_fname + 2) : MAXPATHLEN); + __collector_strlcat (new_pathname, pathname + origin_offset, + MAXPATHLEN - CALL_UTIL (strlen)(new_pathname)); real_pathname = new_pathname; } else TprintfT (0, "ERROR: dladdr(%p): %s\n", caller, dlerror ()); } - if (NULL_PTR (dlopen)) - init_mmap_intf (); TprintfT (DBG_LT2, "libcollector.dlopen(%s,%d) interposing\n", pathname ? pathname : "", mode); void *ret = NULL; @@ -1585,46 +1609,26 @@ __collector_dlopen_symver (void*(real_dlopen) (const char *, int), return ret; } -void * -dlopen (const char *pathname, int mode) -{ - if (NULL_PTR (dlopen)) - init_mmap_intf (); - void* caller = __builtin_return_address (0); // must be called inside dlopen first layer interposition - return __collector_dlopen_symver (CALL_REAL (dlopen), caller, pathname, mode); -} - -#if !defined(__MUSL_LIBC) && ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) -// map interposed symbol versions - -SYMVER_ATTRIBUTE (__collector_dlopen_2_1, dlopen@GLIBC_2.1) -void * -__collector_dlopen_2_1 (const char *pathname, int mode) -{ - if (NULL_PTR (dlopen_2_1)) - init_mmap_intf (); - void *caller = __builtin_return_address (0); // must be called inside dlopen first layer interposition - return __collector_dlopen_symver (CALL_REAL (dlopen_2_1), caller, pathname, mode); -} - -SYMVER_ATTRIBUTE (__collector_dlopen_2_0, dlopen@GLIBC_2.0) -void * -__collector_dlopen_2_0 (const char *pathname, int mode) -{ - if (NULL_PTR (dlopen_2_0)) - init_mmap_intf (); - void* caller = __builtin_return_address (0); // must be called inside dlopen first layer interposition - return __collector_dlopen_symver (CALL_REAL (dlopen_2_0), caller, pathname, mode); -} -#endif +#define DCL_DLOPEN(dcl_f, real_f) \ +void *dcl_f (const char *pathname, int mode) \ + { \ + if ((real_f) == NULL) \ + init_mmap_intf (); \ + void *caller = __builtin_return_address (0); \ + return gprofng_dlopen (real_f, caller, pathname, mode); \ + } + +DCL_FUNC_VER (DCL_DLOPEN, dlopen_2_34, dlopen@GLIBC_2.34) +DCL_FUNC_VER (DCL_DLOPEN, dlopen_2_17, dlopen@GLIBC_2.17) +DCL_FUNC_VER (DCL_DLOPEN, dlopen_2_2_5, dlopen@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_DLOPEN, dlopen_2_1, dlopen@GLIBC_2.1) +DCL_FUNC_VER (DCL_DLOPEN, dlopen_2_0, dlopen@GLIBC_2.0) +DCL_DLOPEN (dlopen, CALL_REAL (dlopen)) /*------------------------------------------------------------- dlclose */ -int -dlclose (void *handle) +static int +gprofng_dlclose (int (real_dlclose) (void *), void *handle) { - if (NULL_PTR (dlclose)) - init_mmap_intf (); - TprintfT (DBG_LT2, "__collector_dlclose(%p) entered\n", handle); hrtime_t hrt = GETRELTIME (); if (!CHCK_REENTRANCE) { @@ -1633,7 +1637,7 @@ dlclose (void *handle) POP_REENTRANCE; hrt = GETRELTIME (); } - int ret = CALL_REAL (dlclose)(handle); + int ret = real_dlclose (handle); /* Don't call update if dlclose failed: preserve dlerror() */ if (!ret && !CHCK_REENTRANCE) @@ -1642,6 +1646,21 @@ dlclose (void *handle) update_map_segments (hrt, 1); POP_REENTRANCE; } - TprintfT (DBG_LT2, "__collector_dlclose(%p) returning %d\n", handle, ret); + TprintfT (DBG_LT2, "gprofng_dlclose @%p (%p) returning %d\n", real_dlclose, + handle, ret); return ret; } + +#define DCL_DLCLOSE(dcl_f, real_f) \ +int dcl_f (void *handle) \ + { \ + if ((real_f) == NULL) \ + init_mmap_intf (); \ + return gprofng_dlclose (real_f, handle); \ + } + +DCL_FUNC_VER (DCL_DLCLOSE, dlclose_2_34, dlclose@GLIBC_2.34) +DCL_FUNC_VER (DCL_DLCLOSE, dlclose_2_17, dlclose@GLIBC_2.17) +DCL_FUNC_VER (DCL_DLCLOSE, dlclose_2_2_5, dlclose@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_DLCLOSE, dlclose_2_0, dlclose@GLIBC_2.0) +DCL_DLCLOSE (dlclose, CALL_REAL (dlclose)) diff --git a/gprofng/libcollector/synctrace.c b/gprofng/libcollector/synctrace.c index c50151bbd52..3d53d1fc882 100644 --- a/gprofng/libcollector/synctrace.c +++ b/gprofng/libcollector/synctrace.c @@ -95,6 +95,9 @@ static long int (*__real_strtol)(const char *nptr, char **endptr, int base) = NU static int (*__real_fprintf) (FILE *stream, const char *format, ...) = NULL; static void (*__real___collector_jprofile_enable_synctrace) (void) = NULL; static int (*__real_pthread_mutex_lock) (pthread_mutex_t *mutex) = NULL; +static int (*__real_pthread_mutex_lock_2_17) (pthread_mutex_t *mutex) = NULL; +static int (*__real_pthread_mutex_lock_2_2_5) (pthread_mutex_t *mutex) = NULL; +static int (*__real_pthread_mutex_lock_2_0) (pthread_mutex_t *mutex) = NULL; static int (*__real_pthread_mutex_unlock) (pthread_mutex_t *mutex) = NULL; static int (*__real_pthread_cond_wait) (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex) = NULL; @@ -102,31 +105,37 @@ static int (*__real_pthread_cond_timedwait) (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime) = NULL; static int (*__real_pthread_join) (pthread_t thread, void **retval) = NULL; +static int (*__real_pthread_join_2_34) (pthread_t thread, void **retval) = NULL; +static int (*__real_pthread_join_2_17) (pthread_t thread, void **retval) = NULL; +static int (*__real_pthread_join_2_2_5) (pthread_t thread, void **retval) = NULL; +static int (*__real_pthread_join_2_0) (pthread_t thread, void **retval) = NULL; static int (*__real_sem_wait) (sem_t *sem) = NULL; +static int (*__real_sem_wait_2_34) (sem_t *sem) = NULL; +static int (*__real_sem_wait_2_17) (sem_t *sem) = NULL; +static int (*__real_sem_wait_2_2_5) (sem_t *sem) = NULL; +static int (*__real_sem_wait_2_1) (sem_t *sem) = NULL; +static int (*__real_sem_wait_2_0) (sem_t *sem) = NULL; +static int (*__real_pthread_cond_wait_2_17) (pthread_cond_t *restrict cond, + pthread_mutex_t *restrict mutex) = NULL; static int (*__real_pthread_cond_wait_2_3_2) (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex) = NULL; +static int (*__real_pthread_cond_wait_2_2_5) (pthread_cond_t *restrict cond, + pthread_mutex_t *restrict mutex) = NULL; +static int (*__real_pthread_cond_wait_2_0) (pthread_cond_t *restrict cond, + pthread_mutex_t *restrict mutex) = NULL; +static int (*__real_pthread_cond_timedwait_2_17) (pthread_cond_t *restrict cond, + pthread_mutex_t *restrict mutex, + const struct timespec *restrict abstime) = NULL; static int (*__real_pthread_cond_timedwait_2_3_2) (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime) = NULL; - -#if WSIZE(32) -static int (*__real_sem_wait_2_1) (sem_t *sem) = NULL; -static int (*__real_sem_wait_2_0) (sem_t *sem) = NULL; -static int (*__real_pthread_cond_wait_2_0) (pthread_cond_t *restrict cond, - pthread_mutex_t *restrict mutex) = NULL; +static int (*__real_pthread_cond_timedwait_2_2_5) (pthread_cond_t *restrict cond, + pthread_mutex_t *restrict mutex, + const struct timespec *restrict abstime) = NULL; static int (*__real_pthread_cond_timedwait_2_0) (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime) = NULL; -#elif WSIZE(64) -#if ARCH(Intel) -static int (*__real_pthread_cond_wait_2_2_5) (pthread_cond_t *restrict cond, - pthread_mutex_t *restrict mutex) = NULL; -static void *__real_pthread_cond_timedwait_2_2_5 = NULL; -#elif ARCH(SPARC) -static void *__real_pthread_cond_wait_2_2 = NULL; -static void *__real_pthread_cond_timedwait_2_2 = NULL; -#endif /* ARCH() */ -#endif /* WSIZE() */ + static void collector_memset (void *s, int c, size_t n) @@ -348,6 +357,23 @@ sync_calibrate () return ret; } +static int +init_pthread_mutex_lock (void *dlflag) +{ + __real_pthread_mutex_lock_2_17 = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.17"); + __real_pthread_mutex_lock_2_2_5 = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.2.5"); + __real_pthread_mutex_lock_2_0 = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.0"); + if (__real_pthread_mutex_lock_2_17) + __real_pthread_mutex_lock = __real_pthread_mutex_lock_2_17; + else if (__real_pthread_mutex_lock_2_2_5) + __real_pthread_mutex_lock = __real_pthread_mutex_lock_2_2_5; + else if (__real_pthread_mutex_lock_2_0) + __real_pthread_mutex_lock = __real_pthread_mutex_lock_2_0; + else + __real_pthread_mutex_lock = dlsym (dlflag, "pthread_mutex_lock"); + return __real_pthread_mutex_lock ? 1 : 0; +} + static int init_thread_intf () { @@ -384,280 +410,118 @@ init_thread_intf () sync_java = 0; } -#if WSIZE(32) - /* ########################################## begin WSIZE(32) */ - /* IMPORTANT!! The GLIBC_* versions below must match those in the er_sync.*.mapfile ! */ dlflag = RTLD_NEXT; - ptr = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.0"); - if (ptr == NULL) + if (init_pthread_mutex_lock (dlflag) == 0) { /* We are probably dlopened after libthread/libc, * try to search in the previously loaded objects */ dlflag = RTLD_DEFAULT; - ptr = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.0"); - if (ptr != NULL) - { - __real_pthread_mutex_lock = ptr; - Tprintf (0, "synctrace: WARNING: init_thread_intf() using RTLD_DEFAULT for OS sync routines\n"); - } - else + if (init_pthread_mutex_lock (dlflag) == 0) { CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_mutex_lock\n"); err = COL_ERROR_SYNCINIT; } } - else - __real_pthread_mutex_lock = ptr; - ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.0"); - if (ptr) - __real_pthread_mutex_unlock = (void *) ptr; + if ((ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.17")) != NULL) + __real_pthread_mutex_unlock = ptr; + else if ((ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.2.5")) != NULL) + __real_pthread_mutex_unlock = ptr; + else if ((ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.0")) != NULL) + __real_pthread_mutex_unlock = ptr; else + __real_pthread_mutex_unlock = dlsym (dlflag, "pthread_mutex_unlock"); + if (__real_pthread_mutex_unlock == NULL) { CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_mutex_unlock\n"); err = COL_ERROR_SYNCINIT; } - ptr = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.3.2"); - if (ptr) - __real_pthread_cond_wait = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_wait\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.3.2"); - if (ptr) - __real_pthread_cond_timedwait = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_timedwait\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_join", "GLIBC_2.0"); - if (ptr) - __real_pthread_join = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_join\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "sem_wait", "GLIBC_2.1"); - if (ptr) - __real_sem_wait = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT sem_wait\n"); - err = COL_ERROR_SYNCINIT; - } -#if ARCH(Intel) - /* ############## Intel specific additional pointers for 32-bits */ - ptr = __real_sem_wait_2_1 = __real_sem_wait; - ptr = dlvsym (dlflag, "sem_wait", "GLIBC_2.0"); - if (ptr) - __real_sem_wait_2_0 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT sem_wait_2_0\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.0"); - if (ptr) - __real_pthread_cond_wait_2_0 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_wait_2_0\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.0"); - if (ptr) - __real_pthread_cond_timedwait_2_0 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT __real_pthread_cond_timedwait_2_0\n"); - err = COL_ERROR_SYNCINIT; - } -#endif /* ARCH(Intel) */ - -#else /* WSIZE(64) */ - /* # most versions are different between platforms */ - /* # the few that are common are set after the ARCH ifdef */ -#if ARCH(Aarch64) - dlflag = RTLD_NEXT; -#define GLIBC_N "GLIBC_2.17" - __real_pthread_mutex_lock = dlvsym(dlflag, "pthread_mutex_lock", GLIBC_N); - __real_pthread_mutex_unlock = dlvsym(dlflag, "pthread_mutex_unlock", GLIBC_N); - __real_pthread_cond_wait = dlvsym(dlflag, "pthread_cond_wait", GLIBC_N); - __real_pthread_cond_timedwait = dlvsym(dlflag, "pthread_cond_timedwait", GLIBC_N); - __real_pthread_join = dlvsym(dlflag, "pthread_join", GLIBC_N); - __real_sem_wait = dlvsym(dlflag, "sem_wait", GLIBC_N); - -#elif ARCH(Intel) - dlflag = RTLD_NEXT; - ptr = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.2.5"); - if (ptr == NULL) - { - /* We are probably dlopened after libthread/libc, - * try to search in the previously loaded objects - */ - dlflag = RTLD_DEFAULT; - ptr = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.2.5"); - if (ptr != NULL) - { - __real_pthread_mutex_lock = ptr; - Tprintf (0, "synctrace: WARNING: init_thread_intf() using RTLD_DEFAULT for Solaris sync routines\n"); - } - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_mutex_lock\n"); - err = COL_ERROR_SYNCINIT; - } - } - else - __real_pthread_mutex_lock = ptr; - ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.2.5"); - if (ptr) - __real_pthread_mutex_unlock = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_mutex_unlock\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.3.2"); - if (ptr) - __real_pthread_cond_wait = (void *) ptr; + __real_pthread_cond_wait_2_17 = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.17"); + __real_pthread_cond_wait_2_3_2 = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.3.2"); + __real_pthread_cond_wait_2_2_5 = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.2.5"); + __real_pthread_cond_wait_2_0 = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.0"); + if (__real_pthread_cond_wait_2_17) + __real_pthread_cond_wait = __real_pthread_cond_wait_2_17; + else if (__real_pthread_cond_wait_2_3_2) + __real_pthread_cond_wait = __real_pthread_cond_wait_2_3_2; + else if (__real_pthread_cond_wait_2_2_5) + __real_pthread_cond_wait = __real_pthread_cond_wait_2_2_5; + else if (__real_pthread_cond_wait_2_0) + __real_pthread_cond_wait = __real_pthread_cond_wait_2_0; else + __real_pthread_cond_wait = dlsym (dlflag, "pthread_cond_wait"); + if (__real_pthread_cond_wait == NULL) { CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_wait\n"); err = COL_ERROR_SYNCINIT; } - ptr = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.3.2"); - if (ptr) - __real_pthread_cond_timedwait = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_timedwait\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_join", "GLIBC_2.2.5"); - if (ptr) - __real_pthread_join = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_join\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "sem_wait", "GLIBC_2.2.5"); - if (ptr) - __real_sem_wait = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT sem_wait\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.2.5"); - if (ptr) - __real_pthread_cond_wait_2_2_5 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_wait_2_2_5\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.2.5"); - if (ptr) - __real_pthread_cond_timedwait_2_2_5 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_timedwait_2_2_5\n"); - err = COL_ERROR_SYNCINIT; - } -#elif ARCH(SPARC) - dlflag = RTLD_NEXT; - ptr = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.2"); - if (ptr == NULL) - { - /* We are probably dlopened after libthread/libc, - * try to search in the previously loaded objects - */ - dlflag = RTLD_DEFAULT; - ptr = dlvsym (dlflag, "pthread_mutex_lock", "GLIBC_2.2"); - if (ptr != NULL) - { - __real_pthread_mutex_lock = ptr; - Tprintf (0, "synctrace: WARNING: init_thread_intf() using RTLD_DEFAULT for Solaris sync routines\n"); - } - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT mutex_lock\n"); - err = COL_ERROR_SYNCINIT; - } - } - else - __real_pthread_mutex_lock = ptr; - ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.2"); - if (ptr) - __real_pthread_mutex_unlock = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_mutex_unlock\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.3.2"); - if (ptr) - __real_pthread_cond_wait = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_wait\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.3.2"); - if (ptr) - __real_pthread_cond_timedwait = (void *) ptr; + __real_pthread_cond_timedwait_2_17 = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.17"); + __real_pthread_cond_timedwait_2_3_2 = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.3.2"); + __real_pthread_cond_timedwait_2_2_5 = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.2.5"); + __real_pthread_cond_timedwait_2_0 = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.0"); + if (__real_pthread_cond_timedwait_2_17) + __real_pthread_cond_timedwait = __real_pthread_cond_timedwait_2_17; + else if (__real_pthread_cond_timedwait_2_3_2) + __real_pthread_cond_timedwait = __real_pthread_cond_timedwait_2_3_2; + else if (__real_pthread_cond_timedwait_2_2_5) + __real_pthread_cond_timedwait = __real_pthread_cond_timedwait_2_2_5; + else if (__real_pthread_cond_timedwait_2_0) + __real_pthread_cond_timedwait = __real_pthread_cond_timedwait_2_0; else + __real_pthread_cond_timedwait = dlsym (dlflag, "pthread_cond_timedwait"); + if (__real_pthread_cond_timedwait == NULL) { CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_timedwait\n"); err = COL_ERROR_SYNCINIT; } - ptr = dlvsym (dlflag, "pthread_join", "GLIBC_2.2"); - if (ptr) - __real_pthread_join = (void *) ptr; + + __real_pthread_join_2_34 = dlvsym (dlflag, "pthread_join", "GLIBC_2.34"); + __real_pthread_join_2_17 = dlvsym (dlflag, "pthread_join", "GLIBC_2.17"); + __real_pthread_join_2_2_5 = dlvsym (dlflag, "pthread_join", "GLIBC_2.2.5"); + __real_pthread_join_2_0 = dlvsym (dlflag, "pthread_join", "GLIBC_2.0"); + if (__real_pthread_join_2_34) + __real_pthread_join = __real_pthread_join_2_34; + else if (__real_pthread_join_2_17) + __real_pthread_join = __real_pthread_join_2_17; + else if (__real_pthread_join_2_2_5) + __real_pthread_join = __real_pthread_join_2_2_5; + else if (__real_pthread_join_2_0) + __real_pthread_join = __real_pthread_join_2_0; else + __real_pthread_join = dlsym (dlflag, "pthread_join"); + if (__real_pthread_join == NULL) { CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_join\n"); err = COL_ERROR_SYNCINIT; } - ptr = dlvsym (dlflag, "sem_wait", "GLIBC_2.2"); - if (ptr) - __real_sem_wait = (void *) ptr; + + __real_sem_wait_2_34 = dlvsym (dlflag, "sem_wait", "GLIBC_2.34"); + __real_sem_wait_2_17 = dlvsym (dlflag, "sem_wait", "GLIBC_2.17"); + __real_sem_wait_2_2_5 = dlvsym (dlflag, "sem_wait", "GLIBC_2.2.5"); + __real_sem_wait_2_1 = dlvsym (dlflag, "sem_wait", "GLIBC_2.1"); + __real_sem_wait_2_0 = dlvsym (dlflag, "sem_wait", "GLIBC_2.0"); + if (__real_sem_wait_2_34) + __real_sem_wait = __real_sem_wait_2_34; + else if (__real_sem_wait_2_17) + __real_sem_wait = __real_sem_wait_2_17; + else if (__real_sem_wait_2_2_5) + __real_sem_wait = __real_sem_wait_2_2_5; + else if (__real_sem_wait_2_1) + __real_sem_wait = __real_sem_wait_2_1; + else if (__real_sem_wait_2_0) + __real_sem_wait = __real_sem_wait_2_0; else + __real_sem_wait = dlsym (dlflag, "sem_wait"); + if (__real_sem_wait == NULL) { CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT sem_wait\n"); err = COL_ERROR_SYNCINIT; } - ptr = dlvsym (dlflag, "pthread_cond_wait", "GLIBC_2.2"); - if (ptr) - __real_pthread_cond_wait_2_2 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_wait_2_2_5\n"); - err = COL_ERROR_SYNCINIT; - } - ptr = dlvsym (dlflag, "pthread_cond_timedwait", "GLIBC_2.2"); - if (ptr) - __real_pthread_cond_timedwait_2_2 = (void *) ptr; - else - { - CALL_REAL (fprintf)(stderr, "synctrace_init COL_ERROR_SYNCINIT pthread_cond_timedwait_2_2\n"); - err = COL_ERROR_SYNCINIT; - } -#endif /* ARCH() */ -#endif /* WSIZE(64) */ - /* the pointers that are common to 32- and 64-bits, and to SPARC and Intel */ - __real_pthread_cond_wait_2_3_2 = __real_pthread_cond_wait; - __real_pthread_cond_timedwait_2_3_2 = __real_pthread_cond_timedwait; + ptr = dlsym (dlflag, "strtol"); if (ptr) __real_strtol = (void *) ptr; @@ -703,25 +567,24 @@ __collector_jsync_end (hrtime_t reqt, void *object) spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) object; - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); - collector_interface->writeDataRecord (sync_hndl, (Common_packet*) & spacket); + spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, + spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); + collector_interface->writeDataRecord (sync_hndl, (Common_packet*) &spacket); } Tprintf (DBG_LT1, "__collector_jsync_begin: end event\n"); POP_REENTRANCE (guard); } - /*-------------------------------------------------------- pthread_mutex_lock */ -int -pthread_mutex_lock (pthread_mutex_t *mp) +static int +gprofng_pthread_mutex_lock (int (real_func) (pthread_mutex_t *), + pthread_mutex_t *mp) { int *guard; - if (NULL_PTR (pthread_mutex_lock)) - init_thread_intf (); if (CHCK_NREENTRANCE (guard)) - return CALL_REAL (pthread_mutex_lock)(mp); + return (real_func) (mp); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); - int ret = CALL_REAL (pthread_mutex_lock)(mp); + int ret = (real_func) (mp); if (RECHCK_NREENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -736,83 +599,39 @@ pthread_mutex_lock (pthread_mutex_t *mp) spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) mp; - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK, &spacket); - collector_interface->writeDataRecord (sync_hndl, (Common_packet*) & spacket); + spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, + spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); + collector_interface->writeDataRecord (sync_hndl, (Common_packet*) &spacket); } POP_REENTRANCE (guard); return ret; } +#define DCL_PTHREAD_MUTEX_LOCK(dcl_f, real_f) \ + int dcl_f (pthread_mutex_t *mp) \ + { \ + if ((real_f) == NULL) \ + init_thread_intf (); \ + return gprofng_pthread_mutex_lock (real_f, mp); \ + } -/*------------------------------------------------------------- pthread_cond_wait */ -// map interposed symbol versions -static int -__collector_pthread_cond_wait_symver (int(real_pthread_cond_wait) (), pthread_cond_t *cond, pthread_mutex_t *mutex); - -#if ARCH(Intel) || ARCH(SPARC) -SYMVER_ATTRIBUTE (__collector_pthread_cond_wait_2_3_2, - pthread_cond_wait@GLIBC_2.3.2) -#endif -int -__collector_pthread_cond_wait_2_3_2 (pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - if (NULL_PTR (pthread_cond_wait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_wait_2_3_2@%p\n", CALL_REAL (pthread_cond_wait_2_3_2)); - return __collector_pthread_cond_wait_symver (CALL_REAL (pthread_cond_wait_2_3_2), cond, mutex); -} - -#if WSIZE(32) - -SYMVER_ATTRIBUTE (__collector_pthread_cond_wait_2_0, - pthread_cond_wait@GLIBC_2.0) -int -__collector_pthread_cond_wait_2_0 (pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - if (NULL_PTR (pthread_cond_wait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_wait_2_0@%p\n", CALL_REAL (pthread_cond_wait_2_0)); - return __collector_pthread_cond_wait_symver (CALL_REAL (pthread_cond_wait_2_0), cond, mutex); -} -#else // WSIZE(64) -#if ARCH(Intel) -SYMVER_ATTRIBUTE (__collector_pthread_cond_wait_2_2_5, - pthread_cond_wait@GLIBC_2.2.5) -int -__collector_pthread_cond_wait_2_2_5 (pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - if (NULL_PTR (pthread_cond_wait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_wait_2_2_5@%p\n", CALL_REAL (pthread_cond_wait_2_2_5)); - return __collector_pthread_cond_wait_symver (CALL_REAL (pthread_cond_wait_2_2_5), cond, mutex); -} -#elif ARCH(SPARC) - -SYMVER_ATTRIBUTE (__collector_pthread_cond_wait_2_2, - pthread_cond_wait@GLIBC_2.2) -int -__collector_pthread_cond_wait_2_2 (pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - if (NULL_PTR (pthread_cond_wait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_wait_2_2@%p\n", CALL_REAL (pthread_cond_wait_2_2)); - return __collector_pthread_cond_wait_symver (CALL_REAL (pthread_cond_wait_2_2), cond, mutex); -} -#endif // ARCH() -#endif // WSIZE() +DCL_FUNC_VER (DCL_PTHREAD_MUTEX_LOCK, pthread_mutex_lock_2_17, timer_create@GLIBC_2.17) +DCL_FUNC_VER (DCL_PTHREAD_MUTEX_LOCK, pthread_mutex_lock_2_2_5, timer_create@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_PTHREAD_MUTEX_LOCK, pthread_mutex_lock_2_0, timer_create@GLIBC_2.0) +DCL_PTHREAD_MUTEX_LOCK (pthread_mutex_lock, CALL_REAL (pthread_mutex_lock)) +/*------------------------------------------------------------- pthread_cond_wait */ static int -__collector_pthread_cond_wait_symver (int(real_pthread_cond_wait) (), pthread_cond_t *cond, pthread_mutex_t *mutex) +gprofng_pthread_cond_wait (int(real_func) (pthread_cond_t *, pthread_mutex_t *), + pthread_cond_t *cond, pthread_mutex_t *mutex) { int *guard; - if (NULL_PTR (pthread_cond_wait)) - init_thread_intf (); if (CHCK_NREENTRANCE (guard)) - return (real_pthread_cond_wait) (cond, mutex); + return (real_func) (cond, mutex); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); int ret = -1; - ret = (real_pthread_cond_wait) (cond, mutex); + ret = (real_func) (cond, mutex); if (RECHCK_NREENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -827,95 +646,42 @@ __collector_pthread_cond_wait_symver (int(real_pthread_cond_wait) (), pthread_co spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) mutex; - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); - collector_interface->writeDataRecord (sync_hndl, (Common_packet*) & spacket); + spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, + spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); + collector_interface->writeDataRecord (sync_hndl, (Common_packet*) &spacket); } POP_REENTRANCE (guard); return ret; } -/*---------------------------------------------------- pthread_cond_timedwait */ -// map interposed symbol versions -static int -__collector_pthread_cond_timedwait_symver (int(real_pthread_cond_timedwait) (), - pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime); - -#if ARCH(Intel) || ARCH(SPARC) -SYMVER_ATTRIBUTE (__collector_pthread_cond_timedwait_2_3_2, - pthread_cond_timedwait@GLIBC_2.3.2) -#endif // ARCH() -int -__collector_pthread_cond_timedwait_2_3_2 (pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime) -{ - if (NULL_PTR (pthread_cond_timedwait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_timedwait_2_3_2@%p\n", CALL_REAL (pthread_cond_timedwait_2_3_2)); - return __collector_pthread_cond_timedwait_symver (CALL_REAL (pthread_cond_timedwait_2_3_2), cond, mutex, abstime); -} - -#if WSIZE(32) -SYMVER_ATTRIBUTE (__collector_pthread_cond_timedwait_2_0, - pthread_cond_timedwait@GLIBC_2.0) -int -__collector_pthread_cond_timedwait_2_0 (pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime) -{ - if (NULL_PTR (pthread_cond_timedwait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_timedwait_2_0@%p\n", CALL_REAL (pthread_cond_timedwait_2_0)); - return __collector_pthread_cond_timedwait_symver (CALL_REAL (pthread_cond_timedwait_2_0), cond, mutex, abstime); -} -#else // WSIZE(64) -#if ARCH(Intel) -SYMVER_ATTRIBUTE (__collector_pthread_cond_timedwait_2_2_5, - pthread_cond_timedwait@GLIBC_2.2.5) -int -__collector_pthread_cond_timedwait_2_2_5 (pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime) -{ - if (NULL_PTR (pthread_cond_timedwait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_timedwait_2_2_5@%p\n", CALL_REAL (pthread_cond_timedwait_2_2_5)); - return __collector_pthread_cond_timedwait_symver (CALL_REAL (pthread_cond_timedwait_2_2_5), cond, mutex, abstime); -} -#elif ARCH(SPARC) +#define DCL_PTHREAD_COND_WAIT(dcl_f, real_f) \ + int dcl_f (pthread_cond_t *cond, pthread_mutex_t *mutex) \ + { \ + if ((real_f) == NULL) \ + init_thread_intf (); \ + return gprofng_pthread_cond_wait (real_f, cond, mutex); \ + } -SYMVER_ATTRIBUTE (__collector_pthread_cond_timedwait_2_2, - pthread_cond_timedwait@GLIBC_2.2) -int -__collector_pthread_cond_timedwait_2_2 (pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime) -{ - if (NULL_PTR (pthread_cond_timedwait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_pthread_cond_timedwait_2_2@%p\n", CALL_REAL (pthread_cond_timedwait_2_2)); - return __collector_pthread_cond_timedwait_symver (CALL_REAL (pthread_cond_timedwait_2_2), cond, mutex, abstime); -} -#endif // ARCH() -#endif // WSIZE() +DCL_FUNC_VER (DCL_PTHREAD_COND_WAIT, pthread_cond_wait_2_17, pthread_cond_wait@GLIBC_2.17) +DCL_FUNC_VER (DCL_PTHREAD_COND_WAIT, pthread_cond_wait_2_3_2, pthread_cond_wait@GLIBC_2.3.2) +DCL_FUNC_VER (DCL_PTHREAD_COND_WAIT, pthread_cond_wait_2_2_5, pthread_cond_wait@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_PTHREAD_COND_WAIT, pthread_cond_wait_2_0, pthread_cond_wait@GLIBC_2.0) +DCL_PTHREAD_COND_WAIT (pthread_cond_wait, CALL_REAL (pthread_cond_wait)) +/*---------------------------------------------------- pthread_cond_timedwait */ static int -__collector_pthread_cond_timedwait_symver (int(real_pthread_cond_timedwait) (), - pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime) +gprofng_pthread_cond_timedwait (int(real_func) (pthread_cond_t *, + pthread_mutex_t*, const struct timespec *), + pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *abstime) { int *guard; - if (NULL_PTR (pthread_cond_timedwait)) - init_thread_intf (); if (CHCK_NREENTRANCE (guard)) - return (real_pthread_cond_timedwait) (cond, mutex, abstime); + return (real_func) (cond, mutex, abstime); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); int ret = -1; - ret = (real_pthread_cond_timedwait) (cond, mutex, abstime); + ret = (real_func) (cond, mutex, abstime); if (RECHCK_NREENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -925,30 +691,46 @@ __collector_pthread_cond_timedwait_symver (int(real_pthread_cond_timedwait) (), if (grnt - reqt >= sync_threshold) { Sync_packet spacket; - collector_memset (&spacket, 0, sizeof ( Sync_packet)); - spacket.comm.tsize = sizeof ( Sync_packet); + collector_memset (&spacket, 0, sizeof (Sync_packet)); + spacket.comm.tsize = sizeof (Sync_packet); spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) mutex; - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); - collector_interface->writeDataRecord (sync_hndl, (Common_packet*) & spacket); + spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, + spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); + collector_interface->writeDataRecord (sync_hndl, (Common_packet*) &spacket); } POP_REENTRANCE (guard); return ret; } +#define DCL_PTHREAD_COND_TIMEDWAIT(dcl_f, real_f) \ + int dcl_f (pthread_cond_t *cond, pthread_mutex_t *mutex, \ + const struct timespec *abstime) \ + { \ + if ((real_f) == NULL) \ + init_thread_intf (); \ + return gprofng_pthread_cond_timedwait (real_f, cond, mutex, abstime); \ + } + +DCL_FUNC_VER (DCL_PTHREAD_COND_TIMEDWAIT, pthread_cond_timedwait_2_17, pthread_cond_timedwait@GLIBC_2.17) +DCL_FUNC_VER (DCL_PTHREAD_COND_TIMEDWAIT, pthread_cond_timedwait_2_3_2, pthread_cond_timedwait@GLIBC_2.3.2) +DCL_FUNC_VER (DCL_PTHREAD_COND_TIMEDWAIT, pthread_cond_timedwait_2_2_5, pthread_cond_timedwait@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_PTHREAD_COND_TIMEDWAIT, pthread_cond_timedwait_2_0, pthread_cond_timedwait@GLIBC_2.0) +DCL_PTHREAD_COND_TIMEDWAIT (pthread_cond_timedwait, CALL_REAL (pthread_cond_timedwait)) + + /*------------------------------------------------------------- pthread_join */ -int -pthread_join (pthread_t target_thread, void **status) +static int +gprofng_pthread_join (int(real_func) (pthread_t, void **), + pthread_t target_thread, void **status) { int *guard; - if (NULL_PTR (pthread_join)) - init_thread_intf (); if (CHCK_NREENTRANCE (guard)) - return CALL_REAL (pthread_join)(target_thread, status); + return real_func (target_thread, status); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); - int ret = CALL_REAL (pthread_join)(target_thread, status); + int ret = real_func(target_thread, status); if (RECHCK_NREENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -958,73 +740,44 @@ pthread_join (pthread_t target_thread, void **status) if (grnt - reqt >= sync_threshold) { Sync_packet spacket; - collector_memset (&spacket, 0, sizeof ( Sync_packet)); - spacket.comm.tsize = sizeof ( Sync_packet); + collector_memset (&spacket, 0, sizeof (Sync_packet)); + spacket.comm.tsize = sizeof (Sync_packet); spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (Vaddr_type) target_thread; - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK, &spacket); - collector_interface->writeDataRecord (sync_hndl, (Common_packet*) & spacket); + spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, + spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); + collector_interface->writeDataRecord (sync_hndl, (Common_packet*) &spacket); } POP_REENTRANCE (guard); return ret; } -/*------------------------------------------------------------- sem_wait */ -// map interposed symbol versions -#if ARCH(Intel) && WSIZE(32) -static int -__collector_sem_wait_symver (int(real_sem_wait) (), sem_t *sp); +#define DCL_PTHREAD_JOIN(dcl_f, real_f) \ + int dcl_f (pthread_t target_thread, void **status) \ + { \ + if ((real_f) == NULL) \ + init_thread_intf (); \ + return gprofng_pthread_join (real_f, target_thread, status); \ + } -SYMVER_ATTRIBUTE (__collector_sem_wait_2_1, sem_wait@GLIBC_2.1) -int -__collector_sem_wait_2_1 (sem_t *sp) -{ - if (NULL_PTR (sem_wait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_sem_wait_2_1@%p\n", CALL_REAL (sem_wait_2_1)); - return __collector_sem_wait_symver (CALL_REAL (sem_wait_2_1), sp); -} +DCL_FUNC_VER (DCL_PTHREAD_JOIN, pthread_join_2_34, pthread_join@GLIBC_2.34) +DCL_FUNC_VER (DCL_PTHREAD_JOIN, pthread_join_2_17, pthread_join@GLIBC_2.17) +DCL_FUNC_VER (DCL_PTHREAD_JOIN, pthread_join_2_2_5, pthread_join@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_PTHREAD_JOIN, pthread_join_2_0, pthread_join@GLIBC_2.0) +DCL_PTHREAD_JOIN (pthread_join, CALL_REAL (pthread_join)) -SYMVER_ATTRIBUTE (__collector_sem_wait_2_0, sem_wait@GLIBC_2.0) -int -__collector_sem_wait_2_0 (sem_t *sp) -{ - if (NULL_PTR (sem_wait)) - init_thread_intf (); - TprintfT (DBG_LTT, "linetrace: GLIBC: __collector_sem_wait_2_0@%p\n", CALL_REAL (sem_wait_2_0)); - return __collector_sem_wait_symver (CALL_REAL (sem_wait_2_0), sp); -} -#endif - -#if ARCH(Intel) && WSIZE(32) +/*------------------------------------------------------------- sem_wait */ static int -__collector_sem_wait_symver (int(real_sem_wait) (), sem_t *sp) +gprofng_sem_wait (int (real_func) (sem_t *), sem_t *sp) { -#else -int -sem_wait (sem_t *sp) -{ -#endif int *guard; - if (NULL_PTR (sem_wait)) - init_thread_intf (); if (CHCK_NREENTRANCE (guard)) - { -#if ARCH(Intel) && WSIZE(32) - return (real_sem_wait) (sp); -#else - return CALL_REAL (sem_wait)(sp); -#endif - } + return real_func (sp); PUSH_REENTRANCE (guard); hrtime_t reqt = gethrtime (); int ret = -1; -#if ARCH(Intel) && WSIZE(32) - ret = (real_sem_wait) (sp); -#else - ret = CALL_REAL (sem_wait)(sp); -#endif + ret = real_func (sp); if (RECHCK_NREENTRANCE (guard)) { POP_REENTRANCE (guard); @@ -1034,19 +787,30 @@ sem_wait (sem_t *sp) if (grnt - reqt >= sync_threshold) { Sync_packet spacket; - collector_memset (&spacket, 0, sizeof ( Sync_packet)); - spacket.comm.tsize = sizeof ( Sync_packet); + collector_memset (&spacket, 0, sizeof (Sync_packet)); + spacket.comm.tsize = sizeof (Sync_packet); spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) sp; - -#if ARCH(Intel) && WSIZE(32) - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); -#else - spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, spacket.comm.tstamp, FRINFO_FROM_STACK, &spacket); -#endif - collector_interface->writeDataRecord (sync_hndl, (Common_packet*) & spacket); + spacket.comm.frinfo = collector_interface->getFrameInfo (sync_hndl, + spacket.comm.tstamp, FRINFO_FROM_STACK_ARG, &spacket); + collector_interface->writeDataRecord (sync_hndl, (Common_packet*) &spacket); } POP_REENTRANCE (guard); return ret; } + +#define DCL_SEM_WAIT(dcl_f, real_f) \ + int dcl_f (sem_t *sp) \ + { \ + if ((real_f) == NULL) \ + init_thread_intf (); \ + return gprofng_sem_wait (real_f, sp); \ + } + +DCL_FUNC_VER (DCL_SEM_WAIT, sem_wait_2_34, sem_wait@GLIBC_2.34) +DCL_FUNC_VER (DCL_SEM_WAIT, sem_wait_2_17, sem_wait@GLIBC_2.17) +DCL_FUNC_VER (DCL_SEM_WAIT, sem_wait_2_2_5, sem_wait@GLIBC_2.2.5) +DCL_FUNC_VER (DCL_SEM_WAIT, sem_wait_2_0, sem_wait@GLIBC_2.0) +DCL_FUNC_VER (DCL_SEM_WAIT, sem_wait_2_1, sem_wait@GLIBC_2.1) +DCL_SEM_WAIT (sem_wait, CALL_REAL (sem_wait)) diff --git a/gprofng/src/collector_module.h b/gprofng/src/collector_module.h index 81f50771975..07bf362ddb7 100644 --- a/gprofng/src/collector_module.h +++ b/gprofng/src/collector_module.h @@ -222,15 +222,4 @@ extern "C" } #endif -#ifdef __has_attribute -# if __has_attribute (__symver__) -# define SYMVER_ATTRIBUTE(sym, symver) \ - __attribute__ ((__symver__ (#symver))) -# endif -#endif -#ifndef SYMVER_ATTRIBUTE -# define SYMVER_ATTRIBUTE(sym, symver) \ - __asm__(".symver " #sym "," #symver); -#endif - #endif /* _COLLECTOR_MODULE_H */