🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Robert R. Henry Wed, 16 Dec 1992 18:52
sizeof large structures broken in gcc2.3.[12]
#1555
Author: Robert R. Henry
Date: Wed, 16 Dec 1992 18:52
69 lines
3218 bytes
When manipulating obscenely large structures...

For gcc2.3.1 target==host==sparc-sun-sunos4.1, the program at the bottom
prints out (lines marked '*' are my editing to show errors)
* sizeof(struct RootSection) == 0xf0000000, 3840 Mb
* sizeof(struct RootMemory) == 0xf0000000, 3840 Mb
  &p->instruction_buffer = 0xc0000000
  &p->outbound_buffer = 0xd0000000
* &p->inbound_buffer = 0xc0000000
For gcc2.3.1, target==host==dec-mips-ultrix, the same program prints out
  sizeof(struct RootSection) == 0x10000000, 256 Mb
* sizeof(struct RootMemory) == 0x10000000, 256 Mb
  &p->instruction_buffer = 0xc0000000
  &p->outbound_buffer = 0xd0000000
* &p->inbound_buffer = 0xc0000000
which is a bit closer to the correct answer; I believe that the correct
answer should be:
  sizeof(struct RootSection) == 0x10000000, 256 Mb
  sizeof(struct RootMemory) == 0x30000000, 768 Mb
  &p->instruction_buffer = 0xc0000000
  &p->outbound_buffer = 0xd0000000
  &p->inbound_buffer = 0xe0000000

At the very least some warning message could be issued.

sun's native cc, and dec-ultrix cc both topple over with this.


Reading specs from /usr/local/lib/gcc-lib/sparc-sun/2.3.1/specs
gcc version 2.3.1
 /usr/local/lib/gcc-lib/sparc-sun/2.3.1/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix junk3.c /usr/tmp/cca02979.i
GNU CPP version 2.3.1 (sparc)
 /usr/local/lib/gcc-lib/sparc-sun/2.3.1/cc1 /usr/tmp/cca02979.i -quiet -dumpbase junk3.c -version -o /usr/tmp/cca02979.s
GNU C version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
 /usr/local/lib/gcc-lib/sparc-sun/2.3.1/as -o /usr/tmp/cca029791.o /usr/tmp/cca02979.s
 /usr/local/lib/gcc-lib/sparc-sun/2.3.1/ld -e start -dc -dp /lib/crt0.o -L/usr/local/lib/gcc-lib/sparc-sun/2.3.1 -L/usr/local/lib /usr/tmp/cca029791.o -lgcc -lc -lgcc

#include <stdio.h>
typedef unsigned int u_int;
#define Mb (1024*1024)
struct RootSection {
  u_int data[(128/sizeof(u_int)) * Mb];
  u_int csr[(128/sizeof(u_int)) * Mb];
};
struct RootMemory {
  struct RootSection instruction_buffer;
  struct RootSection outbound_buffer;
  struct RootSection inbound_buffer;
};

#define ROOT_MEMORY_ADDRESS 0xc0000000

main()
{
  struct RootMemory *p = (struct RootMemory *) ROOT_MEMORY_ADDRESS;

  printf("sizeof(struct RootSection) == 0x%08x, %d Mb\n",
    (u_int)sizeof(struct RootSection),
    (u_int)sizeof(struct RootSection)/Mb
  );
  printf("sizeof(struct RootMemory) == 0x%08x, %d Mb\n",
    (u_int)sizeof(struct RootMemory),
    (u_int)sizeof(struct RootMemory)/Mb
  );

  printf("&p->instruction_buffer = 0x%08x\n", &p->instruction_buffer);
  printf("&p->outbound_buffer = 0x%08x\n", &p->outbound_buffer);
  printf("&p->inbound_buffer = 0x%08x\n", &p->inbound_buffer);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads