runtime loader replaces argv[0]

Patrick Donnelly batrick@batbytes.com
Fri May 15 22:04:00 GMT 2015


Hi,

My colleagues and I are using the runtime loader in preservation
software for scientific applications. To be specific, we preserve the
runtime loader implicitly used by the software so that it can be run
again in the future, possibly on a completely different platform (but
using the same or newer kernel). In this context, we are using Linux
but the problems exists for all kernels.

The problem we see is that the glibc loader unconditionally replaces
argv[0]. So if I want to run an application on a different platform
that uses a different loader, I would do this instead:

execve("./preserved/ld-linux.so", ["argv[0]" /* from original
experiment */, "./preserved/application.exe" /* physical exe */,
"argv[1]", ...], [...]);

I would expect the loader to simply strip off its argv[1] and leave
the rest alone. Unfortunately, it sets argv[0] to argv[1], as if we
ran:

execve("./preserved/application.exe", ["./preserved/application.exe",
"argv[1]", ...], [...]);

This prevents us from passing the original argv[0] to the application.
I have attached two C programs that exhibit the problem.

Ironically enough, the software that is most affected by this is the
loader itself. If argv[0] is not a real path (i.e. beginning with ./
or /), then it will readlink("/proc/self/exe") to determine the
physical path. In the original experiment with an argv[0] of "foo",
that's exactly what it does. In the rerun experiment with the
preserved loader, argv[0] is "./preserved/application.exe". So the
loader uses this path incorrectly in subsequent library lookups,
ultimately causing the application to fail.

So as for my question, is there a viable workaround for this or does
anyone have some other suggestion?

-- 
Patrick Donnelly
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ld-argv0.c
Type: text/x-csrc
Size: 593 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20150515/6e2142b7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: b.c
Type: text/x-csrc
Size: 157 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20150515/6e2142b7/attachment-0001.bin>


More information about the Libc-help mailing list