diff options
Diffstat (limited to 'tools/elfutils')
-rw-r--r-- | tools/elfutils/Makefile | 83 | ||||
-rw-r--r-- | tools/elfutils/patches/001-fix-backport-iquote-include.patch | 12 | ||||
-rw-r--r-- | tools/elfutils/patches/011-backport-mips-support-strip.patch | 230 | ||||
-rw-r--r-- | tools/elfutils/patches/012-backport-mips-support-readelf.patch | 1079 | ||||
-rw-r--r-- | tools/elfutils/patches/013-backport-mips-support-elflint.patch | 157 | ||||
-rw-r--r-- | tools/elfutils/patches/100-portability.patch | 780 | ||||
-rw-r--r-- | tools/elfutils/patches/101-shared-conditional.patch | 184 | ||||
-rw-r--r-- | tools/elfutils/patches/110-objects-manifest.patch | 162 |
8 files changed, 1961 insertions, 726 deletions
diff --git a/tools/elfutils/Makefile b/tools/elfutils/Makefile index 466fc31271..294947df10 100644 --- a/tools/elfutils/Makefile +++ b/tools/elfutils/Makefile @@ -3,22 +3,22 @@ include $(TOPDIR)/rules.mk PKG_NAME:=elfutils -PKG_VERSION:=0.191 -PKG_RELEASE:=2 +PKG_VERSION:=0.192 +PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 PKG_SOURCE_URL:=https://sourceware.org/$(PKG_NAME)/ftp/$(PKG_VERSION) -PKG_HASH:=df76db71366d1d708365fc7a6c60ca48398f14367eb2b8954efc8897147ad871 +PKG_HASH:=616099beae24aba11f9b63d86ca6cc8d566d968b802391334c91df54eab416b4 PKG_LICENSE:=GPL-3.0-or-later PKG_LICENSE_FILES:=COPYING COPYING-GPLV2 COPYING-LGPLV3 PKG_CPE_ID:=cpe:/a:elfutils_project:elfutils PKG_FIXUP:=autoreconf -PKG_INSTALL:=1 + +PKG_PROGRAMS:=elflint findtextrel elfcmp unstrip stack elfcompress elfclassify srcfiles PKG_SUBDIRS := \ - libgnu \ config \ lib \ libelf \ @@ -27,35 +27,77 @@ PKG_SUBDIRS := \ libebl \ libdwelf \ libdwfl \ - libdw + libdw \ + src PKG_GNULIB_BASE:=libgnu PKG_GNULIB_ARGS = \ --dir=$(HOST_BUILD_DIR) \ - --local-dir=$(STAGING_DIR_HOST)/share/gnulib \ - --source-base=$(PKG_GNULIB_BASE) \ --libtool \ --avoid=reallocarray \ --import PKG_GNULIB_MODS = \ argp \ + fallocate-posix \ + fnmatch-gnu \ fts \ - obstack \ + obstack-printf-posix \ progname \ strchrnul \ tsearch +HOST_BUILD_PARALLEL:=1 + include $(INCLUDE_DIR)/host-build.mk +export $(PKG_GNULIB_BASE)=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/.libs/$(PKG_GNULIB_BASE).a + +export $(PKG_GNULIB_BASE)_exitfail=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-exitfail.o +export $(PKG_GNULIB_BASE)_fallocate-posix=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-posix_fallocate.o +export $(PKG_GNULIB_BASE)_mbszero=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-mbszero.o +export $(PKG_GNULIB_BASE)_obstack=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-obstack.o +export $(PKG_GNULIB_BASE)_obstack-printf=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-obstack_printf.o +export $(PKG_GNULIB_BASE)_printf-args=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-printf-args.o +export $(PKG_GNULIB_BASE)_printf-frexp=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-printf-frexp.o +export $(PKG_GNULIB_BASE)_printf-frexpl=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-printf-frexpl.o +export $(PKG_GNULIB_BASE)_printf-parse=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-printf-parse.o +export $(PKG_GNULIB_BASE)_tsearch=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-tsearch.o +export $(PKG_GNULIB_BASE)_vasnprintf=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-vasnprintf.o +export $(PKG_GNULIB_BASE)_xsize=$(HOST_BUILD_DIR)/$(PKG_GNULIB_BASE)/$(PKG_GNULIB_BASE)_la-xsize.o + +HOST_MAKE_FLAGS += \ + am__CONFIG_DISTCLEAN_FILES= \ + DEFAULT_INCLUDES='-iquote . -I$$$$(top_builddir) -I$$$$(top_srcdir)/$(PKG_GNULIB_BASE)' \ + AM_LDFLAGS='$$$$(STACK_USAGE_NO_ERROR)' \ + LIBS+='$$$$(if $$$$(findstring $(lastword $(PKG_SUBDIRS)),$$$$(subdir)), $$$$($(PKG_GNULIB_BASE)))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_exitfail))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_fallocate-posix))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_mbszero))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_obstack))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_obstack-printf))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_printf-args))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_printf-frexp))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_printf-frexpl))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_printf-parse))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_tsearch))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_vasnprintf))' \ + LIBS+='$$$$(wildcard $$$$($(PKG_GNULIB_BASE)_xsize))' \ + REPLACE_FCNTL=0 REPLACE_FREE=0 REPLACE_FSTAT=0 REPLACE_OPEN=0 \ + REPLACE_OBSTACK=0 REPLACE_OBSTACK_PRINTF=0 \ + bin_PROGRAMS='$(PKG_PROGRAMS)' EXEEXT= + +HOST_CPPFLAGS += "'-I$$$$(top_srcdir)/lib'" + ifeq ($(HOST_OS),Darwin) HOST_CFLAGS += -I/opt/homebrew/include endif -HOST_CFLAGS += -Wno-error -fPIC +HOST_CFLAGS += -Wno-error -fPIC -std=gnu17 HOST_CONFIGURE_ARGS += \ + --enable-maintainer-mode \ --without-libintl-prefix \ --without-libiconv-prefix \ --disable-debuginfod \ @@ -71,22 +113,23 @@ ifeq ($(HOST_OS),Darwin) HOST_CONFIGURE_ARGS += --disable-symbol-versioning endif -Hooks/HostConfigure/Pre := Host/Gnulib $(Hooks/HostConfigure/Pre) -define Host/Gnulib - $(STAGING_DIR_HOST)/bin/gnulib-tool $(PKG_GNULIB_ARGS) $(PKG_GNULIB_MODS); - ln -sf ../lib/eu-config.h $(HOST_BUILD_DIR)/libgnu/; -endef +HOST_CONFIGURE_VARS += \ + ac_cv_search_argp_parse=yes \ + ac_cv_search_fts_close=yes \ + ac_cv_search__obstack_free=yes \ + ac_cv_buildid=yes -define Host/Compile - $(call Host/Compile/Default,SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))') -endef +Hooks/HostConfigure/Pre := Host/Gnulib/Prepare $(Hooks/HostConfigure/Pre) +Hooks/HostCompile/Pre := Host/Gnulib/Compile $(Hooks/HostCompile/Pre) -define Host/Install - $(call Host/Compile/Default,install SUBDIRS='$$$$(wildcard $(PKG_SUBDIRS))') +define Host/Configure + $(call Host/Configure/Default) + $(call Host/Uninstall) endef define Host/Uninstall -$(call Host/Compile/Default,uninstall) + -$(call Host/Compile/Default,maintainer-clean) # Clean bootstrap files from the release endef $(eval $(call HostBuild)) diff --git a/tools/elfutils/patches/001-fix-backport-iquote-include.patch b/tools/elfutils/patches/001-fix-backport-iquote-include.patch new file mode 100644 index 0000000000..62ed84dd27 --- /dev/null +++ b/tools/elfutils/patches/001-fix-backport-iquote-include.patch @@ -0,0 +1,12 @@ +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -21,7 +21,8 @@ DEFS += $(YYDEBUG) -DDEBUGPRED=@DEBUGPRE + -DSRCDIR=\"$(shell cd $(srcdir);pwd)\" -DOBJDIR=\"$(shell pwd)\" + + DEFAULT_INCLUDES = +-AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ ++AM_CPPFLAGS = -iquote . -iquote $(srcdir) -I$(top_srcdir)/lib \ ++ -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ + -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf \ + -I$(srcdir)/../libdwfl -I$(srcdir)/../libasm -I../debuginfod + diff --git a/tools/elfutils/patches/011-backport-mips-support-strip.patch b/tools/elfutils/patches/011-backport-mips-support-strip.patch new file mode 100644 index 0000000000..7ea9bedc1a --- /dev/null +++ b/tools/elfutils/patches/011-backport-mips-support-strip.patch @@ -0,0 +1,230 @@ +In mips64 little-endian, r_info consists of four byte fields(contains +three reloc types) and a 32-bit symbol index. In order to adapt +GELF_R_SYM and GELF_R_TYPE, need convert raw data to get correct symbol +index and type. + + libelf/elf_getdata.c: Some eu-utils use read-mmap method to map file, +so we need to malloc and memcpy raw data to avoid segment fault. After +modification, the correct value are saved in the malloced memory not in +process address space. + libelf/elf_updata.c: Because we converted the relocation info in mips +order when we call elf_getdata.c, so we need to convert the modified data +in original order bits before writing the data to the file. + +Signed-off-by: Ying Huang <ying.huang@oss.cipunited.com> +--- + libelf/elf_getdata.c | 132 ++++++++++++++++++++++++++++++++++++++++++- + libelf/elf_update.c | 53 +++++++++++++++++ + 2 files changed, 183 insertions(+), 2 deletions(-) + +--- a/libelf/elf_getdata.c ++++ b/libelf/elf_getdata.c +@@ -135,6 +135,119 @@ __libelf_data_type (GElf_Ehdr *ehdr, int + + /* Convert the data in the current section. */ + static void ++convert_data_for_mips64el (Elf_Scn *scn, int eclass, ++ int data, size_t size, Elf_Type type) ++{ ++ /* Do we need to convert the data and/or adjust for alignment? */ ++ if (data == MY_ELFDATA || type == ELF_T_BYTE) ++ { ++ /* In order to adapt macro GELF_R_SYM and GELF_R_TYPE on mips64, need to convert ++ relocation info(raw data). Some eu-utils use read-mmap method to map file, so ++ we need to malloc and memcpy raw data to avoid segment fault. After modification, ++ the correct value are saved in the malloced memory not in process address space. */ ++ scn->data_base = malloc (size); ++ if (scn->data_base == NULL) ++ { ++ __libelf_seterrno (ELF_E_NOMEM); ++ return; ++ } ++ ++ /* The copy will be appropriately aligned for direct access. */ ++ memcpy (scn->data_base, scn->rawdata_base, size); ++ } ++ else ++ { ++ xfct_t fp; ++ ++ scn->data_base = malloc (size); ++ if (scn->data_base == NULL) ++ { ++ __libelf_seterrno (ELF_E_NOMEM); ++ return; ++ } ++ ++ /* Make sure the source is correctly aligned for the conversion ++ function to directly access the data elements. */ ++ char *rawdata_source; ++ /* In order to adapt macro GELF_R_SYM and GELF_R_TYPE on mips64, need to convert ++ relocation info(raw data). Some eu-utils use read-mmap method to map file, so ++ we need to malloc and memcpy raw data to avoid segment fault. After modification, ++ the correct value are saved in the malloced memory not in process address space. */ ++ rawdata_source = malloc (size); ++ if (rawdata_source == NULL) ++ { ++ __libelf_seterrno (ELF_E_NOMEM); ++ return; ++ } ++ ++ /* The copy will be appropriately aligned for direct access. */ ++ memcpy (rawdata_source, scn->rawdata_base, size); ++ ++ /* Get the conversion function. */ ++ fp = __elf_xfctstom[eclass - 1][type]; ++ ++ fp (scn->data_base, rawdata_source, size, 0); ++ ++ if (rawdata_source != scn->rawdata_base) ++ free (rawdata_source); ++ } ++ ++ scn->data_list.data.d.d_buf = scn->data_base; ++ scn->data_list.data.d.d_size = size; ++ scn->data_list.data.d.d_type = type; ++ scn->data_list.data.d.d_off = scn->rawdata.d.d_off; ++ scn->data_list.data.d.d_align = scn->rawdata.d.d_align; ++ scn->data_list.data.d.d_version = scn->rawdata.d.d_version; ++ ++ scn->data_list.data.s = scn; ++ ++ /* In mips64 little-endian, r_info consists of four byte fields(contains ++ three reloc types) and a 32-bit symbol index. In order to adapt ++ GELF_R_SYM and GELF_R_TYPE, need to convert r_info to get correct symbol ++ index and type. */ ++ /* references: ++ https://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf ++ Page40 && Page41 */ ++ GElf_Shdr shdr_mem; ++ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); ++ if (shdr->sh_type == SHT_REL) ++ { ++ size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_REL, 1, EV_CURRENT); ++ int nentries = shdr->sh_size / sh_entsize; ++ for (int cnt = 0; cnt < nentries; ++cnt) ++ { ++ Elf_Data_Scn *data_scn = (Elf_Data_Scn *) &scn->data_list.data.d; ++ Elf64_Rel *value = &((Elf64_Rel *) data_scn->d.d_buf)[cnt]; ++ Elf64_Xword info = value->r_info; ++ value->r_info = (((info & 0xffffffff) << 32) ++ | ((info >> 56) & 0xff) ++ | ((info >> 40) & 0xff00) ++ | ((info >> 24) & 0xff0000) ++ | ((info >> 8) & 0xff000000)); ++ ((Elf64_Rel *) data_scn->d.d_buf)[cnt] = *value; ++ } ++ } ++ else if (shdr->sh_type == SHT_RELA) ++ { ++ size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_RELA, 1, EV_CURRENT); ++ int nentries = shdr->sh_size / sh_entsize; ++ for (int cnt = 0; cnt < nentries; cnt++) ++ { ++ Elf_Data_Scn *data_scn = (Elf_Data_Scn *) &scn->data_list.data.d; ++ Elf64_Rela *value = &((Elf64_Rela *) data_scn->d.d_buf)[cnt]; ++ Elf64_Xword info = value->r_info; ++ value->r_info = (((info & 0xffffffff) << 32) ++ | ((info >> 56) & 0xff) ++ | ((info >> 40) & 0xff00) ++ | ((info >> 24) & 0xff0000) ++ | ((info >> 8) & 0xff000000)); ++ ((Elf64_Rela *) data_scn->d.d_buf)[cnt] = *value; ++ } ++ } ++} ++ ++/* Convert the data in the current section. */ ++static void + convert_data (Elf_Scn *scn, int eclass, + int data, size_t size, Elf_Type type) + { +@@ -451,8 +564,23 @@ __libelf_set_data_list_rdlock (Elf_Scn * + return; + } + +- /* Convert according to the version and the type. */ +- convert_data (scn, elf->class, ++ GElf_Shdr shdr_mem; ++ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); ++ GElf_Ehdr ehdr_mem; ++ GElf_Ehdr *ehdr = gelf_getehdr (scn->elf, &ehdr_mem); ++ if (shdr != NULL && (shdr->sh_type == SHT_RELA || shdr->sh_type == SHT_REL) && ++ scn->elf->class == ELFCLASS64 && ehdr != NULL && ++ ehdr->e_machine == EM_MIPS && ehdr->e_ident[EI_DATA] == ELFDATA2LSB) ++ convert_data_for_mips64el (scn, elf->class, ++ (elf->class == ELFCLASS32 ++ || (offsetof (struct Elf, state.elf32.ehdr) ++ == offsetof (struct Elf, state.elf64.ehdr)) ++ ? elf->state.elf32.ehdr->e_ident[EI_DATA] ++ : elf->state.elf64.ehdr->e_ident[EI_DATA]), ++ scn->rawdata.d.d_size, scn->rawdata.d.d_type); ++ else ++ /* Convert according to the version and the type. */ ++ convert_data (scn, elf->class, + (elf->class == ELFCLASS32 + || (offsetof (struct Elf, state.elf32.ehdr) + == offsetof (struct Elf, state.elf64.ehdr)) +--- a/libelf/elf_update.c ++++ b/libelf/elf_update.c +@@ -228,7 +228,60 @@ elf_update (Elf *elf, Elf_Cmd cmd) + size = -1; + } + else ++ { ++ /* Because we converted the relocation info in mips order when we call elf_getdata.c, ++ so we need to convert the modified data in original order bits before writing the ++ data to the file. */ ++ Elf_Scn *scn = NULL; ++ while ((scn = elf_nextscn (elf, scn)) != NULL) ++ { ++ GElf_Shdr shdr_mem; ++ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); ++ GElf_Ehdr ehdr_mem; ++ GElf_Ehdr *ehdr = gelf_getehdr (scn->elf, &ehdr_mem); ++ if (shdr != NULL && (shdr->sh_type == SHT_RELA || shdr->sh_type == SHT_REL) && ++ scn->elf->class == ELFCLASS64 && ++ ehdr != NULL && ehdr->e_machine == EM_MIPS && ehdr->e_ident[EI_DATA] == ELFDATA2LSB) ++ { ++ Elf_Data *d = elf_getdata (scn, NULL); ++ if (shdr->sh_type == SHT_REL) ++ { ++ size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_REL, 1, EV_CURRENT); ++ int nentries = shdr->sh_size / sh_entsize; ++ for (int cnt = 0; cnt < nentries; ++cnt) ++ { ++ Elf_Data_Scn *data_scn = (Elf_Data_Scn *) d; ++ Elf64_Rel *value = &((Elf64_Rel *) data_scn->d.d_buf)[cnt]; ++ Elf64_Xword info = value->r_info; ++ value->r_info = (info >> 32 ++ | ((info << 56) & 0xff00000000000000) ++ | ((info << 40) & 0xff000000000000) ++ | ((info << 24) & 0xff0000000000) ++ | ((info << 8) & 0xff00000000)); ++ ((Elf64_Rel *) data_scn->d.d_buf)[cnt] = *value; ++ } ++ } ++ else if (shdr->sh_type == SHT_RELA) ++ { ++ size_t sh_entsize = gelf_fsize (scn->elf, ELF_T_RELA, 1, EV_CURRENT); ++ int nentries = shdr->sh_size / sh_entsize; ++ for (int cnt = 0; cnt < nentries; cnt++) ++ { ++ Elf_Data_Scn *data_scn = (Elf_Data_Scn *) d; ++ Elf64_Rela *value = &((Elf64_Rela *) data_scn->d.d_buf)[cnt]; ++ Elf64_Xword info = value->r_info; ++ value->r_info = (info >> 32 ++ | ((info << 56) & 0xff00000000000000) ++ | ((info << 40) & 0xff000000000000) ++ | ((info << 24) & 0xff0000000000) ++ | ((info << 8) & 0xff00000000)); ++ ((Elf64_Rela *) data_scn->d.d_buf)[cnt] = *value; ++ } ++ } ++ } ++ } + size = write_file (elf, size, change_bo, shnum); ++ } + } + + out: diff --git a/tools/elfutils/patches/012-backport-mips-support-readelf.patch b/tools/elfutils/patches/012-backport-mips-support-readelf.patch new file mode 100644 index 0000000000..3a61acde6e --- /dev/null +++ b/tools/elfutils/patches/012-backport-mips-support-readelf.patch @@ -0,0 +1,1079 @@ +-h: support show Flags name +-S: support show mips related section type +-r: support show type of Relocation section +-w: can work and can show correct "strp" contents +-l: support show mips related program header entry type +-d: can show mips related Dynamic type name +-a: support show complete Object attribute section ".gnu.attributes" + +Also add test/run-readelf-reloc.sh file to test new type2/type3 of +src/readelf -r. + +Signed-off-by: Ying Huang <ying.huang@oss.cipunited.com> +--- + backends/Makefile.am | 2 +- + backends/mips_attrs.c | 140 +++++++++ + backends/mips_init.c | 7 + + backends/mips_symbol.c | 571 +++++++++++++++++++++++++++++++++++++ + libelf/libelfP.h | 1 + + src/readelf.c | 188 +++++++++--- + tests/Makefile.am | 5 +- + tests/run-readelf-reloc.sh | 42 +++ + 8 files changed, 907 insertions(+), 49 deletions(-) + create mode 100644 backends/mips_attrs.c + create mode 100755 tests/run-readelf-reloc.sh + +--- a/backends/Makefile.am ++++ b/backends/Makefile.am +@@ -102,7 +102,7 @@ loongarch_SRCS = loongarch_init.c loonga + + arc_SRCS = arc_init.c arc_symbol.c + +-mips_SRCS = mips_init.c mips_symbol.c mips_initreg.c \ ++mips_SRCS = mips_init.c mips_symbol.c mips_attrs.c mips_initreg.c \ + mips_cfi.c mips_unwind.c mips_regs.c mips_retval.c \ + mips_corenote.c + +--- /dev/null ++++ b/backends/mips_attrs.c +@@ -0,0 +1,140 @@ ++/* Object attribute tags for MIPS. ++ Copyright (C) 2024 CIP United Inc. ++ This file is part of elfutils. ++ ++ This file is free software; you can redistribute it and/or modify ++ it under the terms of either ++ ++ * the GNU Lesser General Public License as published by the Free ++ Software Foundation; either version 3 of the License, or (at ++ your option) any later version ++ ++ or ++ ++ * the GNU General Public License as published by the Free ++ Software Foundation; either version 2 of the License, or (at ++ your option) any later version ++ ++ or both in parallel, as here. ++ ++ 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 copies of the GNU General Public License and ++ the GNU Lesser General Public License along with this program. If ++ not, see <http://www.gnu.org/licenses/>. */ ++ ++#ifdef HAVE_CONFIG_H ++# include <config.h> ++#endif ++ ++#include <string.h> ++#include <dwarf.h> ++ ++#define BACKEND mips_ ++#include "libebl_CPU.h" ++ ++#define KNOWN_VALUES(...) do \ ++ { \ ++ static const char *table[] = { __VA_ARGS__ }; \ ++ if (value < sizeof table / sizeof table[0]) \ ++ *value_name = table[value]; \ ++ } while (0) ++ ++//copy gnu attr tags from binutils-2.34/elfcpp/mips.h ++/* Object attribute tags. */ ++enum ++{ ++ /* 0-3 are generic. */ ++ ++ /* Floating-point ABI used by this object file. */ ++ Tag_GNU_MIPS_ABI_FP = 4, ++ ++ /* MSA ABI used by this object file. */ ++ Tag_GNU_MIPS_ABI_MSA = 8, ++}; ++ ++/* Object attribute values. */ ++enum ++{ ++ /* Values defined for Tag_GNU_MIPS_ABI_MSA. */ ++ ++ /* Not tagged or not using any ABIs affected by the differences. */ ++ Val_GNU_MIPS_ABI_MSA_ANY = 0, ++ ++ /* Using 128-bit MSA. */ ++ Val_GNU_MIPS_ABI_MSA_128 = 1, ++}; ++ ++/* Object attribute values. */ ++enum ++{ ++ /* This is reserved for backward-compatibility with an earlier ++ implementation of the MIPS NaN2008 functionality. */ ++ Val_GNU_MIPS_ABI_FP_NAN2008 = 8, ++}; ++ ++/* copy binutils-2.34/binutils/readelf.c display_mips_gnu_attribute */ ++bool ++mips_check_object_attribute (Ebl *ebl __attribute__ ((unused)), ++ const char *vendor, int tag, uint64_t value, ++ const char **tag_name, const char **value_name) ++{ ++ if (!strcmp (vendor, "gnu")) ++ switch (tag) ++ { ++ case Tag_GNU_MIPS_ABI_FP: ++ *tag_name = "Tag_GNU_MIPS_ABI_FP"; ++ switch (value) ++ { ++ case Val_GNU_MIPS_ABI_FP_ANY: ++ *value_name = "Hard or soft float"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_DOUBLE: ++ *value_name = "Hard float (double precision)"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_SINGLE: ++ *value_name = "Hard float (single precision)"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_SOFT: ++ *value_name = "Soft float"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_OLD_64: ++ *value_name = "Hard float (MIPS32r2 64-bit FPU 12 callee-saved)"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_XX: ++ *value_name = "Hard float (32-bit CPU, Any FPU)"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_64: ++ *value_name = "Hard float (32-bit CPU, 64-bit FPU)"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_64A: ++ *value_name = "Hard float compat (32-bit CPU, 64-bit FPU)"; ++ return true; ++ case Val_GNU_MIPS_ABI_FP_NAN2008: ++ *value_name = "NaN 2008 compatibility"; ++ return true; ++ default: ++ return true; ++ } ++ return true; ++ case Tag_GNU_MIPS_ABI_MSA: ++ *tag_name = "Tag_GNU_MIPS_ABI_MSA"; ++ switch (value) ++ { ++ case Val_GNU_MIPS_ABI_MSA_ANY: ++ *value_name = "Any MSA or not"; ++ return true; ++ case Val_GNU_MIPS_ABI_MSA_128: ++ *value_name = "128-bit MSA"; ++ return true; ++ default: ++ return true; ++ } ++ return true; ++ } ++ ++ return false; ++} +--- a/backends/mips_init.c ++++ b/backends/mips_init.c +@@ -48,6 +48,13 @@ mips_init (Elf *elf __attribute__ ((unus + /* We handle it. */ + mips_init_reloc (eh); + HOOK (eh, reloc_simple_type); ++ HOOK (eh, section_type_name); ++ HOOK (eh, machine_flag_check); ++ HOOK (eh, machine_flag_name); ++ HOOK (eh, segment_type_name); ++ HOOK (eh, dynamic_tag_check); ++ HOOK (eh, dynamic_tag_name); ++ HOOK (eh, check_object_attribute); + HOOK (eh, set_initial_registers_tid); + HOOK (eh, abi_cfi); + HOOK (eh, unwind); +--- a/backends/mips_symbol.c ++++ b/backends/mips_symbol.c +@@ -61,3 +61,574 @@ mips_reloc_simple_type (Ebl *ebl, int ty + return ELF_T_NUM; + } + } ++ ++/* copy binutils-2.34/binutils/readelf.c get_mips_section_type_name */ ++const char * ++mips_section_type_name (int type, ++ char *buf __attribute__ ((unused)), ++ size_t len __attribute__ ((unused))) ++{ ++ switch (type) ++ { ++ case SHT_MIPS_LIBLIST: ++ return "MIPS_LIBLIST"; ++ case SHT_MIPS_MSYM: ++ return "MIPS_MSYM"; ++ case SHT_MIPS_CONFLICT: ++ return "MIPS_CONFLICT"; ++ case SHT_MIPS_GPTAB: ++ return "MIPS_GPTAB"; ++ case SHT_MIPS_UCODE: ++ return "MIPS_UCODE"; ++ case SHT_MIPS_DEBUG: ++ return "MIPS_DEBUG"; ++ case SHT_MIPS_REGINFO: ++ return "MIPS_REGINFO"; ++ case SHT_MIPS_PACKAGE: ++ return "MIPS_PACKAGE"; ++ case SHT_MIPS_PACKSYM: ++ return "MIPS_PACKSYM"; ++ case SHT_MIPS_RELD: ++ return "MIPS_RELD"; ++ case SHT_MIPS_IFACE: ++ return "MIPS_IFACE"; ++ case SHT_MIPS_CONTENT: ++ return "MIPS_CONTENT"; ++ case SHT_MIPS_OPTIONS: ++ return "MIPS_OPTIONS"; ++ case SHT_MIPS_SHDR: ++ return "MIPS_SHDR"; ++ case SHT_MIPS_FDESC: ++ return "MIPS_FDESC"; ++ case SHT_MIPS_EXTSYM: ++ return "MIPS_EXTSYM"; ++ case SHT_MIPS_DENSE: ++ return "MIPS_DENSE"; ++ case SHT_MIPS_PDESC: ++ return "MIPS_PDESC"; ++ case SHT_MIPS_LOCSYM: ++ return "MIPS_LOCSYM"; ++ case SHT_MIPS_AUXSYM: ++ return "MIPS_AUXSYM"; ++ case SHT_MIPS_OPTSYM: ++ return "MIPS_OPTSYM"; ++ case SHT_MIPS_LOCSTR: ++ return "MIPS_LOCSTR"; ++ case SHT_MIPS_LINE: ++ return "MIPS_LINE"; ++ case SHT_MIPS_RFDESC: ++ return "MIPS_RFDESC"; ++ case SHT_MIPS_DELTASYM: ++ return "MIPS_DELTASYM"; ++ case SHT_MIPS_DELTAINST: ++ return "MIPS_DELTAINST"; ++ case SHT_MIPS_DELTACLASS: ++ return "MIPS_DELTACLASS"; ++ case SHT_MIPS_DWARF: ++ return "MIPS_DWARF"; ++ case SHT_MIPS_DELTADECL: ++ return "MIPS_DELTADECL"; ++ case SHT_MIPS_SYMBOL_LIB: ++ return "MIPS_SYMBOL_LIB"; ++ case SHT_MIPS_EVENTS: ++ return "MIPS_EVENTS"; ++ case SHT_MIPS_TRANSLATE: ++ return "MIPS_TRANSLATE"; ++ case SHT_MIPS_PIXIE: ++ return "MIPS_PIXIE"; ++ case SHT_MIPS_XLATE: ++ return "MIPS_XLATE"; ++ case SHT_MIPS_XLATE_DEBUG: ++ return "MIPS_XLATE_DEBUG"; ++ case SHT_MIPS_WHIRL: ++ return "MIPS_WHIRL"; ++ case SHT_MIPS_EH_REGION: ++ return "MIPS_EH_REGION"; ++ case SHT_MIPS_XLATE_OLD: ++ return "MIPS_XLATE_OLD"; ++ case SHT_MIPS_PDR_EXCEPTION: ++ return "MIPS_PDR_EXCEPTION"; ++ case SHT_MIPS_ABIFLAGS: ++ return "MIPS_ABIFLAGS"; ++ case SHT_MIPS_XHASH: ++ return "MIPS_XHASH"; ++ default: ++ break; ++ } ++ return NULL; ++} ++ ++/* Check whether machine flags are valid. */ ++bool ++mips_machine_flag_check (GElf_Word flags) ++{ ++ if ((flags &~ (EF_MIPS_NOREORDER | ++ EF_MIPS_PIC | ++ EF_MIPS_CPIC | ++ EF_MIPS_UCODE | ++ EF_MIPS_ABI2 | ++ EF_MIPS_OPTIONS_FIRST | ++ EF_MIPS_32BITMODE | ++ EF_MIPS_NAN2008 | ++ EF_MIPS_FP64 | ++ EF_MIPS_ARCH_ASE_MDMX | ++ EF_MIPS_ARCH_ASE_M16 | ++ EF_MIPS_ARCH_ASE_MICROMIPS)) == 0) ++ return false; ++ ++ switch(flags & EF_MIPS_MACH) ++ { ++ case EF_MIPS_MACH_3900: ++ case EF_MIPS_MACH_4010: ++ case EF_MIPS_MACH_4100: ++ case EF_MIPS_MACH_4111: ++ case EF_MIPS_MACH_4120: ++ case EF_MIPS_MACH_4650: ++ case EF_MIPS_MACH_5400: ++ case EF_MIPS_MACH_5500: ++ case EF_MIPS_MACH_5900: ++ case EF_MIPS_MACH_SB1: ++ case EF_MIPS_MACH_9000: ++ case EF_MIPS_MACH_LS2E: ++ case EF_MIPS_MACH_LS2F: ++ case EF_MIPS_MACH_GS464: ++ case EF_MIPS_MACH_GS464E: ++ case EF_MIPS_MACH_GS264E: ++ case EF_MIPS_MACH_OCTEON: ++ case EF_MIPS_MACH_OCTEON2: ++ case EF_MIPS_MACH_OCTEON3: ++ case EF_MIPS_MACH_XLR: ++ case EF_MIPS_MACH_IAMR2: ++ case 0: ++ break; ++ default: ++ return false; ++ } ++ ++ switch ((flags & EF_MIPS_ABI)) ++ { ++ case EF_MIPS_ABI_O32: ++ case EF_MIPS_ABI_O64: ++ case EF_MIPS_ABI_EABI32: ++ case EF_MIPS_ABI_EABI64: ++ case 0: ++ break; ++ default: ++ return false; ++ } ++ ++ switch ((flags & EF_MIPS_ARCH)) ++ { ++ case EF_MIPS_ARCH_1: ++ case EF_MIPS_ARCH_2: ++ case EF_MIPS_ARCH_3: ++ case EF_MIPS_ARCH_4: ++ case EF_MIPS_ARCH_5: ++ case EF_MIPS_ARCH_32: ++ case EF_MIPS_ARCH_32R2: ++ case EF_MIPS_ARCH_32R6: ++ case EF_MIPS_ARCH_64: ++ case EF_MIPS_ARCH_64R2: ++ case EF_MIPS_ARCH_64R6: ++ return true; ++ default: ++ return false; ++ } ++ return false; ++} ++ ++/* copy binutils-2.34/binutils/readelf.c get_machine_flags */ ++const char * ++mips_machine_flag_name (Elf64_Word orig __attribute__ ((unused)), Elf64_Word *flagref) ++{ ++ if (*flagref & EF_MIPS_NOREORDER) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_NOREORDER); ++ return "noreorder"; ++ } ++ ++ if (*flagref & EF_MIPS_PIC) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_PIC); ++ return "pic"; ++ } ++ ++ if (*flagref & EF_MIPS_CPIC) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_CPIC); ++ return "cpic"; ++ } ++ ++ if (*flagref & EF_MIPS_UCODE) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_UCODE); ++ return "ugen_reserved"; ++ } ++ ++ if (*flagref & EF_MIPS_ABI2) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_ABI2); ++ return "abi2"; ++ } ++ ++ if (*flagref & EF_MIPS_OPTIONS_FIRST) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_OPTIONS_FIRST); ++ return "odk first"; ++ } ++ ++ if (*flagref & EF_MIPS_32BITMODE) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_32BITMODE); ++ return "32bitmode"; ++ } ++ ++ if (*flagref & EF_MIPS_NAN2008) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_NAN2008); ++ return "nan2008"; ++ } ++ ++ if (*flagref & EF_MIPS_FP64) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_FP64); ++ return "fp64"; ++ } ++ ++ switch (*flagref & EF_MIPS_MACH) ++ { ++ case EF_MIPS_MACH_3900: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_3900); ++ return "3900"; ++ case EF_MIPS_MACH_4010: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4010); ++ return "4010"; ++ case EF_MIPS_MACH_4100: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4100); ++ return "4100"; ++ case EF_MIPS_MACH_4111: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4111); ++ return "4111"; ++ case EF_MIPS_MACH_4120: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4120); ++ return "4120"; ++ case EF_MIPS_MACH_4650: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_4650); ++ return "4650"; ++ case EF_MIPS_MACH_5400: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5400); ++ return "5400"; ++ case EF_MIPS_MACH_5500: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5500); ++ return "5500"; ++ case EF_MIPS_MACH_5900: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_5900); ++ return "5900"; ++ case EF_MIPS_MACH_SB1: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_SB1); ++ return "sb1"; ++ case EF_MIPS_MACH_9000: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_9000); ++ return "9000"; ++ case EF_MIPS_MACH_LS2E: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_LS2E); ++ return "loongson-2e"; ++ case EF_MIPS_MACH_LS2F: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_LS2F); ++ return "loongson-2f"; ++ case EF_MIPS_MACH_GS464: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS464); ++ return "gs464"; ++ case EF_MIPS_MACH_GS464E: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS464E); ++ return "gs464e"; ++ case EF_MIPS_MACH_GS264E: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_GS264E); ++ return "gs264e"; ++ case EF_MIPS_MACH_OCTEON: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON); ++ return "octeon"; ++ case EF_MIPS_MACH_OCTEON2: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON2); ++ return "octeon2"; ++ case EF_MIPS_MACH_OCTEON3: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_OCTEON3); ++ return "octeon3"; ++ case EF_MIPS_MACH_XLR: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_XLR); ++ return "xlr"; ++ case EF_MIPS_MACH_IAMR2: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH_IAMR2); ++ return "interaptiv-mr2"; ++ case 0: ++ /* We simply ignore the field in this case to avoid confusion: ++ MIPS ELF does not specify EF_MIPS_MACH, it is a GNU ++ extension. */ ++ break; ++ default: ++ *flagref &= ~((Elf64_Word) EF_MIPS_MACH); ++ return "unknown CPU"; ++ } ++ switch (*flagref & EF_MIPS_ABI) ++ { ++ case EF_MIPS_ABI_O32: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ABI_O32); ++ return "o32"; ++ case EF_MIPS_ABI_O64: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ABI_O64); ++ return "o64"; ++ case EF_MIPS_ABI_EABI32: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ABI_EABI32); ++ return "eabi32"; ++ case EF_MIPS_ABI_EABI64: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ABI_EABI64); ++ return "eabi64"; ++ case 0: ++ /* We simply ignore the field in this case to avoid confusion: ++ MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. ++ This means it is likely to be an o32 file, but not for ++ sure. */ ++ break; ++ default: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ABI); ++ return "unknown ABI"; ++ } ++ ++ if (*flagref & EF_MIPS_ARCH_ASE_MDMX) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_MDMX); ++ return "mdmx"; ++ } ++ ++ if (*flagref & EF_MIPS_ARCH_ASE_M16) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_M16); ++ return "mips16"; ++ } ++ ++ if (*flagref & EF_MIPS_ARCH_ASE_MICROMIPS) ++ { ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_ASE_MICROMIPS); ++ return "micromips"; ++ } ++ ++ switch (*flagref & EF_MIPS_ARCH) ++ { ++ case EF_MIPS_ARCH_1: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_1); ++ return "mips1"; ++ case EF_MIPS_ARCH_2: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_2); ++ return "mips2"; ++ case EF_MIPS_ARCH_3: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_3); ++ return "mips3"; ++ case EF_MIPS_ARCH_4: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_4); ++ return "mips4"; ++ case EF_MIPS_ARCH_5: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_5); ++ return "mips5"; ++ case EF_MIPS_ARCH_32: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32); ++ return "mips32"; ++ case EF_MIPS_ARCH_32R2: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32R2); ++ return "mips32r2"; ++ case EF_MIPS_ARCH_32R6: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_32R6); ++ return "mips32r6"; ++ case EF_MIPS_ARCH_64: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64); ++ return "mips64"; ++ case EF_MIPS_ARCH_64R2: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64R2); ++ return "mips64r2"; ++ case EF_MIPS_ARCH_64R6: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH_64R6); ++ return "mips64r6"; ++ default: ++ *flagref &= ~((Elf64_Word) EF_MIPS_ARCH); ++ return "unknown ISA"; ++ } ++ return NULL; ++} ++ ++/* copy binutils-2.34/binutils/readelf.c get_mips_segment_type */ ++const char * ++mips_segment_type_name (int segment, char *buf __attribute__ ((unused)), ++ size_t len __attribute__ ((unused))) ++{ ++ switch (segment) ++ { ++ case PT_MIPS_REGINFO: ++ return "REGINFO"; ++ case PT_MIPS_RTPROC: ++ return "RTPROC"; ++ case PT_MIPS_OPTIONS: ++ return "OPTIONS"; ++ case PT_MIPS_ABIFLAGS: ++ return "ABIFLAGS"; ++ default: ++ return NULL; ++ } ++} ++ ++bool ++mips_dynamic_tag_check (int64_t tag) ++{ ++ return ((tag &~ (DT_MIPS_RLD_VERSION ++ | DT_MIPS_TIME_STAMP ++ | DT_MIPS_ICHECKSUM ++ | DT_MIPS_IVERSION ++ | DT_MIPS_FLAGS ++ | DT_MIPS_BASE_ADDRESS ++ | DT_MIPS_MSYM ++ | DT_MIPS_CONFLICT ++ | DT_MIPS_LIBLIST ++ | DT_MIPS_LOCAL_GOTNO ++ | DT_MIPS_CONFLICTNO ++ | DT_MIPS_LIBLISTNO ++ | DT_MIPS_SYMTABNO ++ | DT_MIPS_UNREFEXTNO ++ | DT_MIPS_GOTSYM ++ | DT_MIPS_HIPAGENO ++ | DT_MIPS_RLD_MAP ++ | DT_MIPS_DELTA_CLASS ++ | DT_MIPS_DELTA_CLASS_NO ++ | DT_MIPS_DELTA_INSTANCE ++ | DT_MIPS_DELTA_INSTANCE_NO ++ | DT_MIPS_DELTA_RELOC ++ | DT_MIPS_DELTA_RELOC_NO ++ | DT_MIPS_DELTA_SYM ++ | DT_MIPS_DELTA_SYM_NO ++ | DT_MIPS_DELTA_CLASSSYM ++ | DT_MIPS_DELTA_CLASSSYM_NO ++ | DT_MIPS_CXX_FLAGS ++ | DT_MIPS_PIXIE_INIT ++ | DT_MIPS_SYMBOL_LIB ++ | DT_MIPS_LOCALPAGE_GOTIDX ++ | DT_MIPS_LOCAL_GOTIDX ++ | DT_MIPS_HIDDEN_GOTIDX ++ | DT_MIPS_PROTECTED_GOTIDX ++ | DT_MIPS_OPTIONS ++ | DT_MIPS_INTERFACE ++ | DT_MIPS_DYNSTR_ALIGN ++ | DT_MIPS_INTERFACE_SIZE ++ | DT_MIPS_RLD_TEXT_RESOLVE_ADDR ++ | DT_MIPS_PERF_SUFFIX ++ | DT_MIPS_COMPACT_SIZE ++ | DT_MIPS_GP_VALUE ++ | DT_MIPS_AUX_DYNAMIC ++ | DT_MIPS_PLTGOT ++ | DT_MIPS_RWPLT ++ | DT_MIPS_RLD_MAP_REL ++ | DT_MIPS_XHASH)) == 0); ++} ++ ++/* copy binutils-2.34/binutils/readelf.c get_mips_dynamic_type*/ ++const char * ++mips_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)), ++ size_t len __attribute__ ((unused))) ++{ ++ switch (tag) ++ { ++ case DT_MIPS_RLD_VERSION: ++ return "MIPS_RLD_VERSION"; ++ case DT_MIPS_TIME_STAMP: ++ return "MIPS_TIME_STAMP"; ++ case DT_MIPS_ICHECKSUM: ++ return "MIPS_ICHECKSUM"; ++ case DT_MIPS_IVERSION: ++ return "MIPS_IVERSION"; ++ case DT_MIPS_FLAGS: ++ return "MIPS_FLAGS"; ++ case DT_MIPS_BASE_ADDRESS: ++ return "MIPS_BASE_ADDRESS"; ++ case DT_MIPS_MSYM: ++ return "MIPS_MSYM"; ++ case DT_MIPS_CONFLICT: ++ return "MIPS_CONFLICT"; ++ case DT_MIPS_LIBLIST: ++ return "MIPS_LIBLIST"; ++ case DT_MIPS_LOCAL_GOTNO: ++ return "MIPS_LOCAL_GOTNO"; ++ case DT_MIPS_CONFLICTNO: ++ return "MIPS_CONFLICTNO"; ++ case DT_MIPS_LIBLISTNO: ++ return "MIPS_LIBLISTNO"; ++ case DT_MIPS_SYMTABNO: ++ return "MIPS_SYMTABNO"; ++ case DT_MIPS_UNREFEXTNO: ++ return "MIPS_UNREFEXTNO"; ++ case DT_MIPS_GOTSYM: ++ return "MIPS_GOTSYM"; ++ case DT_MIPS_HIPAGENO: ++ return "MIPS_HIPAGENO"; ++ case DT_MIPS_RLD_MAP: ++ return "MIPS_RLD_MAP"; ++ case DT_MIPS_RLD_MAP_REL: ++ return "MIPS_RLD_MAP_REL"; ++ case DT_MIPS_DELTA_CLASS: ++ return "MIPS_DELTA_CLASS"; ++ case DT_MIPS_DELTA_CLASS_NO: ++ return "MIPS_DELTA_CLASS_NO"; ++ case DT_MIPS_DELTA_INSTANCE: ++ return "MIPS_DELTA_INSTANCE"; ++ case DT_MIPS_DELTA_INSTANCE_NO: ++ return "MIPS_DELTA_INSTANCE_NO"; ++ case DT_MIPS_DELTA_RELOC: ++ return "MIPS_DELTA_RELOC"; ++ case DT_MIPS_DELTA_RELOC_NO: ++ return "MIPS_DELTA_RELOC_NO"; ++ case DT_MIPS_DELTA_SYM: ++ return "MIPS_DELTA_SYM"; ++ case DT_MIPS_DELTA_SYM_NO: ++ return "MIPS_DELTA_SYM_NO"; ++ case DT_MIPS_DELTA_CLASSSYM: ++ return "MIPS_DELTA_CLASSSYM"; ++ case DT_MIPS_DELTA_CLASSSYM_NO: ++ return "MIPS_DELTA_CLASSSYM_NO"; ++ case DT_MIPS_CXX_FLAGS: ++ return "MIPS_CXX_FLAGS"; ++ case DT_MIPS_PIXIE_INIT: ++ return "MIPS_PIXIE_INIT"; ++ case DT_MIPS_SYMBOL_LIB: ++ return "MIPS_SYMBOL_LIB"; ++ case DT_MIPS_LOCALPAGE_GOTIDX: ++ return "MIPS_LOCALPAGE_GOTIDX"; ++ case DT_MIPS_LOCAL_GOTIDX: ++ return "MIPS_LOCAL_GOTIDX"; ++ case DT_MIPS_HIDDEN_GOTIDX: ++ return "MIPS_HIDDEN_GOTIDX"; ++ case DT_MIPS_PROTECTED_GOTIDX: ++ return "MIPS_PROTECTED_GOTIDX"; ++ case DT_MIPS_OPTIONS: ++ return "MIPS_OPTIONS"; ++ case DT_MIPS_INTERFACE: ++ return "MIPS_INTERFACE"; ++ case DT_MIPS_DYNSTR_ALIGN: ++ return "MIPS_DYNSTR_ALIGN"; ++ case DT_MIPS_INTERFACE_SIZE: ++ return "MIPS_INTERFACE_SIZE"; ++ case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: ++ return "MIPS_RLD_TEXT_RESOLVE_ADDR"; ++ case DT_MIPS_PERF_SUFFIX: ++ return "MIPS_PERF_SUFFIX"; ++ case DT_MIPS_COMPACT_SIZE: ++ return "MIPS_COMPACT_SIZE"; ++ case DT_MIPS_GP_VALUE: ++ return "MIPS_GP_VALUE"; ++ case DT_MIPS_AUX_DYNAMIC: ++ return "MIPS_AUX_DYNAMIC"; ++ case DT_MIPS_PLTGOT: ++ return "MIPS_PLTGOT"; ++ case DT_MIPS_RWPLT: ++ return "MIPS_RWPLT"; ++ case DT_MIPS_XHASH: ++ return "MIPS_XHASH"; ++ default: ++ return NULL; ++ } ++ return NULL; ++} +--- a/libelf/libelfP.h ++++ b/libelf/libelfP.h +@@ -624,4 +624,5 @@ extern void __libelf_reset_rawdata (Elf_ + #define ELF64_MIPS_R_TYPE1(i) ((i) & 0xff) + #define ELF64_MIPS_R_TYPE2(i) (((i) >> 8) & 0xff) + #define ELF64_MIPS_R_TYPE3(i) (((i) >> 16) & 0xff) ++#define is_debug_section_type(type) (type == SHT_PROGBITS || type == SHT_MIPS_DWARF) + #endif /* libelfP.h */ +--- a/src/readelf.c ++++ b/src/readelf.c +@@ -2219,17 +2219,41 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr * + (long int) GELF_R_SYM (rel->r_info)); + } + else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION) +- printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n", +- class == ELFCLASS32 ? 10 : 18, rel->r_offset, +- likely (ebl_reloc_type_check (ebl, +- GELF_R_TYPE (rel->r_info))) +- /* Avoid the leading R_ which isn't carrying any +- information. */ +- ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), +- buf, sizeof (buf)) + 2 +- : _("<INVALID RELOC>"), +- class == ELFCLASS32 ? 10 : 18, sym->st_value, +- elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)); ++ { ++ unsigned long inf = rel->r_info; ++ printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n", ++ class == ELFCLASS32 ? 10 : 18, rel->r_offset, ++ likely (ebl_reloc_type_check (ebl, ++ GELF_R_TYPE (rel->r_info))) ++ /* Avoid the leading R_ which isn't carrying any ++ information. */ ++ ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), ++ buf, sizeof (buf)) + 2 ++ : _("<INVALID RELOC>"), ++ class == ELFCLASS32 ? 10 : 18, sym->st_value, ++ elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)); ++ ++ /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */ ++ if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS) ++ { ++ unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf); ++ unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf); ++ const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2; ++ const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2; ++ printf(" Type2: "); ++ if (rtype2 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff); ++ else ++ printf ("%s", rtype2); ++ ++ printf ("\n Type3: "); ++ if (rtype3 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff); ++ else ++ printf ("%s", rtype3); ++ printf("\n"); ++ } ++ } + else + { + /* This is a relocation against a STT_SECTION symbol. */ +@@ -2253,16 +2277,40 @@ handle_relocs_rel (Ebl *ebl, GElf_Ehdr * + (long int) (sym->st_shndx == SHN_XINDEX + ? xndx : sym->st_shndx)); + else +- printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n", +- class == ELFCLASS32 ? 10 : 18, rel->r_offset, +- ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info)) +- /* Avoid the leading R_ which isn't carrying any +- information. */ +- ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), +- buf, sizeof (buf)) + 2 +- : _("<INVALID RELOC>"), +- class == ELFCLASS32 ? 10 : 18, sym->st_value, +- elf_strptr (ebl->elf, shstrndx, secshdr->sh_name)); ++ { ++ unsigned long inf = rel->r_info; ++ printf (" %#0*" PRIx64 " %-20s %#0*" PRIx64 " %s\n", ++ class == ELFCLASS32 ? 10 : 18, rel->r_offset, ++ ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info)) ++ /* Avoid the leading R_ which isn't carrying any ++ information. */ ++ ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), ++ buf, sizeof (buf)) + 2 ++ : _("<INVALID RELOC>"), ++ class == ELFCLASS32 ? 10 : 18, sym->st_value, ++ elf_strptr (ebl->elf, shstrndx, secshdr->sh_name)); ++ ++ /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */ ++ if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS) ++ { ++ unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf); ++ unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf); ++ const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2; ++ const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2; ++ printf(" Type2: "); ++ if (rtype2 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff); ++ else ++ printf ("%s", rtype2); ++ ++ printf ("\n Type3: "); ++ if (rtype3 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff); ++ else ++ printf ("%s", rtype3); ++ printf("\n"); ++ } ++ } + } + } + } +@@ -2410,19 +2458,43 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr + (long int) GELF_R_SYM (rel->r_info)); + } + else if (GELF_ST_TYPE (sym->st_info) != STT_SECTION) +- printf ("\ ++ { ++ unsigned long inf = rel->r_info; ++ printf ("\ + %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n", +- class == ELFCLASS32 ? 10 : 18, rel->r_offset, +- likely (ebl_reloc_type_check (ebl, +- GELF_R_TYPE (rel->r_info))) +- /* Avoid the leading R_ which isn't carrying any +- information. */ +- ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), +- buf, sizeof (buf)) + 2 +- : _("<INVALID RELOC>"), +- class == ELFCLASS32 ? 10 : 18, sym->st_value, +- rel->r_addend, +- elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)); ++ class == ELFCLASS32 ? 10 : 18, rel->r_offset, ++ likely (ebl_reloc_type_check (ebl, ++ GELF_R_TYPE (rel->r_info))) ++ /* Avoid the leading R_ which isn't carrying any ++ information. */ ++ ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), ++ buf, sizeof (buf)) + 2 ++ : _("<INVALID RELOC>"), ++ class == ELFCLASS32 ? 10 : 18, sym->st_value, ++ rel->r_addend, ++ elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)); ++ ++ /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */ ++ if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS) ++ { ++ unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf); ++ unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf); ++ const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2; ++ const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2; ++ printf(" Type2: "); ++ if (rtype2 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type2 & 0xffffffff); ++ else ++ printf ("%s", rtype2); ++ ++ printf ("\n Type3: "); ++ if (rtype3 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff); ++ else ++ printf ("%s", rtype3); ++ printf("\n"); ++ } ++ } + else + { + /* This is a relocation against a STT_SECTION symbol. */ +@@ -2446,18 +2518,42 @@ handle_relocs_rela (Ebl *ebl, GElf_Ehdr + (long int) (sym->st_shndx == SHN_XINDEX + ? xndx : sym->st_shndx)); + else +- printf ("\ ++ { ++ unsigned long inf = rel->r_info; ++ printf ("\ + %#0*" PRIx64 " %-15s %#0*" PRIx64 " %+6" PRId64 " %s\n", +- class == ELFCLASS32 ? 10 : 18, rel->r_offset, +- ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info)) +- /* Avoid the leading R_ which isn't carrying any +- information. */ +- ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), +- buf, sizeof (buf)) + 2 +- : _("<INVALID RELOC>"), +- class == ELFCLASS32 ? 10 : 18, sym->st_value, +- rel->r_addend, +- elf_strptr (ebl->elf, shstrndx, secshdr->sh_name)); ++ class == ELFCLASS32 ? 10 : 18, rel->r_offset, ++ ebl_reloc_type_check (ebl, GELF_R_TYPE (rel->r_info)) ++ /* Avoid the leading R_ which isn't carrying any ++ information. */ ++ ? ebl_reloc_type_name (ebl, GELF_R_TYPE (rel->r_info), ++ buf, sizeof (buf)) + 2 ++ : _("<INVALID RELOC>"), ++ class == ELFCLASS32 ? 10 : 18, sym->st_value, ++ rel->r_addend, ++ elf_strptr (ebl->elf, shstrndx, secshdr->sh_name)); ++ ++ /* copy binutils-2.34/binutils/readelf.c dump_relocations+1753 */ ++ if(ebl->elf->class == ELFCLASS64 && ebl->elf->state.elf64.ehdr->e_machine == EM_MIPS) ++ { ++ unsigned int type2 = ELF64_MIPS_R_TYPE2 (inf); ++ unsigned int type3 = ELF64_MIPS_R_TYPE3 (inf); ++ const char * rtype2 = ebl_reloc_type_name (ebl, type2, buf, sizeof (buf)) + 2; ++ const char * rtype3 = ebl_reloc_type_name (ebl, type3, buf, sizeof (buf)) + 2; ++ printf(" Type2: "); ++ if (rtype2 == NULL) ++ printf (_("unrecognized: %-7lx"), (unsigned long) type2 & 0xffffffff); ++ else ++ printf ("%s", rtype2); ++ ++ printf ("\n Type3: "); ++ if (rtype3 == NULL) ++ printf (_("unrecognized: %lx"), (unsigned long) type3 & 0xffffffff); ++ else ++ printf ("%s", rtype3); ++ printf("\n"); ++ } ++ } + } + } + } +@@ -12037,7 +12133,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl * + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + +- if (shdr != NULL && shdr->sh_type == SHT_PROGBITS) ++ if (shdr != NULL && is_debug_section_type(shdr->sh_type)) + { + const char *name = elf_strptr (ebl->elf, shstrndx, + shdr->sh_name); +@@ -12067,7 +12163,7 @@ print_debug (Dwfl_Module *dwflmod, Ebl * + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + +- if (shdr != NULL && shdr->sh_type == SHT_PROGBITS) ++ if (shdr != NULL && is_debug_section_type(shdr->sh_type)) + { + static const struct + { +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -216,7 +216,7 @@ TESTS = run-arextract.sh run-arsymtest.s + run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \ + run-readelf-dw-form-indirect.sh run-strip-largealign.sh \ + run-readelf-Dd.sh run-dwfl-core-noncontig.sh run-cu-dwp-section-info.sh \ +- run-declfiles.sh \ ++ run-declfiles.sh run-readelf-reloc.sh \ + run-sysroot.sh + + if !BIARCH +@@ -684,7 +684,7 @@ EXTRA_DIST = run-arextract.sh run-arsymt + testfile-dwp-4-cu-index-overflow.bz2 \ + testfile-dwp-4-cu-index-overflow.dwp.bz2 \ + testfile-dwp-cu-index-overflow.source \ +- testfile-define-file.bz2 \ ++ run-readelf-reloc.sh testfile-define-file.bz2 \ + testfile-sysroot.tar.bz2 run-sysroot.sh run-debuginfod-seekable.sh + + +--- /dev/null ++++ b/tests/run-readelf-reloc.sh +@@ -0,0 +1,42 @@ ++#! /bin/bash ++# Copyright (C) 2024 CIP United 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 ++ ++tempfiles test-readelf-h.txt test-readelf-reloc.txt ++testrun ${abs_top_builddir}/src/readelf -h ${abs_top_builddir}/src/strip.o > test-readelf-h.txt ++machine=`cat test-readelf-h.txt | grep Machine` ++class=`cat test-readelf-h.txt | grep Class` ++endian=`cat test-readelf-h.txt | grep Data` ++if [[ "$machine" == *MIPS* && "$class" == *ELF64 && "$endian" == *little* ]]; then ++testrun ${abs_top_builddir}/src/readelf -r ${abs_top_builddir}/src/strip.o | head -n 12 | tail -n 10 > test-readelf-reloc.txt ++ ++testrun_compare cat test-readelf-reloc.txt << EOF ++ Offset Type Value Addend Name ++ 0x0000000000000008 MIPS_GPREL16 000000000000000000 +0 .text ++ Type2: MIPS_SUB ++ Type3: MIPS_HI16 ++ 0x0000000000000010 MIPS_GPREL16 000000000000000000 +0 .text ++ Type2: MIPS_SUB ++ Type3: MIPS_LO16 ++ 0x0000000000000014 MIPS_CALL16 000000000000000000 +0 gelf_getehdr ++ Type2: MIPS_NONE ++ Type3: MIPS_NONE ++EOF ++fi ++ ++exit 0 diff --git a/tools/elfutils/patches/013-backport-mips-support-elflint.patch b/tools/elfutils/patches/013-backport-mips-support-elflint.patch new file mode 100644 index 0000000000..2ef9304bd1 --- /dev/null +++ b/tools/elfutils/patches/013-backport-mips-support-elflint.patch @@ -0,0 +1,157 @@ +The errors were: +$ src/elflint --gnu src/nm +section [ 2] '.MIPS.options' contains unknown flag(s) 0x8000000 +section [ 7] '.dynsym': symbol 165 (_DYNAMIC_LINKING): non-local section symbol +section [24] '.got' contains invalid processor-specific flag(s) 0x10000000 +section [25] '.sdata' contains invalid processor-specific flag(s) 0x10000000 +section [29] '.debug_aranges' has wrong type: expected PROGBITS, is MIPS_DWARF +section [30] '.debug_info' has wrong type: expected PROGBITS, is MIPS_DWARF +section [31] '.debug_abbrev' has wrong type: expected PROGBITS, is MIPS_DWARF +section [32] '.debug_line' has wrong type: expected PROGBITS, is MIPS_DWARF +section [33] '.debug_frame' has wrong type: expected PROGBITS, is MIPS_DWARF +section [34] '.debug_str' has wrong type: expected PROGBITS, is MIPS_DWARF +section [35] '.debug_loc' has wrong type: expected PROGBITS, is MIPS_DWARF +section [36] '.debug_ranges' has wrong type: expected PROGBITS, is MIPS_DWARF +section [38] '.symtab': symbol 785 (_gp): st_value out of bounds +section [38] '.symtab': symbol 910 (_fbss): st_value out of bounds +section [38] '.symtab': symbol 1051 (_DYNAMIC_LINKING): non-local section symbol + +After fixing: +$ src/elflint --gnu src/nm +No errors + +Signed-off-by: Ying Huang <ying.huang@oss.cipunited.com> +--- + backends/mips_init.c | 3 +++ + backends/mips_symbol.c | 37 +++++++++++++++++++++++++++++++++++++ + src/elflint.c | 26 +++++++++++++++++++++----- + 3 files changed, 61 insertions(+), 5 deletions(-) + +--- a/backends/mips_init.c ++++ b/backends/mips_init.c +@@ -51,10 +51,13 @@ mips_init (Elf *elf __attribute__ ((unus + HOOK (eh, section_type_name); + HOOK (eh, machine_flag_check); + HOOK (eh, machine_flag_name); ++ HOOK (eh, machine_section_flag_check); + HOOK (eh, segment_type_name); + HOOK (eh, dynamic_tag_check); + HOOK (eh, dynamic_tag_name); + HOOK (eh, check_object_attribute); ++ HOOK (eh, check_special_symbol); ++ HOOK (eh, check_reloc_target_type); + HOOK (eh, set_initial_registers_tid); + HOOK (eh, abi_cfi); + HOOK (eh, unwind); +--- a/backends/mips_symbol.c ++++ b/backends/mips_symbol.c +@@ -158,6 +158,43 @@ mips_section_type_name (int type, + return NULL; + } + ++bool ++mips_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)), Elf64_Word sh_type) ++{ ++ return (sh_type == SHT_MIPS_DWARF); ++} ++ ++/* Check whether given symbol's st_value and st_size are OK despite failing ++ normal checks. */ ++bool ++mips_check_special_symbol (Elf *elf, ++ const GElf_Sym *sym __attribute__ ((unused)), ++ const char *name __attribute__ ((unused)), ++ const GElf_Shdr *destshdr) ++{ ++ size_t shstrndx; ++ if (elf_getshdrstrndx (elf, &shstrndx) != 0) ++ return false; ++ const char *sname = elf_strptr (elf, shstrndx, destshdr->sh_name); ++ if (sname == NULL) ++ return false; ++ return (strcmp (sname, ".got") == 0 || strcmp (sname, ".bss") == 0); ++} ++ ++/* Check whether SHF_MASKPROC flags are valid. */ ++bool ++mips_machine_section_flag_check (GElf_Xword sh_flags) ++{ ++ return ((sh_flags &~ (SHF_MIPS_GPREL | ++ SHF_MIPS_MERGE | ++ SHF_MIPS_ADDR | ++ SHF_MIPS_STRINGS | ++ SHF_MIPS_NOSTRIP | ++ SHF_MIPS_LOCAL | ++ SHF_MIPS_NAMES | ++ SHF_MIPS_NODUPE)) == 0); ++} ++ + /* Check whether machine flags are valid. */ + bool + mips_machine_flag_check (GElf_Word flags) +--- a/src/elflint.c ++++ b/src/elflint.c +@@ -936,7 +936,9 @@ section [%2d] '%s': symbol %zu (%s): non + } + + if (GELF_ST_TYPE (sym->st_info) == STT_SECTION +- && GELF_ST_BIND (sym->st_info) != STB_LOCAL) ++ && GELF_ST_BIND (sym->st_info) != STB_LOCAL ++ && ehdr->e_machine != EM_MIPS ++ && strcmp (name, "_DYNAMIC_LINKING") != 0) + ERROR (_("\ + section [%2d] '%s': symbol %zu (%s): non-local section symbol\n"), + idx, section_name (ebl, idx), cnt, name); +@@ -3829,6 +3831,10 @@ cannot get section header for section [% + && ebl_bss_plt_p (ebl)) + good_type = SHT_NOBITS; + ++ if (ehdr->e_machine == EM_MIPS ++ && (strstr(special_sections[s].name, ".debug") != NULL)) ++ good_type = SHT_MIPS_DWARF; ++ + /* In a debuginfo file, any normal section can be SHT_NOBITS. + This is only invalid for DWARF sections and .shstrtab. */ + if (shdr->sh_type != good_type +@@ -3989,12 +3995,21 @@ section [%2zu] '%s': size not multiple o + ERROR (_("section [%2zu] '%s'" + " contains invalid processor-specific flag(s)" + " %#" PRIx64 "\n"), +- cnt, section_name (ebl, cnt), sh_flags & SHF_MASKPROC); ++ cnt, section_name (ebl, cnt), sh_flags & SHF_MASKPROC); + sh_flags &= ~(GElf_Xword) SHF_MASKPROC; + } + if (sh_flags & SHF_MASKOS) +- if (gnuld) +- sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN; ++ { ++ if (gnuld) ++ sh_flags &= ~(GElf_Xword) SHF_GNU_RETAIN; ++ if (!ebl_machine_section_flag_check (ebl, ++ sh_flags & SHF_MASKOS)) ++ ERROR (_("section [%2zu] '%s'" ++ " contains invalid os-specific flag(s)" ++ " %#" PRIx64 "\n"), ++ cnt, section_name (ebl, cnt), sh_flags & SHF_MASKOS); ++ sh_flags &= ~(GElf_Xword) SHF_MASKOS; ++ } + if (sh_flags != 0) + ERROR (_("section [%2zu] '%s' contains unknown flag(s)" + " %#" PRIx64 "\n"), +@@ -4060,6 +4075,7 @@ section [%2zu] '%s': merge flag set but + switch (shdr->sh_type) + { + case SHT_PROGBITS: ++ case SHT_MIPS_DWARF: + break; + + case SHT_NOBITS: +@@ -4717,7 +4733,7 @@ program header offset in ELF header and + if (shdr != NULL + && ((is_debuginfo && shdr->sh_type == SHT_NOBITS) + || (! is_debuginfo +- && (shdr->sh_type == SHT_PROGBITS ++ && (is_debug_section_type(shdr->sh_type) + || shdr->sh_type == SHT_X86_64_UNWIND))) + && elf_strptr (ebl->elf, shstrndx, shdr->sh_name) != NULL + && ! strcmp (".eh_frame_hdr", diff --git a/tools/elfutils/patches/100-portability.patch b/tools/elfutils/patches/100-portability.patch index 6f7564731b..a82cd69ba2 100644 --- a/tools/elfutils/patches/100-portability.patch +++ b/tools/elfutils/patches/100-portability.patch @@ -1,135 +1,42 @@ --- a/configure.ac +++ b/configure.ac -@@ -20,6 +20,7 @@ dnl You should have received a copy of - dnl along with this program. If not, see <http://www.gnu.org/licenses/>. - AC_INIT([elfutils],[0.191],[https://sourceware.org/bugzilla],[elfutils],[http://elfutils.org/]) - -+AC_CONFIG_MACRO_DIRS([m4]) - dnl Workaround for older autoconf < 2.64 - m4_ifndef([AC_PACKAGE_URL], - [AC_DEFINE([PACKAGE_URL], ["http://elfutils.org/"], -@@ -43,16 +44,17 @@ elif test "x$program_prefix" = "x"; then - fi +@@ -44,6 +44,7 @@ fi AC_CONFIG_AUX_DIR([config]) --AC_CONFIG_FILES([config/Makefile]) -+AC_CONFIG_FILES([config/Makefile libgnu/Makefile]) + AC_CONFIG_FILES([config/Makefile]) ++AC_CONFIG_FILES([libgnu/Makefile]) AC_COPYRIGHT([Copyright (C) 1996-2024 The elfutils developers.]) --AC_PREREQ(2.63) dnl Minimum Autoconf version required. -+AC_PREREQ(2.64) dnl Minimum Autoconf version required. - - dnl We use GNU make extensions; automake 1.10 defaults to -Wportability. - AM_INIT_AUTOMAKE([gnits 1.11 -Wno-portability dist-bzip2 no-dist-gzip parallel-tests]) - AM_MAINTAINER_MODE - - AM_SILENT_RULES([yes]) -+AC_USE_SYSTEM_EXTENSIONS() + AC_PREREQ(2.63) dnl Minimum Autoconf version required. +@@ -88,11 +89,14 @@ AS_IF([test "$use_locks" = yes], - AC_CONFIG_SRCDIR([libelf/libelf.h]) - AC_CONFIG_FILES([Makefile]) -@@ -89,12 +91,14 @@ AS_IF([test "$use_locks" = yes], AH_TEMPLATE([USE_LOCKS], [Defined if libraries should be thread-safe.]) ++AC_USE_SYSTEM_EXTENSIONS() ++ m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_C99]) -+gl_EARLY -+gl_INIT AC_PROG_CXX --AC_PROG_RANLIB + AC_PROG_RANLIB AC_PROG_YACC AC_PROG_LEX([noyywrap]) ++gl_EARLY # Only available since automake 1.12 m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) -+LT_INIT() AC_CHECK_TOOL([READELF], [readelf]) - AC_CHECK_TOOL([NM], [nm]) - -@@ -195,7 +199,6 @@ AC_CACHE_CHECK([whether the compiler gen - AC_LINK_IFELSE([AC_LANG_PROGRAM()],[ac_cv_buildid=yes; $READELF -n conftest$EXEEXT | grep -q NT_GNU_BUILD_ID || ac_cv_buildid=no],AC_MSG_FAILURE([unexpected compile failure]))]) - if test "$ac_cv_buildid" = "no"; then - AC_MSG_WARN([compiler doesn't generate build-id by default]) -- LDFLAGS="$LDFLAGS -Wl,--build-id" - fi - - ZRELRO_LDFLAGS="-Wl,-z,relro" -@@ -635,36 +638,6 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([])], +@@ -646,6 +650,8 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([])], CFLAGS="$old_CFLAGS"]) AS_IF([test "x$ac_cv_fno_addrsig" = "xyes"], CFLAGS="$CFLAGS -fno-addrsig") --saved_LIBS="$LIBS" --AC_SEARCH_LIBS([argp_parse], [argp]) --LIBS="$saved_LIBS" --case "$ac_cv_search_argp_parse" in -- no) AC_MSG_FAILURE([failed to find argp_parse]) ;; -- -l*) argp_LDADD="$ac_cv_search_argp_parse" ;; -- *) argp_LDADD= ;; --esac --AC_SUBST([argp_LDADD]) -- --saved_LIBS="$LIBS" --AC_SEARCH_LIBS([fts_close], [fts]) --LIBS="$saved_LIBS" --case "$ac_cv_search_fts_close" in -- no) AC_MSG_FAILURE([failed to find fts_close]) ;; -- -l*) fts_LIBS="$ac_cv_search_fts_close" ;; -- *) fts_LIBS= ;; --esac --AC_SUBST([fts_LIBS]) -- --saved_LIBS="$LIBS" --AC_SEARCH_LIBS([_obstack_free], [obstack]) --LIBS="$saved_LIBS" --case "$ac_cv_search__obstack_free" in -- no) AC_MSG_FAILURE([failed to find _obstack_free]) ;; -- -l*) obstack_LIBS="$ac_cv_search__obstack_free" ;; -- *) obstack_LIBS= ;; --esac --AC_SUBST([obstack_LIBS]) -- - dnl The directories with content. - - dnl Documentation. ---- a/libelf/elf_update.c -+++ b/libelf/elf_update.c -@@ -37,6 +37,33 @@ - - #include "libelfP.h" - -+#include "elf_fill.c" ++gl_INIT + -+#ifdef __APPLE__ -+static int posix_fallocate(int fd, off_t offset, off_t len) -+{ -+ off_t c_test; -+ int ret; -+ if (!__builtin_saddll_overflow(offset, len, &c_test)) { -+ fstore_t store = {F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, offset + len, 0}; -+ // Try to get a continuous chunk of disk space -+ ret = fcntl(fd, F_PREALLOCATE, &store); -+ if (ret < 0) { -+ // OK, perhaps we are too fragmented, allocate non-continuous -+ store.fst_flags = F_ALLOCATEALL; -+ ret = fcntl(fd, F_PREALLOCATE, &store); -+ if (ret < 0) { -+ return ret; -+ } -+ } -+ ret = ftruncate(fd, offset + len); -+ } else { -+ // offset+len would overflow. -+ ret = -1; -+ } -+ return ret; -+} -+#endif - - static int64_t - write_file (Elf *elf, int64_t size, int change_bo, size_t shnum) + saved_LIBS="$LIBS" + AC_SEARCH_LIBS([argp_parse], [argp]) + LIBS="$saved_LIBS" --- a/lib/eu-config.h +++ b/lib/eu-config.h -@@ -59,14 +59,18 @@ - # define once(once_control, init_routine) init_routine() - #endif /* USE_LOCKS */ +@@ -31,14 +31,19 @@ + + #include "locks.h" -#include <libintl.h> +#include <gettext.h> @@ -138,8 +45,9 @@ #define _(Str) dgettext ("elfutils", Str) /* Compiler-specific definitions. */ ++#define __PRAGMA(str) _Pragma (#str) +#ifdef __APPLE__ -+#define strong_alias(name, aliasname) ++#define strong_alias(name, aliasname) __PRAGMA(weak aliasname = name) +#else #define strong_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((alias (#name))); @@ -147,20 +55,16 @@ #ifdef __i386__ # define internal_function __attribute__ ((regparm (3), stdcall)) -@@ -77,12 +81,7 @@ +@@ -49,7 +54,7 @@ #define internal_strong_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function; -#ifdef HAVE_VISIBILITY --#define attribute_hidden \ -- __attribute__ ((visibility ("hidden"))) --#else - #define attribute_hidden /* empty */ --#endif - - #ifdef HAVE_GCC_STRUCT - #define attribute_packed \ -@@ -166,7 +165,7 @@ asm (".section predict_data, \"aw\"; .pr ++#if defined(HAVE_VISIBILITY) && !defined(__APPLE__) + #define attribute_hidden \ + __attribute__ ((visibility ("hidden"))) + #else +@@ -138,7 +143,7 @@ asm (".section predict_data, \"aw\"; .pr #endif /* Avoid PLT entries. */ @@ -169,79 +73,6 @@ # define INTUSE(name) _INTUSE(name) # define _INTUSE(name) __##name##_internal # define INTDEF(name) _INTDEF(name) ---- a/config/eu.am -+++ b/config/eu.am -@@ -31,7 +31,7 @@ - ## - - DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"${localedir}"' --AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_srcdir)/lib -I.. -+AM_CPPFLAGS = -I$(top_builddir)/libgnu -I$(top_srcdir)/libgnu -I. -I$(srcdir) -I$(top_srcdir)/lib -I.. - - # Drop the 'u' flag that automake adds by default. It is incompatible - # with deterministic archives. ---- a/libelf/Makefile.am -+++ b/libelf/Makefile.am -@@ -34,9 +34,7 @@ endif - - VERSION = 1 - --lib_LIBRARIES = libelf.a --noinst_LIBRARIES = libelf_pic.a --noinst_DATA = $(noinst_LIBRARIES:_pic.a=.so) -+lib_LTLIBRARIES = libelf.la - include_HEADERS = libelf.h gelf.h nlist.h - - noinst_HEADERS = abstract.h common.h exttypes.h gelf_xlate.h libelfP.h \ -@@ -51,7 +49,8 @@ endif - - pkginclude_HEADERS = elf-knowledge.h - --libelf_a_SOURCES = elf_version.c elf_hash.c elf_error.c elf_fill.c \ -+libelf_la_LIBADD = ../libgnu/libgnu.la ../lib/libeu.la -lz $(zstd_LIBS) -lpthread -+libelf_la_SOURCES = elf_version.c elf_hash.c elf_error.c \ - elf_begin.c elf_next.c elf_rand.c elf_end.c elf_kind.c \ - gelf_getclass.c elf_getbase.c elf_getident.c \ - elf32_fsize.c elf64_fsize.c gelf_fsize.c \ -@@ -102,37 +101,9 @@ libelf_a_SOURCES = elf_version.c elf_has - elf32_getchdr.c elf64_getchdr.c gelf_getchdr.c \ - elf_compress.c elf_compress_gnu.c - --libelf_pic_a_SOURCES = --am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os) -- --libelf_so_DEPS = ../lib/libeu.a --libelf_so_LDLIBS = $(libelf_so_DEPS) -lz $(zstd_LIBS) --if USE_LOCKS --libelf_so_LDLIBS += -lpthread --endif -- --libelf_so_LIBS = libelf_pic.a --libelf.so: $(srcdir)/libelf.map $(libelf_so_LIBS) $(libelf_so_DEPS) -- $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \ -- -Wl,--soname,$@.$(VERSION) \ -- -Wl,--version-script,$< \ -- $(NO_UNDEFINED) \ -- -Wl,--whole-archive $(libelf_so_LIBS) -Wl,--no-whole-archive \ -- $(libelf_so_LDLIBS) -- @$(textrel_check) -- $(AM_V_at)ln -fs $@ $@.$(VERSION) -- --install: install-am libelf.so -+install: install-am - $(mkinstalldirs) $(DESTDIR)$(libdir) -- $(INSTALL_PROGRAM) libelf.so $(DESTDIR)$(libdir)/libelf-$(PACKAGE_VERSION).so -- ln -fs libelf-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libelf.so.$(VERSION) -- ln -fs libelf.so.$(VERSION) $(DESTDIR)$(libdir)/libelf.so - - uninstall: uninstall-am -- rm -f $(DESTDIR)$(libdir)/libelf-$(PACKAGE_VERSION).so -- rm -f $(DESTDIR)$(libdir)/libelf.so.$(VERSION) -- rm -f $(DESTDIR)$(libdir)/libelf.so - - EXTRA_DIST = libelf.map -- --CLEANFILES += $(am_libelf_pic_a_OBJECTS) libelf.so libelf.so.$(VERSION) --- a/backends/i386_auxv.c +++ b/backends/i386_auxv.c @@ -48,5 +48,4 @@ EBLHOOK(auxv_info) (GElf_Xword a_type, c @@ -365,518 +196,34 @@ +#endif --- a/libdw/libdwP.h +++ b/libdw/libdwP.h -@@ -32,10 +32,10 @@ +@@ -32,6 +32,7 @@ #include <stdbool.h> #include <pthread.h> +#include <libeu.h> #include <libdw.h> #include <dwarf.h> + #include "eu-search.h" +--- a/config/libdebuginfod.pc.in ++++ b/config/libdebuginfod.pc.in +@@ -8,5 +8,5 @@ Description: elfutils library to query d + Version: @VERSION@ + URL: http://elfutils.org/ -- - /* Known location expressions already decoded. */ - struct loc_s - { ---- a/libdw/Makefile.am -+++ b/libdw/Makefile.am -@@ -34,14 +34,12 @@ endif - AM_CPPFLAGS += -I$(srcdir)/../libebl -I$(srcdir)/../libelf -I$(srcdir)/../libdwelf -pthread - VERSION = 1 - --lib_LIBRARIES = libdw.a --noinst_LIBRARIES = libdw_pic.a --noinst_DATA = $(noinst_LIBRARIES:_pic.a=.so) -+lib_LTLIBRARIES = libdw.la - - include_HEADERS = dwarf.h - pkginclude_HEADERS = libdw.h known-dwarf.h - --libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \ -+libdw_la_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \ - dwarf_getpubnames.c dwarf_getabbrev.c dwarf_tag.c \ - dwarf_error.c dwarf_nextcu.c dwarf_diename.c dwarf_offdie.c \ - dwarf_attr.c dwarf_formstring.c \ -@@ -103,50 +101,12 @@ $(srcdir)/known-dwarf.h: $(top_srcdir)/c - mv -f $@.new $@ - endif - --libdw_pic_a_SOURCES = --am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os) -- --libdw_so_LIBS = ../libebl/libebl_pic.a ../backends/libebl_backends_pic.a \ -- ../libcpu/libcpu_pic.a libdw_pic.a ../libdwelf/libdwelf_pic.a \ -- ../libdwfl/libdwfl_pic.a --libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so --libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(fts_LIBS) $(obstack_LIBS) $(zip_LIBS) -pthread --libdw.so: $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS) -- $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \ -- -Wl,--soname,$@.$(VERSION),--enable-new-dtags \ -- -Wl,--version-script,$< \ -- $(NO_UNDEFINED) \ -- -Wl,--whole-archive $(libdw_so_LIBS) -Wl,--no-whole-archive \ -- $(libdw_so_LDLIBS) -- @$(textrel_check) -- $(AM_V_at)ln -fs $@ $@.$(VERSION) -- --install: install-am libdw.so -- $(mkinstalldirs) $(DESTDIR)$(libdir) -- $(INSTALL_PROGRAM) libdw.so $(DESTDIR)$(libdir)/libdw-$(PACKAGE_VERSION).so -- ln -fs libdw-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libdw.so.$(VERSION) -- ln -fs libdw.so.$(VERSION) $(DESTDIR)$(libdir)/libdw.so -- --uninstall: uninstall-am -- rm -f $(DESTDIR)$(libdir)/libdw-$(PACKAGE_VERSION).so -- rm -f $(DESTDIR)$(libdir)/libdw.so.$(VERSION) -- rm -f $(DESTDIR)$(libdir)/libdw.so -- rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/elfutils -- --libdwfl_objects = $(shell $(AR) t ../libdwfl/libdwfl.a) --libdw_a_LIBADD = $(addprefix ../libdwfl/,$(libdwfl_objects)) -- --libdwelf_objects = $(shell $(AR) t ../libdwelf/libdwelf.a) --libdw_a_LIBADD += $(addprefix ../libdwelf/,$(libdwelf_objects)) -- --libebl_objects = $(shell $(AR) t ../libebl/libebl.a) --libdw_a_LIBADD += $(addprefix ../libebl/,$(libebl_objects)) -- --backends_objects = $(shell $(AR) t ../backends/libebl_backends.a) --libdw_a_LIBADD += $(addprefix ../backends/,$(backends_objects)) -- --libcpu_objects = $(shell $(AR) t ../libcpu/libcpu.a) --libdw_a_LIBADD += $(addprefix ../libcpu/,$(libcpu_objects)) -+libdw_la_LIBADD = \ -+ ../libdwfl/libdwfl.la \ -+ ../libdwelf/libdwelf.la \ -+ ../libebl/libebl.la \ -+ ../backends/libebl_backends.la \ -+ ../libcpu/libcpu.la - - noinst_HEADERS = libdwP.h memory-access.h dwarf_abbrev_hash.h \ - dwarf_sig8_hash.h cfi.h encoded-value.h ---- a/libasm/Makefile.am -+++ b/libasm/Makefile.am -@@ -32,12 +32,10 @@ AM_CPPFLAGS += -I$(top_srcdir)/libelf -I - - VERSION = 1 - --lib_LIBRARIES = libasm.a --noinst_LIBRARIES = libasm_pic.a --noinst_DATA = $(noinst_LIBRARIES:_pic.a=.so) -+lib_LTLIBRARIES = libasm.la - pkginclude_HEADERS = libasm.h - --libasm_a_SOURCES = asm_begin.c asm_abort.c asm_end.c asm_error.c \ -+libasm_la_SOURCES = asm_begin.c asm_abort.c asm_end.c asm_error.c \ - asm_getelf.c asm_newscn.c asm_newscn_ingrp.c \ - asm_newsubscn.c asm_newsym.c asm_newcomsym.c \ - asm_newabssym.c \ -@@ -51,38 +49,6 @@ libasm_a_SOURCES = asm_begin.c asm_abort - disasm_begin.c disasm_cb.c disasm_end.c disasm_str.c \ - symbolhash.c - --libasm_pic_a_SOURCES = --am_libasm_pic_a_OBJECTS = $(libasm_a_SOURCES:.c=.os) -- --libasm_so_DEPS = ../lib/libeu.a ../libebl/libebl_pic.a ../libelf/libelf.so ../libdw/libdw.so --libasm_so_LDLIBS = $(libasm_so_DEPS) --if USE_LOCKS --libasm_so_LDLIBS += -lpthread --endif -- --libasm_so_LIBS = libasm_pic.a --libasm.so: $(srcdir)/libasm.map $(libasm_so_LIBS) $(libasm_so_DEPS) -- $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \ -- -Wl,--soname,$@.$(VERSION) \ -- -Wl,--version-script,$< \ -- $(NO_UNDEFINED) \ -- -Wl,--whole-archive $(libasm_so_LIBS) -Wl,--no-whole-archive \ -- $(libasm_so_LDLIBS) -- @$(textrel_check) -- $(AM_V_at)ln -fs $@ $@.$(VERSION) -- --install: install-am libasm.so -- $(mkinstalldirs) $(DESTDIR)$(libdir) -- $(INSTALL_PROGRAM) libasm.so $(DESTDIR)$(libdir)/libasm-$(PACKAGE_VERSION).so -- ln -fs libasm-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libasm.so.$(VERSION) -- ln -fs libasm.so.$(VERSION) $(DESTDIR)$(libdir)/libasm.so -- --uninstall: uninstall-am -- rm -f $(DESTDIR)$(libdir)/libasm-$(PACKAGE_VERSION).so -- rm -f $(DESTDIR)$(libdir)/libasm.so.$(VERSION) -- rm -f $(DESTDIR)$(libdir)/libasm.so -- rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/elfutils -- - noinst_HEADERS = libasmP.h symbolhash.h - EXTRA_DIST = libasm.map - ---- a/libdwfl/Makefile.am -+++ b/libdwfl/Makefile.am -@@ -34,13 +34,11 @@ AM_CPPFLAGS += -I$(srcdir) -I$(srcdir)/. - -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf -I$(builddir)/../debuginfod - VERSION = 1 - --noinst_LIBRARIES = libdwfl.a --noinst_LIBRARIES += libdwfl_pic.a -+noinst_LTLIBRARIES = libdwfl.la - - pkginclude_HEADERS = libdwfl.h - -- --libdwfl_a_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c dwfl_version.c \ -+libdwfl_la_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c dwfl_version.c \ - dwfl_module.c dwfl_report_elf.c relocate.c \ - dwfl_module_build_id.c dwfl_module_report_build_id.c \ - derelocate.c offline.c segment.c \ -@@ -73,24 +71,14 @@ libdwfl_a_SOURCES = dwfl_begin.c dwfl_en - gzip.c debuginfod-client.c - - if BZLIB --libdwfl_a_SOURCES += bzip2.c -+libdwfl_la_SOURCES += bzip2.c - endif - if LZMA --libdwfl_a_SOURCES += lzma.c -+libdwfl_la_SOURCES += lzma.c - endif - if ZSTD --libdwfl_a_SOURCES += zstd.c -+libdwfl_la_SOURCES += zstd.c - endif - --libdwfl = $(libdw) --libdw = ../libdw/libdw.so --libelf = ../libelf/libelf.so --libebl = ../libebl/libebl.a --libeu = ../lib/libeu.a -- --libdwfl_pic_a_SOURCES = --am_libdwfl_pic_a_OBJECTS = $(libdwfl_a_SOURCES:.c=.os) -- - noinst_HEADERS = libdwflP.h - --CLEANFILES += $(am_libdwfl_pic_a_OBJECTS) ---- a/backends/Makefile.am -+++ b/backends/Makefile.am -@@ -34,7 +34,7 @@ endif - AM_CPPFLAGS += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \ - -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw - --noinst_LIBRARIES = libebl_backends.a libebl_backends_pic.a -+noinst_LTLIBRARIES = libebl_backends.la - - modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \ - m68k bpf riscv csky loongarch arc -@@ -102,17 +102,13 @@ loongarch_SRCS = loongarch_init.c loonga - - arc_SRCS = arc_init.c arc_symbol.c - --libebl_backends_a_SOURCES = $(i386_SRCS) $(sh_SRCS) $(x86_64_SRCS) \ -+libebl_backends_la_SOURCES = $(i386_SRCS) $(sh_SRCS) $(x86_64_SRCS) \ - $(ia64_SRCS) $(alpha_SRCS) $(arm_SRCS) \ - $(aarch64_SRCS) $(sparc_SRCS) $(ppc_SRCS) \ - $(ppc64_SRCS) $(s390_SRCS) \ - $(m68k_SRCS) $(bpf_SRCS) $(riscv_SRCS) $(csky_SRCS) \ - $(loongarch_SRCS) $(arc_SRCS) - --libebl_backends_pic_a_SOURCES = --am_libebl_backends_pic_a_OBJECTS = $(libebl_backends_a_SOURCES:.c=.os) - - noinst_HEADERS = libebl_CPU.h common-reloc.c linux-core-note.c x86_corenote.c - EXTRA_DIST = $(modules:=_reloc.def) -- --MOSTLYCLEANFILES = $(am_libebl_backends_pic_a_OBJECTS) ---- a/libdwelf/Makefile.am -+++ b/libdwelf/Makefile.am -@@ -34,24 +34,12 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf -I$ - -I$(srcdir)/../libdwfl -I$(srcdir)/../libebl - VERSION = 1 - --noinst_LIBRARIES = libdwelf.a libdwelf_pic.a -+noinst_LTLIBRARIES = libdwelf.la - - pkginclude_HEADERS = libdwelf.h - noinst_HEADERS = libdwelfP.h - --libdwelf_a_SOURCES = dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltlink.c \ -+libdwelf_la_SOURCES = dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltlink.c \ - dwelf_elf_gnu_build_id.c dwelf_scn_gnu_compressed_size.c \ - dwelf_strtab.c dwelf_elf_begin.c \ - dwelf_elf_e_machine_string.c -- --libdwelf = $(libdw) -- --libdw = ../libdw/libdw.so --libelf = ../libelf/libelf.so --libebl = ../libebl/libebl.a --libeu = ../lib/libeu.a -- --libdwelf_pic_a_SOURCES = --am_libdwelf_pic_a_OBJECTS = $(libdwelf_a_SOURCES:.c=.os) -- --CLEANFILES += $(am_libdwelf_pic_a_OBJECTS) ---- a/libebl/Makefile.am -+++ b/libebl/Makefile.am -@@ -34,9 +34,9 @@ endif - AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libdw -I$(srcdir)/../libasm - VERSION = 1 - --noinst_LIBRARIES = libebl.a libebl_pic.a -+noinst_LTLIBRARIES = libebl.la - --libebl_a_SOURCES = eblopenbackend.c eblclosebackend.c eblreloctypename.c \ -+libebl_la_SOURCES = eblopenbackend.c eblclosebackend.c eblreloctypename.c \ - eblsegmenttypename.c eblsectiontypename.c \ - eblmachineflagname.c eblsymboltypename.c \ - ebldynamictagname.c eblsectionname.c \ -@@ -56,9 +56,4 @@ libebl_a_SOURCES = eblopenbackend.c eblc - eblresolvesym.c eblcheckreloctargettype.c \ - ebl_data_marker_symbol.c - --libebl_pic_a_SOURCES = --am_libebl_pic_a_OBJECTS = $(libebl_a_SOURCES:.c=.os) -- - noinst_HEADERS = libebl.h libeblP.h ebl-hooks.h -- --MOSTLYCLEANFILES = $(am_libebl_pic_a_OBJECTS) ---- a/debuginfod/Makefile.am -+++ b/debuginfod/Makefile.am -@@ -40,23 +40,12 @@ AM_CPPFLAGS += -I$(srcdir) -I$(srcdir)/. - program_prefix= - program_transform_name = s,x,x, - --if BUILD_STATIC --libasm = ../libasm/libasm.a --libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl -lpthread --libelf = ../libelf/libelf.a -lz --if DUMMY_LIBDEBUGINFOD --libdebuginfod = ./libdebuginfod.a --else --libdebuginfod = ./libdebuginfod.a -lpthread $(libcurl_LIBS) --endif --else --libasm = ../libasm/libasm.so --libdw = ../libdw/libdw.so --libelf = ../libelf/libelf.so --libdebuginfod = ./libdebuginfod.so --endif --libebl = ../libebl/libebl.a --libeu = ../lib/libeu.a -+libasm = ../libasm/libasm.la -+libdw = ../libdw/libdw.la -lz $(zip_LIBS) $(libelf) $(libebl) -ldl -lpthread -+libelf = ../libelf/libelf.la -+libdebuginfod = ./libdebuginfod.la -+libebl = ../libebl/libebl.la -+libeu = ../lib/libeu.la - - AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw:. - -@@ -76,14 +65,10 @@ debuginfod_find_SOURCES = debuginfod-fin - debuginfod_find_LDADD = $(libdw) $(libelf) $(libeu) $(libdebuginfod) $(argp_LDADD) $(fts_LIBS) - - if LIBDEBUGINFOD --noinst_LIBRARIES = libdebuginfod.a --noinst_LIBRARIES += libdebuginfod_pic.a -+libdebuginfod_la_SOURCES = debuginfod-client.c -+noinst_LTLIBRARIES = libdebuginfod.la - endif - --libdebuginfod_a_SOURCES = debuginfod-client.c --libdebuginfod_pic_a_SOURCES = debuginfod-client.c --am_libdebuginfod_pic_a_OBJECTS = $(libdebuginfod_a_SOURCES:.c=.os) -- - if DUMMY_LIBDEBUGINFOD - AM_CPPFLAGS += -Wno-unused-parameter - endif -@@ -92,42 +77,7 @@ if LIBDEBUGINFOD - pkginclude_HEADERS = debuginfod.h - endif - --if LIBDEBUGINFOD --libdebuginfod_so_LIBS = libdebuginfod_pic.a --if DUMMY_LIBDEBUGINFOD --libdebuginfod_so_LDLIBS = --else --libdebuginfod_so_LDLIBS = -lpthread $(libcurl_LIBS) $(fts_LIBS) $(libelf) --endif --$(LIBDEBUGINFOD_SONAME): $(srcdir)/libdebuginfod.map $(libdebuginfod_so_LIBS) -- $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \ -- -Wl,--soname,$(LIBDEBUGINFOD_SONAME) \ -- -Wl,--version-script,$< \ -- $(NO_UNDEFINED) \ -- -Wl,--whole-archive $(libdebuginfod_so_LIBS) -Wl,--no-whole-archive \ -- $(libdebuginfod_so_LDLIBS) -- @$(textrel_check) -- --libdebuginfod.so: $(LIBDEBUGINFOD_SONAME) -- ln -fs $< $@ -- --install: install-am libdebuginfod.so -- $(mkinstalldirs) $(DESTDIR)$(libdir) -- $(INSTALL_PROGRAM) $(LIBDEBUGINFOD_SONAME) \ -- $(DESTDIR)$(libdir)/libdebuginfod-$(PACKAGE_VERSION).so -- ln -fs libdebuginfod-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/$(LIBDEBUGINFOD_SONAME) -- ln -fs libdebuginfod-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libdebuginfod.so -- --uninstall: uninstall-am -- rm -f $(DESTDIR)$(libdir)/libdebuginfod-$(PACKAGE_VERSION).so -- rm -f $(DESTDIR)$(libdir)/$(LIBDEBUGINFOD_SONAME) -- rm -f $(DESTDIR)$(libdir)/libdebuginfod.so -- rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/elfutils --endif -- - EXTRA_DIST = libdebuginfod.map --MOSTLYCLEANFILES = $(am_libdebuginfod_pic_a_OBJECTS) $(LIBDEBUGINFOD_SONAME) --CLEANFILES += $(am_libdebuginfod_pic_a_OBJECTS) libdebuginfod.so - - # automake std-options override: arrange to pass LD_LIBRARY_PATH - installcheck-binPROGRAMS: $(bin_PROGRAMS) ---- a/lib/Makefile.am -+++ b/lib/Makefile.am -@@ -31,9 +31,9 @@ include $(top_srcdir)/config/eu.am - AM_CFLAGS += $(fpic_CFLAGS) - AM_CPPFLAGS += -I$(srcdir)/../libelf - --noinst_LIBRARIES = libeu.a -+noinst_LTLIBRARIES = libeu.la - --libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \ -+libeu_la_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \ - crc32.c crc32_file.c \ - color.c error.c printversion.c - ---- a/src/Makefile.am -+++ b/src/Makefile.am -@@ -29,9 +29,9 @@ bin_PROGRAMS = readelf nm size strip elf - elfcmp objdump ranlib strings ar unstrip stack elfcompress \ - elfclassify srcfiles - --noinst_LIBRARIES = libar.a -+noinst_LTLIBRARIES = libar.la - --libar_a_SOURCES = arlib.c arlib2.c arlib-argp.c -+libar_la_SOURCES = arlib.c arlib2.c arlib-argp.c - - EXTRA_DIST = arlib.h debugpred.h - -@@ -39,27 +39,16 @@ bin_SCRIPTS = make-debug-archive - EXTRA_DIST += make-debug-archive.in - CLEANFILES += make-debug-archive - --if BUILD_STATIC --libasm = ../libasm/libasm.a --libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) -ldl -lpthread --libelf = ../libelf/libelf.a -lz $(zstd_LIBS) -+libasm = ../libasm/libasm.la -+libdw = ../libdw/libdw.la -lz $(zip_LIBS) $(libelf) -ldl -lpthread -+libelf = ../libelf/libelf.la -lz $(zstd_LIBS) - if LIBDEBUGINFOD --libdebuginfod = ../debuginfod/libdebuginfod.a -lpthread $(libcurl_LIBS) -+libdebuginfod = ../debuginfod/libdebuginfod.la -lpthread $(libcurl_LIBS) - else - libdebuginfod = - endif --else --libasm = ../libasm/libasm.so --libdw = ../libdw/libdw.so --libelf = ../libelf/libelf.so --if LIBDEBUGINFOD --libdebuginfod = ../debuginfod/libdebuginfod.so --else --libdebuginfod = --endif --endif --libebl = ../libebl/libebl.a ../backends/libebl_backends.a ../libcpu/libcpu.a --libeu = ../lib/libeu.a -+libebl = ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la -+libeu = ../lib/libeu.la - - if DEMANGLE - demanglelib = -lstdc++ -@@ -87,9 +76,9 @@ findtextrel_LDADD = $(libdw) $(libelf) $ - addr2line_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD) $(demanglelib) - elfcmp_LDADD = $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD) - objdump_LDADD = $(libasm) $(libebl) $(libdw) $(libelf) $(libeu) $(argp_LDADD) --ranlib_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS) -+ranlib_LDADD = libar.la $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS) - strings_LDADD = $(libelf) $(libeu) $(argp_LDADD) --ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS) -+ar_LDADD = libar.la $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS) - unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) - stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib) - elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) ---- a/tests/Makefile.am -+++ b/tests/Makefile.am -@@ -689,17 +689,11 @@ installcheck-local: - TESTS_ENVIRONMENT="$(installed_TESTS_ENVIRONMENT)" \ - LOG_COMPILER="$(installed_LOG_COMPILER)" check-TESTS - --if BUILD_STATIC --libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl -lpthread --libelf = ../libelf/libelf.a -lz $(zstd_LIBS) --libasm = ../libasm/libasm.a --else --libdw = ../libdw/libdw.so --libelf = ../libelf/libelf.so --libasm = ../libasm/libasm.so --endif --libebl = ../libebl/libebl.a ../backends/libebl_backends.a ../libcpu/libcpu.a --libeu = ../lib/libeu.a -+libdw = ../libdw/libdw.la -lz $(zip_LIBS) $(libelf) $(libebl) -ldl -lpthread -+libelf = ../libelf/libelf.la -+libasm = ../libasm/libasm.la -+libebl = ../libebl/libebl.la ../backends/libebl_backends.la ../libcpu/libcpu.la -+libeu = ../lib/libeu.la - - arextract_LDADD = $(libelf) - arsymtest_LDADD = $(libelf) ---- a/libcpu/Makefile.am -+++ b/libcpu/Makefile.am -@@ -38,19 +38,16 @@ LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAG - LEX_OUTPUT_ROOT = lex.$(<F:lex.l=) - AM_YFLAGS = -p$(<F:parse.y=) - --noinst_LIBRARIES = libcpu.a libcpu_pic.a -+noinst_LTLIBRARIES = libcpu.la - - noinst_HEADERS = i386_dis.h i386_mne.h x86_64_dis.h - --libcpu_a_SOURCES = i386_disasm.c x86_64_disasm.c bpf_disasm.c riscv_disasm.c -- --libcpu_pic_a_SOURCES = --am_libcpu_pic_a_OBJECTS = $(libcpu_a_SOURCES:.c=.os) -+libcpu_la_SOURCES = i386_disasm.c x86_64_disasm.c bpf_disasm.c riscv_disasm.c - - i386_gendis_SOURCES = i386_gendis.c i386_lex.l i386_parse.y - --i386_disasm.o: i386.mnemonics $(srcdir)/i386_dis.h --x86_64_disasm.o: x86_64.mnemonics $(srcdir)/x86_64_dis.h -+$(libcpu_la_OBJECTS): i386.mnemonics $(srcdir)/i386_dis.h -+$(libcpu_la_OBJECTS): x86_64.mnemonics $(srcdir)/x86_64_dis.h - - %_defs: $(srcdir)/defs/i386 - $(AM_V_GEN)m4 -D$* -DDISASSEMBLER $< > $@T -@@ -87,20 +84,15 @@ endif - - i386_lex_no_Werror = yes - --libeu = ../lib/libeu.a -+libeu = ../lib/libeu.la - - i386_lex_CFLAGS = -Wno-unused-label -Wno-unused-function -Wno-sign-compare \ - -Wno-implicit-fallthrough --i386_parse.o: i386_parse.c i386.mnemonics --i386_lex.o: i386_parse.h - i386_gendis_LDADD = $(libeu) -lm $(obstack_LIBS) - --i386_parse.h: i386_parse.c ; -- - bpf_disasm_CFLAGS = -Wno-format-nonliteral +-Libs: -L${libdir} -ldebuginfod ++Libs: -L${libdir} -ldebuginfod -lpthread + Cflags: -I${includedir} +--- a/config/libdw.pc.in ++++ b/config/libdw.pc.in +@@ -8,7 +8,7 @@ Description: elfutils library for DWARF + Version: @VERSION@ + URL: http://elfutils.org/ - EXTRA_DIST = defs/i386 +-Libs: -L${libdir} -ldw ++Libs: -L${libdir} -ldw -lz -lelf -lz -ldl -lpthread + Cflags: -I${includedir} --MOSTLYCLEANFILES = $(am_libcpu_pic_a_OBJECTS) - CLEANFILES += $(foreach P,i386 x86_64,$P_defs $P.mnemonics) - MAINTAINERCLEANFILES = $(foreach P,i386 x86_64, $P_dis.h) + # We need the exact matching elfutils libelf version since internal data --- a/config/libelf.pc.in +++ b/config/libelf.pc.in @@ -8,7 +8,7 @@ Description: elfutils libelf library to @@ -888,13 +235,34 @@ Cflags: -I${includedir} Requires.private: zlib @LIBZSTD@ ---- a/lib/next_prime.c -+++ b/lib/next_prime.c -@@ -27,6 +27,7 @@ - the GNU Lesser General Public License along with this program. If - not, see <http://www.gnu.org/licenses/>. */ - -+#include <config.h> - #include <stddef.h> - +--- a/libebl/eblopenbackend.c ++++ b/libebl/eblopenbackend.c +@@ -202,8 +202,6 @@ static bool default_object_note (const c + uint32_t descsz, const char *desc); + static bool default_debugscn_p (const char *name); + static bool default_copy_reloc_p (int reloc); +-static bool default_none_reloc_p (int reloc); +-static bool default_relative_reloc_p (int reloc); + static bool default_check_special_symbol (Elf *elf, + const GElf_Sym *sym, + const char *name, +@@ -255,8 +253,8 @@ fill_defaults (Ebl *result) + result->object_note = default_object_note; + result->debugscn_p = default_debugscn_p; + result->copy_reloc_p = default_copy_reloc_p; +- result->none_reloc_p = default_none_reloc_p; +- result->relative_reloc_p = default_relative_reloc_p; ++ result->none_reloc_p = default_copy_reloc_p; ++ result->relative_reloc_p = default_copy_reloc_p; + result->check_special_symbol = default_check_special_symbol; + result->data_marker_symbol = default_data_marker_symbol; + result->check_st_other_bits = default_check_st_other_bits; +@@ -638,8 +636,6 @@ default_copy_reloc_p (int reloc __attrib + { + return false; + } +-strong_alias (default_copy_reloc_p, default_none_reloc_p) +-strong_alias (default_copy_reloc_p, default_relative_reloc_p) + static bool + default_check_special_symbol (Elf *elf __attribute__ ((unused)), diff --git a/tools/elfutils/patches/101-shared-conditional.patch b/tools/elfutils/patches/101-shared-conditional.patch new file mode 100644 index 0000000000..4eeee6a682 --- /dev/null +++ b/tools/elfutils/patches/101-shared-conditional.patch @@ -0,0 +1,184 @@ +--- a/configure.ac ++++ b/configure.ac +@@ -102,6 +102,8 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) + AC_CHECK_TOOL([READELF], [readelf]) + AC_CHECK_TOOL([NM], [nm]) + ++LT_INIT([shared disable-static]) ++ + AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))], + ac_cv_visibility, [dnl + save_CFLAGS="$CFLAGS" +@@ -423,7 +425,10 @@ AS_HELP_STRING([--enable-install-elfh],[ + AM_CONDITIONAL(INSTALL_ELFH, test "$install_elfh" = yes) + + AM_CONDITIONAL(BUILD_STATIC, [dnl +-test "$use_gprof" = yes -o "$use_gcov" = yes]) ++test "$use_gprof" = yes -o "$use_gcov" = yes -o "$enable_static" = yes]) ++ ++AM_CONDITIONAL(BUILD_SHARED, [dnl ++test "$enable_shared" = yes]) + + AC_ARG_ENABLE([tests-rpath], + AS_HELP_STRING([--enable-tests-rpath],[build $ORIGIN-using rpath into tests]), +--- a/libelf/Makefile.am ++++ b/libelf/Makefile.am +@@ -35,8 +35,11 @@ endif + VERSION = 1 + + lib_LIBRARIES = libelf.a ++if BUILD_SHARED + noinst_LIBRARIES = libelf_pic.a + noinst_DATA = $(noinst_LIBRARIES:_pic.a=.so) ++endif ++ + include_HEADERS = libelf.h gelf.h nlist.h + + noinst_HEADERS = abstract.h common.h exttypes.h gelf_xlate.h libelfP.h \ +@@ -122,11 +125,15 @@ libelf.so: $(srcdir)/libelf.map $(libelf + @$(textrel_check) + $(AM_V_at)ln -fs $@ $@.$(VERSION) + ++if BUILD_SHARED + install: install-am libelf.so + $(mkinstalldirs) $(DESTDIR)$(libdir) + $(INSTALL_PROGRAM) libelf.so $(DESTDIR)$(libdir)/libelf-$(PACKAGE_VERSION).so + ln -fs libelf-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libelf.so.$(VERSION) + ln -fs libelf.so.$(VERSION) $(DESTDIR)$(libdir)/libelf.so ++else ++libelf_a_LIBADD = $(foreach dep,$(libelf_so_DEPS:.so=.a) $(LIBS:.so=.a),$(if $(findstring a,$(suffix $(dep))),$(addprefix $(dir $(dep)),$(shell cat $(basename $(dep)).manifest)),$(dep))) ++endif + + uninstall: uninstall-am + rm -f $(DESTDIR)$(libdir)/libelf-$(PACKAGE_VERSION).so +--- a/libdw/Makefile.am ++++ b/libdw/Makefile.am +@@ -35,8 +35,10 @@ AM_CPPFLAGS += -I$(srcdir)/../libebl -I$ + VERSION = 1 + + lib_LIBRARIES = libdw.a ++if BUILD_SHARED + noinst_LIBRARIES = libdw_pic.a + noinst_DATA = $(noinst_LIBRARIES:_pic.a=.so) ++endif + + include_HEADERS = dwarf.h + pkginclude_HEADERS = libdw.h known-dwarf.h +@@ -120,11 +122,13 @@ libdw.so: $(srcdir)/libdw.map $(libdw_so + @$(textrel_check) + $(AM_V_at)ln -fs $@ $@.$(VERSION) + ++if BUILD_SHARED + install: install-am libdw.so + $(mkinstalldirs) $(DESTDIR)$(libdir) + $(INSTALL_PROGRAM) libdw.so $(DESTDIR)$(libdir)/libdw-$(PACKAGE_VERSION).so + ln -fs libdw-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libdw.so.$(VERSION) + ln -fs libdw.so.$(VERSION) $(DESTDIR)$(libdir)/libdw.so ++endif + + uninstall: uninstall-am + rm -f $(DESTDIR)$(libdir)/libdw-$(PACKAGE_VERSION).so +@@ -147,6 +151,10 @@ libdw_a_LIBADD += $(addprefix ../backend + libcpu_objects = $(shell $(AR) t ../libcpu/libcpu.a) + libdw_a_LIBADD += $(addprefix ../libcpu/,$(libcpu_objects)) + ++if !BUILD_SHARED ++libdw_a_LIBADD += $(foreach dep,$(libdw_so_DEPS:.so=.a) $(LIBS:.so=.a),$(if $(findstring a,$(suffix $(dep))),$(addprefix $(dir $(dep)),$(shell cat $(basename $(dep)).manifest)),$(dep))) ++endif ++ + noinst_HEADERS = libdwP.h memory-access.h dwarf_abbrev_hash.h \ + dwarf_sig8_hash.h cfi.h encoded-value.h + +--- a/libasm/Makefile.am ++++ b/libasm/Makefile.am +@@ -33,8 +33,11 @@ AM_CPPFLAGS += -I$(top_srcdir)/libelf -I + VERSION = 1 + + lib_LIBRARIES = libasm.a ++if BUILD_SHARED + noinst_LIBRARIES = libasm_pic.a + noinst_DATA = $(noinst_LIBRARIES:_pic.a=.so) ++endif ++ + pkginclude_HEADERS = libasm.h + + libasm_a_SOURCES = asm_begin.c asm_abort.c asm_end.c asm_error.c \ +@@ -71,11 +74,15 @@ libasm.so: $(srcdir)/libasm.map $(libasm + @$(textrel_check) + $(AM_V_at)ln -fs $@ $@.$(VERSION) + ++if BUILD_SHARED + install: install-am libasm.so + $(mkinstalldirs) $(DESTDIR)$(libdir) + $(INSTALL_PROGRAM) libasm.so $(DESTDIR)$(libdir)/libasm-$(PACKAGE_VERSION).so + ln -fs libasm-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libasm.so.$(VERSION) + ln -fs libasm.so.$(VERSION) $(DESTDIR)$(libdir)/libasm.so ++else ++libasm_a_LIBADD = $(foreach dep,$(libasm_so_DEPS:.so=.a) $(LIBS:.so=.a),$(if $(findstring a,$(suffix $(dep))),$(addprefix $(dir $(dep)),$(shell cat $(basename $(dep)).manifest)),$(dep))) ++endif + + uninstall: uninstall-am + rm -f $(DESTDIR)$(libdir)/libasm-$(PACKAGE_VERSION).so +--- a/debuginfod/Makefile.am ++++ b/debuginfod/Makefile.am +@@ -77,8 +77,10 @@ debuginfod_find_LDADD = $(libdw) $(libel + + if LIBDEBUGINFOD + noinst_LIBRARIES = libdebuginfod.a ++if BUILD_SHARED + noinst_LIBRARIES += libdebuginfod_pic.a + endif ++endif + + libdebuginfod_a_SOURCES = debuginfod-client.c + libdebuginfod_pic_a_SOURCES = debuginfod-client.c +@@ -111,12 +113,17 @@ $(LIBDEBUGINFOD_SONAME): $(srcdir)/libde + libdebuginfod.so: $(LIBDEBUGINFOD_SONAME) + ln -fs $< $@ + ++if BUILD_SHARED + install: install-am libdebuginfod.so + $(mkinstalldirs) $(DESTDIR)$(libdir) + $(INSTALL_PROGRAM) $(LIBDEBUGINFOD_SONAME) \ + $(DESTDIR)$(libdir)/libdebuginfod-$(PACKAGE_VERSION).so + ln -fs libdebuginfod-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/$(LIBDEBUGINFOD_SONAME) + ln -fs libdebuginfod-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libdebuginfod.so ++else ++libdebuginfod_a_LIBADD = $(foreach dep,$(wildcard $(libdebuginfod_so_LDLIBS:.so=.a)) $(LIBS:.so=.a),$(if $(findstring a,$(suffix $(dep))),$(addprefix $(dir $(dep)),$(shell cat $(basename $(dep)).manifest)),$(dep))) ++endif ++ + uninstall: uninstall-am + rm -f $(DESTDIR)$(libdir)/libdebuginfod-$(PACKAGE_VERSION).so + rm -f $(DESTDIR)$(libdir)/$(LIBDEBUGINFOD_SONAME) +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -50,7 +50,7 @@ check_PROGRAMS = arextract arsymtest new + dwfl-report-offline-memory \ + varlocs backtrace backtrace-child \ + backtrace-data backtrace-dwarf debuglink debugaltlink \ +- buildid deleted deleted-lib.so aggregate_size peel_type \ ++ buildid aggregate_size peel_type \ + vdsosyms \ + getsrc_die strptr newdata newzdata \ + elfstrtab dwfl-proc-attach \ +@@ -181,7 +181,7 @@ TESTS = run-arextract.sh run-arsymtest.s + run-readelf-addr.sh run-readelf-str.sh \ + run-readelf-multi-noline.sh \ + run-readelf-types.sh \ +- run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \ ++ run-readelf-dwz-multi.sh run-allfcts-multi.sh \ + run-linkmap-cut.sh run-aggregate-size.sh run-peel-type.sh \ + vdsosyms run-readelf-A.sh \ + run-getsrc-die.sh run-strptr.sh newdata newzdata \ +@@ -298,6 +298,11 @@ check_PROGRAMS += funcretval_test_struct + funcretval_test_struct_SOURCES = funcretval_test_struct.c + TESTS += run-funcretval-struct-native.sh + ++if BUILD_SHARED ++check_PROGRAMS += deleted deleted-lib.so ++TESTS += run-deleted.sh ++endif ++ + EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ + run-ar-N.sh \ + run-show-die-info.sh run-get-files.sh run-get-lines.sh \ diff --git a/tools/elfutils/patches/110-objects-manifest.patch b/tools/elfutils/patches/110-objects-manifest.patch new file mode 100644 index 0000000000..35ef131190 --- /dev/null +++ b/tools/elfutils/patches/110-objects-manifest.patch @@ -0,0 +1,162 @@ +--- a/libdw/Makefile.am ++++ b/libdw/Makefile.am +@@ -136,19 +136,19 @@ uninstall: uninstall-am + rm -f $(DESTDIR)$(libdir)/libdw.so + rmdir --ignore-fail-on-non-empty $(DESTDIR)$(includedir)/elfutils + +-libdwfl_objects = $(shell $(AR) t ../libdwfl/libdwfl.a) ++libdwfl_objects = $(shell cat ../libdwfl/libdwfl.manifest) + libdw_a_LIBADD = $(addprefix ../libdwfl/,$(libdwfl_objects)) + +-libdwelf_objects = $(shell $(AR) t ../libdwelf/libdwelf.a) ++libdwelf_objects = $(shell cat ../libdwelf/libdwelf.manifest) + libdw_a_LIBADD += $(addprefix ../libdwelf/,$(libdwelf_objects)) + +-libebl_objects = $(shell $(AR) t ../libebl/libebl.a) ++libebl_objects = $(shell cat ../libebl/libebl.manifest) + libdw_a_LIBADD += $(addprefix ../libebl/,$(libebl_objects)) + +-backends_objects = $(shell $(AR) t ../backends/libebl_backends.a) ++backends_objects = $(shell cat ../backends/libebl_backends.manifest) + libdw_a_LIBADD += $(addprefix ../backends/,$(backends_objects)) + +-libcpu_objects = $(shell $(AR) t ../libcpu/libcpu.a) ++libcpu_objects = $(shell cat ../libcpu/libcpu.manifest) + libdw_a_LIBADD += $(addprefix ../libcpu/,$(libcpu_objects)) + + if !BUILD_SHARED +@@ -160,5 +160,10 @@ noinst_HEADERS = libdwP.h memory-access. + + EXTRA_DIST = libdw.map + +-MOSTLYCLEANFILES = $(am_libdw_pic_a_OBJECTS) libdw.so libdw.so.$(VERSION) ++EXTRA_libdw_a_DEPENDENCIES = libdw.manifest ++ ++libdw.manifest: $(libdw_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(am_libdw_pic_a_OBJECTS) $(EXTRA_libdw_a_DEPENDENCIES) libdw.so libdw.so.$(VERSION) + MAINTAINERCLEANFILES = $(srcdir)/known-dwarf.h +--- a/libdwfl/Makefile.am ++++ b/libdwfl/Makefile.am +@@ -94,4 +94,10 @@ am_libdwfl_pic_a_OBJECTS = $(libdwfl_a_S + + noinst_HEADERS = libdwflP.h + ++EXTRA_libdwfl_a_DEPENDENCIES = libdwfl.manifest ++ ++libdwfl.manifest: $(libdwfl_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(EXTRA_libdwfl_a_DEPENDENCIES) + CLEANFILES += $(am_libdwfl_pic_a_OBJECTS) +--- a/libdwelf/Makefile.am ++++ b/libdwelf/Makefile.am +@@ -54,4 +54,10 @@ libeu = ../lib/libeu.a + libdwelf_pic_a_SOURCES = + am_libdwelf_pic_a_OBJECTS = $(libdwelf_a_SOURCES:.c=.os) + ++EXTRA_libdwelf_a_DEPENDENCIES = libdwelf.manifest ++ ++libdwelf.manifest: $(libdwelf_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(EXTRA_libdwelf_a_DEPENDENCIES) + CLEANFILES += $(am_libdwelf_pic_a_OBJECTS) +--- a/libebl/Makefile.am ++++ b/libebl/Makefile.am +@@ -61,4 +61,9 @@ am_libebl_pic_a_OBJECTS = $(libebl_a_SOU + + noinst_HEADERS = libebl.h libeblP.h ebl-hooks.h + +-MOSTLYCLEANFILES = $(am_libebl_pic_a_OBJECTS) ++EXTRA_libebl_a_DEPENDENCIES = libebl.manifest ++ ++libebl.manifest: $(libebl_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(am_libebl_pic_a_OBJECTS) $(EXTRA_libebl_a_DEPENDENCIES) +--- a/backends/Makefile.am ++++ b/backends/Makefile.am +@@ -122,4 +122,9 @@ am_libebl_backends_pic_a_OBJECTS = $(lib + noinst_HEADERS = libebl_CPU.h common-reloc.c linux-core-note.c x86_corenote.c + EXTRA_DIST = $(modules:=_reloc.def) + +-MOSTLYCLEANFILES = $(am_libebl_backends_pic_a_OBJECTS) ++EXTRA_libebl_backends_a_DEPENDENCIES = libebl_backends.manifest ++ ++libebl_backends.manifest: $(libebl_backends_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(am_libebl_backends_pic_a_OBJECTS) $(EXTRA_libebl_backends_a_DEPENDENCIES) +--- a/libcpu/Makefile.am ++++ b/libcpu/Makefile.am +@@ -101,6 +101,11 @@ bpf_disasm_CFLAGS = -Wno-format-nonliter + + EXTRA_DIST = defs/i386 + +-MOSTLYCLEANFILES = $(am_libcpu_pic_a_OBJECTS) ++EXTRA_libcpu_a_DEPENDENCIES = libcpu.manifest ++ ++libcpu.manifest: $(libcpu_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(am_libcpu_pic_a_OBJECTS) $(EXTRA_libcpu_a_DEPENDENCIES) + CLEANFILES += $(foreach P,i386 x86_64,$P_defs $P.mnemonics) + MAINTAINERCLEANFILES = $(foreach P,i386 x86_64, $P_dis.h) +--- a/libelf/Makefile.am ++++ b/libelf/Makefile.am +@@ -142,4 +142,10 @@ uninstall: uninstall-am + + EXTRA_DIST = libelf.map + ++EXTRA_libelf_a_DEPENDENCIES = libelf.manifest ++ ++libelf.manifest: $(libelf_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(EXTRA_libelf_a_DEPENDENCIES) + CLEANFILES += $(am_libelf_pic_a_OBJECTS) libelf.so libelf.so.$(VERSION) +--- a/lib/Makefile.am ++++ b/lib/Makefile.am +@@ -42,3 +42,10 @@ noinst_HEADERS = fixedsizehash.h libeu.h + atomics.h stdatomic-fbsd.h dynamicsizehash_concurrent.h \ + eu-search.h locks.h + EXTRA_DIST = dynamicsizehash.c dynamicsizehash_concurrent.c ++ ++EXTRA_libeu_a_DEPENDENCIES = libeu.manifest ++ ++libeu.manifest: $(libeu_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(EXTRA_libeu_a_DEPENDENCIES) +--- a/libasm/Makefile.am ++++ b/libasm/Makefile.am +@@ -93,4 +93,10 @@ uninstall: uninstall-am + noinst_HEADERS = libasmP.h symbolhash.h + EXTRA_DIST = libasm.map + ++EXTRA_libasm_a_DEPENDENCIES = libasm.manifest ++ ++libasm.manifest: $(libasm_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(EXTRA_libasm_a_DEPENDENCIES) + CLEANFILES += $(am_libasm_pic_a_OBJECTS) libasm.so libasm.so.$(VERSION) +--- a/debuginfod/Makefile.am ++++ b/debuginfod/Makefile.am +@@ -132,7 +132,13 @@ uninstall: uninstall-am + endif + + EXTRA_DIST = libdebuginfod.map +-MOSTLYCLEANFILES = $(am_libdebuginfod_pic_a_OBJECTS) $(LIBDEBUGINFOD_SONAME) ++ ++EXTRA_libdebuginfod_a_DEPENDENCIES = libdebuginfod.manifest ++ ++libdebuginfod.manifest: $(libdebuginfod_a_OBJECTS) ++ echo $^ > $@ ++ ++MOSTLYCLEANFILES = $(am_libdebuginfod_pic_a_OBJECTS) $(LIBDEBUGINFOD_SONAME) $(EXTRA_libdebuginfod_a_DEPENDENCIES) + CLEANFILES += $(am_libdebuginfod_pic_a_OBJECTS) libdebuginfod.so + + # automake std-options override: arrange to pass LD_LIBRARY_PATH |