[Bug binutils/30692] New: [RISC-V] Symbol offset in .eh_frame section is not adjusted after relaxation

2023-07-27 Thread yanzhang.wang at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30692

Bug ID: 30692
   Summary: [RISC-V] Symbol offset in .eh_frame section is not
adjusted after relaxation
   Product: binutils
   Version: unspecified
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: binutils
  Assignee: unassigned at sourceware dot org
  Reporter: yanzhang.wang at intel dot com
  Target Milestone: ---

When we build the test with option -static -pg, the binary will be segment
fault. This is also a block issue to enable -static-pie for us.

» cat hello.c
int main(void)
{
return 0;
}

» riscv64-unknown-linux-gnu-gcc -static -pg hello.c

(gdb) r
Starting program: /home/riscv/a.out

Program received signal SIGSEGV, Segmentation fault.
classify_object_over_fdes (ob=0x82320 , this_fde=0x100051fba,
range=0x3ff380)
at ../../.././gcc/libgcc/unwind-dw2-fde.c:727
727 ../../.././gcc/libgcc/unwind-dw2-fde.c: No such file or directory.
(gdb) bt
#0  classify_object_over_fdes (ob=0x82320 , this_fde=0x100051fba,
range=0x3ff380)
at ../../.././gcc/libgcc/unwind-dw2-fde.c:727
#1  0x000513ee in __register_frame_info_bases (dbase=0x0, tbase=0x0,
ob=0x82320 ,
begin=) at ../../.././gcc/libgcc/unwind-dw2-fde.c:129
#2  __register_frame_info_bases (dbase=0x0, tbase=0x0, ob=0x82320 ,
begin=)
at ../../.././gcc/libgcc/unwind-dw2-fde.c:109
#3  __register_frame_info (begin=, ob=0x82320 )
at ../../.././gcc/libgcc/unwind-dw2-fde.c:145
#4  0x000106d8 in frame_dummy ()
#5  0x00010980 in __libc_start_main_impl ()
#6  0x000105e8 in _start ()


The root cause is the variable __EH_FRAME_BEGIN__ defined in .eh_frame section
has wrong value. Some objdump's output,

000106b6 :
   106b6:   000517b7lui a5,0x51
   106ba:   3c278793add a5,a5,962 # 513c2
<__register_frame_info>
   106be:   c385beqza5,106de 
   106c0:   000825b7lui a1,0x82
   106c4:   0006e537lui a0,0x6e
   106c8:   1141add sp,sp,-16
   106ca:   32058593add a1,a1,800 # 82320 
   106ce:   0e050513add a0,a0,224 # 6e0e0
<__EH_FRAME_BEGIN__>

Disassembly of section .eh_frame:

0006e0f0 <__EH_FRAME_BEGIN__+0x10>:

On x86 and ARM, it seems the reference of __EH_FRAME_BEGIN__ will be converted
to section with offset in gas. But on RISC-V, because tc_fix_adjustable was
disabled, so the symbol will not be adjusted.

If we dive deeper, the wrong value comes from the relaxation. The local symbols
in .eh_frame will be adjusted in bfd_elf_discard_info, but will not be adjusted
when and after relaxation. For example, before relaxation, the symbol will be
offset 0x50 due to the alignment requirement; after relaxation, the offset will
be 0x40 because no need to align. That's why .eh_frame start is the
__EH_FRAME_BEGIN__ + 0x10.

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


[Bug binutils/30692] [RISC-V] Symbol offset in .eh_frame section is not adjusted after relaxation

2023-07-27 Thread yanzhang.wang at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30692

--- Comment #1 from Wang, Yanzhang  ---
We tried to fix it with two methods,

- one is to support tc_fix_adjustable in gas.

  But there's a comment /* Let the linker resolve all the relocs due to 
  relaxation.  */. I'm not sure whether we can support it without breaking the 
  ld.

- another is to fix the symbol offset in after_allocation.

  Tried to readjust the offset of the symbol after relaxation but failed.

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


[Bug binutils/30692] [RISC-V] Symbol offset in .eh_frame section is not adjusted after relaxation

2023-07-31 Thread yanzhang.wang at intel dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=30692

--- Comment #3 from Wang, Yanzhang  ---
Hi Andreas Schwab. Thanks, this is the same. I didn't realize this can be
resolved in gcc by disabling the unwind-tables.

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