From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7529 invoked by alias); 12 Jan 2008 06:20:27 -0000 Received: (qmail 7516 invoked by uid 22791); 12 Jan 2008 06:20:26 -0000 X-Spam-Check-By: sourceware.org Received: from krynn.se.axis.com (HELO krynn.se.axis.com) (193.13.178.10) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 12 Jan 2008 06:20:07 +0000 Received: from ignucius.se.axis.com (ignucius.se.axis.com [10.83.5.18]) by krynn.se.axis.com (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id m0C6K3oD006270; Sat, 12 Jan 2008 07:20:03 +0100 Received: from ignucius.se.axis.com (localhost [127.0.0.1]) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) with ESMTP id m0C6K3aO013172; Sat, 12 Jan 2008 07:20:03 +0100 Received: (from hp@localhost) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) id m0C6K3p1013168; Sat, 12 Jan 2008 07:20:03 +0100 Date: Sat, 12 Jan 2008 08:26:00 -0000 Message-Id: <200801120620.m0C6K3p1013168@ignucius.se.axis.com> From: Hans-Peter Nilsson To: gcc@gcc.gnu.org Subject: How to stop gcc from not calling noinline functions Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2008-01/txt/msg00166.txt.bz2 Also known as "nooo, it's not *inlined*, it's just the call being removed because the called function was found to be pure/const". :) This happens when you try to synthesize executable test-cases and you need e.g. a call with such-and-such parameters, but the called function doesn't do anything; it's the caller you care about. You need the call, and can't just leave the called function undefined. But such a stub function called in the same compilation unit, may surprisingly not be called, *even if you declare it __attribute ((__noinline__))*, and when you look at *just* the call site, the cause is not just that the call is dead as-is. It's a bit confusing until you remember or are being told that all functions are analyzed for pure-or-constness and the noinline attribute doesn't have say in what happens next. The remedy is -fno-ipa-pure-const or sticking a naked asm ("") in the stub function. At least, that works for now. I'm testing the waters for a more well-defined solution. IMHO a construct is needed for e.g. such test-cases to stand more of a chance to not turn into NOPs with the next smart not-inlined-but-you-can't-tell-the-difference optimization. There appears to be a use for this in the Linux kernel too (kprobe?), and there's a (timing) use case in PR 16922 too. If you agree, how should it be done? Redefine the noinline attribute to also stop gcc from analyzing such functions and "keep them called" (my favorite, because as a user, you can't really tell the call-removed effect apart from being-inlined). Or, another attribute. Name? Maybe "always_extern", but I'm not sure that's as intuitive and obvious as "noinline". I don't like the perhaps immediately obvious "always_call", because I think the calls should be deleted if the call-site is dead, just not for reasons found out from analysis of the called function, and the name suggests otherwise (alternatively, an implementation to stop dead-code elimination would be troublesome and useless. :) Or, just make "noinline" functions that are also "extern" stay extern and called. (Yeah, new attributes "impure" and/or "nonconst" would solve this, but only for IPA and there's already the existing option and asm I mentioned. And if you say different files/compilation units, I say LTO.) brgds, H-P