Bug 30944 - LoongArch linker relaxation support breaks .balign
Summary: LoongArch linker relaxation support breaks .balign
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.41
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-05 13:45 UTC by Icenowy Zheng
Modified: 2024-01-22 10:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Icenowy Zheng 2023-10-05 13:45:07 UTC
The following assembly code:

```
.text
.balign 256
func1:
la.global $a0,exit
nop
nop
nop

.balign 256
func2:
la.global $a0,exit
nop
nop
nop
```

Surely we expect func1 @ 0x0 and func2 @ 0x100, however when assembled with no extra options with GAS 2.41, func1 is @ 0xfc and func2 0x20c.

Add `-mno-relax` option to GAS could workaround this.

This leads to miscompilation of https://github.com/NVIDIA/libglvnd/blob/master/src/GLdispatch/vnd-glapi/entry_loongarch64_tsd.c (which emits thousands of function thunks .baligned to 256B, and referenced by the index at runtime), and leads to broken GL and thus broken desktop.
Comment 1 Icenowy Zheng 2023-10-05 15:20:41 UTC
Sorry for disturbance here, the misaligned symbols in the .o file is expected; however ld is expected to re-align it, which failed in the case of libglvnd.
Comment 2 Icenowy Zheng 2023-10-06 07:20:51 UTC
The new code used to reproduce the ld issue is here:

```
.text
.balign 256
func1:
la.global $a0,exit
nop
.word 0x12345678
.word 0x0

.balign 256
func2:
la.global $a0,exit
nop
.word 0x12345678
.word 0x0
```

Build it with: (assume it's saved as test.s)

```
# as test.s -o test.o
# ld test.o -shared
```

On my setup with binutils 2.41 native, I got func1 @ 0x2fc and func2 @ 0x40c, both are not properly aligned.
Comment 3 Xi Ruoyao 2024-01-22 10:42:20 UTC
It should be fixed with 2.42.