From owner-freebsd-hackers@freebsd.org Sun Jan 3 18:24:46 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 79F4AA60ACD for ; Sun, 3 Jan 2016 18:24:46 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: from mail-pa0-x22c.google.com (mail-pa0-x22c.google.com [IPv6:2607:f8b0:400e:c03::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 51A3E1245 for ; Sun, 3 Jan 2016 18:24:46 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: by mail-pa0-x22c.google.com with SMTP id uo6so165256014pac.1 for ; Sun, 03 Jan 2016 10:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ue5rSjH5+6PBb9BDU8hVUi3FXBoeY0EFFXqaOrj107Y=; b=tPIdVaZtpcd7KwNYLHSj+aO7hiNngs3L/gj9+PGTkobXPIwX3D2Xd2p8VNzdCg6dDB F4OxDcg4QkzQP1bGnfXOi+Ct273z9E9onzTmTJQ2+CS2lsFYynFxK4mWUqXgdtI9amIx lSKfRwvLN1yIls2QCDES58CO/ehy9/B582HQ8HG1u+A4QVB/RTuzRH2wX5UMtMFu6Bzc VlJx/cKnVGSlOGXwO1438OyTKbGMvfMw4hpbPFqSIR25IzRZStKBRWeI67aZ+VTa8Bhp zoMDBSGbG+SEGFpPL6lK2tggJRX1KV06kZglgfJmUCoK3lO1Q/U5627vWqroamx2C8le 68wA== X-Received: by 10.66.55.66 with SMTP id q2mr54487937pap.120.1451845485929; Sun, 03 Jan 2016 10:24:45 -0800 (PST) Received: from [192.168.20.7] (c-24-16-212-205.hsd1.wa.comcast.net. [24.16.212.205]) by smtp.gmail.com with ESMTPSA id 71sm26223558pfh.4.2016.01.03.10.24.44 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 03 Jan 2016 10:24:44 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Subject: Re: variables optimized out From: NGie Cooper In-Reply-To: <20160103181139.GA16659@britannica.bec.de> Date: Sun, 3 Jan 2016 10:24:43 -0800 Cc: freebsd-hackers@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <51901B1D-BCB2-4C9B-977C-C69E56C60A4D@gmail.com> References: <20160103145923.GA16970@becker.bs.l> <20160103181139.GA16659@britannica.bec.de> To: Joerg Sonnenberger X-Mailer: Apple Mail (2.2104) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jan 2016 18:24:46 -0000 > On Jan 3, 2016, at 10:11, Joerg Sonnenberger = wrote: >=20 > On Sun, Jan 03, 2016 at 03:59:23PM +0100, Bertram Scharpf wrote: >> Hi, >>=20 >> On Sunday, 03. Jan 2016, 14:38:33 +0100, robbinson defau wrote: >>> Im debugging some issues in the kernel and as the kernel is compiled = by >>> default with -O2, a lot of variables are optimized out. So i made = changes >>> to make.conf (CFLAGS and COPTFLAGS).\ >>>=20 >>> All builds fine, but I get the weirdest of panics that most = certainly not >>> happen with -O2. [...] >>=20 >> I just had a look at "man make.conf" and that says: >>=20 >> CFLAGS (str) Controls the compiler setting when compiling C = code. >> Optimization levels other than -O and -O2 are not = sup=E2=80=90 >> ported. >>=20 >> At least to me this is a surprise. I'm really disappointed >> about what programming style has become common. >=20 > There are two strong historical reasons from GCC behavior: > - a lot of the -O3 optimisations has been known to break questionable > code > - a lot of the warnings significantly change behavior depending on the > optmizer. >=20 > While the former is not a big problem for disabling optimisation, the > latter certainly is. Note that with clang there is no difference = between > -O and -O2. Hi Joerg, We had some discussion on this a while ago internally at $work. = clang optimizes a lot of variables away and doesn=E2=80=99t track them = like later versions of gcc does (unfortunately 4.2.1 in base also lacks = this capability): https://llvm.org/bugs/show_bug.cgi?id=3D23636 (clang = lacks -ftracking[-assignments]). The only way you can reliably debug a = program today is to compile code with `DEBUG_FLAGS=3D"-g -O0=E2=80=9D`, = but that might change behavior of the code due to how it was optimized = (and it might make things less efficient), so caveat emptor. You will = definitely need to increase your stack space with the kernel for = instance. Hope this helps! -NGie=