Commit Graph

119 Commits

Author SHA1 Message Date
Jörg Thalheim
d9ae0a5498 tests: use proper exit code to mark tests as skipped
(cherry picked from commit acee2a4bb4)
2025-08-12 23:20:42 -04:00
John Ericson
ba938c55b2 Merge remote-tracking branch 'upstream/0.15-maintenance' into 0.15-maintenance 2025-08-12 22:02:11 -04:00
John Ericson
c0186ccf5a Add regression test for #64
This issue has been solved in the decade since it was reported. We just
need the test to prove it.

Closes #64
2025-08-12 21:45:15 -04:00
John Ericson
d27e04333c Merge commit '7281d999e95d6730d1d08fc7517c15e27ddfb65f' into 0.15-maintenance 2025-08-12 18:37:16 -04:00
Heiko Becker
6b0d933887 Also respect a prefixed nm and strings too
(cherry picked from commit 1ab6930d15)
2025-08-12 17:11:38 -04:00
Heiko Becker
731fcc20ef Also pass STRIP to the tests
It is used in tests/no-gnu-hash.sh.

(cherry picked from commit d9ff398634)
2025-08-12 17:11:12 -04:00
Breno Rodrigues Guimaraes
a97bfdf479 Fix all shellcheck issues
(cherry picked from commit 8adc31ed7b)
2025-08-12 15:06:56 -04:00
Jörg Thalheim
61fdb6e999 tests: apply suggestions from shellcheck
(cherry picked from commit be4b84635f)
2025-08-12 15:04:30 -04:00
Jörg Thalheim
2d18660af7 fix checkPhase for cross builds
fixes https://github.com/NixOS/patchelf/issues/417

(cherry picked from commit f7b184c004)
2025-08-12 15:04:13 -04:00
Bo Anderson
33e3e8b617 tests/contiguous-note-sections.sh: use scratch directory
(cherry picked from commit a93de9d4ce)
2025-08-12 15:03:34 -04:00
Jörg Thalheim
06b8a41214 make objdump/objcopy/readelf configurable and respect cross-compiling related prefixes
(cherry picked from commit b0599fe776)
2025-08-12 14:59:49 -04:00
Robert Scheck
f7053d0237 Handle glibc-hwcaps on ppc64le on CentOS/RHEL/Rocky 8 for tests/replace-add-needed.sh (fixes #406)
ldd(1) usually returns for ELF binaries output like this:

	libc.so.6 => /lib64/libc.so.6 (0x00007fbacd6ca000)

But with glibc-hwcaps, the output could also be like this:

	libc.so.6 => /lib64/glibc-hwcaps/power9/libc-2.28.so (0x00007fffb5800000)

See also: https://sourceware.org/pipermail/libc-alpha/2020-June/115250.html
2022-09-27 00:41:51 +02:00
deadwood
b92e442be0 Add test for --add-debug-tag argument 2022-02-23 16:42:51 +01:00
Farid Zakaria
b92a6e8951 Fix replace-add-needed.sh test for musl 2021-12-21 14:30:45 -08:00
Farid Zakaria
d02a3ecdd7 Code clarity and test working with musl
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
2021-12-21 06:05:13 -08:00
Farid Zakaria
e268662c32 Add a unit test 2021-12-20 17:34:26 -08:00
Klemens Nanni
5f6cc74be8 Avoid GNU seq(1)
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.
2021-12-07 20:41:26 +01:00
Jörg Thalheim
a4027142bf tests/grow-file.sh: fix compat with non-gnu systems 2021-12-07 19:44:37 +01:00
Jörg Thalheim
ba000786e9 tests/too-many-strtab: fix linking with lld
llvm's lld also tests the section type and fails otherwise

fixes https://github.com/NixOS/patchelf/issues/350
2021-12-07 19:44:37 +01:00
Jörg Thalheim
44fea0de2f tests/endianess.sh: fix out-of-tree build 2021-12-07 17:05:01 +01:00
Jörg Thalheim
ce99c93c57 Merge pull request #353 from klemensn/out-of-tree-build
Use absoloute paths to linker scripts
2021-12-07 15:44:42 +00:00
Jörg Thalheim
301aa6ae34 fix build-id test on openbsd 2021-12-06 21:45:26 +01:00
Klemens Nanni
fd82dfffab Use absoloute paths to linker scripts
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.
2021-12-06 21:25:25 +01:00
Klemens Nanni
b0cdf15e26 Use correct double-dashes for ld(1)'s build-id option
(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
2021-12-06 21:04:26 +01:00
Rolf Eike Beer
b4cb6cac78 fix corrupted library names when using --replace-needed multiple times
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.
2021-11-27 11:06:49 +01:00
Domen Kožar
18a389ba35 Merge pull request #324 from ovpanait/strip
configure.ac: add check for strip
2021-09-26 11:54:19 -05:00
Ovidiu Panait
424d3f5083 tests: add testcase for PT_PHDR VirtAddr corruption
A PT_PHDR corruption was previously reported and fixed in [1]: the issue was
that the VirtAddr field of the PT_PHDR program header would get overwritten
with the file offset of the program header table rather than the virtual
address. A testcase for this was also added in [2]. However, the tescase is not
included in the Makefile.am regression testsuite and also tries to run a x86_64
prebuilt binary unconditionally, which would not work on other architectures.

To fix this, create a standalone testcase for the PT_PHDR VirtAddr field
corruption and include it in Makefile.am. In order to reproduce [1], a binary
with the following characteristics is needed:
- the ELF file type must be ET_DYN
- the ELF file must contain a PT_PHDR program header
- the file offset and the VirtAddr field of the PT_PHDR program header must be
  different

[1] https://github.com/NixOS/patchelf/pull/243
[2] 8f94e116f3

Signed-off-by: Ovidiu Panait <ovpanait@gmail.com>
2021-09-26 19:09:55 +03:00
Ovidiu Panait
512c0f3c60 configure.ac: add check for strip
Currently, "make check" fails on Ubuntu 20.04 because the STRIP variable is not
set in the resulting tests/Makefile:
"""
git clone https://github.com/NixOS/patchelf.git
./bootstrap.sh
./configure
make VERBOSE=1 check
...
gcc -fPIC -shared -o libbig-dynstr.so big-dynstr.c
only-keep-debug libbig-dynstr.so -o libbig-dynstr.debug
/bin/bash: only-keep-debug: command not found
make[2]: [Makefile:1526: libbig-dynstr.debug] Error 127 (ignored)
...
FAIL: no-dynamic-section.sh
===========================

patchelf: getting info about 'libbig-dynstr.debug': No such file or directory
FAIL no-dynamic-section.sh (exit status: 1)
"""

strip is used by the regression testsuite, so add a check for it configure.ac.

Signed-off-by: Ovidiu Panait <ovpanait@gmail.com>
2021-09-26 19:03:14 +03:00
Jörg Thalheim
90da38b8cf grow-test: fix on non-gcc systems 2021-09-13 17:55:05 +02:00
Andrew Laucius
a4ae03d638 New test for growing the file 2021-09-13 15:00:44 +00:00
Jörg Thalheim
de3901853d fix setting empty rpath 2021-09-12 10:27:01 +02:00
Jörg Thalheim
e9ccf62867 rename test: external.sh -> args-from-file.sh 2021-09-11 07:34:42 +02:00
Jörg Thalheim
742d772a7f also test if external file does not exists 2021-09-11 07:33:00 +02:00
Andrew Laucius
d69bafc3b3 Allow string arguments to be read from files.
If a string argument to an option is prefixed with @, then a file with the
following name will be read into that string.
2021-09-10 19:28:32 +00:00
Jörg Thalheim
51ecac17c2 add flag tests
let's start with the easy targets from coverage reports
2021-08-25 21:43:41 +00:00
Jörg Thalheim
a71334dc2e add failing test for .dynamic == NOBITS 2021-08-23 20:57:47 +02:00
Ivan A. Melnikov
b240bb8dcf Adjust DT_MIPS_RLD_MAP_REL dynamic section entry if present
`patchelf --set-rpath` corrupted executables on mips32el: the dynamic
liker crushed with Segmentation fault when loading any executable with
RPATH added that way.

The problem was around the MIPS-specific mechanism of setting up the
debug map pointer. When DT_MIPS_RLD_MAP_REL entry in the dynamic section
is present, it holds the relative address of __RLD_MAP -- an offset
relative to this dynamic section entry. Dynamic linker puts the
pointer to the `r_debug` structure there.

When patchelf updates the executable RPATH, it moves the .dynamic
section both in the binary and in memory, while __RLD_MAP is not moved
in memory, since it belongs to special .rld_map section that has type
PROGBITS. So, the offset stored in DT_MIPS_RLD_MAP_REL entry is not
valid anymore and should be updated.

This commit adds the necessary update.

In the corner case when DT_MIPS_RLD_MAP_REL is present, but
.rld_map section is not, the dynamic loader writes the debug
pointer to some arbitrary bytes in memory. To avoid crushes
on otherwise "working" binaries, we set offset to zero
so that the dynamic loader would just overwrite the dynamic
section.

Here we also import DT_MIPS_RLD_MAP_REL definition in elf.h form
glibc commit a2057c984e4314c3740f04cf54e36c824e4c8f32.

Refs: #82
Signed-off-by: Ivan A. Melnikov <iv@altlinux.org>
2021-08-11 17:49:41 +04:00
Jörg Thalheim
9e364e5fca tests/contiguous-note-sections: rename for consistency 2021-08-10 14:36:25 +02:00
Jörg Thalheim
2f88e6f312 Merge pull request #296 from Mic92/gnu-hash
fix binaries without .gnu.hash section
2021-08-10 11:57:19 +01:00
Jörg Thalheim
57fe1d3835 fix binaries without .gnu.hash section 2021-08-10 07:54:50 +02:00
Joerie de Gram
094022f06c tests/contiguous_note_sections.s: use alternate section type prefix
fixes #294
2021-08-09 19:16:47 +02:00
Domen Kožar
eed0a903c5 Merge branch 'master' into multiple 2021-08-05 17:59:01 +02:00
Domen Kožar
dab44118d7 Merge pull request #246 from xavierabellan/add-rpath
Added option --add-rpath
2021-08-05 12:10:59 +02:00
Domen Kožar
4e1b46a334 fix tests DIST 2021-08-05 12:03:39 +02:00
Domen Kožar
f823fa3143 Merge branch 'master' into endianness-fix 2021-08-05 11:55:53 +02:00
Ovidiu Panait
d2bb23badf tests: add testcase for alignment issues with contiguous note sections
Add a testcase for the following reported alignment issue with contiguous note
sections (#275):

"""
If a binary has multiple SHT_NOTE sections and corresponding PT_NOTE
headers, we can see the error:

patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections

if the SHT_NOTE sections aren't sized to end on aligned boundaries. An example
would be a binary with:

[ 2] .note.ABI-tag NOTE 00000000000002f4 000002f4
0000000000000020 0000000000000000 A 0 0 4
[ 3] .note.gnu.propert NOTE 0000000000000318 00000318
0000000000000030 0000000000000000 A 0 0 8
[ 4] .note.gnu.build-i NOTE 0000000000000348 00000348
0000000000000024 0000000000000000 A 0 0 4

NOTE 0x0000000000000318 0x0000000000000318 0x0000000000000318
0x0000000000000030 0x0000000000000030 R 0x8
NOTE 0x00000000000002f4 0x00000000000002f4 0x00000000000002f4
0x0000000000000078 0x0000000000000074 R 0x4

since the PT_NOTE section at 2f4 covers [2] and [3] but the code
calclates curr_off should be 314, not the 318 in the binary. This
is an alignment issue.
"""

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
2021-08-04 12:31:15 +03:00
Domen Kožar
4d03718b17 Revert "tests: add testcase for alignment issues with contiguous note sections"
This reverts commit fccd901efe.
2021-08-03 16:30:13 +02:00
Domen Kožar
83fac7e0ce Merge pull request #289 from ovpanait/master
tests: add testcase for alignment issues with contiguous note sections
2021-08-03 15:53:42 +02:00
Ovidiu Panait
3300999317 tests: plain-needed.sh: add tescases for --add-needed-/--remove-needed
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
2021-07-24 19:25:16 +03:00
Joerie de Gram
4052850d22 tests: add e_machine endianness test (#269) 2021-07-24 01:32:37 +02:00