<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/68417>68417</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [llvm-readelf/readobj] Incorrectly handle .eh_frame with a non-zero offset within the output section
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            tools:llvm-objdump,
            tools:llvm-readobj/readelf
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          simpal01
      </td>
    </tr>
</table>

<pre>
    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 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**. Actually it should point at the **offset 0x10088 address 0x88** . Therefore CIE length becomes zero which is not right.

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

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

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV1tv2zoS_jX0y8ACdbEtP_jBieOzBQKn2CSnu08GJY0kthRpkFTj9NcvSF2sOG2wB4gQxORcPg5nhuQMM4ZXEnFDFjdksZux1tZKbwxvTkzQcJap4nXzrUYJtkYIsD6WmjUI3MBJsBwLYBakkvNfqBWosjRo4YXbmkvg1oBq7am1YDC3XEkS3QIHx_zh8axSwoAQP5u5RlagKJ3EOFfZd2Cy6Agq-160zcmtLJUFXqC0vHzlsvJQxjJtQZUTG3OlNeZWvMJLzfMaciahYT_Qy7fyhcsCuCyVbpgzDl60klUAhO4I3Xb_n82AX_GfzgloLOTMIIl7CbKkJEogZxZYYDpa0G8XAotnG9DQ7YpEETuTKCLRLYkWJ62qjNtBoRIqYwLKsJ_b1xO6mddblK3s3OeZZTguHuQlP_qdn7TKh8VPLEdIJhIoiwu__9_bPIRursoysB3v8e726cvD4RHI6qajQLcTIPHWEYFEWxKlHa3bo6esgax2o8YYh15rYACQaE-iLXxlReHc26fLRMGB7S_yAZDohsQ7CKOUxAPQ8TgodC4AJxFc-H4hb-cg5y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