From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA256EB64D9 for ; Sat, 17 Jun 2023 20:52:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346469AbjFQUwi (ORCPT ); Sat, 17 Jun 2023 16:52:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbjFQUwf (ORCPT ); Sat, 17 Jun 2023 16:52:35 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1184EAB for ; Sat, 17 Jun 2023 13:52:34 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-341cb9528f5so9376265ab.1 for ; Sat, 17 Jun 2023 13:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687035153; x=1689627153; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=xt5tBCuh4bk3gvKA/8WN+ze1HqhBkx/y9yaXcS2DBMw=; b=frMyDzvgISt4X0LwHS98A4npWdg9QVbUXE5SUgdgGRPqJy52mC0YjAOjj/q70ulAch xQmIki6RlXQDh6CawqlvzhuIO3Ddth2tzkVGJj5GDWoOnITRalsDVVWx8N1+iPdqgAjL URaIWI4GmiomumbmjMvHAf2XjMcVL053AetlZbC6BLRVsf++T9D88oIdHZTiMtrj+FTw CkiLjujl9qC5wByYBwrl4NskvkMOeW03trf4ZE/MmS6uXA8qRXSNe0T2axo2VVa0d3k6 OJ5rdLT844+ROINIZ2xg1C3qy4ayk19tX0YTTU/eZ4TSYM2IAUnB2LhHUta9+NAFWs6M oEDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687035153; x=1689627153; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=xt5tBCuh4bk3gvKA/8WN+ze1HqhBkx/y9yaXcS2DBMw=; b=jFFGpFA5zKw0p0V+LRhLWu6m/r8pCHNhSLkz9jjNQJdtTH72hU/PAst2cg5LkuxUcH EmAf1OwJfx/vlfbUecIq6qKW3gfgAJJSFZW/kz3+lHJghu+mxTLRnmo1p6IZagED0xca 0MeLzacxn9+xeP1jVbM1u3pNUanC35uGfGAbrSXDv2VcsjHq8Rz7sn6AfhfKuMdN+qq4 erJO7DGe/gvN8pBycGA54GnsxBTiEc/eKA3vDlDc7mTvmUu6R+UosYQhDaz8ICTigBUP weVFBsHCJy+rUIZC651Ldj2EQay7CdKGmUCVj6c3UOuyEUStS7eTRgGIhNG6MT+sEDlQ 2taA== X-Gm-Message-State: AC+VfDxtnsQuc3fjcsTVUVLXbvAsjeK03yawKTd+YMmp5+lrLRVLhLsC dvyPSnSDF0/AfE46JBEaN8MxhC7ShwSeo/Qc X-Google-Smtp-Source: ACHHUZ7xm1WJwIyioKRmT8IfFY0m8vymuHsWwHM2t+XlmFRjPDbPyE8eBWSVfm4SMTZTb3Etxk7BBA== X-Received: by 2002:a92:d3d0:0:b0:340:5661:5186 with SMTP id c16-20020a92d3d0000000b0034056615186mr3321941ilh.14.1687035153073; Sat, 17 Jun 2023 13:52:33 -0700 (PDT) Received: from [192.168.43.16] ([199.7.157.10]) by smtp.gmail.com with ESMTPSA id s7-20020a92d907000000b003350c8ae201sm7577337iln.29.2023.06.17.13.52.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Jun 2023 13:52:32 -0700 (PDT) Message-ID: Date: Sat, 17 Jun 2023 16:52:28 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Content-Language: en-US To: linux-kernel@vger.kernel.org From: Aravind Ceyardass Subject: reference counting gcc plugin Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Kernel People, I have developed a gcc plugin for implementing reference counting. I see that the kernel has implemented many different techniques over the years, but I couldn't find any with compiler support. I would like your ideas, inputs before I release the plugin for everyone hoping that it would benefit the Linux kernel. Here is a sample code to give you an idea of usage and the code transformation done by the plugin. #include "hrcmm.h" /* REFTRACK_STRUCT macro defines the following declarations struct foo; void foo_addref(const struct foo *const); void foo_removeref(const struct foo *const); void foo_destroy(struct foo *const); */ REFTRACK_STRUCT(foo){ int bar; }; /* REFTRACK_EPILOG_WITH_DTOR macro calls foo_destroy when reference count is zero. This is optional, if there is no special cleanup to be done, use REFTRACK_EPILOG. */ REFTRACK_EPILOG_WITH_DTOR(foo); // This function is called when the reference count for object pointed to by p is zero void foo_destroy(struct foo *p){ if (p) printf("foo destroyed:%p\n", p); } typedef struct foo foo; // statements commented out are injected by the plugin void baz(foo *p){ printf("%d\n", p->bar); // foo_removeref(p); } int main(int argc, char *argv[]){ foo *p = rc_malloc(sizeof(foo)); // rc_malloc is a default wrapper provided // foo_addref(p); p->bar = 123; // foo_addref(p); foo *q = p; // foo_addref(q); baz(q); // foo_removeref(p); // foo_removeref(q); } Aravind