You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can the small code model assume the GOT is within 2 GiB of text? #343
I'm asking because the R_AARCH64_GOTPCREL32 relocation introduced in #223 appears to implicitly make this assumption. I want to use the same assumption to encode Clang's indirect references to the personality function and typeinfo objects inside eh_frame sections as sdata4 instead of sdata8 (see my LLVM Discourse post for more details if interested), and I'm wondering how safe that is. Note 2 of https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst#code-models states:
The definition of the text segment includes the shareable PLT, code and read-only data sections.
The GOT isn't technically read-only since relocations need to be applied to it, but if you're using RELRO (which I imagine is the case more often than not) then it's functionally read-only, so it seems useful to make the max text segment size of 2 GiB apply to the GOT as well, at least for the small code model. Are there problems I'm not foreseeing with this?
Yes it is looking like I need to add something like max distance from text to GOT < 2 GiB at least when R_AARCH64_GOTPCREL32 is in use.
Only clang/lld supports R_AARCH64_GOTPCREL32 so it is likely that there will be an option to not use it (for compatibility with GNU ld) for some time. I think it will probably be worth making the distinction, at least until GCC/GNU ld decide to support R_AARCH64_GOTPCREL32. The counter argument is that no known program has > 2 GiB distance to the .got which, due to being RELRO is almost always early in the .data.
In general this wouldn't create a new restriction since R_AARCH64_GOTPCREL32 relocations would be in eh_frame at the end of the text segment, and the GOT is at the start of the data segment. So you can still create binaries with 2GB of text and 2GB of data.
Activity
smithp35 commentedon Aug 12, 2025
Yes it is looking like I need to add something like
max distance from text to GOT < 2 GiBat least whenR_AARCH64_GOTPCREL32is in use.Only clang/lld supports
R_AARCH64_GOTPCREL32so it is likely that there will be an option to not use it (for compatibility with GNU ld) for some time. I think it will probably be worth making the distinction, at least until GCC/GNU ld decide to supportR_AARCH64_GOTPCREL32. The counter argument is that no known program has > 2 GiB distance to the .got which, due to being RELRO is almost always early in the .data.I'll see if I can make a PR this week.
Wilco1 commentedon Aug 12, 2025
In general this wouldn't create a new restriction since
R_AARCH64_GOTPCREL32relocations would be ineh_frameat the end of the text segment, and the GOT is at the start of the data segment. So you can still create binaries with 2GB of text and 2GB of data.[sysvabi64] Code Models. Limit range to GOT to 2GiB
smithp35 commentedon Aug 15, 2025
I've created #345 have added the limitation and a note explaining that the limitation to 2 is due to
R_AARCH64_GOTPCREL32.[sysvabi64] Code Models. Limit range to GOT to 2GiB (ARM-software#345)