LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1348 - x86_64 codegen bug in md5.c
Summary: x86_64 codegen bug in md5.c
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: trunk
Hardware: PC Linux
: P release blocker
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-23 19:02 PDT by Scott Michel
Modified: 2010-02-22 12:52 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
md5.bc bytecode that produces the error... (13.50 KB, application/octet-stream)
2007-04-23 19:03 PDT, Scott Michel
Details
Associated assembly language output for md5.c (18.47 KB, text/plain)
2007-04-23 20:35 PDT, Scott Michel
Details
Assembly output from llc (18.40 KB, text/plain)
2007-04-24 16:20 PDT, Scott Michel
Details
-print-machineinstrs output from llc (191.83 KB, text/plain)
2007-04-24 16:20 PDT, Scott Michel
Details
cc1 -mllvm -print-machineinstrs output (193.97 KB, text/plain)
2007-04-24 19:41 PDT, Scott Michel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Scott Michel 2007-04-23 19:02:00 PDT
This occurs while compiling the C frontend, xgcc produces the following 
diagnostic:

(bosbok) libiberty make
if [ x"" != x ]; then \
          /work/scottm/llvm-cfrontend/obj/x86_64-unknown-linux-gnu/gcc/xgcc -B/work/scottm/llvm-cfrontend/obj/x86_64-unknown-linux-gnu/gcc/ -B/work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/bin/ -B/work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/lib/ -isystem /work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/include -isystem /work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/sys-include -c -DHAVE_CONFIG_H -O2 -g -O2 -I. -I../../../../libiberty/../include  -W -Wall -Wtraditional -pedantic  ../../../../libiberty/md5.c -o 
pic/md5.o; \
        else true; fi
