llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.05k stars 11.98k forks source link

[lld] feasibility of `.loh` linker optimization hints on elf platforms #60534

Closed nickdesaulniers closed 1 year ago

nickdesaulniers commented 1 year ago

I noticed that clang on macos is emitting .loh assembler directives. I couldn't find much documentation on these, but it seems there's some logic implemented in llvm/include/llvm/MC/MCLinkerOptimizationHint.h.

It looks like the linker is able to fold:

Lloh0:
adrp x0, lhello@PAGE
Lloh1:
add  x0, x0, lhello@PAGEOFF
.loh AdrpAdd Lloh0, Lloh1
adr x0, #36
nop

I don't understand what #36 is. Is that some kind of slot that the loader will relocate? llvm-objdump -dr and otool -tVr don't show any kind of specifial relocations for these.

cc @TNorthover @MaskRay @smithp35

llvmbot commented 1 year ago

@llvm/issue-subscribers-backend-aarch64

llvmbot commented 1 year ago

@llvm/issue-subscribers-lld-elf

MaskRay commented 1 year ago

https://maskray.me/blog/2021-08-29-all-about-global-offset-table#got-optimization ld64 uses .loh to perform GOT optimizations. To some degree it is a mechanism to lift the relocation type size limitation of Mach-O. ELF platforms supports more relocation types and don't need a separate metadata section.