[cfe-dev] alignment of internal Global Values

Arnaud Allard de Grandmaison Arnaud.AllardDeGrandMaison at dibcom.com
Mon Mar 8 09:24:47 PST 2010


Hi,

I am a bit puzzled by the alignement set on GlobalValues for which the only differences should be the linkage. I get the same behaviour with llvm-2.6 or with the svn head, using x86 as the target.

The following C code can be used to reproduce it:

short GV[] = { 1,2,3,4,5,6,7,8 };

int test(unsigned a)
{
  static short internalGV[] = { 1,2,3,4,5,6,7,8};

  return internalGV[a]++;
}

The IR output from clang looks like:
@GV = global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8], align 2
@test.internalGV = internal global [8 x i16] [i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8]

Note the alignement specifier for GV, which does not show up for internalGV. The issue will happen later on, when the backend will choose some default alignement, which may even depend on the size of the global value : the size of the data section will depend on the visibility of its data. For example, running the above example with 16 elements in GV & internalGV will make a big difference in the x86 .S file : GV will still be 2 bytes aligned, whereas internalGV will be 16bytes aligned.

I can not see any obvious reason why this could be the desired behaviour, so I attached a patch to fix this.

Best regards,
--
Arnaud de Grandmaison
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100308/2e4ead1e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: internalGV-alignment.patch
Type: application/octet-stream
Size: 320 bytes
Desc: internalGV-alignment.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100308/2e4ead1e/attachment.obj>


More information about the cfe-dev mailing list