/work/scottm/llvm-cfrontend/obj/x86_64-unknown-linux-gnu/gcc/xgcc -B/work/scottm/llvm-cfrontend/obj/x86_64-unknown-linux-gnu/gcc/ -B/work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/bin/ -B/work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/lib/ -isystem /work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/include -isystem /work/scottm/llvm-cfrontend/i686-unknown-linux-gnu/x86_64-unknown-linux-gnu/sys-include -c -DHAVE_CONFIG_H -O2 -g -O2 -I. -I../../../../libiberty/../include  -W -Wall -Wtraditional -pedantic ../../../../libiberty/md5.c -o 
md5.o
/tmp/ccSlUbtP.s: Assembler messages:
/tmp/ccSlUbtP.s:924: Error: suffix or operands invalid for `sub'

The relevant portion from the assembler source is:

        .align  16
        .globl  md5_buffer
        .type md5_buffer,@function
md5_buffer:
        subq $4294966344, %rsp
        movq %rbp, -960(%rsp)
        leaq -960(%rsp), %rbp
        movq %rbx, -8(%rbp)
        movq %r12, -16(%rbp)
        movq %r14, -24(%rbp)
        movq %r15, -32(%rbp)

The "$42949663444" is the invalid constant about which xgcc (actually, gas) 
complains.
Comment 1 Scott Michel 2007-04-23 19:03:27 PDT
Created attachment 793 [details]
md5.bc bytecode that produces the error...
Comment 2 Scott Michel 2007-04-23 20:35:08 PDT
Created attachment 794 [details]
Associated assembly language output for md5.c
Comment 3 Chris Lattner 2007-04-24 00:03:16 PDT
Ok, some silly questions:

1. This is LLVM CVS/SVN, not 1.9, right?

2. What does:
  llc md5.o -o - -relocation-model=pic -disable-fp-elim

produce for you?  I get:

md5_buffer:
        subq $200, %rsp
        movq %rbp, 192(%rsp)
        leaq 192(%rsp), %rbp
...

Which is fine.  If you get the bogus output, please attach the output and the output of -print-
machineinstrs.

Finally, what is your system GCC version?  Is it in this list?
http://llvm.org/docs/GettingStarted.html#brokengcc

-Chris
Comment 4 Scott Michel 2007-04-24 16:19:24 PDT
a) Yes, current CVS/SVN.
b) "lli md5.bc -o - -relocation-model=pic -disable-fp-elim" produces:

        .align  16
        .globl  md5_buffer
        .type md5_buffer,@function
md5_buffer:
        subq $552, %rsp
        movq %rbp, 544(%rsp)
        leaq 544(%rsp), %rbp

c) llvm and llvm-cfrontend are compiled using gcc 4.0.4, built from gcc's 
gcc-4_0-branch source:

GNU C version 4.0.1 LLVM (Apple Computer, Inc. build 5432) 
(x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.0.4.
Comment 5 Scott Michel 2007-04-24 16:20:04 PDT
Created attachment 796 [details]
Assembly output from llc
Comment 6 Scott Michel 2007-04-24 16:20:32 PDT
Created attachment 797 [details]
-print-machineinstrs output from llc
Comment 7 Chris Lattner 2007-04-24 19:25:35 PDT
Very strange.  Your llc output looks good, like I would expect.  Okay, try this:

1. Run the llvm-gcc command line again, it should crash.  Pass -v to it in addition to the other options.  
This should show how it invokes "cc1".
2. Invoke cc1 with the same option.  This time, pass "-mllvm -print-machineinstrs"  or "-mllvm=-print-
machineinstrs" (whichever works), and attach the dump again.

Thanks

-Chris
Comment 8 Scott Michel 2007-04-24 19:40:53 PDT
cc1 output uploaded. And it has the bogotic constant!
Comment 9 Scott Michel 2007-04-24 19:41:36 PDT
Created attachment 799 [details]
cc1 -mllvm -print-machineinstrs output
Comment 10 Chris Lattner 2007-04-24 19:46:29 PDT
Ah, interesting.  There are multiple bugs here.  The main issue is that the CFE is producing this type:
%struct.md5_ctx = type { i32, i32, i32, i32, [2 x i32], i32, [128 x i8], [4294966912 x i8] }

That last part seems bad.  Devang, can you look into why this is happening?



The second issue is that this type isn't turning into the proper (large) size.  I'll fix this part.

-Chris
Comment 11 Chris Lattner 2007-04-24 19:47:50 PDT
actually, I am getting this from the code generator now:

md5_buffer:
        subq $4294967112, %rsp
        movq %rbx, -192(%rsp)

from the .bc file in comment #1.

Devang, can you investigate the struct layout issue please?

-Chris
Comment 12 Devang Patel 2007-04-24 19:48:56 PDT
ok
Comment 13 Devang Patel 2007-04-24 20:10:18 PDT
Now, I see (using md5.c  from llvm-gcc sources on darwin platform)

        %struct.md5_ctx = type { i32, i32, i32, i32, [2 x i32], i32, [128 x i8] }

which is correct.  

Would it be possible to send me preprocessed C source file to reproduce this ? Thank you.
Comment 14 Chris Lattner 2007-04-24 20:12:43 PDT
that is with -m64, right?  It seems like this may have been fixed by one of your recent patches.
Comment 15 Devang Patel 2007-04-24 20:14:00 PDT
Yes -m64.
It is possible that this was covered by one of the recent patches.
Comment 16 Chris Lattner 2007-04-24 22:59:55 PDT
> actually, I am getting this from the code generator now:
> md5_buffer:
>       subq $4294967112, %rsp
> from the .bc file in comment #1.

Even more strange.  I get something completely different when I'm on an x86 host.  Still investigating.
Comment 17 Chris Lattner 2007-04-24 23:33:39 PDT
After a raft of random fixes to the code generator to support >4G stack frames, I'm now seeing the X86 
backend emit illegal subq instructions when the frame is >4G.  For me, mission accomplished :)

Devang, please investigate the CFE issue.  If already fixed, feel free to close this and Scott can try when he 
is back in town.
Comment 19 Scott Michel 2007-04-27 13:31:25 PDT
WFM. Now off to figure out why compiler now bails during local_init.cc...
Comment 20 Chris Lattner 2007-04-27 13:32:23 PDT
great, thanks!