Assembly functions have same name with suffix ..0 and ..1

Viewed 63

I'm looking at the assembly of some compiled code, and while searching for a particular function, I found two, sharing the same name:

000000000042da10 <my_function..0>:

000000000042dc50 <my_function..1>:

There is only one declaration of this function within the C code. I notice both of these functions are called in the assembly code in different places, with slightly different arguments.

This is a non-gcc compiler, but I'm not sure which (I've just been told this wasn't compiled with gcc). I know that it is compiled with maximum optimization (-O3), so I'm curious if this is the compiler optimizing for integer-constant arguments and creating the function twice, once for each time it's called.

What reason is there for two of the same function to exist within a program?

1 Answers

I'm curious if this is the compiler optimizing for integer-constant arguments and creating the function twice, once for each time it's called.

Very likely. This optimization is called function cloning and is one way to achieve constant propagation through function calls without inlining. I couldn't immediately find a comprehensive reference but there are some notes at Influencing function cloning/duplication/constant propagation in gcc. (If you google, try searching for "function cloning compiler" or "procedure cloning compiler" as otherwise there are a lot of hits for a molecular biology concept called "functional cloning".)

Although the link above is for gcc, other compilers support this too. The reference to -O3 suggests that the compiler in question for you might be clang, and it certainly has such a feature.

Related