[llvm] [AArch64] Refactor @plt, @gotpcrel, and @AUTH to use parseDataExpr (PR #134202)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 9 23:13:57 PDT 2025


MaskRay wrote:




> I'm now not so sure this syntax is invalid. Here's what Xcode's clang outputs:
> 
> ```
> % clang --version
> Apple clang version 17.0.0 (clang-1700.0.13.3)
> Target: arm64-apple-darwin24.3.0
> Thread model: posix
> InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> % cat foo.c
> static int x[20];
> 
> int *get_ptr() {
>     return x + 5;
> }
> % clang -S -O2 foo.c
> % cat foo.s
> 	.section	__TEXT,__text,regular,pure_instructions
> 	.build_version macos, 15, 0	sdk_version 15, 4
> 	.globl	_get_ptr                        ; -- Begin function get_ptr
> 	.p2align	2
> _get_ptr:                               ; @get_ptr
> 	.cfi_startproc
> ; %bb.0:
> Lloh0:
> 	adrp	x0, _x at PAGE+20
> Lloh1:
> 	add	x0, x0, _x at PAGEOFF+20
> 	ret
> 	.loh AdrpAdd	Lloh0, Lloh1
> 	.cfi_endproc
>                                         ; -- End function
> .zerofill __DATA,__bss,_x,80,2          ; @x
> .subsections_via_symbols
> ```
> 
> That is definitely not the syntax I would have expected, given that `@PAGE` and `@PAGEOFF` are presumably intended to modify the whole argument, but it seems Clang also prefers to emit this funny interleaved version.

While `add x0, x0, _x at PAGEOFF+1` is valid in Mach-O, `add	x0, x0, _x at PAGEOFF-1` as the referenced location and `_x` belong to different atoms. The linker might reorder `_x` so that the referenced location and `x` is no longer apart by 1 byte.

However, `add x23,x23,Lone_mont at PAGEOFF-64` looks valid. `L...` defines a temporary symbol, which does not create a new atom. `Lone_mont at PAGEOFF-64` and `Lone_mont at PAGEOFF` could belong to the same subsection.

Restored the support in 3fd0d22d74027c00bd2365ea1691dc530bb9709a. Sorry for the trouble!

https://github.com/llvm/llvm-project/pull/134202


More information about the llvm-commits mailing list