[Bug general/30812] New: ../libelf/gelf.h:32:10: fatal error: libelf.h: No such file or directory

2023-08-30 Thread schwab--- via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=30812

Bug ID: 30812
   Summary: ../libelf/gelf.h:32:10: fatal error: libelf.h: No such
file or directory
   Product: elfutils
   Version: unspecified
Status: NEW
  Keywords: testsuite
  Severity: normal
  Priority: P2
 Component: general
  Assignee: unassigned at sourceware dot org
  Reporter: sch...@linux-m68k.org
CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

Building the test system-elf-gelf-test fails with:

gcc -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"/usr/share/locale"' -I. -I..
-std=gnu99 -Wall -Wshadow -Wformat=2 -Wold-style-definition -Wstrict-prototypes 
-Wtrampolines -Wlogical-op -Wduplicated-cond -Wnull-dereference
-Wimplicit-fallt
hrough=5 -Wuse-after-free=3 -Werror -Wunused -Wextra -Wstack-usage=262144   -O2 
-Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
-funwind-ta
bles -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type
-
flto=auto -ffat-lto-objects -Werror=date-time -g -c -o
system_elf_gelf_test-syst
em-elf-gelf-test.o `test -f 'system-elf-gelf-test.c' || echo
'./'`system-elf-gelf-test.c
In file included from system-elf-gelf-test.c:22:
../libelf/gelf.h:32:10: fatal error: libelf.h: No such file or directory
   32 | #include 
  |  ^~

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug tools/29073] New: program header entry 2: unknown program header entry type 0x70000003

2022-04-19 Thread schwab--- via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=29073

Bug ID: 29073
   Summary: program header entry 2: unknown program header entry
type 0x7003
   Product: elfutils
   Version: unspecified
Status: NEW
  Severity: normal
  Priority: P2
 Component: tools
  Assignee: unassigned at sourceware dot org
  Reporter: sch...@linux-m68k.org
CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

FAIL: run-strip-strmerge.sh
===

elflint /home/abuild/rpmbuild/BUILD/elfutils-0.186/tests/elfstrmerge
program header entry 2: unknown program header entry type 0x7003
program header entry 2: file size greater than memory size
section [25] '.riscv.attributes' has unsupported type 1879048195
FAIL run-strip-strmerge.sh (exit status: 1)

FAIL: run-elflint-self.sh
=

program header entry 2: unknown program header entry type 0x7003
program header entry 2: file size greater than memory size
section [26] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/addr2line
program header entry 2: unknown program header entry type 0x7003
program header entry 2: file size greater than memory size
section [26] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elfclassify
program header entry 2: unknown program header entry type 0x7003
program header entry 2: file size greater than memory size
section [26] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/stack
program header entry 2: unknown program header entry type 0x7003
program header entry 2: file size greater than memory size
section [26] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/unstrip
program header entry 0: unknown program header entry type 0x7003
program header entry 0: file size greater than memory size
section [25] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/libelf/libelf.so
program header entry 0: unknown program header entry type 0x7003
program header entry 0: file size greater than memory size
section [25] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/libasm/libasm.so
section [71] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/size.o
section [78] '.riscv.attributes' has unsupported type 1879048195
*** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/elflint --quiet
--gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/strip.o
FAIL run-elflint-self.sh (exit status: 1)

FAIL: run-reverse-sections-self.sh
==


copy_elf: /home/abuild/rpmbuild/BUILD/elfutils-0.186/src/addr2line ->
addr2line.rev (read,reverse)
setshstrndx: 37
Swapping offsets of section 25 and 26
Swapping offsets of section 28 and 29
Swapping offsets of section 30 and 31
Swapping offsets of section 32 and 33
Swapping offsets of section 36 and 37
program header entry 2: unknown program header entry type 0x7003
program header entry 2: file size greater than memory size
section [26] '.riscv.attributes' has unsupported type 1879048195
FAIL run-reverse-sections-self.sh (exit status: 1)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug tools/29073] program header entry 2: unknown program header entry type 0x70000003

2022-08-11 Thread schwab--- via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=29073

Andreas Schwab  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Andreas Schwab  ---
This has been fixed by:

2f275fc1 elflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES
d703772e backends: Handle new RISC-V specific definitions
de209d23 libelf: Sync elf.h from glibc

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[PATCH] libelf: Sync elf.h from glibc

2023-06-26 Thread Andreas Schwab via Elfutils-devel
Adds new RISC-V relocations.

* elf.h: Update from glibc.

Signed-off-by: Andreas Schwab 
---
 libelf/elf.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libelf/elf.h b/libelf/elf.h
index 4bc0e429..89fc8021 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -210,7 +210,7 @@ typedef struct
 #define EM_68HC12  53  /* Motorola M68HC12 */
 #define EM_MMA 54  /* Fujitsu MMA Multimedia Accelerator */
 #define EM_PCP 55  /* Siemens PCP */
-#define EM_NCPU56  /* Sony nCPU embeeded RISC */
+#define EM_NCPU56  /* Sony nCPU embedded RISC */
 #define EM_NDR157  /* Denso NDR1 microprocessor */
 #define EM_STARCORE58  /* Motorola Start*Core processor */
 #define EM_ME1659  /* Toyota ME16 processor */
@@ -559,7 +559,7 @@ typedef struct
 
 /* Possible bitmasks for si_flags.  */
 #define SYMINFO_FLG_DIRECT 0x0001  /* Direct bound symbol */
-#define SYMINFO_FLG_PASSTHRU   0x0002  /* Pass-thru symbol for translator */
+#define SYMINFO_FLG_PASSTHRU   0x0002  /* Pass-through symbol for translator */
 #define SYMINFO_FLG_COPY   0x0004  /* Symbol is a copy-reloc */
 #define SYMINFO_FLG_LAZYLOAD   0x0008  /* Symbol bound to object to be lazy
   loaded */
@@ -728,6 +728,7 @@ typedef struct
 #define PT_GNU_STACK   0x6474e551  /* Indicates stack executability */
 #define PT_GNU_RELRO   0x6474e552  /* Read-only after relocation */
 #define PT_GNU_PROPERTY0x6474e553  /* GNU property */
+#define PT_GNU_SFRAME  0x6474e554  /* SFrame segment.  */
 #define PT_LOSUNW  0x6ffa
 #define PT_SUNWBSS 0x6ffa  /* Sun Specific segment */
 #define PT_SUNWSTACK   0x6ffb  /* Stack segment */
@@ -1223,6 +1224,9 @@ typedef struct
 #define AT_HWCAP2  26  /* More machine-dependent hints about
   processor capabilities.  */
 
+#define AT_RSEQ_FEATURE_SIZE   27  /* rseq supported feature size.  */
+#define AT_RSEQ_ALIGN  28  /* rseq allocation alignment.  */
+
 #define AT_EXECFN  31  /* Filename of executable.  */
 
 /* Pointer to the global system page used for system calls and other
@@ -3998,8 +4002,11 @@ enum
 #define R_RISCV_SET32  56
 #define R_RISCV_32_PCREL   57
 #define R_RISCV_IRELATIVE  58
+#define R_RISCV_PLT32  59
+#define R_RISCV_SET_ULEB12860
+#define R_RISCV_SUB_ULEB12861
 
-#define R_RISCV_NUM59
+#define R_RISCV_NUM62
 
 /* RISC-V specific values for the st_other field.  */
 #define STO_RISCV_VARIANT_CC   0x80/* Function uses variant calling
-- 
2.41.0


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] backends: Update list of RISC-V relocations

2023-06-26 Thread Andreas Schwab via Elfutils-devel
* backends/riscv_reloc.def: Add IRELATIVE, PLT32, SET_ULEB128,
SUB_ULEB128.

