diff options
| author | Di Chen <[email protected]> | 2024-10-17 22:38:52 -0400 |
|---|---|---|
| committer | Aaron Merey <[email protected]> | 2024-10-18 01:47:39 -0400 |
| commit | e77d120d0bc1ce864069ee90219c3ea8a0adc910 (patch) | |
| tree | 66fd05322a086173cde8c7f6747de8b63ce2db9c /tests | |
| parent | 245f19c1e285599bc7441d096d672628bed13797 (diff) | |
libdwelf: add dwelf_elf_remove_debug_relocsupstream/users/amerey/try-remove-relocs2
Provide a public function for removing debug section relocations.
eu-strip previously contained the code to remove debug section
relocations. This patch moves that code into
dwelf_elf_remove_debug_relocs.
https://sourceware.org/bugzilla/show_bug.cgi?id=31447
Signed-off-by: Di Chen <[email protected]>
Signed-off-by: Aaron Merey <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Makefile.am | 5 | ||||
| -rw-r--r-- | tests/remove-relocs.c | 38 | ||||
| -rwxr-xr-x | tests/run-remove-relocs.sh | 54 | ||||
| -rw-r--r-- | tests/testfile-remove-relocs.bz2 | bin | 0 -> 1088 bytes |
4 files changed, 96 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index ffccb0cd..a3c4a745 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -59,7 +59,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ get-units-invalid get-units-split attr-integrate-skel \ all-dwarf-ranges unit-info next_cfi \ elfcopy addsections xlate_notes elfrdwrnop \ - dwelf_elf_e_machine_string \ + dwelf_elf_e_machine_string remove-relocs \ getphdrnum leb128 read_unaligned \ msg_tst system-elf-libelf-test system-elf-gelf-test \ nvidia_extended_linemap_libdw elf-print-reloc-syms \ @@ -204,6 +204,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-strip-version.sh run-xlate-note.sh \ run-readelf-discr.sh \ run-dwelf_elf_e_machine_string.sh \ + run-remove-relocs.sh \ run-elfclassify.sh run-elfclassify-self.sh \ run-disasm-riscv64.sh \ run-pt_gnu_prop-tests.sh \ @@ -576,6 +577,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-readelf-discr.sh \ testfile-rng.debug.bz2 testfile-urng.debug.bz2 \ run-dwelf_elf_e_machine_string.sh \ + run-remove-relocs.sh testfile-remove-relocs.bz2 \ run-elfclassify.sh run-elfclassify-self.sh \ run-disasm-riscv64.sh \ testfile-riscv64-dis1.o.bz2 testfile-riscv64-dis1.expect.bz2 \ @@ -856,6 +858,7 @@ debuginfod_build_id_find_LDADD = $(libelf) $(libdw) xlate_notes_LDADD = $(libelf) elfrdwrnop_LDADD = $(libelf) dwelf_elf_e_machine_string_LDADD = $(libelf) $(libdw) +remove_relocs_LDADD = $(libelf) $(libdw) getphdrnum_LDADD = $(libelf) $(libdw) leb128_LDADD = $(libelf) $(libdw) read_unaligned_LDADD = $(libelf) $(libdw) diff --git a/tests/remove-relocs.c b/tests/remove-relocs.c new file mode 100644 index 00000000..9a678f59 --- /dev/null +++ b/tests/remove-relocs.c @@ -0,0 +1,38 @@ +/* Test program for dwelf_elf_remove_debug_relocs + Copyright (C) 2024 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <fcntl.h> +#include ELFUTILS_HEADER(dw) +#include ELFUTILS_HEADER(dwelf) + +int main(int argc __attribute__ ((unused)), char **argv) { + Elf *elf; + elf_version (EV_CURRENT); + int fd = open (argv[1], O_RDWR); + + elf = elf_begin (fd, ELF_C_RDWR, NULL); + + dwelf_elf_remove_debug_relocations (elf); + elf_update (elf, ELF_C_WRITE); + + elf_end (elf); + return 0; +} diff --git a/tests/run-remove-relocs.sh b/tests/run-remove-relocs.sh new file mode 100755 index 00000000..3a49a5ab --- /dev/null +++ b/tests/run-remove-relocs.sh @@ -0,0 +1,54 @@ +#! /usr/bin/env bash +# Test dwelf_elf_remove_debug_relocations +# Copyright (C) 2024 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# = qq.c = +# int add (int a, int b) +# { +# return a+b; +# } +# +# int main() +# { +# return 0; +# } + +# Using gcc (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1) +# gcc -g -c qq.c -o testfile-remove-relocs + +testfiles testfile-remove-relocs + +# Before debug relocations are removed some indices into string tables are +# set to a default value of 0. This causes incorrect file and function +# names to be displayed. +testrun_compare ${abs_builddir}/allfcts testfile-remove-relocs <<\EOF +qq.c/qq.c:6:GNU C17 14.2.1 20240801 (Red Hat 14.2.1-1) -mtune=generic -march=x86-64 -g +qq.c/qq.c:1:add +EOF + +# Remove debug relocations and write the changes to the testfile. +testrun ${abs_builddir}/remove-relocs testfile-remove-relocs + +# Correct file and function names should now be displayed. +testrun_compare ${abs_builddir}/allfcts testfile-remove-relocs <<\EOF +/home/dichen/elfutils/tests/qq.c:6:main +/home/dichen/elfutils/tests/qq.c:1:add +EOF + +exit 0 diff --git a/tests/testfile-remove-relocs.bz2 b/tests/testfile-remove-relocs.bz2 Binary files differnew file mode 100644 index 00000000..2f7ca9b6 --- /dev/null +++ b/tests/testfile-remove-relocs.bz2 |
