Skip to content

Can the small code model assume the GOT is within 2 GiB of text? #343

Closed

Description

@smeenai

https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst#code-models explicitly states that for the large code model, the max distance from text to GOT has to be under 4 GiB. #288 clarifies that this should also apply to the medium code model. For the small code model, is it reasonable to assume a distance of 2 GiB or less?

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?

Activity

  1. smithp35 commented on Aug 12, 2025

    @smithp35
    Contributor

    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.

    I'll see if I can make a PR this week.

  2. Wilco1 commented on Aug 12, 2025

    @Wilco1
    Contributor

    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.

  3. added a commit that references this issue on Aug 15, 2025
    6217919
  4. smithp35 commented on Aug 15, 2025

    @smithp35
    Contributor

    I've created #345 have added the limitation and a note explaining that the limitation to 2 is due to R_AARCH64_GOTPCREL32.

  5. added a commit that references this issue on Sep 10, 2025
    8e73a1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions