<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112919>112919</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lld] location counter alignment not affecting . when assigning an output section address and a MEMORY region.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
smithp35
</td>
</tr>
</table>
<pre>
This example is derived from an internal linker script used with ld.bfd that brought up an unexpected warning with LLD. There are ways to work around it. Raising to log the discrepancy.
When assigning an OutputSection an address an explicit address and a MEMORY region, my reading of the ld.bfd manual is that the explicit address takes precedence over the location in the MEMORY region (https://sourceware.org/binutils/docs/ld/Output-Section-Address.html)
It looks like when assigning the OutputSection the value of the location counter as the address, lld uses the location counter from the MEMORY region and not the global location counter. For example:
```
.section s01, "ax", %progbits
.byte 1
.section s02, "ax", %progbits
.balign 4
.word 1
```
With linker script:
```
MEMORY
{
FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0x100
RAM (rw) : ORIGIN = 0x2000, LENGTH = 0x1000
}
SECTIONS
{
/* s01 is 1 byte */
s01 : { *(s01) } > FLASH
/* . == 1 */
. = ALIGN(4);
/* . == 4 expectation that s02 gets 4-byte aligned address */
s02 . : { *(s02) } > FLASH
}
```
However we get
```
ld.lld: warning: address (0x1001) of section s02 is not a multiple of alignment (4)
```
With Map file:
```
VMA LMA Size Align Out In Symbol
1000 1000 1 1 s01
1000 1000 1 1 align.o:(s01)
1001 1001 3 1 . = ALIGN(4)
1001 1001 5 4 s02
1004 1004 2 4 align.o:(s02)
```
Whereas with ld.bfd we get
```
s01 0x0000000000001000 0x1
*(s01)
s01 0x0000000000001000 0x1 align.o
0x0000000000001004 . = ALIGN (0x4)
s02 0x0000000000001004 0x2
*(s02)
s02 0x0000000000001004 0x2 align.o
```
If I move the ALIGN to inside the s01 OutputSection `{ *(s01); . = ALIGN(4); }`, we get similar results
```
1000 1000 4 1 s01
1000 1000 1 1 align.o:(s01)
1001 1001 3 1 . = ALIGN(4)
1004 1004 2 4 s02
1004 1004 2 4 align.o:(s02)
```
My suspicion is that when using `.` in the context of Memory regions is using the location counter from the MEMORY region and not the global location counter.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV19v4jgQ_zTmZdQocQIlDzzQpewi9Y_UVre6RycZwFcnjmyHP_fpT-MECils904XoZCMPePfjH_jmQhr5apCnLDhHRvOBqJxa20mtpRuXcfDQaaL_eRtLS3gTpS1QpAWCjRygwUsjS5BVCArh6YSCpSs3tGAzY2sHTQWC9hKtwZVBNmyALcWDjKjm9XaQVOTalPhrsbc0UxhKlmtWo2Hh1kAb2s0CMIgbMXegtOw1eYdhNFNVYB0AbwIaUnHaVB6BW6NUEibG6xFle8DFs5YOG3vP9dYQesuaYgKnhtXN-4Vcyd1RQJRFAatpUfc1Urm0p3IChDweP_4_PInGFxJXTH-Dco9GBQFWdRLv37naymqRiiKlveaRj7ZdOIdLdQGcyywyhH0Bk1rROfCo5KVfz9bFxgfr52rLYunjM8Zn1vdmBy3wmCgzYrxeSarxkllGZ8XOqc_VTA-bz2-6Vy-mbY4grUrFePpabQWDpTW7xaUfEfYnseOEJ0HjyQboRo8RuHgQK4bYgcI6-Wd6xQ6pQqiiL0833Prs-u0DZVu47lSOiPS9VQDmGtzoCuFqHVrFHY__wrdFdjOAxtGBIpxLnaM8_Z5WBu9yqSzPaVs7xCi03hdsMf_hT2h5KqCpCfealMclznH_9On1Wm6XfO0jV83dHt3WGL-MH39QUwyO8ZTYPEUnl8W3xdPwOIZhLsoDEMC_XD_9P3tx4fwoP8yffTa24va_Ip2eMAxOw3e6_23t8Xz02sfpCf3lLaG8igCH3bGPek7GDRGq7Pbu3Zk7DcyBXY7Axbft36e2wsID0GKesb8AEwfFt-fGB8nlBLx3RXdBNqDS3T8F462HFboLCQ3HqnfVCyO6d5Hzr21c-z8CvaPiJ3v7g-9RTo0tkhLw8U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