Hi there - I was wondering if it's possible to somehow set argv[0] when calling the dynamic linker to load a program.

The reason I want to do this (in case there's a better way) - I was looking into compiling programs with musl libc, and distributing the binaries with the needed libc.so file, so I could have a directory structure like:

/bin
|  app
/lib
|  libc.so
|  some_other_lib.so

I can set the rpath to $ORIGIN/../lib so the whole folder is relocatable, but as far as i know, there's no equivalent concept for setting the dynamic linker with a path that's relative to the binary.

My current idea is to have a wrapper script, so my structure would be something like:

/bin
|  app.bin <- actual binary
|  app
/lib
|  libc.so
|  some_other_lib.so

The 'app' script could find the actual, absolute path to itself and figure out where libc.so is, ending with a line like

exec /path/to/libc.so /path/to/app.bin arg1 arg2 etc

I'd like to retain whatever was actually typed on the command line (in this case, set argv[0] to "app"), since many apps look at argv[0] to change behavior, ie - gzip vs gunzip.

I tried seeing if there was some switch I could pass to the linker, etc - as far as I can tell, there's no easy way to do this.

Thanks in advance!!

-John Regan