<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69225>69225</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
.ltorg ignores subsection number
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:ARM,
mc
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
john-brawn-arm
</td>
</tr>
</table>
<pre>
With the following example
```
.global var1
.text 1
a:
ldr r0, =var1
bx lr
.ltorg
.text 2
b:
ldr r0, =var2
bx lr
.ltorg
.text 3
c:
ldr r0, =var3
bx lr
.ltorg
```
Assembling with ``clang --target=arm-none-eabi`` then disassembling with llvm-objdump the result is
```
Disassembly of section .text:
00000000 <.text>:
0: 00 00 00 00 .word 0x00000000
4: 00 00 00 00 .word 0x00000000
8: 00 00 00 00 .word 0x00000000
0000000c <a>:
c: e51f0014 ldr r0, [pc, #-0x14] @ 0x0 <.text>
10: e12fff1e bx lr
00000014 <b>:
14: e51f0018 ldr r0, [pc, #-0x18] @ 0x4 <.text+0x4>
18: e12fff1e bx lr
0000001c <c>:
1c: e51f001c ldr r0, [pc, #-0x1c] @ 0x8 <.text+0x8>
20: e12fff1e bx lr
```
however assembling with gnu arm-none-eabi-as the result is
```
Disassembly of section .text:
00000000 <a>:
0: e51f0000 ldr r0, [pc, #-0x0] @ 0x8 <a+0x8>
4: e12fff1e bx lr
8: 00 00 00 00 .word 0x00000000
0000000c <b>:
c: e51f0000 ldr r0, [pc, #-0x0] @ 0x14 <b+0x8>
10: e12fff1e bx lr
14: 00 00 00 00 .word 0x00000000
00000018 <c>:
18: e51f0000 ldr r0, [pc, #-0x0] @ 0x20 <c+0x8>
1c: e12fff1e bx lr
20: 00 00 00 00 .word 0x00000000
```
With clang all the constant pools are going in text subsection 0, meaning they end up before all the other .text subsections. When assembling for a target that doesn't have pc-relative ldr with negative offset (e.g. cortex-m23) then this results in the error
```
tmp.s:5:9: error: out of range pc-relative fixup value
ldr r0, =var1
^
tmp.s:11:9: error: out of range pc-relative fixup value
ldr r0, =var2
^
tmp.s:17:9: error: out of range pc-relative fixup value
ldr r0, =var3
^
```
It looks like the cause of this is that emitConstantPool in llvm/lib/MC/ConstantPools.cpp calls Streamer.switchSection without a subsection argument, causing it to default to subsection 0.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk2PozgQ_TXOpRRkDCRwyCHTmUh7GGm1c5izDQV4xmBkmyTz71cGuhPyMeneVaMoSrCpevVePcrcWlm1iBuSfCHJbsF7V2uz-anrdikMP7ZLbpqF0MXvzQ_panA1QqmV0kfZVoAn3nQKCd0RuiUrOn2GvzBdQaW04AoO3ITTxvm6w5ODaYmT6GpZFQYMJewFSLQ7x3hdFidQ5iqgctpUs1RjDjb-E09zsMc57gSf1RGNN_OnOaKP1THndmstNkJ5CY5elXEtV7ytYLl03FToSLTjplm2usUlciHHPV7AFgpp-VUIpQ7NUoufRd90g8oGba8cSHsXwe4twm_QJVjMndTtSMJb7eM3nS4g0cu0_vVMDyXRFig9fwCCozYFANDT66MzYuJHTzzYn74_wwxw7gHzGdjx8uICJmFJaRif1fXXpHDypcuHHyxa0lMYk2T3qiqJqU87I-MieDjwgSEryzLEt94Yk5hblGHsI4kZyjC-AJi-B2B6AzA-A2Rf6Ck-wwzTDyIceMxveQwvecyfIMxvEKZzhOkVkWxO5A3CeTvX-ogHNHDtiqrtYeaiJbef5457zUbPJA2t-0xLekHUJVP8Lkujmf4s5jMbPTeR-LOJ_mtdr71_r7D3-GgyysdfDWH6qKXT_18Vo2Pwu1Xl75WLPXyv3hQ2b91hyo-ThCs19HquW-t466DTWlngBqHS3iKyhWHo2V68tvhQZIO89euuxt-AbQF9BwJLbfAtpnY1mmlmnh-3Afzw8-nChqU2wGEcaeBq7qDQaFvC1g5qfkDo8qVBxZ084MD14NsWq_GOLkuLDghLMagCyLVxeFo2LCIsG2ehq6Wd7GyHimoENEbff1G4pgssibYJib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