Download GNU ld script using dlopen

I have C ++ 14 code that should load an arbitrary file of shared objects using dlopen . Unfortunately, on some systems (for example, my archlinux is also reported to apply to some .so on ubuntu and gentoo), these so-called files may be "GNU ld scripts" instead of real binary files.

For reference, here is the contents of my /usr/lib/libm.so :

 /* GNU ld script */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /usr/lib/libm.so.6 AS_NEEDED ( /usr/lib/libmvec.so.1 ) ) 

I found a couple of codes that relate to this problem in ghc or ruby . I would not want to resort to the manual analysis of a text file based on the analysis of the dlerror text and the file. I feel that this is terribly evil, and I will not be able to implement and support corner cases of this format.

Is there a clean way to implement handling this case? Honestly, I am puzzled by why dlopen is actually not doing this.

Note. Given the above fixes, I think this is not just a problem with my configuration / system versions. If this should work out of the box with dlopen (error instead of missing function), let me know.

+6
source share
1 answer

Linker scripts are for use by the linker, not the runtime linker.

The GNU ld script comment should have been at hand: this is for ld , not ld.so .; -)

See for example: http://www.math.utah.edu/docs/info/ld_3.html

Therefore, I assume that using this parameter with dlopen() would mean emulating / importing some of the ld magic for this, which will confirm your concerns about manually parsing text and saving awfully evil code.

EDIT: There seems to be one thing that can help you:

https://www.sourceware.org/ml/libc-alpha/2011-07/msg00152.html

<gnu/lib-names.h> should contain a LIBM_SO definition that should point you to the correct file, which you can actually make dlopen ().

This means that usually no code is required.

+4
source

All Articles