Hello,
For background, I'm writing a pass and would like to find all instructions that could allocate memory, but this question mainly concerns strdup.
I'm seeing that calls to strdup are getting replaced by calls to __strdup when I compile with -O2. Can anyone tell me why and what the difference is?
The replacement is a minor issue for me because isAllocationFn doesn't return true for calls to __strdup (but it does for strdup). My current workaround is to check the name of every called function.
Also, if there are any other functions that are replaced (like strdup is with __strdup), that'd be useful information to me.
My test case is [1]. I'm getting the bitcode using Module.print inside my pass. [2] is without -O2 and [3] is with -O2. My pass is in CodeGen in case that is relevant.
Thanks,
Scott
[1] test.c - Pastebin.com
[2] without -O2 - Pastebin.com
[3] with -O2 - Pastebin.com
Maybe this has been asked before but it's difficult to Google 
Hi Scott,
For background, I'm writing a pass and would like to find all instructions
that could allocate memory, but this question mainly concerns strdup.
I'm seeing that calls to strdup are getting replaced by calls to __strdup
when I compile with -O2. Can anyone tell me why and what the difference is?
The replacement is a minor issue for me because isAllocationFn doesn't
return true for calls to __strdup (but it does for strdup). My current
workaround is to check the name of every called function.
Also, if there are any other functions that are replaced (like strdup is
with __strdup), that'd be useful information to me.
My test case is [1]. I'm getting the bitcode using Module.print inside my
pass. [2] is without -O2 and [3] is with -O2. My pass is in CodeGen in case
that is relevant.
I don't think it's LLVM that's replacing the strdup call with
__strdup, but the header files in your standard library.
On my machine, /usr/include/string.h includes
/usr/include/x86_64-linux-gnu/bits/string2.h when __OPTIMIZE__ is
defined (which would happen at -O2 but not -O0). string2.h then
defines strdup(s) to __strdup(s) (line 1278 on my machine). string.h
says this can be inhibited by defining __NO_STRING_INLINES.
- Hans