Could I do this code without posix_memalign?

121 views Asked by At

I have this code in polybench.c (from the Polybench benchmark suite):

static void * xmalloc (size_t num)
{
  void* new = NULL;
  int ret = posix_memalign (&new, 32, num);
  if (! new)
  {
    fprintf (stderr, "[PolyBench] posix_memalign: cannot allocate memory");
    exit (1);
  }
 return new; 
}


 void* polybench_alloc_data(unsigned long long int n, int elt_size)
 {
   /// FIXME: detect overflow!
    size_t val = n;
    val *= elt_size;
    void* ret = xmalloc (val);
    return ret;
  }

LLVM Interpreter deals with posix_memalign as an external function. I need to remove posix_memalign without getting a segmentation fault. Is this possible? If yes, how could I do that? If no, how could I solve this problem, without using malloc, valloc, mmalloc, and aligned_alloc? As all of these functions gave me the same error.

The error message:

LLVM ERROR: Tried to execute an unknown external function: posix_memalign
0

There are 0 answers