[cfe-dev] Why a few std::string function definitions are not in the object code?

Xiaolong Tang xiaolong.snake at gmail.com
Fri Feb 18 13:18:38 PST 2011


Hi all, 

I am working on whole-program analysis, and expect the final bitcode
to have all function definitions. When I examined the final bitcode of
a simple program using the standard string, I found that some function
defintions are missing. Particularly I am interested in the following
function definitions which are missing in the final bitcode. 

  // string constructor
  declare void @_ZNSsC1Ev(%"struct.std::string")
  // After name demangling 
  declare void @std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()(%"struct.std::string")

  // allocator constructor
  declare void @_ZNSaIcEC1Ev(%"struct.std::allocator<char>") nounwind
  // After name demangling 
  declare void @std::allocator<char>::allocator()(%"struct.std::allocator<char>") nounwind

  // string constructor from a C string
  declare void @_ZNSsC1EPKcRKSaIcE(%"struct.std::string", i8, %"struct.std::allocator<char>")
  // After name demangling 
  declare void @std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)(%"struct.std::string", i8, %"struct.std::allocator<char>")

  // string assignment
  declare %"struct.std::string" @_ZNSsaSERKSs(%"struct.std::string", %"struct.std::string")
  // After name demangling 
  declare %"struct.std::string" @std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)(%"struct.std::string", %"struct.std::string")

So, I am wondering why it is so? Specifically, I have a few questions. 

1. Is the above compilation result related to the compilation mode and
instantiation mechanism of C++ templates?

2. Does clang (or linker) provide any way to force these function
   definitions to be present in the final bitcode? 

Thanks, 
Xiaolong
 



More information about the cfe-dev mailing list