Subject: Re: newvers.sh padding problem
To: Charles M. Hannum <root@ihack.net>
From: Richard Earnshaw <rearnsha@arm.com>
List: tech-toolchain
Date: 02/01/1999 11:46:16
> 
> BTW, note that with Curt's change, libkvm, kvm_mkdb(8) and savecore(8)
> (and anything else that reads the version string out of the kernel)
> would all have to be changed, because the `version' symbol would now
> point to the address of the string.  This is kind of a PITA for
> upgrade purposes.
> 


I've just had a quick look at what the compiler/assembler were generating.

If the sccs variable is initialized from a set of quoted chars, then the 
compiler doesn't put out any alignment directive.  If however, it is 
initialized from a string, then the string is aligned first.   The effect 
is that the sccs variable is not aligned, but the version variable is, so 
on the ARM (which aligns string constants) we get

vers.c

char ostype[] = "NetBSD";
char osrelease[] = "1.3I";
char sccs[8] = { ' ', ' ', ' ', ' ', '@', '(', '#', ')' };
char version[] =     "NetBSD 1.3I (SHARK) #8: Mon Jan 11 15:05:18 GMT 
1999\n
rearnsha@shark1:/work/rearnsha/netbsd/sys/arch/arm32/compile/SHARK\n";

which compiles to 

Disassembly of section .data:

00000000 <_ostype>:
   0:   4274654e
   4:   00004453

00000008 <_osrelease>:
   8:   49332e31
        ...

0000000d <_sccs>:		<---------- NOT ALIGNED
   d:   20202020
  11:   29232840
  15:   4e000000		<---------- 3 bytes of padding

00000018 <_version>:		<---------- ALIGNED
  18:   4274654e
  1c:   31204453

but changing vers.c to

char ostype[] = "NetBSD";
char osrelease[] = "1.3I";
char sccs[8] = "    @(#)";
char version[] =     "NetBSD 1.3I (SHARK) #8: Mon Jan 11 15:05:18 GMT 
1999\n    rearnsha@shark1:/work/rearnsha/netbsd/sys/arch/arm32/compile/SHAR
K\n";

which compiles to

Disassembly of section .data:

00000000 <_ostype>:
   0:   4274654e
   4:   00004453

00000008 <_osrelease>:
   8:   49332e31
   c:   00000000

00000010 <_sccs>:		<----------- NOW ALIGNED
  10:   20202020
  14:   29232840

00000018 <_version>:
  18:   4274654e
  1c:   31204453


Of course, if any platform aligns strings to a 16 byte boundary, then the 
sccs variable should be made 16 bytes long, with additional front padding.

Final note (probably stating the obvious), the size of the sccs variable 
must be bounded to prevent \0 termination.

R.

PS.  Why aren't these const char arrays?