Issue Details (XML | Word | Printable)

Key: PCC-80
Type: Bug Bug
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Major Major
Assignee: Unassigned
Reporter: Gregory McGarry
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
pcc

change to i386 structure copies broken OSX

Created: 19/Aug/09 01:32 AM   Updated: 01/May/14 04:01 PM
Component/s: i386 target
Affects Version/s: None
Fix Version/s: None

File Attachments: 1. GZip Archive pftn.i.gz (22 kB)

Environment: OSX/i386 10.5


 Description  « Hide
Between 2009-08-16 and 2009-08-17 a change was introduced to the i386 target to handle structure copies differently. This change removed code the MACHO systems.

The symptom is that pcc (compiled with gcc) fails to compile itself:

pcc -DGCC_COMPAT -DPCC_DEBUG -Dos_darwin -Dmach_i386 -D_ISOC99_SOURCE -I. -I. -I../.. -I../../mip -I../../arch/i386 -I../../os/darwin -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wsign-compare -Wtruncate -c -o pftn.o pftn.c
pftn.c, line 1839: compiler error: Cannot generate code, node 0x845270 op OREG

I'm not sure why there is a problem here. Maybe the register constraints are causing a problem. A good way to test changes for OSX is to compile with -k, since OSX requires all code to be compiled PIC. Maybe the problem will appear on other systems using -k.


Here is the diff on that date:

Index: pcc/arch/i386/local2.c
diff -u pcc/arch/i386/local2.c:1.129 pcc/arch/i386/local2.c:1.130
--- pcc/arch/i386/local2.c:1.129 Fri Aug 14 20:38:09 2009
+++ pcc/arch/i386/local2.c Sun Aug 16 09:39:57 2009
@@ -1,4 +1,4 @@
-/* $Id: local2.c,v 1.129 2009/08/14 18:38:09 ragge Exp $ */
+/* $Id: local2.c,v 1.130 2009/08/16 07:39:57 ragge Exp $ */
 /*
  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
  * All rights reserved.
@@ -562,25 +562,52 @@
  break;
 
  case 'Q': /* emit struct assign */
- /* XXX - optimize for small structs */
-#if defined(MACHOABI)
- printf("\tsubl $4,%%esp\n");
-#endif
- printf("\tpushl $%d\n", p->n_stsize);
- expand(p, INAREG, "\tpushl AR\n");
- expand(p, INAREG, "\tleal AL,%eax\n\tpushl %eax\n");
-#if defined(MACHOABI)
- if (kflag) {
- printf("\tcall L%s$stub\n", EXPREFIX "memcpy");
- addstub(&stublist, EXPREFIX "memcpy");
- } else {
- printf("\tcall %s\n", EXPREFIX "memcpy");
+ /*
+ * With <= 16 bytes, put out mov's, otherwise use movsb/w/l.
+ * esi/edi/ecx are available.
+ */
+ switch (p->n_stsize) {
+ case 1:
+ expand(p, INAREG, " movb (AR),%cl\n");
+ expand(p, INAREG, " movb %cl,AL\n");
+ break;
+ case 2:
+ expand(p, INAREG, " movw (AR),%cx\n");
+ expand(p, INAREG, " movw %cx,AL\n");
+ break;
+ case 4:
+ expand(p, INAREG, " movl (AR),%ecx\n");
+ expand(p, INAREG, " movl %ecx,AL\n");
+ break;
+ default:
+ expand(p, INAREG, " leal AL,%edi\n");
+ expand(p, INAREG, " movl AR,%esi\n");
+ if (p->n_stsize <= 16 && (p->n_stsize & 3) == 0) {
+ printf(" movl (%%esi),%%ecx\n");
+ printf(" movl %%ecx,(%%edi)\n");
+ printf(" movl 4(%%esi),%%ecx\n");
+ printf(" movl %%ecx,4(%%edi)\n");
+ if (p->n_stsize > 8) {
+ printf(" movl 8(%%esi),%%ecx\n");
+ printf(" movl %%ecx,8(%%edi)\n");
+ }
+ if (p->n_stsize == 16) {
+ printf("\tmovl 12(%%esi),%%ecx\n");
+ printf("\tmovl %%ecx,12(%%edi)\n");
+ }
+ } else {
+ if (p->n_stsize > 4) {
+ printf("\tmovl $%d,%%ecx\n",
+ p->n_stsize >> 2);
+ printf(" rep movsl\n");
+ }
+ if (p->n_stsize & 2)
+ printf(" movsw\n");
+ if (p->n_stsize & 1)
+ printf(" movsb\n");
+ }
+ break;
  }
- printf("\taddl $16,%%esp\n");
-#else
- printf("\tcall %s\n", EXPREFIX "memcpy");
- printf("\taddl $12,%%esp\n");
-#endif
  break;
 
  case 'S': /* emit eventual move after cast from longlong */
Index: pcc/arch/i386/order.c
diff -u pcc/arch/i386/order.c:1.54 pcc/arch/i386/order.c:1.55
--- pcc/arch/i386/order.c:1.54 Sat Sep 27 09:35:22 2008
+++ pcc/arch/i386/order.c Sun Aug 16 09:39:57 2009
@@ -1,4 +1,4 @@
-/* $Id: order.c,v 1.54 2008/09/27 07:35:22 ragge Exp $ */
+/* $Id: order.c,v 1.55 2009/08/16 07:39:57 ragge Exp $ */
 /*
  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
  * All rights reserved.
@@ -159,6 +159,16 @@
  }
 
  case STASG:
+ {
+ static struct rspecial s[] = {
+ { NEVER, ESI }, { NEVER, EDI },
+ { NORIGHT, ESI }, { NORIGHT, EDI },
+ { NOLEFT, ESI }, { NOLEFT, EDI },
+ { NOLEFT, ECX }, { NORIGHT, ECX },
+ { NEVER, ECX }, { 0 } };
+ return s;
+ }
+
  case STARG:
  {
  static struct rspecial s[] = {


 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Gregory McGarry made changes - 20/Aug/09 01:17 AM
Field Original Value New Value
Attachment pftn.i.gz [ 10070 ]
Anders Magnusson made changes - 01/May/14 04:01 PM
Status Open [ 1 ] Closed [ 6 ]
Resolution Cannot Reproduce [ 5 ]