I meet a odd problem. The native library cannot operate openssl correctly with unity on linux.
At gdb, I can see the problem is openssl cannot return correct info about cipher data. Although the ssl3_ciphers is allocated at0x7fffc93e4240, but it try to return an corrupted address at 0x1db9438.
Finally we found unity also contains a symbol ssl3_ciphers (I guess unity built openssl internal). Because in linux, when the name conflict in executable with shared library, the first loaded symbol will be used.
Does unity linux have any load option to handle this. Or I can only rebuilt openssl with a different global namespace
Update:
Rename variable in openssl seems not work.
1 Like
Finally, I solve this. Just make a note for someone may meet this bug.
- global variable/function/symbol only have one instance in linux elf format (even in shared library)
- unity linux contains curl and openssl internally. And The structure used by unity is slightly different with the official lib. So the global symbol used openssl is polluted by unity.
- To avoid this, make all symbol visibility in openssl into âhiddenâ to distinguish from unity symbols (-fvisibility=hidden)
- Becasue all symobls are hidden, must static link openssl in native plugin lib (-Wl,-Bstatic -lssl ⌠-Wl,-Bdynamic)
- Remember set the native plugin public function as attribute((visibility(âdefaultâ))), and still build native library with default hidden visibility (-fvisibility=hidden)
P.S. If Unity use the system shared openssl lib, no need do this fix. Because the structure wonât be polluted by unity
3 Likes