<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64571>64571</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ld.lld: ALIGN() directive incorrectly increasing LMA after empty section
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
finchky
</td>
</tr>
</table>
<pre>
An ALIGN() directive applied to the LMA of an empty section will influence the LMA of the next non-empty section that follows.
However, when using GCC/ld, in this scenario, the next non-empty section's LMA will begin at the last available LMA address prior to the ALIGN occurirng on the empty section's LMA.
For a simplified example, I modified [a sample project from the embedded toolchain](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/tree/main/samples/src/baremetal-uart).
Changes:
1. Add map file generation to the build target of the [Makefile](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/blob/main/samples/src/baremetal-uart/Makefile) - `$(BIN_PATH)/clang $(MICROBIT_TARGET) $(CRT) -g -Xlinker -Map=hello.map -T ../../ldscripts/microbit.ld -o hello.elf $^`
2. Add the `align_bug` section to `/opt/LLVMEmbeddedToolchainForArm-17.0.0-Linux-x86_64/lib/clang-runtimes/arm-none-eabi/armv6m_soft_nofp/lib/picolibcpp.ld`
![image](https://github.com/llvm/llvm-project/assets/139795925/7adfdce8-03db-4512-98f3-0c3d7736a910)
**Actual Result**: LMA of `.data` is the aligned LMA of empty section `.align_bug`
```
3320 3320 28 4 .except_unordered
3320 3320 0 1 . = ALIGN ( 8 )
3320 3320 28 4 <internal>:(.ARM.exidx)
20000000 3350 0 16 .align_bug
20000000 3350 0 1 . = .
20000000 3350 38 4 .data
20000000 3350 30 4 /tmp/hello-6adfd4.o:(.data)
20000000 3350 4 1 gpio_dir_set
20000004 3354 4 1 uart_starttx
20000008 3358 4 1 uart_txdrdy
```
**Expected Result**: LMA of `.data` is the the address immediately following 0x3320 + 0x28 (LMA of `.except_unordered` + size of `.except_unordered`)
```
3320 3320 28 4 .except_unordered
3320 3320 0 1 . = ALIGN ( 8 )
3320 3320 28 4 <internal>:(.ARM.exidx)
20000000 3348 38 4 .data
20000000 3348 30 4 /tmp/hello-dc4e29.o:(.data)
20000000 3348 4 1 gpio_dir_set
20000004 334c 4 1 uart_starttx
20000008 3350 4 1 uart_txdrdy
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVluPozoS_jXOSwkE5hJ4yEP6kjktdZ9dtVqrfYsMLoh3jI1s053eX7-ySTJJX07P7BkUBRvqK1d9_soFs1b0CnFFiitS3CzY5HbarDqh2t3310Wj-etqrWB9f_ftT0IrQmvgwmDrxDMCG0cpkIPT4HYI9w9r0B0wBTiM7hWsN9MKXoSUIFQnJ1Qtnpv6ocK9A6VVdAlyO-ag01LqFxsDSW5Isp7__9Av-IyG0Gt42aGCyQrVw7fra0I3kvvHwsOFBduiYkZo_-zzpQhd2hBQiLPBXihgLgAksw7YMxOSNXKOmnFu0FoYjdDmmHmgB3TbTkYY1UOIH-HDZeLzXDbaAAMrhlGKzlOJezaMEn3EdzBoPj8lxRUDG97AaPR_sHXQGT0cVmmQ87ANWrY7JhQpbgitds6NlmRrQjeEbnrhdlMTt3ogdLN-fIis7twLM0jo5v7-Xw_R0U10chN12kRr4wHOoDccvHO6mSOxfmRaQjcNMzigYzKamHGE1hc5Xu-Y6jFEEuZpDGvOYWAjdEIi9KjQsHnTZzqbSUgOjpke3VEmpLh6YN_RI35_eo3Uzc-ntzkFQmuIgJQJoTmh1dXdn9t_rp_-ILQmdNNKpnqY3zzcXT_-4-ruafu0fvx2--Rx84vrxzCJeoj-LYX6jgaiBzaS7GaHUurYkxQ9QRwTugl_ktvWiNH56AbRGt0IF0sOkYYZgbILvotbH1cgnM6EBxbLhEnRq20z9aRMflSbntPY6NEdGLs9EPZ05GujzdoMUbqMkziJ7oWa9tG-Krdl7uMSzTHnyEzKiSEQyMwQKa0wQtaIef5cDlu_OVulu_GEHE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