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

    <tr>
        <th>Summary</th>
        <td>
            This makes your program crash at load time
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          jacob-navia
      </td>
    </tr>
</table>

<pre>
    Consider this assembly code:

.section __TEXT,text,regular,pure_instructions
_foo:
     adrp x14,Lswitch@PAGE
      add x14,x14,Lswitch@PAGEOFF // Get the address of a jump table into x14
      ldp q0,q1,[x0,16]
      ldr x15,[x14,x10,lsl 3] // Get the label you want to jump into by indexing the jump table
      ldp q2,q3,[x0,48]
      br x15.     // do it: jump to the label

At the end of the assembler file I have the jump table:
Lswitch:
    .quad L_ERROR
    .quad L_DO_1
    .quad L_DO_2
    .quad L_DO_3
    .quad L_DO_4
    .quad L_DO_5
    .quad L_DO_6
    .quad L_DO_7
    .quad L_ERROR
    .quad L_ERROR
    .quad L_ERROR
    .quad L_ERROR
    .quad L_ERROR



The program will assemble correctly and link correctly but the dynamic loader will crash with:
(lldb) run
Process 17303 launched: '/Users/jacob/lcc/qlibarm64/qtime' (arm64)
Process 17303 stopped
* thread #1, stop reason = EXC_BAD_ACCESS (code=2, address=0x10000f5f0)
    frame #0: 0x0000000100039a54 dyld`invocation function for block in dyld4::Loader::applyFixupsGeneric(Diagnostics&, dyld4::RuntimeState&, dyld3::Array<void const*> const&, dyld3::Array<void const*> const&, bool, dyld3::Array<dyld4::Loader::MissingFlatLazySymbol> const&) const + 60
dyld`invocation function for block in dyld4::Loader::applyFixupsGeneric(Diagnostics&, dyld4::RuntimeState&, dyld3::Array<void const*> const&, dyld3::Array<void const*> const&, bool, dyld3::Array<dyld4::Loader::MissingFlatLazySymbol> const&) const:
->  0x100039a54 <+60>: str    x19, [x20]
 The program crashes in the dynamic loader. It costed me 3 days of work to figure this stuff out.
1) What is the correct way to layout a jump table?
2) Could you PLEEEEEEZE make some error message hinting at the error instead of the incomprehensible stuff?

Thanks in advance guys!

jacob

P.S. I have tried to put it in the text segment, the data segment, it always crashes. OI tried doing:
ldr x14,=Lswitch

and then .pool later

It also crashes.

This  as so difficult to find because the assembler code was in a library within a fairly big program. Just linking with the library
suffices to crash the program. Note that NO ERRORS were issued by the assembler. The relocations looked fairly normal also.



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVktv4zYQ_jXyhYiglx374IPXjyBFugmSLbroxaBESuaGFhWSiq3--s6QsqMkXqBoe6xgSPRwOPz4zYu5Yt18qWojGNfE7oQh1Bi-z2VHCsV4kC6CaBVE_Ts0vLBC1WS7_bb-_i1IlpYfLXw0r1pJNYyaVvOtqI3VrVM1fuW2VOpsjOBDmW7IMc5gzZ05CFvsgix6WNysBzqgxHqdS5r3mw0Jkg38yA23AJ_jAs2NIaoklPxo9w2xNJeciNoqZ2lgXLKGvERg9SWGVzD-csQ_8SQYr96raVg57lV6MKgpjSQpKH_EIGnOJelUSw60BpHyQByEvIMv40dRV073DeInZAkiSwfIsukHZLkDFrpxj4EpIiwQ3RtWb4CGflx4oLxmSJTjzXsdgqAUQNct2dFX_hHhyX8nLwz9Gb60lJG77frx8f7xs3h1v40vSpOL0vSiNLsoHV-UTi5Kr_824P9a_Pn9DchttKo03ZODkPLsA8g8rSHRIAcpeEiK-nkgylvvPNbVdC8KIhXF3HUWCk3NDob2zTdBMpWS5UEyI7qtvexBqwKTJL5OoxSio62LHWcYNUFyDVH0m-HawPcHLRSs3MiigPeLFDnV-0mGYyv2HJRhwbSXzS7ZNlY1DZjuoSwAueZATZCkmHNunoDEQE0J0hVZf19uvyxW28VyuX56Quu-Cq0wGU7JDX8jyEB4ynEZnXdG4ksgk6P1CE8THSP_oHI6o-MMWJMsmESiflUFdaWshNP7gdIkl6p4hgx1ehmSmC7uHMF-TJtGdhtxbBtzw2u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