public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "egmont at uhulinux dot hu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/26172]  New: generates wrong code for pam_lastlog w/o optimization
Date: Wed, 08 Feb 2006 10:57:00 -0000	[thread overview]
Message-ID: <bug-26172-12154@http.gcc.gnu.org/bugzilla/> (raw)

Take
ftp://ftp.kernel.org/pub/linux/libs/pam/pre/library/Linux-PAM-0.99.3.0.tar.gz
compile it with
export CFLAGS="-fPIC -march=i586 -mtune=i586"
./configure [args...]; make

The resulted pam_lastlog.so module is wrong, there's an off-by-8-bytes bug
during a strncpy. However, if -O2 is also included amongst the CFLAGS, the
generated code is okay.

I attach the pam_lastlog.c file with two debug fprintf's inserted as well as
preprocessed source. The miscompiled part of the source is at line 278:

fprintf(stderr, "tl = %s\n", terminal_line); /* GCC BUG BELOW THIS LINE */
    strncat(last_login.ll_line, terminal_line, sizeof(last_login.ll_line)-1);
fprintf(stderr, "ll = %s\n", last_login.ll_line); /* GCC BUG ABOVE THIS LINE */

Without -O2, the following is printed to stderr during a "su -":
tl = pts/2
ll = ?@????P*pts/2
     ^^^^^^^^ this is 8 bytes of binary garbage, always different.

With -O2, strncat copies the string as expected:
tl = pts/2
ll = pts/2

The gcc command line:
i586-uhu-linux-gcc -DHAVE_CONFIG_H -I. -I. -I../.. -I../../libpam/include
-I../../libpamc/include -fPIC -march=i586 -mtune=i586 -DPAM_DYNAMIC -W -Wall
-Wbad-function-cast -Wcast-align -Wcast-qual -Wmissing-declarations
-Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wstrict-prototypes
-Wwrite-strings -Winline -Wshadow -MT pam_lastlog.lo -MD -MP -MF
.deps/pam_lastlog.Tpo -c pam_lastlog.c  -fPIC -DPIC -o .libs/pam_lastlog.o


-- 
           Summary: generates wrong code for pam_lastlog w/o optimization
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: egmont at uhulinux dot hu
 GCC build triplet: i586-uhu-linux
  GCC host triplet: i586-uhu-linux
GCC target triplet: i586-uhu-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26172


             reply	other threads:[~2006-02-08 10:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-08 10:57 egmont at uhulinux dot hu [this message]
2006-02-08 10:58 ` [Bug c/26172] " egmont at uhulinux dot hu
2006-02-08 10:58 ` egmont at uhulinux dot hu
2006-02-08 11:03 ` egmont at uhulinux dot hu
2006-02-08 11:07 ` rguenth at gcc dot gnu dot org
2006-02-08 11:21 ` egmont at uhulinux dot hu

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-26172-12154@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).