From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jim Meyering Newsgroups: gmane.emacs.devel Subject: bleeding-edge gcc miscompiles latest emacs' fileio.c(file_accessible_directory_p) Date: Sun, 15 Jul 2018 21:01:24 -0700 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1531713591 3881 195.159.176.226 (16 Jul 2018 03:59:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Jul 2018 03:59:51 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 16 05:59:47 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1feufo-0000uD-9x for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2018 05:59:44 +0200 Original-Received: from localhost ([::1]:48741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1feuhv-00018t-Ah for ged-emacs-devel@m.gmane.org; Mon, 16 Jul 2018 00:01:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1feuho-00018c-3G for emacs-devel@gnu.org; Mon, 16 Jul 2018 00:01:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1feuhm-0007Uv-QR for emacs-devel@gnu.org; Mon, 16 Jul 2018 00:01:48 -0400 Original-Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:45842) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1feuhm-0007UE-Ju for emacs-devel@gnu.org; Mon, 16 Jul 2018 00:01:46 -0400 Original-Received: by mail-wr1-x434.google.com with SMTP id c4-v6so17703457wrs.12 for ; Sun, 15 Jul 2018 21:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to; bh=8iIfuZyfZlmm3UTJvETUNYqCl1vu7wt9uOR13x6gacQ=; b=XgFAUz6OfkM3wjxnVe3q9cGXeyEwzgAiHlYbRGaIhzEyo7Jz9UNs6tnpbSvVfys3SB EnEkZH3Fn4AO4BnzbHNsTbr9sQizzrn8TPVJYs3sa5VlLzHMufUER8hz4XtwIHr+RJkP jYuO9FAhdRshLHHPVpsarUFZ6U/i9CFp3z+Q/4qLmtUneurG8f3yx0iHXtUalix8F5bH zyvuH8WcBRC+Hd+GbsX7p+Ma3mCMQLibnSLtEwCP1pw72kKadiqZP3QvGU2Z9Iotsl37 Zje0PFsaKI8G5O0IY4deJmSuhF1UiRvEyfYqpDM2ZQuFp/OytlMClepD51z+8yEXM/o/ L8UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=8iIfuZyfZlmm3UTJvETUNYqCl1vu7wt9uOR13x6gacQ=; b=iWwEF+c/4bBXw03yBO160k4gLNpFWpAVs/BV9BAQ2jCC/je8hNW7xB279sL4/QQDhH QyCPY1yVDg3JG1nyrtWIQqeLRx5xWgbfuxLUBxmjsqslLbvXKa01xDDLf12N7uSXa+Hi KZMIhIlLV06IpA1/P4fce2/3rL/V19miKjoay+b9wDP7dZ1WyCYPzWf1M2THVsooCojG 2KYv4rhUmXy3iyVoh2X5N2XsQ765AHj/kSZ9VgCFArkz98G/kJPzCG5EgUqWa/S1CVJd kHMh4gclKcebAnYDWR0LgHSSRqEHCHK1tz9Z+BABliHXH1PRKGBEOtoP6Y78i9te7TIa Xn8g== X-Gm-Message-State: AOUpUlEzbJx6wPVPi0dzFJ+4K3kL6KMhwKpX9S7zzvddXJr5WKSFoVcB rVlAWwCeK7g0oknmjHlyEHRzzSLBXUXpMMx2C+k= X-Google-Smtp-Source: AAOMgpdC8i/YVP/dpW9MbamlpY3VW+A1ghNyIoWpUv6NZWBHXhaYSkSPJ5T7rpWU5qw10TeS6AHGzRC3xQbFLJLCF/c= X-Received: by 2002:adf:e749:: with SMTP id c9-v6mr10732889wrn.143.1531713704857; Sun, 15 Jul 2018 21:01:44 -0700 (PDT) Original-Received: by 2002:adf:ec4e:0:0:0:0:0 with HTTP; Sun, 15 Jul 2018 21:01:24 -0700 (PDT) X-Google-Sender-Auth: HkyA2cGEuD8QDgNPWerRfTYlI0A X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::434 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:227444 Archived-At: FYI, building latest emacs with gcc from July 8 or newer led to an annoying new warning... ---------- Forwarded message ---------- From: jim at meyering dot net Date: Sun, Jul 15, 2018 at 8:58 PM Subject: [Bug middle-end/86528] New: strlen of constant string malfunction -- had to back out fix for PR middle-end/77357 To: jim@meyering.net https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86528 Bug ID: 86528 Summary: strlen of constant string malfunction -- had to back out fix for PR middle-end/77357 Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: jim at meyering dot net Target Milestone: --- gcc miscompiles latest emacs' fileio.c(file_accessible_directory_p) It all started with a new unwarranted warning from emacs. This one is ok: /p/emacs-2018-07-11.10h58/bin/emacs k this one and all subsequent (up to at least 2018-07-15) emit a warning: /p/emacs-2018-07-12.10h35/bin/emacs k Here's the warning: Warning (initialization): Unable to access `user-emacs-directory' (~/.emacs.d/). Any data that would normally be written there may be lost! If you never want to see this message again, customize the variable `user-emacs-directory-warning'. That's obviously wrong, because that directory *does* exist. Running it under strace shows a suspicious file name. It looks like use of uninitialized memory: $ strace -efile -ok.log emacs -q k $ grep -m3 x/.ema k.log faccessat(AT_FDCWD, "/m/.emacs.d/abbrev_defs", R_OK) = 0 openat(AT_FDCWD, "/m/.emacs.d", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_PATH) = 7 faccessat(AT_FDCWD, "/m/.emacs.d/\10YY|\376\177", F_OK) = -1 ENOENT (No such file or directory) Once the debugger showed which lines were involved, I found that this patch works around it. Besides, I have a tiny preference for memcpy over strcpy, since the length is known. diff --git a/src/fileio.c b/src/fileio.c index 5a1c7ae10e..3363cc0cf6 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2861,9 +2861,11 @@ file_accessible_directory_p (Lisp_Object file) here. After appending '.', append another '/' to work around a macOS bug (Bug#30350). */ static char const appended[] = "/./"; + bool trailing_slash = data[len - 1] == '/'; char *buf = SAFE_ALLOCA (len + sizeof appended); memcpy (buf, data, len); - strcpy (buf + len, &appended[data[len - 1] == '/']); + memcpy (buf + len, &appended[trailing_slash], + sizeof appended - trailing_slash); dir = buf; } Then, I realized: it's related to a recent change in gcc and optimization. I had built latest emacs with latest built-from-git gcc. Emacs works when built with gcc from around July 8: rm src/fileio.o;make CC=/p/p/gcc-2018-07-08.16h57/bin/gcc CFLAGS='-ggdb3 -O2' Yet fails when built with gcc from July 11: rm src/fileio.o;make CC=/p/p/gcc-2018-07-11.11h00/bin/gcc CFLAGS='-ggdb3 -O2' Also, -O0 works in either case. Bisecting gcc led me to a commit that involves strlen of constant, which is what the replaced strcpy uses. 47d2cd73185a207ecc90970a73f5b38b114c48c2 PR middle-end/77357 - strlen of constant strings not folded Revert that, and emacs once again works when compiled with latest gcc. -- You are receiving this mail because: You reported the bug.