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.
(Old) linkers such as BFD's ld(1) aka. GNU ld (version 2.17 on OpenBSD)
don't know `--build-id`, but they know `-b input-format` which patchelf
triggers by ommitting the second dash.
LLD's ld(1) seems to cope with this, although it's incorrect usage.
Use the double dash for correctness to get accurate error messages with
such incompatible linkers:
-/usr/bin/ld: invalid BFD target `uild-id'
+/usr/bin/ld: unrecognized option '--build-id'
+/usr/bin/ld: use the --help option for usage information
This can happen especially if .gnu.version_r stores the strings in .dynstr, so
replacing the library names would add them twice to the same section. Keep a map
of what was already added and where, and simply reuse the old entries if they
are needed again.
When it happens that the .gnu.version_r stores the strings in .dynstr it can
come to corruption of the library names written into DT_NEEDED:
-the library names in DT_NEEDED are replaced, new entries are written to the end
of .dynstr
-the version library names are replaced, and written to the end of the string
section.
If the section for the version strings is also ".dynstr", the previous
modifications were _not_ taken into account and things were written from the old
end of .dynstr again. The order in which these strings were written is not the
same as the previous replacement, so things would end up with the same size, but
different offsets. The .gnu.version_r table is correct, the file contents are
fine, but the offsets in the DT_NEEDED entries are wrong. Since they are printed
as 0-terminated strings the first one replaced will always be shown correct,
which also is the case if the argument is only used once as the string is
replaced with itself afterwards.