public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: thousel@usa.net To: gcc-gnats@gcc.gnu.org Cc: stcarrez@nerim.fr Subject: target/6899: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment Date: Sat, 01 Jun 2002 13:56:00 -0000 [thread overview] Message-ID: <20020601205507.30121.qmail@sources.redhat.com> (raw) >Number: 6899 >Category: target >Synopsis: construction of C++ classes with less than 5 bytes of storage can cause stack misalignment >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Sat Jun 01 13:56:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: thousel@usa.net >Release: gcc compiler 3.1 m68hc1x-20020517 >Organization: >Environment: Cygwin/Win2k >Description: Under certain scenarios, it appears that a loop of construction of one class followed by a construction of another class with less than 5 bytes of storage will cause stack misalignment. >How-To-Repeat: see comments in attachment >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="test.txt" Content-Disposition: inline; filename="test.txt" > m6812-elf-gcc -v Reading specs from /cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.1/specs Configured with: ./configure --target=m6812-elf --program-prefix=m6812-elf- --prefix=/cygdrive/c/m6812-elf-tools --exec-prefix=/cygdrive/c/m6812-elf-tools --enable-languages=c,c++ Thread model: single gcc version 3.1 m68hc1x-20020517 Suppose you have the following code called test.cpp: class bar { public : bar(int index); }; class foo { private: unsigned short attr1; unsigned short attr2; unsigned char attr3; }; class glerg { public : static void Init(); private : static foo* pFoo; }; void glerg::Init() { int i; bar* pBar[4]; for (i = 0; i < 4; i++) pBar[i] = new bar(i); pFoo = new foo(); } Compile it with: > m6812-elf-gcc -m68hc12 -mshort -Os -mauto-incdec -fomit-frame-pointer -fno-rtti -fno-exceptions -S test.cpp This will create the following test.s: ;;;----------------------------------------- ;;; Start MC68HC11 gcc assembly output ;;; gcc compiler 3.1 m68hc1x-20020517 ;;; Command: /cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.1/cc1plus.exe -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -Dmc68hc1x -D__mc68hc1x__ -D__mc68hc1x -D__OPTIMIZE_SIZE__ -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D__HAVE_SHORT_INT__ -D__INT__=16 -D__INT_MAX__=32767 -Dmc6812 -DMC6812 -Dmc68hc12 test.cpp -D__GNUG__=3 -D__DEPRECATED -D__GXX_ABI_VERSION=100 -quiet -dumpbase test.cpp -m68hc12 -mshort -mauto-incdec -Os -fomit-frame-pointer -fno-rtti -fno-exceptions -o test.s ;;; Compiled: Sat Jun 1 15:42:11 2002 ;;; (META)compiled by GNU C version 2.95.3-5 (cygwin special). ;;;----------------------------------------- .file "test.cpp" ; extern _Znwt ; extern _ZN3barC1Ei ; extern _ZN5glerg4pFooE ; extern memset .sect .text .globl _ZN5glerg4InitEv .type _ZN5glerg4InitEv,@function _ZN5glerg4InitEv: leas -16,sp clr 9,sp clr 8,sp sts 14,sp .L6: ldd #1 bsr _Znwt std 10,sp *** movw 8,sp,2,-sp ldd 12,sp bsr _ZN3barC1Ei ldx 16,sp movw 12,sp,2,x+ stx 16,sp *** pulx ldx 8,sp inx stx 8,sp cpx #3 ble .L6 ldd #5 bsr _Znwt std 12,sp movw #5,2,-sp clr 1,-sp clr 1,-sp ldd 16,sp bsr memset ldx 16,sp stx _ZN5glerg4pFooE leas 20,sp rts .Lfe1: .size _ZN5glerg4InitEv,.Lfe1-_ZN5glerg4InitEv .ident "GCC: (GNU) 3.1 m68hc1x-20020517" Note the two lines that begin with "***". The first line autodecrements the stack by two, and the second uses "pulx" to realign it. Now we comment out one of the attributes in class foo: class bar { public : bar(int index); }; class foo { private: unsigned short attr1; unsigned short attr2; // unsigned char attr3; }; class glerg { public : static void Init(); private : static foo* pFoo; }; void glerg::Init() { int i; bar* pBar[4]; for (i = 0; i < 4; i++) pBar[i] = new bar(i); pFoo = new foo(); } Compile it again with: > m6812-elf-gcc -m68hc12 -mshort -Os -mauto-incdec -fomit-frame-pointer -fno-rtti -fno-exceptions -S test.cpp This will create the following test.s: ;;;----------------------------------------- ;;; Start MC68HC11 gcc assembly output ;;; gcc compiler 3.1 m68hc1x-20020517 ;;; Command: /cygdrive/c/m6812-elf-tools/lib/gcc-lib/m6812-elf/3.1/cc1plus.exe -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -Dmc68hc1x -D__mc68hc1x__ -D__mc68hc1x -D__OPTIMIZE_SIZE__ -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D__HAVE_SHORT_INT__ -D__INT__=16 -D__INT_MAX__=32767 -Dmc6812 -DMC6812 -Dmc68hc12 test.cpp -D__GNUG__=3 -D__DEPRECATED -D__GXX_ABI_VERSION=100 -quiet -dumpbase test.cpp -m68hc12 -mshort -mauto-incdec -Os -fomit-frame-pointer -fno-rtti -fno-exceptions -o test.s ;;; Compiled: Sat Jun 1 15:44:24 2002 ;;; (META)compiled by GNU C version 2.95.3-5 (cygwin special). ;;;----------------------------------------- .file "test.cpp" ; extern _Znwt ; extern _ZN3barC1Ei ; extern _ZN5glerg4pFooE .sect .text .globl _ZN5glerg4InitEv .type _ZN5glerg4InitEv,@function _ZN5glerg4InitEv: leas -14,sp clr 9,sp clr 8,sp sts 12,sp .L6: ldd #1 bsr _Znwt std 10,sp *** movw 8,sp,2,-sp ldd 12,sp bsr _ZN3barC1Ei ldx 14,sp movw 12,sp,2,x+ stx 14,sp ??? ldx 8,sp inx stx 8,sp cpx #3 ble .L6 ldd #4 bsr _Znwt tfr d,x clr 3,x clr 2,x clr 1,x clr 0,x std _ZN5glerg4pFooE leas 14,sp rts .Lfe1: .size _ZN5glerg4InitEv,.Lfe1-_ZN5glerg4InitEv .ident "GCC: (GNU) 3.1 m68hc1x-20020517" The generated code is fairly similar, but there is no pulx above the ??? line this time and the stack therefore becomes misaligned.
next reply other threads:[~2002-06-01 20:56 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-06-01 13:56 thousel [this message] 2002-06-14 14:53 ciceron 2002-07-22 13:29 ciceron
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=20020601205507.30121.qmail@sources.redhat.com \ --to=thousel@usa.net \ --cc=gcc-gnats@gcc.gnu.org \ --cc=stcarrez@nerim.fr \ /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: linkBe 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).