This PR adds a command line option `--no-sort` which causes patchelf
to refrain from sorting the program headers and section headers. A
comment in the preexisting source code says that this was done only
"for neatness".
The `--no-sort` option, combined with `readelf -a` and `colordiff` is
very useful for debugging patchelf problems. Without `--no-sort` the
diffs are not usable -- everything changes because of the sorting.
A shared library (-shared) by default does not receive DT_DEBUG tag.
This means that when a shared library has an entry point (so that it
can be run as an executable), the debugger does not connect to it
correctly and symbols are not resolved.
--add-debug option adds DT_DEBUG tag if it not yet present to an ELF
object.
Made changes according to feedback from @Mic92 such as moving the
`rewriteSections` inline into every method.
Improved `replace-add-needed.sh` to work with musl libc
`patchelf` previously would incorrectly patch the ELF header if it was
called with multiple changes at once such as _add_ & _replace_.
In order to support that, rewrite the sections in between each section
modification.
Fix#359
Added a header file to make things easier to navigate.
Renamed findSection3 -> getSectionIndex since thats more sensible to
read.
Renamed findSection -> findSectionHeader to better distinguish sections
from headers.
Fix off by one error in the code that reads interpreter from the ELF
file. This was not evident when it was written directly to STDOUT but
became problematic through my exploration of new functionality (#357)
since there was an additional '\0' and the strings would not concatenate
as a result.
MacOS, FreeBSD and Linux using GNU have it, but at least OpenBSD
does not (the non-compatible BSD equivalent jot(1) exists, though).
Counting up is easy enough to do in POSIX sh(1).
Looks like this after GNU make(1)'s escaping and produces the same
big-dynstr.c file:
```
cat main.c > big-dynstr.c
i=1; while [ $i -le 2000 ]; do echo "void f$i(void) { };"; i=$(($i + 1)); done >> big-dynstr.c
```
This is the last bit required to build and pass all tests on OpenBSD
without local patches/dependencies.
As is common with autotools enabled software, building and testing
happens outside the source directory.
The introduction of `contiguous-note-sections` test in 0.13 broke this
by assuming linker scripts to exist in the current working directory.
Point at the absoloute source directory explicitly to unbreak linking in
such build environments.
Spotted on OpenBSD where source and build assets are commonly separated
iff possible.