yugr / SymbolHider

A tool which hides symbols exported from shared libraries or relocatable object files
MIT License
37 stars 2 forks source link

Unable to hide symbols of a shared library #2

Open amontoison opened 1 year ago

amontoison commented 1 year ago

Hi @yugr!

I try to use your tool SymbolHider to hide some symbols of a shared library. I would like to link a package with libblastrampoline for the BLAS/LAPACK symbols and libmkl_rt for the MKL Pardiso solver. The issue is that libmkl_rt also exports BLAS and LAPACK symbols. I would like to use your tool to hide symbols not related to pardiso in libmkl_rt but it seems that nothing is updated.

nm -D libmkl_rt.so.2
...
00000000006acb00 T ZUPMTR
00000000006acb00 T zupmtr
00000000006acb00 T zupmtr_
00000000006acbb0 T ZUPMTR_64
00000000006acbb0 T zupmtr_64
00000000006acbb0 T zupmtr_64_
./sym-hider -v --hide libmkl_rt.so.2 zupmtr_64_
...
00000000006acb00 T ZUPMTR
00000000006acb00 T zupmtr
00000000006acb00 T zupmtr_
00000000006acbb0 T ZUPMTR_64
00000000006acbb0 T zupmtr_64
00000000006acbb0 T zupmtr_64_

libmkl_rt.so can be downloaded from https://anaconda.org/intel/mkl/files.

yugr commented 1 year ago

Thank you for the report, let me take a look at this within couple of days.

yugr commented 1 year ago

Actually I think nm is imprecise here. readelf shows that symbol is indeed hidden:

$ readelf --dyn-syms -W libmkl_rt.so.2 | grep '\<zupmtr_64_\>'
 45616: 00000000006acbb0   176 FUNC    GLOBAL DEFAULT   13 zupmtr_64_
$ ~/src/SymbolHider/bin/sym-hider libmkl_rt.so.2 zupmtr_64_
$ readelf --dyn-syms -W libmkl_rt.so.2 | grep '\<zupmtr_64_\>'
 45616: 00000000006acbb0   176 FUNC    GLOBAL HIDDEN    13 zupmtr_64_
amontoison commented 1 year ago

Great, it's exactly what I need!

I plan to use it in the cross-compiler BinaryBuilder.jl. Is it working if the shared library libmkl_rt.so and sym-hider are compiled on different platforms?

I will compile SymbolHider on the host (x86_64-linux-musl) and use it to hide the symbols of the shared library of the following platforms:

I suppose that the support of 32-bit ELFs is needed for the platforms:

But it's already great if I can use it for the 3 main 64-bits platforms.

yugr commented 1 year ago

I plan to use it in the cross-compiler BinaryBuilder.jl. Is it working if the shared library libmkl_rt.so and sym-hider are compiled on different platforms?

It should although TBH I haven't tested it. I'll be around for bugs if any.

x86_64-apple-darwin x86_64-w64-mingw32

These might be a problem - unfortunately they use different object file formats (Mach-O and PE) whereas SymbolHider only supports ELFs at the moment (I should make it clear in README). I can't say right now whether it's possible to modify symbol table for linked executables on these platforms.

I suppose that the support of 32-bit ELFs is needed for the platforms:

  • i686-linux-gnu
  • i686-w64-mingw32

This can be added if needed.