Commit Graph

74 Commits

Author SHA1 Message Date
Eelco Dolstra
8d7076e8cf * Set a interpreter with a short name. 2005-09-30 15:38:42 +00:00
Eelco Dolstra
5349440827 * C++-ify. 2005-09-30 11:40:20 +00:00
Eelco Dolstra
955d3334ed * Use a real programming language. 2005-09-30 09:50:51 +00:00
Eelco Dolstra
3dd9c1ffca * Don't use an impure test path. 2005-09-29 16:16:20 +00:00
Eelco Dolstra
3b4fd53eec * Debug. 2005-09-29 16:01:32 +00:00
Eelco Dolstra
64e3c5d087 * Add an operation `--print-rpath' to print the RPATH of the library
or executable and exit.
2005-09-29 15:58:41 +00:00
Eelco Dolstra
a49db8e569 * Put in a highly Nix-specific hack to make the tests work. 2005-09-29 15:46:07 +00:00
Eelco Dolstra
190a60c025 * Add a failing test for `--set-rpath'. Test-driven development! 2005-09-29 15:41:04 +00:00
Eelco Dolstra
4f3658be12 * Added some real tests. 2005-09-29 14:21:40 +00:00
Eelco Dolstra
111c97cf88 * Added a flag `--print-interpreter' that prints the path of the
executable's ELF interpreter on standard output and exits.
2005-09-29 14:20:45 +00:00
Eelco Dolstra
8685534261 * Add dist files. 2005-09-29 12:17:56 +00:00
Eelco Dolstra
0da4ea8b65 * Add tests. 2005-09-29 12:03:56 +00:00
Eelco Dolstra
0177cc4483 * Document other people's bugs ;-) 2005-09-29 08:59:45 +00:00
Eelco Dolstra
8a5558f65d * Dummy commit. 2005-08-23 08:33:26 +00:00
Eelco Dolstra
90371dac82 * Don't remove non-absolute paths from the RPATH like "$ORIGIN". 2005-02-23 13:16:39 +00:00
Eelco Dolstra
514e54cabd * Keep same permissions, and handle the case where the file is
read-only.
2004-09-27 14:00:50 +00:00
Eelco Dolstra
bb097a56c9 * Fix equality check. 2004-09-27 13:47:19 +00:00
Eelco Dolstra
f4f4117040 * Autoconfiscate patchelf. 2004-09-24 22:05:46 +00:00
Eelco Dolstra
10d5f346ad * The new interpreter can be specified with the `--interpreter
FILENAME' switch.
* Shrinking of the RPATH.  The switch `--shrink-rpath' will cause all
  directories in the RPATH that don't actually contain libraries
  required by the executable to be removed from the RPATH.
* Only grow the front of the executable if needed.
2004-09-24 21:15:00 +00:00
Eelco Dolstra
586653f47e * Also move the section header table to the start of the file. 2004-09-24 17:37:19 +00:00
Eelco Dolstra
b80baf1605 * Dummy test program. 2004-09-24 16:25:59 +00:00
Eelco Dolstra
1a64cf7edc * Made changing the ELF interpreter more robust. Previously I just
added the new PT_INTERP segment at the end of the file, which
  however makes it (typically) appear right in the middle of the
  (uninitialised) data segment.  Worse, it wasn't guaranteed that the
  new segment was mapped into memory, and the dynamic loader does
  expect that.  If the segment crossed or started beyond the last page
  of the last mapped segment, the program would crash.

  The "simple" solution is to add a PT_LOAD segment that maps the
  PT_INTERP segment into memory, but that creates a new problem,
  namely, that we then have to grow the program header table.  Moving
  the program header table to the end of the file doesn't work,
  unfortunately, due to a bug in the Linux kernel: the address that it
  passes to the interpreter is wrong if there are holes or duplicates
  in the address space (it passes the base address + the program
  header table offset, instead of the virtual address specified in the
  PT_PHDR segment) - this is almost always the case due to the
  uninitialised part of the data segment which doesn't appear in the
  executable.

  The real solution used now is to move the entire contents of the
  executable one page (4096 bytes), put the new program header table
  (and the PT_INTERP segment) in the first page of the file thus
  created, add a PT_LOAD segment that starts one page before the
  original segments of the executable (typically 0x8047000 and
  0x8048000, respectively), and adjust the internal offsets in the ELF
  header and program and section headers.

  The downside is that it makes all executables 4 KB larger.
2004-09-24 15:40:52 +00:00
Eelco Dolstra
db2ebf1f93 * Bug fix. 2004-09-24 08:59:57 +00:00
Eelco Dolstra
f967dff666 * Proof-of-concept of a tool to patch *existing* ELF executable to use
our own glibc, to change the rpath, and so on.  This enable us to
  use third-party programs in a pure Nix environment, and to "shrink"
  the rpath of Nix-built executables to contain only those directories
  that are actually needed (in order to reduce the number of retained
  dependencies).

  In order to use our own glibc, we have to set the executable's ELF
  interpreter field to our glib'c ld-linux.so instead of the typical
  /lib/ld-linux.so.2.  The name of the interpreter is stored in the
  PT_INTERP segment of the executable.  A complication is that this
  segment is too small to store the path to our ld-linux.so.  We
  cannot just make this segment bigger, since the segment is actually
  mapped into the executable's virtual memory space, so that making it
  bigger will move all following segments in memory.  That would break
  executables, since they are typically not position-independant (they
  expect to be loaded at specific addresses in memory).

  The solution is to add a *new* segment at the end of the
  executable.  (The data containing the original PT_INTERP segment
  becomes "dead" space within the executable.)  This seems to work:
  e.g., I've succesfully patched SuSE's /bin/cat.

  Something similar could be done for the rpath, although that's a bit
  more complicated since the rpath string is stored indirectly (the
  PT_DYNAMIC segment merely contains a pointer to a string in the
  DT_STRTAB section of the executable, which we cannot grow either, so
  we would have to copy it to the end of the file).
2004-09-23 20:48:21 +00:00