CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

always_inline ignored at O0 #149

Closed arichardson closed 6 years ago

arichardson commented 7 years ago

Test case:

#include <iostream>
int main() {
  std::cout << "Hello world" << std::endl;
  return 0;
}

Results in

/local/scratch/alr48/cheri/output/sdk256/bin/ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__recommend(unsigned long)
>>> referenced by /local/scratch/alr48/cheri/cheri-tests/minimal_cxx/helloworld_iostream.cpp
>>>               minimal_cxx/CMakeFiles/cxx_helloworld_iostream_dynamic.dir/helloworld_iostream.cpp.o:(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char))

/local/scratch/alr48/cheri/output/sdk256/bin/ld.lld: error: undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__recommend(unsigned long)
>>> referenced by /local/scratch/alr48/cheri/cheri-tests/minimal_cxx/helloworld_iostream.cpp
>>>               minimal_cxx/CMakeFiles/cxx_helloworld_iostream_dynamic.dir/helloworld_iostream.cpp.o:(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char))
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)

std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__recommend(unsigned long) is defined as _LIBCPP_INLINE_VISIBILITY which expands to __attribute__ ((__visibility__("hidden"), __always_inline__))

It seems like we are emitting call instructions that cannot be handled by the inliner at O0: %69 = call i8 addrspace(200)* @llvm.cheri.cap.offset.set(i8 addrspace(200)* %68, i64 ptrtoint (i64 (i64)* @_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE11__recommendEm to i64))

The test links successfully at -O2.

arichardson commented 6 years ago

This is broken again with cap-table since LLVM doesn't understand how to inline AS200 call instructions.