[Info-vax] GCC for VMS, was: Re: fortran compiler roadmap?
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Mon Apr 29 18:38:45 EDT 2013
On 2013-04-28, Craig A. Berry <craigberry at mac.com.invalid> wrote:
>
> Or one or more of the many macros referenced in stat.h is different
> between the gcc cross compiler and the native compiler. There is no
> hello.exe locally, but I can certainly reproduce getting different
> structure sizes with different options:
>
Ok, I played with it a bit more this evening and I've figured it out.
It turns out my hunch about the 32 bit versus 64 bit issue was right.
It turns out DEC C by default is basically _still_ a 32 bit compiler
with 64 bit addons (which I had not fully appreciated; I don't use
DEC C all that much these days), but gcc (when built using the
alpha64-dec-vms triplet) is a pure 64 bit compiler through and through.
That makes the DEC C headers incompatible with gcc when you have, for
example, pointers in structs and want to use that struct with existing
functions in the DEC C RTL.
A modified version of my demo program:
=========================================================================
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/* A cut down version of the pragmas and stat structure found in VMS stat.h. */
# pragma __member_alignment __save
# pragma __nomember_alignment
struct simon_stat
{
__dev_t st_dev; /* pointer to physical device name */
__ino16_t st_ino[3]; /* 3 words to receive fid */
};
# pragma __member_alignment __restore
typedef char * __simon_t;
__simon_t __simon_ptr;
off_t get_file_size (const char * file_name)
{
struct stat statbuf;
if (stat (file_name, &statbuf) < 0)
{
printf("Error performing stat() on %s\n", file_name);
}
else if (! S_ISREG (statbuf.st_mode))
printf ("Warning: '%s' is not an ordinary file\n", file_name);
else
return statbuf.st_size;
return (off_t) -1;
}
main()
{
off_t fsize;
printf("sizeof(struct simon_stat) = %lu\n",
(unsigned long int) sizeof(struct simon_stat));
printf("sizeof(struct stat) = %lu\n",
(unsigned long int) sizeof(struct stat));
printf("sizeof(__dev_t) = %lu\n", sizeof(__dev_t));
printf("sizeof(__ino16_t) = %lu\n", sizeof(__ino16_t));
printf("sizeof(__simon_ptr) = %lu\n", sizeof(__simon_ptr));
fsize = get_file_size("statt.exe");
printf("fsize = %lu\n", (unsigned long int) fsize);
}
=========================================================================
And the output:
$ r statt
sizeof(struct simon_stat) = 14
sizeof(struct stat) = 69
sizeof(__dev_t) = 8
sizeof(__ino16_t) = 2
sizeof(__simon_ptr) = 8
Warning: 'statt.exe' is not an ordinary file
fsize = 4294967295
$ cc statt
$ link statt
$ r statt
sizeof(struct simon_stat) = 10
sizeof(struct stat) = 49
sizeof(__dev_t) = 4
sizeof(__ino16_t) = 2
sizeof(__simon_ptr) = 4
fsize = 4096
=========================================================================
As before, the first statt.exe was built using the gcc cross compiler under
Linux and the second one was built, as you can see above, on Eisner using
DEC C.
The critical variable above is __simon_ptr which is defined as "char *";
look at the difference in size. This matches the definition of __dev_t:
grep -ni __dev_t decc\$types.h
257: typedef unsigned __int64 __dev_t; /* device id */
436: typedef char *__dev_t;
The second definition from decc$types.h is the one which is in use.
Simon.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list