[torch deploy] Add -rdynamic option explicitly to CMakeLists.txt (#75461)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75461
This flag is needed in the OSS example and it wasn't clear that it was needed because it wasn't explicitly used when linking to torch deploy for the tests.
Since torch deploy builds the tests using `python setup.py develop`, Pytorch actually sets this flag in the `CMAKE_EXE_LINKER_FLAGS` variable somewhere along the build. I had to print out all the variables used in the pytorch build to realize that I did not have this flag set in my OSS torch deploy example.
I think having it explicit for the tests makes it clear which flags are actually necessary in an open source environment.
**What is -rdynamic?**
This flag (also known as `--export-dynamic` at the linker level) signals that the library it is targeting should export its symbols to the dynamic table. In doing so, shared libraries that are opened using `dlopen` (which is what torch deploy uses to launch subinterpreters: https://www.internalfb.com/code/fbsource/[ff6d5cfcc2b3]/xplat/caffe2/torch/csrc/deploy/deploy.cpp?lines=254), will be able to reference symbols defined in the modules that launched them.
Without this flag, the symbols from the `torch::deploy` library that the subinterpreters need, remain `undefined`.
This leads to runtime errors like:
`/tmp/torch_XYZ: undefined symbol - torch::deploy::Etc.`
`/tmp/torch_XYZ` is a subinterpreter.
Test Plan:
Ran the tests in an OSS environment
`python torch/csrc/deploy/example/generate_examples.py`
`./build/bin/test_deploy`
Reviewed By: PaliC
Differential Revision: D35477135
fbshipit-source-id: 30bd2b9fadd36b2a32066a52cda5b746d597e99f
(cherry picked from commit efb8030d41c4f657820d0121c5a2de2fa2e0b240)