Signed-off-by: Andreas Schwab 
---
 backends/riscv_reloc.def | 4 
 1 file changed, 4 insertions(+)

diff --git a/backends/riscv_reloc.def b/backends/riscv_reloc.def
index 2bd3513e..f52f6489 100644
--- a/backends/riscv_reloc.def
+++ b/backends/riscv_reloc.def
@@ -81,3 +81,7 @@ RELOC_TYPE (SET8, REL)
 RELOC_TYPE (SET16, REL)
 RELOC_TYPE (SET32, REL)
 RELOC_TYPE (32_PCREL,  REL)
+RELOC_TYPE (IRELATIVE, EXEC|DYN)
+RELOC_TYPE (PLT32, REL)
+RELOC_TYPE (SET_ULEB128,   REL)
+RELOC_TYPE (SUB_ULEB128,   REL)
-- 
2.41.0


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] libelf: Sync elf.h from glibc

2022-08-08 Thread Andreas Schwab via Elfutils-devel
Adds PT_RISCV_ATTRIBUTES, SHT_RISCV_ATTRIBUTES, PT_AARCH64_MEMTAG_MTE,
RELR definitions, LoongArch relocations.

dwelf_elf_e_machine_string was updated to handle EM_LOONGARCH, and
ebl_dynamic_tag_name was updated to handle the new RELR dynamic tags.

Signed-off-by: Andreas Schwab 
---
 libdwelf/ChangeLog|  5 ++
 libdwelf/dwelf_elf_e_machine_string.c |  2 +
 libebl/ChangeLog  |  5 ++
 libebl/ebldynamictagname.c|  2 +-
 libelf/ChangeLog  |  4 ++
 libelf/elf.h  | 99 ++-
 6 files changed, 113 insertions(+), 4 deletions(-)

diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index c9010af8..d5800751 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,8 @@
+2022-08-08  Andreas Schwab  
+
+   * dwelf_elf_e_machine_string.c (dwelf_elf_e_machine_string): Add
+   EM_LOONGARCH LoongArch.
+
 2022-03-24  Mark Wielaard  
 
* dwelf_elf_e_machine_string.c (dwelf_elf_e_machine_string): Add
diff --git a/libdwelf/dwelf_elf_e_machine_string.c 
b/libdwelf/dwelf_elf_e_machine_string.c
index 051c70b5..6d588ea8 100644
--- a/libdwelf/dwelf_elf_e_machine_string.c
+++ b/libdwelf/dwelf_elf_e_machine_string.c
@@ -398,6 +398,8 @@ dwelf_elf_e_machine_string (int machine)
   return "BPF";
 case EM_CSKY:
   return "C-SKY";
+case EM_LOONGARCH:
+  return "LoongArch";
 
 case EM_ALPHA:
   return "Alpha";
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 52b9c609..19548718 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,8 @@
+2022-08-08  Andreas Schwab  
+
+   * ebldynamictagname.c (ebl_dynamic_tag_name): Handle DT_RELRSZ,
+   DT_RELR, DT_RELRENT.
+
 2022-06-01  Ulrich Drepper  
 
* eblopenbackend.c (default_machine_flag_name): Add original flag
diff --git a/libebl/ebldynamictagname.c b/libebl/ebldynamictagname.c
index 3f8d8ee4..5d4a3a58 100644
--- a/libebl/ebldynamictagname.c
+++ b/libebl/ebldynamictagname.c
@@ -54,7 +54,7 @@ ebl_dynamic_tag_name (Ebl *ebl, int64_t tag, char *buf, 
size_t len)
  "RELENT", "PLTREL", "DEBUG", "TEXTREL", "JMPREL", "BIND_NOW",
  "INIT_ARRAY", "FINI_ARRAY", "INIT_ARRAYSZ", "FINI_ARRAYSZ",
  "RUNPATH", "FLAGS", "ENCODING", "PREINIT_ARRAY",
