[llvm-dev] A struct {i8, i64} has size == 12, clang says size 16
edA-qa mort-ora-y via llvm-dev
llvm-dev at lists.llvm.org
Thu Apr 19 02:47:47 PDT 2018
I think I've figured it out now. The setup of my triple/datalayout for
the module was apparently not correct. It likely worked mainly to this
point since the default dataLayout is close to the host ABI, but not quite.
I have the following setup, which appears to work:
module = new llvm::Module( "test", *llvm_context );
module->setTargetTriple( platform::target->triple );
//x86_64-pc-linux-gnu
std::string err_str;
auto triple_str = llvm::Triple::normalize(platform::target->triple);
llvm::Target const * target = llvm::TargetRegistry::lookupTarget(
triple_str, err_str );
STATE_CHECK( target, err_str ); //assert target != nullptr
auto targetMachine = target->createTargetMachine(triple_str,
"generic", "", llvm::TargetOptions{},
llvm::Optional<llvm::Reloc::Model>());
module->setDataLayout( targetMachine->createDataLayout() );
I'll be testing on Mac later today, but I suspect it has the same data
layout.
On 19/04/18 11:37, mats petersson wrote:
> What exactly is your alignment settings in your LLVM struct?
>
> Something like this would tell you the alignment of "something".
> const llvm::DataLayout dl(theModule);
> size_t size = dl.getPrefTypeAlignment(something);
>
> IIn "my" compiler, I don't do anything special to align structs, so
> it's plausibly your specific data-layout that says that i64 only needs
> aligning to 32-bits (and clang adjusts it because "it can", by adding
> extra padding elements) - or you're using different targets (or
> settings for the targets)
>
> --
> Mats
> On 18 April 2018 at 21:47, edA-qa mort-ora-y via llvm-dev
> <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>
> 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 <mailto: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 <mailto:llvm-dev at lists.llvm.org>
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> <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
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> <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/20180419/54b4f1ad/attachment.html>
More information about the llvm-dev
mailing list