I am trying to compile a specific function without optimization using clang to prevent the optimization of certain security related calls from memset() .
According to the documentation that can be found here , there is an optnone attribute that allows this. In addition, an example can be found here .
Unfortunately (at least in the clang version below, in OS X 10.9.5), this causes compiler warnings, as shown in this example:
$ clang --version Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin13.4.0 Thread model: posix $ cat optnone.c #include <string.h> __attribute__((optnone)) void* always_memset(void *b, int c, size_t len) { return memset(b, c, len); } $ clang -Wall -O3 -c -o optnone.o optnone.c optnone.c:3:16: warning: unknown attribute 'optnone' ignored [-Wattributes] __attribute__((optnone)) void* ^ 1 warning generated.
I also tried using #pragma clang optimize off , but this triggered an unknown pragma ignored .
Does anyone know why this is not working? Did I miss the prerequisite for using this function? (I also tried using various different -std= options, including c11 , gnu11 , c99 and gnu99 , but nothing changed the behavior.)
source share