llvm / llvm/llvm-project

[lld/ELF] removeUnusedSyntheticSections can remove sections required later

Open
#212,325 1 comment 0 reactions 0 assignees View on GitHub
lld:ELF
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

For example as mentioned in https://github.com/llvm/llvm-project/pull/211911, `X86_64::relaxOnce` can add GOT entries for GOTPCRELX relocations that were relaxed to PC32 but actually would end up overflowing and we undo the relaxation. However, if there are no `.rela.dyn`/`.relr.dyn` entries, `removeUnusedSyntheticSections()` will remove them prior to `X86_64::relaxOnce` and we'll end up without the dynamic relocations.

```
$ cat repro.s
.text
.globl _start
_start:
movq foo@GOTPCREL(%rip), %rax

.section .data,"aw",@progbits
.globl foo
foo:
.byte 0

$ llvm-mc -filetype=obj -triple=x86_64 repro.s -o repro.o
$ ld.lld -pie --pack-dyn-relocs=relr --section-start=.text=0x10000 --section-start=.got=0x20000 --section-start=.data=0x100000000 repro.o -o repro
$ llvm-readobj -r repro

File: repro
Format: elf64-x86-64
Arch: x86_64
AddressSize: 64bit
LoadName:
Relocations [
]
```

#96496 has a similar issue with `.relr.auth.dyn` -> `.rela.dyn`.

Contributor guide

Open the contributing guide

Research direction

Start with the repro.s assembly and run the listed llvm-mc, ld.lld, and llvm-readobj commands to reproduce the missing dynamic relocations. Trace removeUnusedSyntheticSections and X86_64::relaxOnce, including the related #96496 case; done means the required dynamic relocation sections remain available when relaxation is undone and the repro reports the expected relocations.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.