-1

I use polybench kernels. In polybench.c, code has a line as follows:

  int ret = posix_memalign (&new, 32, num);

This line makes problem with lli interpreter. I tries to use malloc instead, but I have the same error

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

Is there any other function could be used without having this problem?

apaderno
  • 28,547
  • 16
  • 75
  • 90
R.Omar
  • 645
  • 1
  • 6
  • 18

1 Answers1

0

You will not be surprised to hear that posix_memalign() is standardized as part of POSIX, not part of standard C. As such, providing that function is not a requirement on conforming C implementations. On the other hand, as part of POSIX, it is widely available.

malloc() promises to return a pointer to memory aligned properly for an object of any type. I'm not sure why you want to ensure an even stronger alignment requirement, but your next best bet for doing so is the aligned_alloc() function, which is standard C since C2011. If your C library conforms to C2011, then you can replace your posix_memalign() call with

#include <stdlib.h>
#include <errno.h>

// ...

new = aligned_alloc(32, num);
int ret = (new ? 0 : errno);

If you don't have aligned_alloc(), either, then your implementation may provide other alternatives, but none of them are standard.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • I used aligned_alloc , the problem is that LLVM compiler does not accept them . – R.Omar Jul 31 '17 at 08:10
  • This does not appear to be a compiler problem, @R.Omar. Rather it looks like a problem of what functions are provided by your system's C library. You cannot call functions that are not, in fact, available. You may find useful information here: [How can I use C++ 11 features in Clang?](https://stackoverflow.com/q/10408849/2402272) (even though it's about C++, not C), but I cannot usefully run down a list of possible non-standard alternatives. Check your system's / implementation's documentation for that kind of information. – John Bollinger Jul 31 '17 at 14:26