This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/26172] New: generates wrong code for pam_lastlog w/o optimization


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]