- "PREINIT_ARRAYSZ", "SYMTAB_SHNDX"
+ "PREINIT_ARRAYSZ", "SYMTAB_SHNDX", "RELRSZ", "RELR", "RELRENT"
};
  eu_static_assert (sizeof (stdtags) / sizeof (const char *) == DT_NUM);
 
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 00d4ac0f..35f49516 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2022-08-08  Andreas Schwab  
+
+   * elf.h: Update from glibc.
+
 2022-04-24  Mark Wielaard  
 
* elf_update.c (write_file): Check HAVE_MREMAP.
diff --git a/libelf/elf.h b/libelf/elf.h
index 0735f6b5..02a1b3f5 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -358,8 +358,9 @@ typedef struct
 
 #define EM_BPF 247 /* Linux BPF -- in-kernel virtual machine */
 #define EM_CSKY252 /* C-SKY */
+#define EM_LOONGARCH   258 /* LoongArch */
 
-#define EM_NUM 253
+#define EM_NUM 259
 
 /* Old spellings/synonyms.  */
 
@@ -443,7 +444,8 @@ typedef struct
 #define SHT_PREINIT_ARRAY 16   /* Array of pre-constructors */
 #define SHT_GROUP17/* Section group */
 #define SHT_SYMTAB_SHNDX  18   /* Extended section indices */
-#defineSHT_NUM   19/* Number of defined types.  */
+#define SHT_RELR 19/* RELR relative relocations */
+#defineSHT_NUM   20/* Number of defined types.  */
 #define SHT_LOOS 0x6000/* Start OS-specific.  */
 #define SHT_GNU_ATTRIBUTES 0x6ff5  /* Object attributes.  */
 #define SHT_GNU_HASH 0x6ff6/* GNU-style hash table.  */
@@ -662,6 +664,11 @@ typedef struct
   Elf64_Sxword r_addend;   /* Addend */
 } Elf64_Rela;
 
+/* RELR relocation table entry */
+
+typedef Elf32_Word Elf32_Relr;
+typedef Elf64_XwordElf64_Relr;
+
 /* How to extract and insert information held in the r_info field.  */
 
 #define ELF32_R_SYM(val)   ((val) >> 8)
@@ -887,7 +894,10 @@ typedef struct
 #define DT_PREINIT_ARRAY 32/* Array with addresses of preinit fct*/
 #define DT_PREINIT_ARRAYSZ 33  /* size in bytes of DT_PREINIT_ARRAY */
 #define DT_SYMTAB_SHNDX34  /* Address of SYMTAB_SHNDX 
section */
-#defineDT_NUM  35  /* Number used */
+#define DT_RELRSZ  35  /* Total size of RELR relative 
relocations */
+#define DT_RELR36  /* Address of RELR relative 
relocations */
+#define DT_RELRENT 37  /* Size of one RELR relative 
relocaction */
+#defineDT_NUM  38  /* Number used */
 #define DT_LOOS0x60

[PATCH] backends: Handle new RISC-V specific definitions

2022-08-09 Thread Andreas Schwab via Elfutils-devel
Handle PT_RISCV_ATTRIBUTES, SHT_RISCV_ATTRIBUTES, DT_RISCV_VARIANT_CC.

Signed-off-by: Andreas Schwab 
---
 backends/riscv_init.c   |  4 
 backends/riscv_symbol.c | 45 +
 2 files changed, 49 insertions(+)

