Search code examples
c++g++stack-overflowstack-smash

Why mi code compiles ok in SSE2 but not in ARM(no NEON)?


Well, this is the problem: i was trying to compile my altoin in ARM and i get stack smashing error: . Aborted. then, i try to compile exactly the same code but with SSE2 flags in my other linux computer, and it success. if i disable stack protection on the makefile im able to compile. But isnt good idea disable that. I try use older GCC, but nothing, is the same. my question is, why im able to compile in SSE2 instructions but no in ARM? This is the code that create a warning on the build logs:

double GaussianQuad_N(double func(const double), const double a2, const double b2, int NptGQ)
{
    double s = 0.0;
    double x[NptGQ], w[NptGQ];

    gauleg(a2, b2, x, w, NptGQ);
    for (int j = 1 ; j <= NptGQ ; j++)
        s += w[j] * func(x[j]);

    return s;
}

i get:

warning: stack protector not protecting local variables: variable length buffer [-Wstack-protecto ] double GaussianQuad_N(double func(const double)


Solution

  • double x[NptGQ], w[NptGQ]; variable length arrays are not standard in C++. Use std:: vector in C++

    std::vector<double> x(NptGQ), w(NptGQ);
    gauleg(a2, b2, x.data(), w.data(), NptGQ);