[cfe-dev] Alignment problems in Clang's internal data structures?

mats petersson mats at planetcatfish.com
Tue Feb 17 02:50:39 PST 2015


It would probably be a relatively simple feature to add a private
system call to an x86-system [in Linux, doing this for Windows or
MacOS would be noticeably harder as it is not so easy to add code to
the OS there] to set he AM flag in CR0 and AC flag in EFLAGS, which
would cause unaligned accesses to trap in x86 (only in usermode). Of
course, you would have to then rely on for example libc and libc++ etc
to have correct alignment accesses...

--
Mats

On 17 February 2015 at 09:42, Renato Golin <renato.golin at linaro.org> wrote:
> On 17 February 2015 at 00:38, Ahmed Bougacha <ahmed.bougacha at gmail.com> wrote:
>>   std::size_t Size = sizeof(DeclRefExpr);
>>   if (...)
>>     Size += sizeof(...);
>>   ...
>>   void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>());
>
> This sounds wrong. You should have something like:
>
>    std::size_t Size = sizeof(DeclRefExpr);
>    std::size_t Align = llvm::alignOf<DeclRefExpr>();
>    if (...) {
>      Size += sizeof(...);
>      Align = std::max(Align, llvm::alignOf<...>());
>    }
>    ...
>    void *Mem = Context.Allocate(Size, Align);
>
>
>> UBSan's alignment sanitizer would be *very* useful here, but my
>> understanding is, ARM isn't currently supported, and running it on X86
>> is futile (at least x86_64, maybe i386 could reproduce though; that's
>> on my todo list.)
>
> It'd be great to have UBSAN working on ARM, at least that small part. :)
>
> But that also mean we'd have to actually run it as a buildbot to make
> sure we don't re-introduce the pattern.
>
> Another thing we could do is to run as many santisers as we can during
> releases, at least when running the test-suite. But first, I need to
> set this up and actually run it with all SANs and fix all bugs before
> the next release (3.7). We'll get there, eventually. :)
>
> cheers,
> --renato
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list