diff --git a/backends/riscv_init.c b/backends/riscv_init.c
index 141e0821..f2d46082 100644
--- a/backends/riscv_init.c
+++ b/backends/riscv_init.c
@@ -65,6 +65,10 @@ riscv_init (Elf *elf,
   HOOK (eh, check_special_symbol);
   HOOK (eh, machine_flag_check);
   HOOK (eh, set_initial_registers_tid);
+  HOOK (eh, segment_type_name);
+  HOOK (eh, section_type_name);
+  HOOK (eh, dynamic_tag_name);
+  HOOK (eh, dynamic_tag_check);
   if (eh->class == ELFCLASS64)
 eh->core_note = riscv64_core_note;
   else
diff --git a/backends/riscv_symbol.c b/backends/riscv_symbol.c
index c34b7702..c149b8ba 100644
--- a/backends/riscv_symbol.c
+++ b/backends/riscv_symbol.c
@@ -119,3 +119,48 @@ riscv_check_special_symbol (Elf *elf, const GElf_Sym *sym,
 
   return false;
 }
+
+const char *
+riscv_segment_type_name (int segment, char *buf __attribute__ ((unused)),
+size_t len __attribute__ ((unused)))
+{
+  switch (segment)
+{
+case PT_RISCV_ATTRIBUTES:
+  return "RISCV_ATTRIBUTES";
+}
+  return NULL;
+}
+
+/* Return symbolic representation of section type.  */
+const char *
+riscv_section_type_name (int type,
+char *buf __attribute__ ((unused)),
+size_t len __attribute__ ((unused)))
+{
+  switch (type)
+{
+case SHT_RISCV_ATTRIBUTES:
+  return "RISCV_ATTRIBUTES";
+}
+
+  return NULL;
+}
+
+const char *
+riscv_dynamic_tag_name (int64_t tag, char *buf __attribute__ ((unused)),
+   size_t len __attribute__ ((unused)))
+{
+  switch (tag)
+{
+case DT_RISCV_VARIANT_CC:
+  return "RISCV_VARIANT_CC";
+}
+  return NULL;
+}
+
+bool
+riscv_dynamic_tag_check (int64_t tag)
+{
+  return tag == DT_RISCV_VARIANT_CC;
+}
-- 
2.37.1


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] elflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES

2022-08-09 Thread Andreas Schwab via Elfutils-devel
The RISCV_ATTRIBUTES segment is not meant to be loaded.

Signed-off-by: Andreas Schwab 
---
 src/ChangeLog | 5 +
 src/elflint.c | 5 -
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 42ce6640..fbcef29e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2022-08-09  Andreas Schwab  
+
+   * elflint.c (check_program_header): Don't complain about p_filesz
+   > p_memsz if p_memsz is zero and p_type is PT_RISCV_ATTRIBUTES.
+
 2022-08-01  Mark Wielaard  
 
