Search code examples
c++exceptionstackstack-unwindinguncaughtexceptionhandler

Does exception handling work if the throw block and landing pad are in diffrent section?


Consider below case, Which ends up crashing with unwinder complaining _URC_END_OF_STACK and no handler found in _UA_SEARCH_PHASE

class array{
public: 
 int foo() {
      throw 5;
  }
};

int main() {
  array a0;
  try {
    a0.foo();  
  }
  catch(const int )
  {}
}

For above case my linker puts foo in .text._ZN5array3fooEv section and everything else in .text section? which is not case with llvm ld.lld(all in .text).


Solution

  • main -> .text foo -> .text._ZN5array3fooEv (linker not merging them)

    Answer depends on your unwind library, for this case mylibUnwind.a checks for bounds of .text and foo not being in .text results in _URC_END_OF_STACK.