Menu

#433 libspectrum: Hide all symbols except the ones in the public API

NextRelease
closed-accepted
nobody
None
5
2021-03-10
2021-03-02
No

The libspectrum shared library is exporting symbols that are not part of the public API, for example those defined in internal.h (you can see that with nm --defined-only -D libspectrum.so).

This is unnecessary and creates confusion when comparing the changes between two versions of the library.

Luckily all public symbols are already tagged with WIN32_DLL, so we can take advantage of that and hide all symbols except the ones that are meant to be public.

So this patch does three things:

  1. It renames WIN32_DLL to LIBSPECTRUM_API (this is what makes the patch so big).
  2. In Linux builds it defines LIBSPECTRUM_API to mean __attribute__ ((visibility ("default")))
  3. It builds libspectrum with -fvisibility=hidden so all other symbols are hidden.

Note: libspectrum_szx_write() is marked as public although it's not part of the API. The reason is because it's used directly by one of the tests.

1 Attachments

Discussion

  • Fredrick Meunier

    • status: open --> closed-accepted
    • Group: future --> NextRelease
     
  • Fredrick Meunier

    Thanks, committed in [da6be4].

     

    Related

    Commit: [da6be4]

  • Fredrick Meunier

    • Group: v1.6.0 --> NextRelease
     
  • Sergio Baldoví

    Sergio Baldoví - 2021-03-07

    Note: libspectrum_szx_write() is marked as public although it's not part of the API. The reason is because it's used directly by one of the tests.

    Test program doesn't run on Windows because libspectrum_szx_write() is not exported in the dynamic DLL library, despite being declared in internals.h

    I think we could rewrite the test to use the public libspectrum_snap_write() and fix this oddity. Patch attached.

     
    • Alberto Garcia

      Alberto Garcia - 2021-03-07

      I haven't had the time to review your patch yet, but yes, ideally the tests should only use the public API and we should not export internal symbols.

      Anyway #433 is now closed, maybe you could open a new one so this patch does not fall through the cracks?

       
    • Fredrick Meunier

      I agree that updating the test so that we can make libspectrum_szx_write() internal is the best way forward.

       
    • Fredrick Meunier

      Hi Sergio, do you want to commit the patch? It looks good to me

       
  • Sergio Baldoví

    Sergio Baldoví - 2021-03-10

    Thanks. Committed in [dbddb1].

     

    Related

    Commit: [dbddb1]


Log in to post a comment.