Commit Graph

85 Commits

Author SHA1 Message Date
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
Ovidiu Panait
fccd901efe 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-07-21 22:41:36 +03:00
Satadru Pramanik
8f94e116f3 add PR243 reproducer 2021-05-20 17:10:38 -04:00
Satadru Pramanik
d75ad358f4 Add testfile from PR270 2021-05-20 13:40:54 -04:00
Julian Stecklina
c105b1c837 Add test case with invalid phdr offset
Parsing this file results in patchelf segfaulting at:

Program received signal SIGSEGV, Segmentation fault.
std::vector<Elf32_Phdr, std::allocator<Elf32_Phdr> >::_M_realloc_insert<Elf32_Phdr const&> (this=0x7fffffff80a8, __position=..., __args=...)
    at /nix/store/h31cy7jm6g7cfqbhc5pm4rf9c53i3qfb-gcc-9.3.0/include/c++/9.3.0/bits/vector.tcc:449
449		  _Alloc_traits::construct(this->_M_impl,
(gdb) bt
    at /nix/store/h31cy7jm6g7cfqbhc5pm4rf9c53i3qfb-gcc-9.3.0/include/c++/9.3.0/bits/vector.tcc:449
    at /nix/store/h31cy7jm6g7cfqbhc5pm4rf9c53i3qfb-gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:1195
    this=0x7fffffff8088, fileContents=...) at patchelf.cc:421
2020-11-15 16:46:53 +01:00
Julian Stecklina
de9fa4def4 Add test case with invalid section header sh_name
Parsing this file results in patchelf segfaulting at:

    at /nix/store/h31cy7jm6g7cfqbhc5pm4rf9c53i3qfb-gcc-9.3.0/include/c++/9.3.0/bits/char_traits.h:335
    at /nix/store/h31cy7jm6g7cfqbhc5pm4rf9c53i3qfb-gcc-9.3.0/include/c++/9.3.0/bits/basic_string.h:527
    this=0x7fffffff8028, fileContents=...) at patchelf.cc:449
2020-11-15 16:46:53 +01:00
Julian Stecklina
e57205fec9 Add test case with non-terminated string table
Parsing this file results in patchelf triggering an assertion:

patchelf: patchelf.cc:442: ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, unsigned short>::ElfFile(FileContents) [Elf_Ehdr = Elf64_Ehdr, Elf_Phdr = Elf64_Phdr, Elf_Shdr = Elf64_Shdr, Elf_Addr = unsigned long, Elf_Off = unsigned long, Elf_Dyn = Elf64_Dyn, Elf_Sym = Elf64_Sym, Elf_Verneed = Elf64_Verneed, Elf_Versym = unsigned short]: Assertion `shstrtab[shstrtabSize - 1] == 0' failed.
Aborted (core dumped)
2020-11-15 16:46:53 +01:00
Julian Stecklina
62e39e05dc Add ELF test case with empty string table
Parsing this file results in patchelf triggering an assertion:

patchelf: patchelf.cc:439: ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, unsigned short>::ElfFile(FileContents) [Elf_Ehdr = Elf64_Ehdr, Elf_Phdr = Elf64_Phdr, Elf_Shdr = Elf64_Shdr, Elf_Addr = unsigned long, Elf_Off = unsigned long, Elf_Dyn = Elf64_Dyn, Elf_Sym = Elf64_Sym, Elf_Verneed = Elf64_Verneed, Elf_Versym = unsigned short]: Assertion `shstrtabSize > 0' failed.
Aborted (core dumped)
2020-11-15 16:46:53 +01:00
Julian Stecklina
1162de53b5 Add test case with invalid shrstab size
Parsing this file results in patchelf triggering an assertion:

patchelf: patchelf.cc:384: void checkPointer(const FileContents &, void *, unsigned int): Assertion `q >= contents->data() && q + size <= contents->data() + contents->size()' failed.
Aborted (core dumped)
2020-11-15 16:46:53 +01:00
Julian Stecklina
1457195875 Add ELF test case with invalid string table index
Parsing this file results in patchelf triggering an assertion:

patchelf: patchelf.cc:431: ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, unsigned long, unsigned long, Elf64_Dyn, Elf64_Sym, Elf64_Verneed, unsigned short>::ElfFile(FileContents) [Elf_Ehdr = Elf64_Ehdr, Elf_Phdr = Elf64_Phdr, Elf_Shdr = Elf64_Shdr, Elf_Addr = unsigned long, Elf_Off = unsigned long, Elf_Dyn = Elf64_Dyn, Elf_Sym = Elf64_Sym, Elf_Verneed = Elf64_Verneed, Elf_Versym = unsigned short]: Assertion `shstrtabIndex < shdrs.size()' failed.
Program received signal SIGABRT, Aborted.
2020-11-15 16:46:53 +01:00
Xavier Abellan Ecija
055802e636 Added option --add-rpath 2020-10-05 17:06:15 +01:00
Xavier Abellan Ecija
62e8db4343 Added option --add-rpath 2020-10-05 16:59:13 +01:00
Conrad Ratschan
b04764d2e7 Add regression tests for powerpc PIE endianness 2020-10-03 23:43:53 -05:00
Pablo Galindo
a89d508130 Handle libraries with more than one .shstrtab section 2020-09-22 20:59:55 +01:00
Jörg Thalheim
9621e85b9e add regression test for NOTE section relocation 2020-07-31 08:33:32 +01:00
Domen Kožar
4dc6e9e3d5 Merge pull request #130 from am813nt/master
Fixed parallel execution of tests (parallel-tests in automake)
2020-06-16 10:18:22 +02:00
Aaron D. Marasco
e522b14edc Add libasan build option and test print-needed
(cherry picked from commit 288eb61a173ce6f4cdf0be0d744c9c6b6b5598a4)
2020-06-10 09:51:37 -04:00
Domen Kožar
aa0b0e705f Merge pull request #104 from mkoloberdin/master
tests: Do not exit on an expected failure code.
2020-06-03 23:21:11 +02:00
Thomas Holder
6e5e98ce77 Consistently use --force-rpath (fixes #94) 2020-06-03 13:37:13 +02:00
Dan L. Stahlke
71ed440127 Added --output flag 2020-06-01 12:12:54 -07:00
am813nt
a6e524c418 Fixed tests to be running with parallel-tests 2017-08-02 16:57:33 +05:00
Michael Koloberdin
ceafc00e88 tests: Do not exit on an expected failure code.
The comment in the code below the patched line
clearly suggests that it should go on in this case.
This condition occurs on Alpine Linux (musl-libc-based):
http://patchwork.alpinelinux.org/patch/2206/
2016-07-10 03:53:01 +03:00
Tuomas Tynkkynen
4814341494 Add '--allowed-rpath-prefixes' option to '--shrink-rpath'
Fixes #97. In essence, the problem is that some packages in Nixpkgs have
RPATHs pointing to both $NIX_BUILD_TOP and $out, e.g.:

/tmp/nix-build-openldap-2.4.44.drv-0/openldap-2.4.44/libraries/libldap_r/.libs
/tmp/nix-build-openldap-2.4.44.drv-0/openldap-2.4.44/libraries/liblber/.libs
/nix/store/bfkmdxmv3a3f0g3d2q8jkdz2wam93c5z-openldap-2.4.44/lib
/nix/store/bfkmdxmv3a3f0g3d2q8jkdz2wam93c5z-openldap-2.4.44/lib64

Currently, running `patchelf --shrink-rpath` does the wrong thing by
keeping the /tmp/ paths and deleting the /nix/store ones. Now we can fix
the problem by using

patchelf --shrink-rpath --allowed-rpath-prefixes $NIX_STORE_DIR

in the Nixpkgs fixupPhase instead.
2016-06-04 00:25:02 +03:00
Felipe Sateler
bb04c06a66 no-rpath-prebuild: force pagesize to 4096 on prebuilt binaries
They all have that page size, and the host-detected one might be
different.
2016-02-29 17:38:07 -03:00
Eelco Dolstra
b202ad239e PR #40 had the side-effect of fixing the ia64 test 2015-07-24 01:36:39 +02:00
darealshinji
d4720dcb72 soname test: set an initial DT_SONAME entry 2015-07-13 19:54:30 +02:00
darealshinji
453660e7db tests: build libsimple without soname 2015-07-13 19:53:38 +02:00
Eelco Dolstra
bf4b579d63 Fix build on Linux
http://hydra.nixos.org/build/13337912
2014-08-18 12:40:05 +02:00
Eelco Dolstra
2ca39b8060 no-rpath-prebuild.sh: Don't run resulting binary
This leads to numerous build failures:

  http://hydra.nixos.org/eval/1136585

because ELF interpreter names are not unique (e.g. ld-linux.so.2 is
used on systems other than i686-linux).
2014-07-18 12:40:15 +02:00
Eelco Dolstra
1090b56a0a Merge branch 'master' of github.com:vdanjean/patchelf
Conflicts:
	tests/Makefile.am
2014-04-24 16:58:45 +02:00
Chingis Dugarzhapov
02c185ff69 Added tests for --print-soname and --set-soname 2014-04-19 10:05:56 +00:00
Vincent Danjean
c4220eaf0f rewrite no-rpath test
* compile locally this test in the no-rpath test
* add tests for prebuilt no-rpath binaries on various ELF platforms
  => ia64 does not work, probably a bug in patchelf. Marking it as XFAIL for now
2012-07-11 10:10:32 +02:00
Vincent Danjean
00b2fa4f77 Rewrite tests in automake
- add options in AM_INIT_AUTOMAKE to be more strict
  and to enable more advanced features (color-tests and parallel-tests)
- rewrite tests/Makefile.am to use automake rules for building program and libraries

=> we can now do:
./bootstrap.sh && mkdir build && cd build && ../configure && make -j distcheck
2012-07-10 18:16:24 -04:00
Vincent Danjean
3226dea361 Allow parallel execution of tests
Each test use its own subdirectory in scratch/
2012-07-10 18:16:24 -04:00
Vincent Danjean
4f66601450 fix build *and check* out of tree
- use Makefile variables $< (and $@) so that sources are found correctly
- use ${srcdir} in test scripts to find the sources

This allows "make distcheck" to successfully pass
2012-07-10 18:16:24 -04:00