From owner-freebsd-bugs@freebsd.org Sat Feb 3 19:08:44 2018 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 74861EE4A5D for ; Sat, 3 Feb 2018 19:08:44 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) (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 04E53761FE; Sat, 3 Feb 2018 19:08:43 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-it0-f67.google.com with SMTP id j21-v6so4243809ita.1; Sat, 03 Feb 2018 11:08:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=28f0jqGaFXICncqqYmOCmK3PprEFDOngX8fgCn4MLYE=; b=MCz8BgC5uzE+KuI7LzHGdFRIXXgx2TGDb9wN8rnizkmd8H8/4hh1V6P0/dy9fmr2nD XbyAg3ziT1ke2ttZyYDpmAZAaOIMrZoXDAtH9FGT+bv3cJNshiQXYv/2Ybzx9ywlVOeg DQbqWLdxJBgYK0tSXSHn8QuijjZXZKrzwm494DDLdyZag0h/PnNpS34hEH0cS3IqkQwq vh7XpW2dmUAO9xnaXwoYQbcnYHT21bkB9r/oS4Fy6ncqL2SN2Ta4yanECEwiCp0d9PCa Q5es37QRGQtDowlnRLcpMTqJmLgYxIAQFzvEDwkZk6KxASCnlx1HJcnr/FEuKvfNIJ7+ OETA== X-Gm-Message-State: APf1xPAzoS8OHKpufKBwbCowbt2S95vAN07pDz+xHG8Way+zzG4fRLOT q7KcByarxip0Zoua0rsiv+XBd4/V X-Google-Smtp-Source: AH8x225FZmUK/Gl4e+cnvHy1uZdIoSvmJu/T6pd+IbRQaABYNB7+t4qKRpxP4T5NqSFLTWxfW5R9rw== X-Received: by 10.36.61.142 with SMTP id n136mr2066002itn.6.1517683496012; Sat, 03 Feb 2018 10:44:56 -0800 (PST) Received: from mail-io0-f172.google.com (mail-io0-f172.google.com. [209.85.223.172]) by smtp.gmail.com with ESMTPSA id u128sm2823990itb.1.2018.02.03.10.44.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Feb 2018 10:44:55 -0800 (PST) Received: by mail-io0-f172.google.com with SMTP id b198so26307270iof.6; Sat, 03 Feb 2018 10:44:55 -0800 (PST) X-Received: by 10.107.35.84 with SMTP id j81mr45437928ioj.226.1517683494867; Sat, 03 Feb 2018 10:44:54 -0800 (PST) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.2.95.152 with HTTP; Sat, 3 Feb 2018 10:44:54 -0800 (PST) In-Reply-To: <20180203215302.T1064@besplex.bde.org> References: <20180203215302.T1064@besplex.bde.org> From: Conrad Meyer Date: Sat, 3 Feb 2018 10:44:54 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [Bug 225626] r325865 malloc vs bzero To: Bruce Evans Cc: freebsd-bugs@freebsd.org, Brooks Davis Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Feb 2018 19:08:44 -0000 Hi Bruce, Brooks, On Sat, Feb 3, 2018 at 3:52 AM, Bruce Evans wrote: > On Fri, 2 Feb 2018 a bug that doesn't want replies@freebsd.org wrote: > >> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225626 >> >> --- Comment #1 from Brooks Davis --- > ... >> Note that memset should be used in preference to bzero as the compiler >> should >> be able to elide most of the cost of the memset since it can emit it >> inline and >> then delete the dead stores. (To Brooks:) Not in -ffreestanding by default, unfortunately. We can give it that hint back by defining memset() in terms of __builtin_memset(), though. We have done so for some sizes of constant bzero(), but not for bcopy, memcpy, or memmove, unfortunately. > Note that memset() should _not_ be used in preference to bzero() since: > - using memset() in the kernel is a style bug, except possibly with a > nonzero > fill byte > - the existence of memset() in the kernel is an umplementation style bug, > except possibly with a nonzero fill byte. This is total nonsense. > ... > - using memset() instead of bzero() in the kernel is a pessimization. Since > memset() is only compatibilty cruft and should not be used, it is > intentionally not as optimized as bzero(). > ... This can and should be fixed. > Not so simlarly for memcpy(). Its use in the kernel is now just a style > bug, since the compiler is not allowed to inline it (except in my version > of course). This should be fixed. > ... > FreeBSD was changed to use -ffreestanding because without it the compiler > is allowed to inline functions like printf() and gcc started doing that > (it converts printf(3) into puts() galore, and puts() doesn't exist in > the kernel). This broke all inlining, but no one cared (except me of > course). Isn't the other issue that non-freestanding links libgcc (GPL) into the kernel? We could work around puts() by adding a puts() implementation, of course. Conrad