News for hackers. Stuff that matters.
Re:A bug story: data alignment on x86 by stephencanon on Monday November 07, 2016 @11:33AM (#12892326)
This is documented as not working[1] in all but the most recent GCC versions. E.g. gcc-5.4 documents:

> "The aligned attribute can only increase the alignment; but you can decrease it by specifying packed as well. See below."

but gcc-6.2 documentation adds:

> "When used as part of a typedef, the aligned attribute can both increase and decrease alignment, and specifying the packed attribute generates a warning."

FWIW, Clang has supported reducing alignment in this fashion for a few years now.

[1] it's possible (likely, even) that it has been working for a while but the documentation was only recently brought up to date; I haven't investigated too carefully.

Re:A bug story: data alignment on x86 by qb45 on Monday November 07, 2016 @03:05PM (#12894514)
Must have been supported for a while because this stuff is even used in Linux:

  #define __packed2__     __attribute__((packed, aligned(2)))
  
  /*
   * SystemV FS comes in two variants:
   * sysv2: System V Release 2 (e.g. Microport), structure elements aligned(2).
   * sysv4: System V Release 4 (e.g. Consensys), structure elements aligned(4).
   */
  
  struct sysv2_super_block {
          __fs16  s_isize;                /* index of first data zone */
          __fs32  s_fsize __packed2__;    /* total number of zones of this fs */
http://lxr.free-electrons.com/source/include/linux/sysv_fs.h...
Re:A bug story: data alignment on x86 by codys on Monday November 07, 2016 @03:08PM (#12894537)
Note the use of `packed`. `packed` causes the alignment to be set as small as possible (1 byte). The aligned(2) that follows then increases the alignment from 1 byte to 2 bytes.
Re:A bug story: data alignment on x86 by qb45 on Monday November 07, 2016 @03:20PM (#12894660)
Yeah, you're right. Add packed then if you want but I swear the code I posted works on 5.4 as it is.