5

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 ?

  • 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 1 '15 at 6: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 1 '15 at 7: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 1 '15 at 7:06
2
+50

You can use the standard ELF program dump:

dump -Lv libxxx.so | grep SYMBOLIC

  • 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 3 '15 at 3: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 3 '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 3 '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: schillix.sourceforge.net/man/man3elf – schily Sep 3 '15 at 13:37
  • libelf helped me to an extent , I will update the post soon with details. – amisax Sep 8 '15 at 10:29
0

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
  • 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 3 '15 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.