I'm trying to compile a specific function with no optimization using clang
, in order to prevent certain security-related calls to memset()
from being optimized away.
According to the documentation that can be found here, there exists an optnone
attribute which allows this. Also, an example can be found here.
Unfortunately, (at least on the below version of clang
, on OS X 10.9.5), this is causing compiler warnings, as can be seen 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 caused an unknown pragma ignored
warning.
Does anyone know why this isn't working? Did I miss a prerequisite for using this feature? (I also tried using various different -std=
parameters, including c11
, gnu11
, c99
, and gnu99
, but nothing changed the behavior.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…