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]

Re: Nasty problem with egcs-1.0.1 on Irix 6.4


Hi again,
        I think I have tracked reason for the bug I reported earlier.  I
wrote a small test program to examine how small structures are passed to
functions in the n32 abi which I have included below.

It appears to me that structures less than 8 bytes in length are packed
into a single 64 bit register with the first byte of the structure
occupying the most significant byte to the register.  So if I pass this
structure:

	struct ss {
	  int a;
	};

then the argument register will look like this:

	+----+----+----+----+----+----+----+----+
	| a3 | a2 | a1 | a0 | 00 | 00 | 00 | 00 |
	+----+----+----+----+----+----+----+----+

Where aN are the bytes of a.

Unfortunately gcc (egcs-1.0.1) passes the same 4 byte structure in the
low 32 bits of the register, which is why my previous semctl() example
failed.

Here is my test program:

---paramtest.c--------------------------------------------------------
#include <stdio.h>

struct ss {
  int a;
};

void f(struct ss x);

int main(int argc, char *argv[]) {
  struct ss x;

  x.a = 42;

  f(x);

  return 0;
}

void f(struct ss x) {
  printf("x.a = %d\n", x.a);
}
----------------------------------------------------------------------

Here assemlber generated by:

	cc -O -n32 -S paramtest.c

for the line:
	
	f(x);

----------------------------------------------------------------------
 #  13  
 #  14    f(x);
	lw $25,%call16(f)($gp)        	# [3]  
	sd $31,8($sp)                 	# [4]  .gra_spill_b001
	addiu $4,$sp,0                	# [4]  x
	lw $4,0($4)                   	# [5]  id:4 x+0x0
	jalr $25                      	# [6]  
	dsll32 $4,$4,0                	# [7]  
----------------------------------------------------------------------

I think that the line:

	dsll32 $4,$4,0

is equivalent to:

	dsll $4,$4,32

which shifts $4 (the first argument) left by 32.  It appears that the
assembler output by cc already has the branch delay slots filled.

Here is the assembler produced by:

	gcc -O2 -S -mabi=n32 paramtest.c 

for the same line.

----------------------------------------------------------------------
	li	$4,42			# 0x0000002a
	la	$25,f
	jal	$31,$25
----------------------------------------------------------------------

As you can see, $4 is not shifted.

I believe this is a symptom of the same problem that causes
gcc.c-torture/execute/complex-5.c to fail.

Does anyone out there know how to fix this problem, I don't know much
about the internals of gcc, but if someone can point me in the right
direction I may be able to help.

Thanks, 
	Hugh

P.S. I am attaching the full assembler output from cc and gcc.


_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

paramtest-cc-n32.s

paramtest-gcc-n32.s


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