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

James Zern jzern at google.com
Thu Feb 27 05:36:46 EET 2025


On Wed, Feb 26, 2025 at 11:44 AM Pranav Kant via ffmpeg-devel
<ffmpeg-devel at ffmpeg.org> wrote:
>
> [...]
> --- a/libavutil/attributes_internal.h
> +++ b/libavutil/attributes_internal.h
> @@ -31,4 +31,19 @@
>  #    define FF_VISIBILITY_POP_HIDDEN
>  #endif
>
> +/**
> + * Some globals defined in C files are used from hardcoded asm that assumes small
> + * code model (that is, accessing these globals without GOT). This is a problem
> + * when FFMpeg is built with medium code model (-mcmodel=medium) which allocates
> + * all globals in a data section that's unreachable with PC relative instructions
> + * (small code model instruction sequence). We mark all such globals with this
> + * attribute_mcmodel_small to ensure assembly accessible globals continue to be
> + * allocated in sections reachable from PC relative instructions.
> + */
> +#if ARCH_X86_64 && defined(__ELF__) && __has_attribute(model)

You should check `defined(__has_attribute)` before using it [1], the
preprocessor won't short circuit. See also __has_feature in
libavutil/aarch64/asm.S.

> +#    define attribute_mcmodel_small __attribute__(model("small"))
> +#else
> +#    define attribute_mcmodel_small
> +#endif
> +
>  #endif /* AVUTIL_ATTRIBUTES_INTERNAL_H */
> --

[1]: https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute


More information about the ffmpeg-devel mailing list