0

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
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
R.Omar
  • 645
  • 1
  • 6
  • 18
  • 1
    if you have access to c11 there is [`aligned_alloc`](https://en.cppreference.com/w/c/memory/aligned_alloc) – Mgetz Jun 11 '18 at 13:38
  • I tried them with the same error. The problem is from my interpreter which is not stable, but I have to use it now. – R.Omar Jun 11 '18 at 13:40
  • 1
    You asked this question yesterday by my time (it may still be today in SO time). When I duplicated the question to one which shows how to ensure your memory is aligned without using `posix_memalign()`, you deleted the question. One other person wasn’t convinced of the duplicate but wasn’t sure what you’re asking either. You need to decide (deduce) why the code uses `posix_memalign()`. You may be able to simply use `malloc()`. You may have to manually align the address used. – Jonathan Leffler Jun 11 '18 at 14:05
  • Sorry for my multiple questions, I am not expert in memory alignment. I removed the question because I thought it was not mentioned clearly and to try other solutions. The code is standard polybench. – R.Omar Jun 11 '18 at 14:30
  • JFTR, the previous proposed duplicate is [How to allocate aliigned memory using only the standard library?](https://stackoverflow.com/questions/227897/how-to-allocate-aligned-memory-only-using-the-standard-library/227900#227900) – Jonathan Leffler Jun 11 '18 at 14:38

0 Answers0