I can reproduce what looks like the same issue of SIGSEGV on current
glibc master when building with `-Os` on riscv64....

---
Build:
  > CC="riscv64-unknown-linux-gnu-gcc" \
    CFLAGS="-march=rv64g_zca_zcd_v -mabi=lp64d -g -Os" \
    $HOME/glibc/configure \
      --prefix=/usr \
      --host=riscv64-unknown-linux-gnu \
      --with-arch=rv64g_zca_zcd_v --with-abi=lp64d \
      --with-timeoutfactor=2
  > make -j24
Reproduce:
  > qemu-riscv64 -d cpu,in_asm -D /tmp/qemu-ldconfig-Os.log ./elf/ldconfig 
--help >/dev/null 2>&1
  > tail -n 120 /tmp/qemu-ldconfig-Os.log
  [1]    33231 segmentation fault (core dumped)  qemu-riscv64 -d cpu,in_asm -D 
/tmp/qemu-ldconfig-Os.log ./elf/ldconfig --help
   x0/zero  0000000000000000 x1/ra    000055555557b574 x2/sp    
00007c2172dfb2d0 x3/gp    00005555555e4110
   x4/tp    0000000000000000 x5/t0    000000000000000a x6/t1    
0000000000000025 x7/t2    0000000000000000
   x8/s0    0000000000000000 x9/s1    00005555555e88a0 x10/a0   
000000006ffffdff x11/a1   0000000008000000
   x12/a2   0000000000000006 x13/a3   0000000000000000 x14/a4   
0000000000000000 x15/a5   0000000000000000
   x16/a6   0000000070000025 x17/a7   00005555555e3120 x18/s2   
0000000000000000 x19/s3   0000000000000000
   x20/s4   0000000000000000 x21/s5   00005555555e30e0 x22/s6   
0000000000000002 x23/s7   00007c2172dfb428
   x24/s8   0000000000000000 x25/s9   000055555555fd6e x26/s10  
0000000000000000 x27/s11  0000000000000000
   x28/t3   000000000000000f x29/t4   fffffffffffffffc x30/t5   
000000000000000b x31/t6   0000000000000035
In this trace, we have the following sequences in _dl_relocate_static_pie seems 
to looks like setup for a memset call:
  0x55555557b804:  1800              addi                    s0,sp,48
  0x55555557b806:  04000613          addi                    a2,zero,64
  0x55555557b80a:  4581              mv                      a1,zero
  0x55555557b80c:  8522              mv                      a0,s0
  0x55555557b80e:  fffe4097          auipc                   ra,-28             
     # 0x55555555f80e
  0x55555557b812:  fc2080e7          jalr                    ra,ra,-62
And the next block entered is a PLT stub:
  0x55555555f7d0:  00083e17          auipc                   t3,131             
     # 0x5555555e27d0
  0x55555555f7d4:  838e3e03          ld                      t3,-1992(t3)
  0x55555555f7d8:  000e0367          jalr                    t1,t3,0
---

It seems that _dl_relocate_static_pie is trying to call memset without
including `dl-symbol-redir-ifunc.h`, so it's not safe for IFUNC
indirection here.

So....We can also trigger this issue on x86_64 by

> CC="gcc" \
CFLAGS="-g -Os -mstringop-strategy=libcall" \
$HOME/glibc/configure \
  --prefix=/usr \
  --enable-static-pie \
  --with-timeoutfactor=2

> make -j"$(nproc)"
> ./elf/ldconfig --help
[1]    1906 segmentation fault (core dumped)  ./elf/ldconfig --help

Would the following change make sense here? It fixes the reproducer here on 
both riscv64 and x86_64:
```
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index bdff2b5ee2..08a694bc28 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -22,6 +22,7 @@
 #include <assert.h>
 #include <unistd.h>
 #include <ldsodefs.h>
+#include <dl-symbol-redir-ifunc.h>
 
 #include <dl-machine.h>
 #include <dl-debug.h>
```

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2142067

Title:
  static-pie binaries crash on riscv64 with glibc 2.43 on resolute.

To manage notifications about this bug go to:
https://bugs.launchpad.net/glibc/+bug/2142067/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to