Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1292993pxf; Fri, 12 Mar 2021 06:37:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAEpiSNYFdBkd5vlb4ZDdGsJgHuPAcyaI3v+91/rt+iHNfVhbDYsO3Lrsi+1EeRRq+ss6D X-Received: by 2002:a17:906:85b:: with SMTP id f27mr9092615ejd.414.1615559832010; Fri, 12 Mar 2021 06:37:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615559832; cv=none; d=google.com; s=arc-20160816; b=er3PCnh4LRanbo6SErQnbjwEcsK8gX8BiAZ2vTrkSLajd8G4kK+/arHEDY1Y169rpr Bb6nINefW6KvGoLwEuSspZ+TG2iVAZNIAMgzUBF102jJ5g5HnIKhYH2ivGPUJbHl/dwy CD+dRgURdAY8poQlutGC7Pu+e6LW00c6K92b0JX/zOEmyHRWnfcKp849MvYjOrCJLWQc 1tVke9/Ya3ZAVK8SSgpEoosIHmNq1BW2A9WbjJGkxjmXX5XItA0fTqRukAKScrzG7lzC NMbLdh9Qa459rBFpxJdeNmmGSluPv2S8wj3kPjbLZpa1wJ6qYscnYq97UxKVPnwUD0WI 9Tig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=xTKJOWAg/nCkwg+WiH6YPixbreLyi+V0Yg6aocNs1uc=; b=ds5aB46xEELmBI8ANVhKDwDMyje44H+SQ3EfrRF1cqLvICNlfwvpAXyWUhLjoU7Dc4 AlFFjEklVw2acc6FcBCaZ7QdZpVm/kKEaQWZ8QZ7NH+cROFwO2/zPPixIgaGutGjO143 HJN0GZxKpVgpY7VKCsCPf1ow1w6HFZY/KUSWwP62ODCmhvWQVQ89yoRwpny0hnJbxkCT 60y1+5/iP4AmEPfSYkg45UYYctJPyB8sOZEv4aiGRcQDB0AEJ0yLJgPIULxqV1OKy3Dt slYdwoZDNVc0YKPnT6bsIdIiCX3GZSVH7kIRFR4FZBstHc7donyjQNrhF1SIXzzr0F0h xrBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s5si4158698ejx.287.2021.03.12.06.36.49; Fri, 12 Mar 2021 06:37:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231416AbhCLOdb (ORCPT + 99 others); Fri, 12 Mar 2021 09:33:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbhCLOdN (ORCPT ); Fri, 12 Mar 2021 09:33:13 -0500 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A79C061574; Fri, 12 Mar 2021 06:33:13 -0800 (PST) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94) (envelope-from ) id 1lKiqc-00FE4K-N4; Fri, 12 Mar 2021 15:33:02 +0100 Message-ID: Subject: Re: [PATCH 0/6] um: fix up CONFIG_GCOV support From: Johannes Berg To: linux-kernel@vger.kernel.org, linux-um@lists.infradead.org Cc: Jessica Yu , Alexander Viro , linux-fsdevel@vger.kernel.org Date: Fri, 12 Mar 2021 15:33:01 +0100 In-Reply-To: <20210312095526.197739-1-johannes@sipsolutions.net> References: <20210312095526.197739-1-johannes@sipsolutions.net> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-malware-bazaar: not-scanned Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-03-12 at 10:55 +0100, Johannes Berg wrote: > CONFIG_GCOV is fairly useful for ARCH=um (e.g. with kunit, though > my main use case is a bit different) since it writes coverage data > directly out like a normal userspace binary. Theoretically, that > is. > > Unfortunately, it's broken in multiple ways today: > >  1) it doesn't like, due to 'mangle_path' in seq_file, and the only >     solution to that seems to be to rename our symbol, but that's >     not so bad, and "mangle_path" sounds very generic anyway, which >     it isn't quite > >  2) gcov requires exit handlers to write out the data, and those are >     never called for modules, config CONSTRUCTORS exists for init >     handlers, so add CONFIG_MODULE_DESTRUCTORS here that we can then >     select in ARCH=um Yeah, I wish. None of this can really work. Thing is, __gcov_init(), called from the constructors, will add the local data structure for the object file into the global list (__gcov_root). So far, so good. However, __gcov_exit(), which is called from the destructors (fini_array which I added support for here) never gets passed the local data structure pointer. It dumps __gcov_root, and that's it. That basically means each executable/shared object should have its own instance of __gcov_root and the functions. But the code in UML was set up to export __gcov_exit(), which obviously then dumps the kernel's gcov data. So to make this really work we should treat modules like shared objects, and link libgcov.a into each one of them. That might even work, but we get ERROR: modpost: "free" [module.ko] undefined! ERROR: modpost: "vfprintf" [module.ko] undefined! ERROR: modpost: "fcntl" [module.ko] undefined! ERROR: modpost: "setbuf" [module.ko] undefined! ERROR: modpost: "exit" [module.ko] undefined! ERROR: modpost: "fwrite" [module.ko] undefined! ERROR: modpost: "stderr" [module.ko] undefined! ERROR: modpost: "fclose" [module.ko] undefined! ERROR: modpost: "ftell" [module.ko] undefined! ERROR: modpost: "fopen" [module.ko] undefined! ERROR: modpost: "fread" [module.ko] undefined! ERROR: modpost: "fdopen" [module.ko] undefined! ERROR: modpost: "fseek" [module.ko] undefined! ERROR: modpost: "fprintf" [module.ko] undefined! ERROR: modpost: "strtol" [module.ko] undefined! ERROR: modpost: "malloc" [module.ko] undefined! ERROR: modpost: "getpid" [module.ko] undefined! ERROR: modpost: "getenv" [module.ko] undefined! We could of course export those, but that makes me nervous, e.g. printf() is known to use a LOT of stack, far more than we have in the kernel. Also, we see: WARNING: modpost: "__gcov_var" [module] is COMMON symbol WARNING: modpost: "__gcov_root" [module] is COMMON symbol which means the module cannot be loaded. I think I'll just make CONFIG_GCOV depend on !MODULE instead, and for my use case use CONFIG_GCOV_KERNEL. Or maybe just kill CONFIG_GCOV entirely, since obviously nobody has ever tried to use it with modules or with recent toolchains (gcc 9 or newer, the mangle_path conflict). johannes