* readelf.c (handle_dynamic): Pass start of buffer to memrchr.
diff --git a/src/elflint.c b/src/elflint.c
index d919936f..b0e5415e 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -4731,7 +4731,10 @@ section [%2zu] '%s' must not be executable\n"),
}
 
   if (phdr->p_filesz > phdr->p_memsz
- && (phdr->p_memsz != 0 || phdr->p_type != PT_NOTE))
+ && (phdr->p_memsz != 0
+ || (phdr->p_type != PT_NOTE
+ && !(ehdr->e_machine == EM_RISCV
+  && phdr->p_type == PT_RISCV_ATTRIBUTES
ERROR (_("\
 program header entry %d: file size greater than memory size\n"),
   cnt);
-- 
2.37.1


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] readelf: Handle SHT_RISCV_ATTRIBUTES like SHT_GNU_ATTRIBUTES

2022-08-10 Thread Andreas Schwab via Elfutils-devel
Signed-off-by: Andreas Schwab 
---
 src/ChangeLog | 4 
 src/readelf.c | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index fbcef29e..88db4051 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2022-08-10  Andreas Schwab  
+
+   * readelf.c (print_attributes): Also handle SHT_RISCV_ATTRIBUTES.
+
 2022-08-09  Andreas Schwab  
 
* elflint.c (check_program_header): Don't complain about p_filesz
diff --git a/src/readelf.c b/src/readelf.c
index f1f77ce8..1a10fd01 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -3672,7 +3672,9 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr)
   && (shdr->sh_type != SHT_ARM_ATTRIBUTES
   || ehdr->e_machine != EM_ARM)
   && (shdr->sh_type != SHT_CSKY_ATTRIBUTES
-  || ehdr->e_machine != EM_CSKY)))
+  || ehdr->e_machine != EM_CSKY)
+  && (shdr->sh_type != SHT_RISCV_ATTRIBUTES
+  || ehdr->e_machine != EM_RISCV)))
continue;
 
   printf (_("\
-- 
2.37.1


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH RFC] backends: Add RISC-V object attribute printing

2022-08-10 Thread Andreas Schwab via Elfutils-devel
This does not work yet.  The RISC-V attribute tags use the same
convention as the GNU attributes: odd numbered tags take a string value,
even numbered ones an integer value, but print_attributes assumes the
ARM numbering scheme by default for non-GNU attributes.

---
 backends/ChangeLog |  6 
 backends/Makefile.am   |  3 +-
 backends/riscv_attrs.c | 80 ++
 backends/riscv_init.c  |  2 ++
 4 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 backends/riscv_attrs.c

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 5b0daffe..a642fe9e 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,9 @@
+2022-08-10  Andreas Schwab  
+
+   * Makefile.am (riscv_SRCS): Add riscv_attrs.c.
+   * riscv_init.c (riscv_init): Hook in riscv_check_object_attribute.
+   * riscv_attrs.c: New file.
+
 2022-08-09  Andreas Schwab  
 
* riscv_init.c (riscv_init): HOOK segment_type_name,
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 9566377f..1863f66a 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -91,7 +91,8 @@ m68k_corenote_no_Wpacked_not_aligned = yes
 bpf_SRCS = bpf_init.c bpf_regs.c bpf_symbol.c
 
 riscv_SRCS = riscv_init.c riscv_symbol.c riscv_cfi.c riscv_regs.c \
-riscv_initreg.c riscv_corenote.c riscv64_corenote.c riscv_retval.c
+riscv_initreg.c riscv_corenote.c riscv64_corenote.c \
+riscv_retval.c riscv_attrs.c
 
 csky_SRCS = csky_attrs.c csky_init.c csky_symbol.c csky_cfi.c \
csky_regs.c csky_initreg.c csky_corenote.c
diff --git a/backends/riscv_attrs.c b/backends/riscv_attrs.c
new file mode 100644
index ..6947be6e
--- /dev/null
+++ b/backends/riscv_attrs.c
@@ -0,0 +1,80 @@
+/* Object attribute tags for RISC-V.
+   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 .  */
+
+#ifdef HAVE_CONFIG_H
+# include 
+#endif
+
+#include 
+#include 
+
+#define BACKEND riscv_
+#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)
+
+bool
+riscv_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, "riscv"))
+switch (tag)
+  {
+  case 4:
+   *tag_name = "RISCV_stack_align";
+   return true;
+
+  case 5:
+   *tag_name = "RISCV_arch";
+   return true;
+
+  case 6:
+   *tag_name = "RISCV_unaligned_access";
+   KNOWN_VALUES ("No unaligned access", "Unaligned access");
+   return true;
+
+  case 8:
+   *tag_name = "RISCV_priv_spec";
+   return true;
+
+  case 10:
+*tag_name = "RISCV_priv_spec_minor";
+return true;
+
+  case 12:
+*tag_name = "RISCV_priv_spec_revision";
+return true;
+  }
+
+  return false;
+}
diff --git a/backends/riscv_init.c b/backends/riscv_init.c
index f2d46082..e5e9e33e 100644
--- a/backends/riscv_init.c
+++ b/backends/riscv_init.c
@@ -69,6 +69,8 @@ riscv_init (Elf *elf,
   HOOK (eh, section_type_name);
   HOOK (eh, dynamic_tag_name);
   HOOK (eh, dynamic_tag_check);
+  HOOK (eh, check_object_attribute);
+  HOOK (eh, set_initial_registers_tid);
   if (eh->class == ELFCLASS64)
 eh->core_note = riscv64_core_note;
   else
-- 
2.37.1


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."