Skip to content

[llvm-readelf/readobj] Incorrectly handle .eh_frame with a non-zero offset within the output section #68417

Open
@simpal01

Description

@simpal01

When the .eh_frame is placed at non-zero offset within its output section, i think the tools llvm-readelf, llvm-readobj and llvm-objdump is not identifying the start of .eh_frame correctly which can make the display of unwind information wrong.

Using the given test case:

$ cat a.s
.section .text.01, "ax",%progbits
.global f1
.type f1, %function
f1:
.cfi_startproc
.space 4
.cfi_endproc

$ cat non-zero-off.t
SECTIONS {
  .text : { *(.text .text.*) }
  .eh_frame : {
    /* Padding within .eh_frame */
    . += 128;
    __eh_frame_start = .;
    *(.eh_frame) ;
    __eh_frame_end = .;
  }
}

and using the command line options

llvm-mc -filetype=obj -triple=aarch64 a.s -o a.o
ld.lld a.o -T non-zero-off.t -o non-zero
lvm-readelf --program-headers --unwind --symbols -x .eh_frame non-zero

 Segment Sections...
   00     .text 
   01     .eh_frame 
   02     
   None   .comment .symtab .shstrtab .strtab 

.eh_frame section at offset 0x1008 address 0x8:
  [0x8] CIE length=0
    version: 0
    augmentation: 
    code_alignment_factor: 0
    data_alignment_factor: 0
    return_address_register: 0

    Program:
Symbol table '.symtab' contains 4 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT     1 f1
     2: 0000000000000088     0 NOTYPE  GLOBAL DEFAULT     2 __eh_frame_start
     3: 00000000000000bc     0 NOTYPE  GLOBAL DEFAULT     2 __eh_frame_end
Hex dump of section '.eh_frame':
0x00000008 00000000 00000000 00000000 00000000 ................
0x00000018 00000000 00000000 00000000 00000000 ................
0x00000028 00000000 00000000 00000000 00000000 ................
0x00000038 00000000 00000000 00000000 00000000 ................
0x00000048 00000000 00000000 00000000 00000000 ................
0x00000058 00000000 00000000 00000000 00000000 ................
0x00000068 00000000 00000000 00000000 00000000 ................
0x00000078 00000000 00000000 00000000 00000000 ................
0x00000088 14000000 00000000 017a5200 01781001 .........zR..x..
0x00000098 1b0c0708 90010000 14000000 1c000000 ................
0x000000a8 58ffffff 04000000 00000000 00000000 X...............
0x000000b8 00000000 

We can see that .eh_frame section is pointing at the offset 0x1008 address 0x8. May be it should point at the offset 0x10088 address 0x88 to get the correct exception frame records? CIE length is zero which does not look right.

The executable created using GNU ld also has the same issue.

This is affected to all the targets which generates .eh_frame sections.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions