Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Dec 2015 12:55:24 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 205663] clang++ 3.7.1 gets Bus Errors during compilation on arm that has SCTLR bit[1]==1 (alignment required)
Message-ID:  <bug-205663-8@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D205663

            Bug ID: 205663
           Summary: clang++ 3.7.1 gets Bus Errors during compilation on
                    arm that has SCTLR bit[1]=3D=3D1 (alignment required)
           Product: Base System
           Version: 11.0-CURRENT
          Hardware: arm
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs@FreeBSD.org
          Reporter: markmi@dsl-only.net

# more /tmp/main-5dac8d.cpp
# 1 "<built-in>"
# 1 "main.cc"
template <class _Tp, class _Up>
struct __has_rebind
{
    template <class _Xp> static char __test(typename _Xp::template rebind<_=
Up>*
=3D 0);
};

int
main ()
{
return 0;
}

# more /tmp/main-5dac8d.sh
# Crash reproducer for FreeBSD clang version 3.7.1 (tags/RELEASE_371/final
255217) 20151225
# Driver args: "--driver-mode=3Dg++" "main.cc"
# Original command:  "/usr/bin/clang++" "-cc1" "-triple"
"armv6k--freebsd11.0-gnueabi" "-emit-obj" "-mrelax-all" "-disable-free"
"-main-file-name" "main.cc" "-mrelocation-model" "static" "-mthread-model"
"posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases"
"-target-cpu" "arm1176jzf-s" "-target-feature" "+soft-float" "-target-featu=
re"
"+soft-float-abi" "-target-feature" "-neon" "-target-feature" "-crypto"
"-target-abi" "aapcs-linux" "-msoft-float" "-mfloat-abi" "soft"
"-dwarf-column-info" "-resource-dir" "/usr/bin/../lib/clang/3.7.1"
"-internal-isystem" "/usr/include/c++/v1" "-fdeprecated-macro"
"-fdebug-compilation-dir" "/root/c_tests" "-ferror-limit" "19"
"-fmessage-length" "338" "-mstackrealign" "-fno-signed-char"
"-fobjc-runtime=3Dgnustep" "-fcxx-exceptions" "-fexceptions"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/main-e20b38.o"
"-x" "c++" "main.cc"
 "/usr/bin/clang++" "-cc1" "-triple" "armv6k--freebsd11.0-gnueabi" "-emit-o=
bj"
"-mrelax-all" "-disable-free" "-main-file-name" "main.cc" "-mrelocation-mod=
el"
"static" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose"
"-mconstructor-aliases" "-target-cpu" "arm1176jzf-s" "-target-feature"
"+soft-float" "-target-feature" "+soft-float-abi" "-target-feature" "-neon"
"-target-feature" "-crypto" "-target-abi" "aapcs-linux" "-msoft-float"
"-mfloat-abi" "soft" "-dwarf-column-info" "-fdeprecated-macro" "-ferror-lim=
it"
"19" "-fmessage-length" "338" "-mstackrealign" "-fno-signed-char"
"-fobjc-runtime=3Dgnustep" "-fcxx-exceptions" "-fexceptions"
"-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c++" "main-5dac8d.c=
pp"

The code involved is from lib/AST/Type.cpp :

DependentTemplateSpecializationType::DependentTemplateSpecializationType(
                        ElaboratedTypeKeyword Keyword,
                        NestedNameSpecifier *NNS, const IdentifierInfo *Nam=
e,
                        unsigned NumArgs, const TemplateArgument *Args,
                        QualType Canon)
 : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, t=
rue,
                   /*VariablyModified=3D*/false,
                   NNS && NNS->containsUnexpandedParameterPack()),
   NNS(NNS), Name(Name), NumArgs(NumArgs) {
 assert((!NNS || NNS->isDependent()) &&
        "DependentTemplateSpecializatonType requires dependent qualifier");
 for (unsigned I =3D 0; I !=3D NumArgs; ++I) {
   if (Args[I].containsUnexpandedParameterPack())
     setContainsUnexpandedParameterPack();

   new (&getArgBuffer()[I]) TemplateArgument(Args[I]);
 }
}

The failing code is for the "placement new" in the loop:

A) &getArgBuffer()[I] is not always an address for which the vst1.64
instruction gets an aligned address.

but. . .

B) TemplateArgument(Args[I])'s copy construction activity has code (such as=
 the
vst1.64) requiring a specific alignment when SCTLR bit[1]=3D=3D1.

C) Nothing here has any explicitly packed data structures.

As for (A):

class DependentTemplateSpecializationType :
 public TypeWithKeyword, public llvm::FoldingSetNode {
. . .
 const TemplateArgument *getArgBuffer() const {
   return reinterpret_cast<const TemplateArgument*>(this+1);
 }
 TemplateArgument *getArgBuffer() {
   return reinterpret_cast<TemplateArgument*>(this+1);
 }

clang++ is over-allocating the space for the
DependentTemplateSpecializationType objects and using the extra space that =
is
afterwards to hold (a somewhat C-style array of) TemplateArgument instances.
But the logic for this does nothing explicit about alignment of the
TemplateArgument instance pointers, not even partially via explicitly
controlling sizeof(DependentTemplateSpecializationType).

sizeof(TemplateArgument) also needs to be controlled in order to have the
notation &getArgBuffer()[I] maintain alignment in its results when
&getArgBuffer()[0] is well aligned.

The existing code does not explicitly force any specific minimum
TemplateArgument alignment, other than 1. (Implicit ABI rules might get some
alignment --if some of those rules are being applied.

Separately there is the issue that the code produced did not treat the poin=
ters
returned from getArgBuffer() methods as "opaque pointer" examples but they =
are.
Having compiled with -fmax-type-align=3D4 the code should have not have req=
uired
8 byte alignment (vst1.64). It should have produced code that required 4 (o=
r 2
or 1). Quoting for -fmax-type-align=3D?:

Instruct the code generator to not enforce a higher alignment than the given
number (of bytes) when accessing memory via an opaque pointer or reference

Those pointers certainly are opaque and should be treated as such. The
"reinterpret_cast" use is a big clue that clang++ should respect.

In other words: I see two clang++ defects in the overall evidence, one of w=
hich
directly leads to the Bus Errors being possible.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-205663-8>