Skip to content
Snippets Groups Projects

Mark C globals with assembly reference to small code model

Open Pranav Kant requested to merge pranavk/x264:mcmodel into master

By default, all globals in C/C++ compiled by clang are allocated in non-large data sections. See [1] for background on code models. For PIC (Position independent code), this is fine as long as binary is small but as binary size increases, users maybe want to use medium/large code models (-mcmodel=medium) which moves data in to large sections. As data in these large sections cannot be accessed using PIC code anymore (as it's too far away), compiler ends up using a different instruction sequence when building C/C++ code -- using GOT to access these globals (which can be relaxed by linker at link time if binary ends up being small). However, assembly files continue to access these globals defined in C/C++ files using older (and invalid instruction sequence). So, we mark all such globals with an attribute that forces them to be allocated in small sections allowing them to validly be accessed from the assembly code.

This patch should not have any affect on builds that use small code model, which is the default mode.

[1] https://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models

There is similar patch in dav1d which inspired this patch: dav1d!1785 (merged)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
Please register or sign in to reply
Loading