Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: adding a prefix (or suffix) to all function names exported from shared library #436

Closed
tkelman opened this issue Aug 19, 2014 · 4 comments

Comments

@tkelman
Copy link
Contributor

tkelman commented Aug 19, 2014

We would like to be able to build a shared library of OpenBLAS using 64 bit integers, and add a prefix or suffix to all functions exported from that shared library, so that we can also load a separate 32-bit-integer shared library OpenBLAS (or Netlib, Atlas, Accelerate, etc) with conventional function names into the same process without having conflicting ABI's. Ref JuliaLang/julia#4923

I found a way to modify https://github.com/xianyi/OpenBLAS/blob/a69dd3fbc5c38f7098d1539a69963c0d2bd3163a/exports/gensymbol#L2827-L2873 for the Windows case, and something similar may also work for OSX. I'm stuck on Linux though. We tried using objcopy, but that is apparently unable to modify dynamic symbols. Any ideas?

@xianyi
Copy link
Collaborator

xianyi commented Aug 20, 2014

Hi @tkelman ,

You can try to modified FU and BU in makefile. OpenBLAS generate FU or BU in Makefile.conf by f_check. Usually, the BU is _ and FU is empty.

In Makefile.system, it uses these macro to generate the fortran blas name. e.g. dgemm as following.

$(FU)gemm$(BU)

@tkelman
Copy link
Contributor Author

tkelman commented Aug 22, 2014

Hi @xianyi. It looks like FU only gets added as a prefix to ASMNAME and ASMFNAME here? https://github.com/xianyi/OpenBLAS/blob/a69dd3fbc5c38f7098d1539a69963c0d2bd3163a/Makefile.system#L851

I tried adding prefixes to everything on that line but had linking failures.

Luckily I think I found a solution, at least for Linux. We can't use objcopy on the shared library because it can't rename dynamic symbols, but I just tried it on the static library right before linking the .so and that appears to work:

--- exports/Makefile-old        2014-08-20 20:47:51.000000000 -0700
+++ exports/Makefile    2014-08-20 20:45:16.000000000 -0700
@@ -103,7 +103,10 @@

 so : ../$(LIBSONAME)

-../$(LIBSONAME) : ../$(LIBNAME) linktest.c
+../$(LIBSONAME) : ../$(LIBNAME) linktest.c aix.def
+       rm -f prefix.def
+       for i in `cat aix.def`; do echo "$$i jl_$$i" >> prefix.def; done
+       objcopy --redefine-syms prefix.def ../$(LIBNAME)
 ifneq ($(C_COMPILER), LSB)
        $(CC) $(CFLAGS) $(LDFLAGS) -shared -o ../$(LIBSONAME) \
        -Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive \

I'm using aix.def as a simple list of exported symbols. objcopy --prefix-symbols=jl_ ../$(LIBNAME) went a little overboard renaming everything in the static library (including things from libm, pthreads, libgfortran, etc), it couldn't link the .so from it afterwards.

@tkelman
Copy link
Contributor Author

tkelman commented Aug 22, 2014

Whoops, sorry, this is actually a duplicate of #319 - but I got a little further in testing than @stevengj did.

Now I'm also wondering, would it be possible to build one copy of openblas with INTERFACE64=1 and renamed symbols, and then build another copy with INTERFACE64=0 without having to rebuild everything? Could any of the build results be reused successfully, or is it just simpler to build 2 copies each from scratch?

@tkelman
Copy link
Contributor Author

tkelman commented Nov 18, 2014

closed by #459, though the question of building both interfaces into the same library is still open in #319

@tkelman tkelman closed this as completed Nov 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants