Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Tue, 16 May 2017 20:38:56 -0400
From: John Regan <>
Subject: Question about setting argv[0] when manually using dynamic linker

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 file, so I could have a directory structure like:

|  app

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:

|  app.bin <- actual binary
|  app

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

exec /path/to/ /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

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.