SymbolHider icon indicating copy to clipboard operation
SymbolHider copied to clipboard

Unable to hide symbols of a shared library

Open amontoison opened this issue 2 years ago • 4 comments

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.

amontoison avatar Apr 17 '23 23:04 amontoison

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

yugr avatar Apr 18 '23 04:04 yugr

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_

yugr avatar Apr 18 '23 05:04 yugr

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:

  • x86_64-apple-darwin
  • x86_64-linux-gnu
  • x86_64-w64-mingw32

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

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

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

amontoison avatar Apr 18 '23 06:04 amontoison

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.

yugr avatar Apr 18 '23 07:04 yugr