Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

native library use openssl conflict with unity on linux

Discussion in 'Linux' started by chenyuchih, May 17, 2016.

  1. chenyuchih

    chenyuchih

    Joined:
    Jun 3, 2015
    Posts:
    37
    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.
     
    Last edited: May 18, 2016
    omri_unity961 likes this.
  2. chenyuchih

    chenyuchih

    Joined:
    Jun 3, 2015
    Posts:
    37
    Finally, I solve this. Just make a note for someone may meet this bug.
    1. global variable/function/symbol only have one instance in linux elf format (even in shared library)
    2. 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.
    3. To avoid this, make all symbol visibility in openssl into 'hidden' to distinguish from unity symbols (-fvisibility=hidden)
    4. Becasue all symobls are hidden, must static link openssl in native plugin lib (-Wl,-Bstatic -lssl ... -Wl,-Bdynamic)
    5. 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
     
    omri_unity961, Deleted User and larku like this.