Arm needs to decode flags and I modeled it after the binutils code.
The same messages are printed. Given the requirement of the interface
and the ABIs the current version of the callback function isn't
sufficient unless one wants to create a stateful interface. The
problem is that most flags need to be interpreted in the context of
the ABI version. So I changed the API to also pass the original flag
value. This shouldn't be a problem because there are no users yet.
There is also a bug in ebl_machine_flag_name. When copying the string
provided by the callback cp is moved past the NUL byte. It should
move to the NUL byte. Otherwise one cannot anything but the first
added flag description. Finally some cosmetic changes (space after
each comma in the output).
Signed-off-by: Mark Wielaard <mark@klomp.org>
+2022-06-01 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile.am (arm_SRCS): Add arm_machineflagname.c.
+ * arm_init.c (arm_init): Hook in arm_machine_flag_name.
+ * arm_machineflagname.c: New file.
+
2022-02-16 Mark Wielaard <mark@klomp.org>
* ppc_initreg.c (ppc_set_initial_registers_tid): Define struct
alpha_corenote.c alpha_auxv.c
arm_SRCS = arm_init.c arm_symbol.c arm_regs.c arm_corenote.c \
- arm_auxv.c arm_attrs.c arm_retval.c arm_cfi.c arm_initreg.c
+ arm_auxv.c arm_attrs.c arm_retval.c arm_cfi.c arm_initreg.c \
+ arm_machineflagname.c
aarch64_SRCS = aarch64_init.c aarch64_regs.c aarch64_symbol.c \
aarch64_corenote.c aarch64_retval.c aarch64_cfi.c \
HOOK (eh, check_reloc_target_type);
HOOK (eh, symbol_type_name);
HOOK (eh, data_marker_symbol);
+ HOOK (eh, machine_flag_name);
/* We only unwind the core integer registers. */
eh->frame_nregs = 16;
--- /dev/null
+/* Arm-specific ELF flag names.
+ Copyright (C) 2022 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of 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
+
+#define BACKEND arm_
+#include "libebl_CPU.h"
+
+const char *
+arm_machine_flag_name (Elf64_Word orig, Elf64_Word *flagref)
+{
+ unsigned version = EF_ARM_EABI_VERSION (*flagref) >> 24;
+ if (version != 0)
+ {
+ static const char vername[5][14] =
+ {
+ "Version1 EABI",
+ "Version2 EABI",
+ "Version3 EABI",
+ "Version4 EABI",
+ "Version5 EABI",
+ };
+ *flagref &= ~((Elf64_Word) EF_ARM_EABIMASK);
+ return vername[version - 1];
+ }
+ switch (EF_ARM_EABI_VERSION (orig))
+ {
+ case EF_ARM_EABI_VER2:
+ if ((*flagref & EF_ARM_DYNSYMSUSESEGIDX) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_DYNSYMSUSESEGIDX);
+ return "dynamic symbols use segment index";
+ }
+ if ((*flagref & EF_ARM_MAPSYMSFIRST) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_MAPSYMSFIRST);
+ return "mapping symbols precede others";
+ }
+ FALLTHROUGH;
+ case EF_ARM_EABI_VER1:
+ if ((*flagref & EF_ARM_SYMSARESORTED) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_SYMSARESORTED);
+ return "sorted symbol tables";
+ }
+ break;
+ case EF_ARM_EABI_VER3:
+ break;
+ case EF_ARM_EABI_VER5:
+ if ((*flagref & EF_ARM_SOFT_FLOAT) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_SOFT_FLOAT);
+ return "soft-float ABI";
+ }
+ if ((*flagref & EF_ARM_VFP_FLOAT) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_VFP_FLOAT);
+ return "hard-float ABI";
+ }
+ FALLTHROUGH;
+ case EF_ARM_EABI_VER4:
+ if ((*flagref & EF_ARM_BE8) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_BE8);
+ return "BE8";
+ }
+ if ((*flagref & EF_ARM_LE8) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_LE8);
+ return "LE8";
+ }
+ break;
+ case EF_ARM_EABI_UNKNOWN:
+ if ((*flagref & EF_ARM_INTERWORK) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_INTERWORK);
+ return "interworking enabled";
+ }
+ if ((*flagref & EF_ARM_APCS_26) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_APCS_26);
+ return "uses APCS/26";
+ }
+ if ((*flagref & EF_ARM_APCS_FLOAT) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_APCS_FLOAT);
+ return "uses APCS/float";
+ }
+ if ((*flagref & EF_ARM_PIC) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_PIC);
+ return "position independent";
+ }
+ if ((*flagref & EF_ARM_ALIGN8) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_ALIGN8);
+ return "8 bit structure alignment";
+ }
+ if ((*flagref & EF_ARM_NEW_ABI) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_NEW_ABI);
+ return "uses new ABI";
+ }
+ if ((*flagref & EF_ARM_OLD_ABI) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_OLD_ABI);
+ return "uses old ABI";
+ }
+ if ((*flagref & EF_ARM_SOFT_FLOAT) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_SOFT_FLOAT);
+ return "software FP";
+ }
+ if ((*flagref & EF_ARM_VFP_FLOAT) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_VFP_FLOAT);
+ return "VFP";
+ }
+ if ((*flagref & EF_ARM_MAVERICK_FLOAT) != 0)
+ {
+ *flagref &= ~((Elf64_Word) EF_ARM_MAVERICK_FLOAT);
+ return "Maverick FP";
+ }
+ break;
+ default:
+ break;
+ }
+ return NULL;
+}
+2022-06-01 Ulrich Drepper <drepper@redhat.com>
+
+ * eblopenbackend.c (default_machine_flag_name): Add original flag
+ as first parameter.
+ * ebl-hooks.h (machine_flag_name): Ditto.
+ * eblmachineflagname.c (ebl_machine_flag_name): Modernize, use bool
+ for first. Pass original flag value to machine_flag_name
+ callback as well. Add space after comma in printed list.
+ Fix appending strings provided by callback.
+
2021-12-21 Luca Boccassi <bluca@debian.org>
* eblobjnote.c (ebl_object_note): Handle NT_FDO_PACKAGING_METADATA.
const char *EBLHOOK(section_name) (int, int, char *, size_t);
/* Return next machine flag name. */
-const char *EBLHOOK(machine_flag_name) (GElf_Word *);
+const char *EBLHOOK(machine_flag_name) (GElf_Word, GElf_Word *);
/* Check whether machine flags are valid. */
bool EBLHOOK(machine_flag_check) (GElf_Word);
res = "";
else
{
+ Elf64_Word orig_flags = flags;
char *cp = buf;
- int first = 1;
+ bool first = true;
const char *machstr;
size_t machstrlen;
{
if (! first)
{
- if (cp + 1 >= buf + len)
+ if (cp + 2 >= buf + len)
break;
*cp++ = ',';
+ *cp++ = ' ';
}
- machstr = ebl != NULL ? ebl->machine_flag_name (&flags) : NULL;
+ machstr = ebl != NULL ? ebl->machine_flag_name (orig_flags, &flags) : NULL;
if (machstr == NULL)
{
/* No more known flag. */
}
cp = mempcpy (cp, machstr, machstrlen);
+ --cp;
- first = 0;
+ first = false;
}
while (flags != 0);
size_t len);
static const char *default_section_name (int ignore, int ignore2, char *buf,
size_t len);
-static const char *default_machine_flag_name (Elf64_Word *ignore);
+static const char *default_machine_flag_name (Elf64_Word orig, Elf64_Word *ignore);
static bool default_machine_flag_check (Elf64_Word flags);
static bool default_machine_section_flag_check (GElf_Xword flags);
static const char *default_symbol_type_name (int ignore, char *buf,
}
static const char *
-default_machine_flag_name (Elf64_Word *ignore __attribute__ ((unused)))
+default_machine_flag_name (Elf64_Word orig __attribute__ ((unused)),
+ Elf64_Word *ignore __attribute__ ((unused)))
{
return NULL;
}
+2022-06-01 Mark Wielaard <mark@klomp.org>
+
+ * testfile-arm-flags.bz2: New test file.
+ * run-readelf-arm-flags.sh: New test.
+ * Makefile.am (TESTS): Add run-readelf-arm-flags.sh.
+ (EXTRA_DIST): Add readelf-arm-flags.sh and testfile-arm-flags.bz2
+
2022-05-13 Noah Sanci <nsanci@redhat.com>
* run-debuginfod-fd-prefetch-caches.sh: Rewritten.
run-backtrace-core-aarch64.sh run-backtrace-core-sparc.sh \
run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \
run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \
+ run-readelf-arm-flags.sh \
run-readelf-addr.sh run-readelf-str.sh \
run-readelf-multi-noline.sh \
run-readelf-types.sh \
run-readelf-dwz-multi.sh libtestfile_multi_shared.so.bz2 \
testfile_multi.dwz.bz2 testfile_multi_main.bz2 \
testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \
+ run-readelf-arm-flags.sh testfile-arm-flags.bz2 \
run-readelf-addr.sh run-readelf-str.sh \
run-readelf-multi-noline.sh testfile_multi_noline.bz2 \
run-readelf-types.sh \
--- /dev/null
+#! /bin/sh
+
+. $srcdir/test-subr.sh
+
+# echo "int main () {}" | gcc -xc -o testfile-arm-flags -
+testfiles testfile-arm-flags
+
+testrun_compare ${abs_top_builddir}/src/readelf -h testfile-arm-flags <<\EOF
+ELF Header:
+ Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
+ Class: ELF32
+ Data: 2's complement, little endian
+ Ident Version: 1 (current)
+ OS/ABI: UNIX - System V
+ ABI Version: 0
+ Type: DYN (Shared object file)
+ Machine: ARM
+ Version: 1 (current)
+ Entry point address: 0x3d1
+ Start of program headers: 52 (bytes into file)
+ Start of section headers: 6920 (bytes into file)
+ Flags: Version5 EABI, hard-float ABI
+ Size of this header: 52 (bytes)
+ Size of program header entries: 32 (bytes)
+ Number of program headers entries: 9
+ Size of section header entries: 40 (bytes)
+ Number of section headers entries: 29
+ Section header string table index: 28
+
+EOF