This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/70755] New: [ARM] excessive struct alignment for globals
- From: "bruck.michael at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 21 Apr 2016 16:34:42 +0000
- Subject: [Bug c++/70755] New: [ARM] excessive struct alignment for globals
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70755
Bug ID: 70755
Summary: [ARM] excessive struct alignment for globals
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bruck.michael at googlemail dot com
Target Milestone: ---
Discussion at the end
$ arm-none-eabi-g++.exe -std=c++11 -Ofast -c align_foo.cpp -S -fdata-sections
$ cat align_foo.cpp
struct S
{
bool val;
};
S s1; // 32 bit align
alignas(S) S s2; // 8 bit align
struct alignas(bool) SA
{
bool val;
};
struct alignas(long long) SB
{
bool val;
};
SA sa; // 32 bit align
SB sb; // 64 bit align
$ cat align_foo.s
.cpu arm7tdmi
.fpu softvfp
.eabi_attribute 23, 1
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 2
.eabi_attribute 34, 0
.eabi_attribute 18, 4
.arm
.syntax divided
.file "align_foo.cpp"
.global sb
.global sa
.global s2
.global s1
.section .bss.s1,"aw",%nobits
.align 2
.type s1, %object
.size s1, 1
s1:
.space 1
.section .bss.s2,"aw",%nobits
.type s2, %object
.size s2, 1
s2:
.space 1
.section .bss.sa,"aw",%nobits
.align 2
.type sa, %object
.size sa, 1
sa:
.space 1
.section .bss.sb,"aw",%nobits
.align 3
.type sb, %object
.size sb, 8
sb:
.space 8
.ident "GCC: (GNU Tools for ARM Embedded Processors) 5.3.1 20160307
(release) [ARM/embedded-5-branch revision 234589]"
---
The code comments show how the respective variable was aligned in the assembly
output.
a) s1 should be byte aligned.
b) alignas works around the problem but only for s2 but not SA. Even though the
compiler clearly accepts the alignment increase for SB.
c) sb blocks 8 bytes, rather then just being 8 byte aligned
"-fdata-sections" is for clarity, without it we get basically the same,
although for sa the alignment could be unintentional:
...
.bss
.align 3
.type sb, %object
.size sb, 8
sb:
.space 8
.type sa, %object
.size sa, 1
sa:
.space 1
.type s2, %object
.size s2, 1
s2:
.space 1
.space 2
.type s1, %object
.size s1, 1
s1:
.space 1