8

My application loads custom code using dlopen on the fly. For common symbols, the global symbol table is used by default.

However, I want to provide the functionality where - if the user has linked their so with -Bsymbolic-functions, I pass the RTLD_DEEPBIND flag to the dlopen function.

Is there a way I can programmatically know whether a .so is linked with -Bsymbolic-functions or not using C ?

amisax
  • 2,957
  • 17
  • 23
  • 1
    My reading of the documentation on `-Bsymbolic-functions` and `RTLD_DEEPBIND` suggests to me that `RTLD_DEEPBIND` would do nothing for a library that had been linked with `-Bsymbolic-functions` because such a library would not contain any references to functions defined within itself: they would all have been already resolved to internal locations at link time! – Celada Sep 01 '15 at 06:44
  • @Celada , the behavior I am seeing is that if deliberately just pass `RTLD_LAZY` with a library that is deep bound, then the symbols are not loaded from within the .so in case of conflicts. I have to pass `RTLD_DEEPBIND | RTLD_LAZY ` for such cases. – amisax Sep 01 '15 at 07:02
  • Hmm, I would have thought that couldn't happen because `-Bsymbolic-functions` would resolve internal references in a way that the runtime dynamic linker can't see them, can't even know that exist. So I have no idea what's going on and I hope someone with lots of ELF expertise will come along to help you. Good question, +1. – Celada Sep 01 '15 at 07:06
  • Your _question_ accidentally just saved me, I was using `RTLD_DEEPBIND` to solve a problem of using wrong symbols (symbol inside .so was not being used because a different symbol with the same name was loaded earlier). I didn't know about `-Bsymbolic-functions`, just learned about it now, and it seems to be a much better solution ;) – e.tadeu Dec 03 '19 at 20:26
  • if nm says no symbols, you can try with the -D like: > nm -D libxxx.so | grep "my_routine_name" – Natan Lotério Jan 05 '21 at 13:13

2 Answers2

3

You can use the standard ELF program dump:

dump -Lv libxxx.so | grep SYMBOLIC

schily
  • 18,806
  • 5
  • 38
  • 60
  • Is there a way I can get the same information using an API from C ? My question is specifically looking for a C API. – amisax Sep 03 '15 at 03:52
  • 1
    Did you check libelf? It may not be vailable in a GNU environment but it is the original ELF library from UNIX, OSS and free to use. – schily Sep 03 '15 at 10:12
  • libelf is available on GNU systems and AFAIK is a part of the GCC suite (otherwise GCC would not be able to build binaries :) ) – galaxy Sep 03 '15 at 13:24
  • I am not sure whether the GNU lib has the same content. as the Sun/AT&T lib. You may like to have a look into the man pages: http://schillix.sourceforge.net/man/man3elf/ – schily Sep 03 '15 at 13:37
  • libelf helped me to an extent , I will update the post soon with details. – amisax Sep 08 '15 at 10:29
1

There is a command named nm

nm - list symbols from object files

You can use the command

nm Absolute_path_of_.so_file_name | grep -i -Bsymbolic-functions
SHW
  • 14,454
  • 14
  • 63
  • 101
  • Is there a way I can get the same information using an API from C ? My question is specifically looking for a C API... – amisax Sep 03 '15 at 03:51