edA-qa mort-ora-y via llvm-dev
2018-Apr-18 19:04 UTC
[llvm-dev] A struct {i8,i64} has size == 12, clang says size 16
I'm creating a struct of `{i8,i64}` and `DataLayout::getTypeAllocSize` is returning `12`. `getStructLayout` also gives an `4` offset for the second element. The native ABI, and clang, for the same type are producing a size of 16, with an alignment of 8, for the second element. This is for the system triple "x86_64-linux-gnu" What could be causing this difference in alignment and how can I fix it? I'm verifying the native ABI with: // clang -emit-llvm ll_struct_arg.c -S -o /dev/tty #include <stddef.h> typedef struct vpt_data { _Bool c; long int b; } vpt_data; int main() { vpt_data v; vpt_test(v); auto a = sizeof(v); auto off = offsetof(vpt_data,b); } 16 is stored to `a` and 8 to `off`. -- edA-qa mort-ora-y http://mortoray.com/ Creator of the Leaf language http://leaflang.org/ Streaming algorithms, AI, and design on Twitch https://www.twitch.tv/mortoray Twitter edaqa
Martin J. O'Riordan via llvm-dev
2018-Apr-18 19:16 UTC
[llvm-dev] A struct {i8, i64} has size == 12, clang says size 16
This is because of alignment requirements. The alignment for the 'i64' is 8, so assuming the compiler is required to insert 7 bytes of padding between the first member and the second to ensure that the second 'i64' member is validly aligned. You can use '__attribute__((packed))' to cause the compiler to remove the padding, and the size will become '9'. MartinO -----Original Message----- From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of edA-qa mort-ora-y via llvm-dev Sent: 18 April 2018 20:05 To: LLVM Developers Mailing List <llvm-dev at lists.llvm.org> Subject: [llvm-dev] A struct {i8,i64} has size == 12, clang says size 16 I'm creating a struct of `{i8,i64}` and `DataLayout::getTypeAllocSize` is returning `12`. `getStructLayout` also gives an `4` offset for the second element. The native ABI, and clang, for the same type are producing a size of 16, with an alignment of 8, for the second element. This is for the system triple "x86_64-linux-gnu" What could be causing this difference in alignment and how can I fix it? I'm verifying the native ABI with: // clang -emit-llvm ll_struct_arg.c -S -o /dev/tty #include <stddef.h> typedef struct vpt_data { _Bool c; long int b; } vpt_data; int main() { vpt_data v; vpt_test(v); auto a = sizeof(v); auto off = offsetof(vpt_data,b); } 16 is stored to `a` and 8 to `off`. -- edA-qa mort-ora-y http://mortoray.com/ Creator of the Leaf language http://leaflang.org/ Streaming algorithms, AI, and design on Twitch https://www.twitch.tv/mortoray Twitter edaqa _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reid Kleckner via llvm-dev
2018-Apr-18 19:37 UTC
[llvm-dev] A struct {i8, i64} has size == 12, clang says size 16
It sounds like your DataLayout may not match clang's for x86_64-linux. What does it say about the alignment of i64? On Wed, Apr 18, 2018 at 12:05 PM edA-qa mort-ora-y via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I'm creating a struct of `{i8,i64}` and `DataLayout::getTypeAllocSize` > is returning `12`. `getStructLayout` also gives an `4` offset for the > second element.> The native ABI, and clang, for the same type are producing a size of 16, > with an alignment of 8, for the second element.> This is for the system triple "x86_64-linux-gnu"> What could be causing this difference in alignment and how can I fix it?> I'm verifying the native ABI with:> // clang -emit-llvm ll_struct_arg.c -S -o /dev/tty > #include <stddef.h>> typedef struct vpt_data { > _Bool c; > long int b; > } vpt_data;> int main() { > vpt_data v; > vpt_test(v); > auto a = sizeof(v); > auto off = offsetof(vpt_data,b); > }> 16 is stored to `a` and 8 to `off`.> -- > edA-qa mort-ora-y > http://mortoray.com/> Creator of the Leaf language > http://leaflang.org/> Streaming algorithms, AI, and design on Twitch > https://www.twitch.tv/mortoray> Twitter > edaqa> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
edA-qa mort-ora-y via llvm-dev
2018-Apr-18 20:42 UTC
[llvm-dev] A struct {i8, i64} has size == 12, clang says size 16
The getABITypeAlignment <http://llvm.org/doxygen/classllvm_1_1DataLayout.html#a43556646ad677cfdcfde2b031fa59173> function is returning only 4 for an i64, which would explain the discrepency. I double-checked my triple again and ensured it's the same one as clang. That's apparently not enough. What else do I need to adjust to get the platform default ABI? On 18/04/18 21:37, Reid Kleckner wrote:> It sounds like your DataLayout may not match clang's for x86_64-linux. What > does it say about the alignment of i64? > On Wed, Apr 18, 2018 at 12:05 PM edA-qa mort-ora-y via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I'm creating a struct of `{i8,i64}` and `DataLayout::getTypeAllocSize` >> is returning `12`. `getStructLayout` also gives an `4` offset for the >> second element. >> The native ABI, and clang, for the same type are producing a size of 16, >> with an alignment of 8, for the second element. >> This is for the system triple "x86_64-linux-gnu" >> What could be causing this difference in alignment and how can I fix it? > >> I'm verifying the native ABI with: >> // clang -emit-llvm ll_struct_arg.c -S -o /dev/tty >> #include <stddef.h> >> typedef struct vpt_data { >> _Bool c; >> long int b; >> } vpt_data; >> int main() { >> vpt_data v; >> vpt_test(v); >> auto a = sizeof(v); >> auto off = offsetof(vpt_data,b); >> } > >> 16 is stored to `a` and 8 to `off`. >> -- >> edA-qa mort-ora-y >> http://mortoray.com/ >> Creator of the Leaf language >> http://leaflang.org/ >> Streaming algorithms, AI, and design on Twitch >> https://www.twitch.tv/mortoray >> Twitter >> edaqa > >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- edA-qa mort-ora-y http://mortoray.com/ Creator of the Leaf language http://leaflang.org/ Streaming algorithms, AI, and design on Twitch https://www.twitch.tv/mortoray Twitter edaqa -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180418/d47eb64b/attachment.html>
edA-qa mort-ora-y via llvm-dev
2018-Apr-18 20:47 UTC
[llvm-dev] A struct {i8, i64} has size == 12, clang says size 16
I think I see a potential issue. My ExecutionEngine setup may not be using the same target as my object code emitting, and in this test case I'm running in the ExecutionEngine. I'll go over this code to ensure I'm creating the same triple and see if that helps -- I'm assuming it will, since I can't imagine the exact same triple with clang would produce a different layout. On 18/04/18 21:37, Reid Kleckner wrote:> It sounds like your DataLayout may not match clang's for x86_64-linux. What > does it say about the alignment of i64? > On Wed, Apr 18, 2018 at 12:05 PM edA-qa mort-ora-y via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I'm creating a struct of `{i8,i64}` and `DataLayout::getTypeAllocSize` >> is returning `12`. `getStructLayout` also gives an `4` offset for the >> second element. >> The native ABI, and clang, for the same type are producing a size of 16, >> with an alignment of 8, for the second element. >> This is for the system triple "x86_64-linux-gnu" >> What could be causing this difference in alignment and how can I fix it? > >> I'm verifying the native ABI with: >> // clang -emit-llvm ll_struct_arg.c -S -o /dev/tty >> #include <stddef.h> >> typedef struct vpt_data { >> _Bool c; >> long int b; >> } vpt_data; >> int main() { >> vpt_data v; >> vpt_test(v); >> auto a = sizeof(v); >> auto off = offsetof(vpt_data,b); >> } > >> 16 is stored to `a` and 8 to `off`. >> -- >> edA-qa mort-ora-y >> http://mortoray.com/ >> Creator of the Leaf language >> http://leaflang.org/ >> Streaming algorithms, AI, and design on Twitch >> https://www.twitch.tv/mortoray >> Twitter >> edaqa > >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- edA-qa mort-ora-y http://mortoray.com/ Creator of the Leaf language http://leaflang.org/ Streaming algorithms, AI, and design on Twitch https://www.twitch.tv/mortoray Twitter edaqa
Reasonably Related Threads
- A struct {i8, i64} has size == 12, clang says size 16
- A struct {i8, i64} has size == 12, clang says size 16
- A struct {i8, i64} has size == 12, clang says size 16
- Why does clang do a memcpy? Is the cast not enough? (ABI function args)
- Why does clang do a memcpy? Is the cast not enough? (ABI function args)