mirror of
https://github.com/openharmony/third_party_elfutils.git
synced 2026-07-01 06:41:51 -04:00
de2ed97f33
* Change name from "Red Hat elfutils" to "elfutils". * Update license of standalone tools and test from GPLv2 to GPLv3+. * Change license of libraries from GPLv2+exception to GPLv2/LGPLv3+. * Add Developer Certificate of Origin based contributor policy. top-level: - COPYING: Upgraded from GPLv2 to GPLv3. - CONTRIBUTING, COPYING-GPLv2, COPYING-LGPLv3: New files. - NEWS: Added note about new contribution and license policy. - Makefile.am: Updated to GPLv3, added new files to EXTRA_DIST. - configure.ac: Update to GPLv3, changed AC_INIT name to 'elfutils'. backends, lib, libasm, libcpu, libdw, libdwfl, libebl, libelf: - All files updated to GPLv2/LGPLv3+. Except some very small files (<5 lines) which didn't have any headers at all before, the linker .maps files and the libcpu/defs files which only contain data and libelf/elf.h which comes from glibc and is under LGPLv2+. config: - elfutils.spec.in: Add new License: headers and new %doc files. - Update all license headers to GPLv2/LGPLv3+ for files used by libs. src, tests: - All files updated to GPLv3+. Except for the test bz2 data files, the linker maps and script files and some very small files (<5 lines) that don't have any headers. Signed-off-by: Richard Fontana <rfontana@redhat.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
137 lines
3.2 KiB
C
137 lines
3.2 KiB
C
/* Copyright (C) 1999, 2000, 2002 Red Hat, Inc.
|
|
This file is part of elfutils.
|
|
Written by Ulrich Drepper <drepper@redhat.com>, 1999.
|
|
|
|
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/>. */
|
|
|
|
#include <config.h>
|
|
|
|
#include <fcntl.h>
|
|
#include <libelf.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
FILE *fp;
|
|
Elf *elf;
|
|
Elf_Arsym *arsym;
|
|
size_t narsym;
|
|
|
|
if (argc < 3)
|
|
exit (1);
|
|
|
|
/* Open the archive. */
|
|
fd = open (argv[1], O_RDONLY);
|
|
if (fd == -1)
|
|
{
|
|
printf ("Cannot open input file: %m");
|
|
exit (1);
|
|
}
|
|
|
|
/* Open the output file. */
|
|
fp = fopen (argv[2], "w");
|
|
if (fp == NULL)
|
|
{
|
|
printf ("Cannot open output file: %m");
|
|
exit (1);
|
|
}
|
|
|
|
/* Set the ELF version. */
|
|
elf_version (EV_CURRENT);
|
|
|
|
/* Create an ELF descriptor. */
|
|
elf = elf_begin (fd, ELF_C_READ, NULL);
|
|
if (elf == NULL)
|
|
{
|
|
printf ("Cannot create ELF descriptor: %s\n", elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
|
|
/* If it is no archive punt. */
|
|
if (elf_kind (elf) != ELF_K_AR)
|
|
{
|
|
printf ("`%s' is no archive\n", argv[1]);
|
|
exit (1);
|
|
}
|
|
|
|
/* Now get the index of the archive. */
|
|
arsym = elf_getarsym (elf, &narsym);
|
|
if (arsym == NULL)
|
|
{
|
|
printf ("Cannot get archive index: %s\n", elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
|
|
/* If there is no element in the index do nothing. There always is
|
|
an empty entry at the end which is included in the count and
|
|
which we want to skip. */
|
|
if (narsym-- > 1)
|
|
while (narsym-- > 0)
|
|
{
|
|
Elf *subelf;
|
|
Elf_Arhdr *arhdr;
|
|
|
|
if (elf_rand (elf, arsym[narsym].as_off) != arsym[narsym].as_off)
|
|
{
|
|
printf ("random access for symbol `%s' fails: %s\n",
|
|
arsym[narsym].as_name, elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
|
|
subelf = elf_begin (fd, ELF_C_READ, elf);
|
|
if (subelf == NULL)
|
|
{
|
|
printf ("Cannot create ELF descriptor for archive member: %s\n",
|
|
elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
|
|
arhdr = elf_getarhdr (subelf);
|
|
if (arhdr == NULL)
|
|
{
|
|
printf ("Cannot get archive header for element `%s': %s\n",
|
|
arsym[narsym].as_name, elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
|
|
/* Now print what we actually want. */
|
|
fprintf (fp, "%s in %s\n", arsym[narsym].as_name, arhdr->ar_name);
|
|
|
|
/* Free the ELF descriptor. */
|
|
if (elf_end (subelf) != 0)
|
|
{
|
|
printf ("Error while freeing subELF descriptor: %s\n",
|
|
elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
}
|
|
|
|
/* Free the ELF descriptor. */
|
|
if (elf_end (elf) != 0)
|
|
{
|
|
printf ("Error while freeing ELF descriptor: %s\n", elf_errmsg (-1));
|
|
exit (1);
|
|
}
|
|
|
|
close (fd);
|
|
fclose (fp);
|
|
|
|
return 0;
|
|
}
|