Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp705312pxb; Thu, 19 Nov 2020 11:39:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5lT41pVeJNrroBId3iyC2KQjy8RUN2qrn2CzZJ2P0cD4rPd4T07pJSivsvPE0zUSFefhP X-Received: by 2002:a17:907:2805:: with SMTP id eb5mr29344923ejc.27.1605814789819; Thu, 19 Nov 2020 11:39:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605814789; cv=none; d=google.com; s=arc-20160816; b=m2Jmka6khO4vrVtkgpy4SI+rtbVRJNLu4GeoWr6QY7uazl3MuovSSSFkNXY1daE7Ce 4ehnfoxQb9Z4pDtGaZrB1/IumpMDpzHc2mBDzhNJLDtyiLxU13csDX2ZKGz4VmZI8LKp 8YrnxOopRXxICHUTdcP2jb4SII3V50m7hjCROLu+PoFyYLsW9EKxbM2EZftKTMPZICo/ Z5Gww2SbFcRmAmHQS45vDHifet81a77d8PEBxp/4/SfpOelOlSC4F+Hmcq+36HIaTzqI jCXn20QuE/80MBVAeEKA/7UZQ2N76J+woAHROyP5tNZPqTocfcR18O6dbjjXJVrQulqn gT2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=/4sWN5lAbcmZbYl0OsX96iAgmUHRszt0fEDDZMvEDr8=; b=WYH261z73+tbH+9Hyc5/kOMRilm/56xPmih9dawaIkkiJ5L4SBZOuyD5szJi6XhgMb G2Sr2mT4zDJJUL+s1E08ysfdJdEqWADNbt/qpuQyONj4+a1PxJlAvl5rnWIlkWOGt6qR YnzEaijp/hPfFyvevH249ZWUM9kZqGJ5WbHMorVXbr4UuMYMl2dgQMdCpcKNP62NLelv 9R1KMHv0K8rrXw5PeCpqW6uo0wTYKTVtDo8mySE+/JYMdaYwZS2eSeZ/wGhVQBSt32Zh 3HSVk925HYYYP3F35ZNhQPZFTWcUoB5qLB5LQY8nypT5beCfYP4UYkOs9991M+cIipGp QTuQ== 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 ok23si403415ejb.243.2020.11.19.11.39.25; Thu, 19 Nov 2020 11:39:49 -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 S1728324AbgKSTgc (ORCPT + 99 others); Thu, 19 Nov 2020 14:36:32 -0500 Received: from gate.crashing.org ([63.228.1.57]:39398 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727593AbgKSTgb (ORCPT ); Thu, 19 Nov 2020 14:36:31 -0500 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 0AJJRBpu004150; Thu, 19 Nov 2020 13:27:11 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 0AJJR87q004149; Thu, 19 Nov 2020 13:27:08 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Thu, 19 Nov 2020 13:27:08 -0600 From: Segher Boessenkool To: David Laight Cc: Steven Rostedt , Peter Zijlstra , Florian Weimer , Nick Desaulniers , Sami Tolvanen , Mathieu Desnoyers , linux-kernel , Matt Mullins , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Dmitry Vyukov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev , bpf , Kees Cook , Josh Poimboeuf , "linux-toolchains@vger.kernel.org" Subject: Re: violating function pointer signature Message-ID: <20201119192708.GW2672@gate.crashing.org> References: <20201118121730.12ee645b@gandalf.local.home> <20201118181226.GK2672@gate.crashing.org> <87o8jutt2h.fsf@mid.deneb.enyo.de> <20201118135823.3f0d24b7@gandalf.local.home> <20201118191127.GM2672@gate.crashing.org> <20201119083648.GE3121392@hirez.programming.kicks-ass.net> <20201119143735.GU2672@gate.crashing.org> <20201119095951.30269233@gandalf.local.home> <20201119163529.GV2672@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 05:42:34PM +0000, David Laight wrote: > From: Segher Boessenkool > > Sent: 19 November 2020 16:35 > > I just meant "valid C language code as defined by the standards". Many > > people want all UB to just go away, while that is *impossible* to do for > > many compilers: for example where different architectures or different > > ABIs have contradictory requirements. > > Some of the UB in the C language are (probably) there because > certain (now obscure) hardware behaved that way. Yes. > For instance integer arithmetic may saturate on overflow > (or do even stranger things if the sign is a separate bit). And some still does! > I'm not quite sure it was ever possible to write a C compiler > for a cpu that processed numbers in ASCII (up to 10 digits), > binary arithmetic was almost impossible. A machine that really stores decimal numbers? Not BCD or the like? Yeah wow, that will be hard. > There are also the CPU that only have 'word' addressing - so > that 'pointers to characters' take extra instructions. Such machines are still made, and are programmed in C as well. > ISTM that a few years ago the gcc developers started looking > at some of these 'UB' and decided they could make use of > them to make some code faster (and break other code). When UB would happen in some situation, the compiler can simply assume that situation does not happen. This makes it possible to do a lot of optimisations (many to do with loops) that cannot be done otherwise (including those to do with signed overflow). And many of those optimisations are worthwhile. > One of the problems with UB is that whereas you might expect > UB arithmetic to generate an unexpected result and/or signal > it is completely open-ended and could fire an ICBM at the coder. Yes, UB is undefined behaviour. Unspecified is something else (and C has that as well, also implementation-defined, etc.) In some cases GCC (and any other modern compiler) can make UB be IB instead, with some flag for example, like -fno-strict-* does. In other cases it isn't so easy at all. In cases like you have here (where the validity of what you want to do depends on the ABI in effect) things are not easy :-/ Segher