[FFmpeg-devel] [PATCH] Mark C globals with small code model

Michael Niedermayer michael at niedermayer.cc
Fri Feb 28 03:14:09 EET 2025


On Wed, Feb 26, 2025 at 07:44:37PM +0000, Pranav Kant via ffmpeg-devel wrote:
> 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 may be 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 smaller). 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
> 
> Signed-off-by: Pranav Kant <prka at google.com>
> ---
>  libavcodec/ac3dsp.c             |  2 ++
>  libavcodec/cabac.c              |  2 ++
>  libavcodec/x86/constants.c      |  8 ++++++++
>  libavutil/attributes_internal.h | 15 +++++++++++++++
>  4 files changed, 27 insertions(+)

This produces many warnings:

CC	libavcodec/svq1.o
In file included from libavcodec/svq1.h:40,
                 from libavcodec/svq1.c:35:
./libavutil/attributes_internal.h:43:5: warning: "ARCH_X86_64" is not defined, evaluates to 0 [-Wundef]
   43 | #if ARCH_X86_64 && defined(__ELF__) && __has_attribute(model)
      |     ^~~~~~~~~~~

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250228/915b2b25/attachment.sig>


More information about the ffmpeg-devel mailing list