[Bug libelf/26734] New: ELF saving fails for an AARCH64 binary built with -mbranch-protection=standard

2020-10-14 Thread mliska at suse dot cz via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=26734

Bug ID: 26734
   Summary: ELF saving fails for an AARCH64 binary built with
-mbranch-protection=standard
   Product: elfutils
   Version: unspecified
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: libelf
  Assignee: unassigned at sourceware dot org
  Reporter: mliska at suse dot cz
CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

Created attachment 12897
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12897&action=edit
Problematic binary

The following code snippet fails (isolated from debugedit.c from rpm package):

$ cat demo.c
#include 
#include 
#include 
#include 
#include 

int main(int argc, char **argv)
{
  elf_version (EV_CURRENT);
  int fd = open (argv[1], O_RDWR);
  Elf *elf = NULL;
  int i;

  elf = elf_begin (fd, ELF_C_RDWR, NULL);
  if (elf == NULL)
{
  error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1));
  exit (1);
}
  if (elf_update (elf, ELF_C_NULL) < 0)
{
  fprintf (stderr, "Failed to update file: %s\n",
   elf_errmsg (elf_errno ()));
  exit (1);
}
}

I used latest elfutils libelf.so:

$ gcc demo.c -lelf &&
LD_PRELOAD=/home/marxin/Programming/elfutils/libelf/libelf.so ./a.out
/tmp/authvar
Failed to update file: invalid section entry size

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

[Bug libelf/26734] ELF saving fails for an AARCH64 binary built with -mbranch-protection=standard

2020-10-14 Thread mliska at suse dot cz via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=26734

--- Comment #1 from Martin Liska  ---
Fails here:

./libelf/elf32_updatenull.c:

  if (unlikely (sh_size % shdr->sh_entsize != 0))
{
  __libelf_seterrno (ELF_E_INVALID_SHENTSIZE);
  return -1;
}

and the problematic section is:

$ readelf -S --wide /tmp/authvar
...
  [15] .plt  PROGBITS00402b00 002b00 000a40 18  AX 
0   0 16

Where 0x000a40 == 2624 and 0x18 = 24. 2624 % 24 == 8.

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

[Bug libelf/26734] ELF saving fails for an AARCH64 binary built with -mbranch-protection=standard

2020-10-14 Thread mliska at suse dot cz via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=26734

--- Comment #2 from Martin Liska  ---
And there's the problematic .plt entry:

$ objdump -D -j .plt /tmp/authvar

/tmp/authvar: file format elf64-littleaarch64

Disassembly of section .plt:

00402b00 <.plt>:
  402b00:   d503245fbti c
  402b04:   a9bf7bf0stp x16, x30, [sp, #-16]!
  402b08:   b0f0adrpx16, 41f000 <__FRAME_END__+0x174cc>
  402b0c:   f9462611ldr x17, [x16, #3144]
  402b10:   91312210add x16, x16, #0xc48
  402b14:   d61f0220br  x17
  402b18:   d503201fnop
  402b1c:   d503201fnop

00402b20 :
  402b20:   d503245fbti c
  402b24:   b0f0adrpx16, 41f000 <__FRAME_END__+0x174cc>
  402b28:   f9462a11ldr x17, [x16, #3152]
  402b2c:   91314210add x16, x16, #0xc50
  402b30:   d61f0220br  x17
  402b34:   d503201fnop

The first .plt is longer (size == 0x20).

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

[Bug libelf/26734] ELF saving fails for an AARCH64 binary built with -mbranch-protection=standard

2020-10-14 Thread mliska at suse dot cz via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=26734

Martin Liska  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Martin Liska  ---
It's caused by missing patch in out binutils package:
https://sourceware.org/bugzilla/show_bug.cgi?id=26312

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