0

I know dlopen is used for loading a shared library compiled with "-shared" and possibly "-fPIC". But since the executable and dynamic library share the same format, I'm wondering if it is possible to directly load an executable?

It is acceptable that we may need to re-construct a customized dlopen and dlsym, just want to know whether it is possible to do such things while being transparent to the binaries.

BTW, It is also acceptable that the loaded executable cannot be reused (since it is not compiled with -fPIC).

Thanks in advance.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
aquatoney
  • 3
  • 2
  • You can try it, but whatever the result should be, it will be platform-dependent. (Make sure the executable is compiled and linked with option `-fPIC`.) – Lorinczy Zsigmond May 03 '21 at 08:08

2 Answers2

0

This used to be possible to dlopen a PIE executable on Linux, but not anymore -- GLIBC-2.30 prohibits this.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
0

Since it is possible to execute a .so file:

Can you turn the question around to compile the executable (application) as a '.so' file? With -shared etc?

Andrew G Morgan
  • 141
  • 1
  • 6