| Issue |
243526
|
| Summary |
[JITLink][MachO] Section alignment exponent is shifted before it is validated (UB for align >= 64)
|
| Labels |
orcjit
|
| Assignees |
|
| Reporter |
AnantaSrikar
|
`MachOLinkGraphBuilder` turns a section's `align` field (a log2 exponent from the input) into an alignment with `1ULL << Sec64.align` without checking the exponent. For `align` 64 or more that shift is undefined. UBSan reports it; without UBSan, on x86-64 the result is 1, so the section is linked with alignment 1 and the existing `Segment alignment greater than page size` check (which rejects `align` 13) is skipped.
**Version**: main at c7014922f582 (2026-11-16), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_USE_SANITIZER="Address;Undefined"`, on x86_64 Linux.
### Reproducer
```sh
printf '.globl _main\n_main:\n ret\n' > main.s
llvm-mc -triple=x86_64-apple-macosx -filetype=obj main.s -o main.o
obj2yaml main.o | sed 's/^ align: 0$/ align: 64/' > a64.yaml
yaml2obj a64.yaml -o a64.o
llvm-jitlink -noexec a64.o
```
With `align` 0 the object links (status 0); with 13 it is rejected with `Segment alignment greater than page size` (status 1).
### Observed
```
llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp:136:29: runtime error: shift exponent 64 is too large for 64-bit type 'unsigned long long'
```
Without sanitizers the same command exits 0, and `-show-graphs='.*'` shows the `__text` block with `align = 1`.
### Expected
An error for the invalid alignment, as for `align` 13.
### Analysis
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp#L134-L136
The 32-bit `section` path does the same:
https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp#L148-L149
Rejecting an exponent of 64 or more (or anything above what the later page-size check allows) before the shift would fix it.
This report was drafted with help from an AI assistant (Claude); I reviewed it and reproduced it myself.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs