public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "joey.dumont at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/100431] New: Fixes to enable compiling with -Werror=format-security
Date: Wed, 05 May 2021 11:24:40 +0000	[thread overview]
Message-ID: <bug-100431-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100431

            Bug ID: 100431
           Summary: Fixes to enable compiling with -Werror=format-security
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: bootstrap
          Assignee: unassigned at gcc dot gnu.org
          Reporter: joey.dumont at gmail dot com
  Target Milestone: ---

Created attachment 50757
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50757&action=edit
Patch to fix -Werror=format-security errors

As mentioned in bug 100207, Arch Linux recently starting compiling its packages
with the -Werror=format-security option. In this bug report, I attach two
patches that enable compiling gcc with that flag. 

The first patch expliclity adds "%s" format strings to functions that pass its
arguments to printf. 

However, during my testing, I found that libgcc uses -Wno-format in its CFLAGS,
making the flags inconsistent. It seemed that adding the
--enable-build-format-warnings should remove the -Wno-format option from the
compile flags, but it didn't seem to work as expected, leading to errors like
this: 

/build/gcc/src/gcc-build/./gcc/xgcc -B/build/gcc/src/gcc-build/./gcc/
-B/usr/x86_64-pc-linux-gnu/bin/ -B/usr/x86_64-pc-linux-gnu/lib/ -isystem
/usr/x86_64-pc-linux-gnu/include -isystem /usr/x86_64-pc-linux-gnu/sys-include 
 -fno-checking -g -march=x86-64 -mtune=generic -O2 -fno-plt -fexceptions
-Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS -Wformat -Werror=format-security
-fstack-clash-protection -fcf-protection -m32 -O2  -g -march=x86-64
-mtune=generic -O2  -fno-plt -fexceptions        
-Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS         -Wformat
-Werror=format-security         -fstack-clash-protection -fcf-protection
-DIN_GCC    -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual
-Wno-error=format-diag -Wno-format -Wstrict-prototypes -Wmissing-prototypes
-Wno-error=format-diag -Wold-style-definition  -isystem ./include  -fpic
-mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -g -DIN_LIBGCC2
-fbuilding-libgcc -fno-stack-protector  -fpic -mlong-double-80 -DUSE_ELF_SYMVER
-fcf-protection -mshstk -I. -I. -I../../.././gcc -I/build/gcc/src/gcc/libgcc
-I/build/gcc/src/gcc/libgcc/. -I/build/gcc/src/gcc/libgcc/../gcc
-I/build/gcc/src/gcc/libgcc/../include
-I/build/gcc/src/gcc/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT
-DHAVE_CC_TLS  -DUSE_TLS -o _muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep
-DL_muldi3 -c /build/gcc/src/gcc/libgcc/libgcc2.c -fvisibility=hidden
-DHIDE_EXPORTS
cc1: error: ‘-Wformat-security’ ignored without ‘-Wformat’
[-Werror=format-security]

I am not sure how these flags are set. In any case, the second patch works
around the issue by changing the --enable-build-format-warnings to add
-Wno-format-security to the flags, making the flags consistent again.

I think the first patch is a genuine fix, but I'm not sure about the second. I
would have expected --enable-build-format-warnings to entirely remove the
-Wno-format option, but it seems to stick somewhere in the build process, and I
can't see where.

             reply	other threads:[~2021-05-05 11:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 11:24 joey.dumont at gmail dot com [this message]
2021-05-05 11:25 ` [Bug bootstrap/100431] " joey.dumont at gmail dot com
2021-05-05 11:47 ` jakub at gcc dot gnu.org
2021-05-11 13:45 ` joey.dumont at gmail dot com
2021-05-11 13:57 ` jakub at gcc dot gnu.org
2021-06-20  2:33 ` joey.dumont at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-100431-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).