From: Michael Niedermayer via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Michael Niedermayer <michael@niedermayer.cc>
Subject: [FFmpeg-devel] Re: [FFFjo] [FFmpeg/FFmpeg] -fshort-enum breaks ABI compatibility and enum/int pointer conversions (Issue #21289)
Date: Tue, 30 Dec 2025 21:44:09 +0100
Message-ID: <aVQ5mefYSYfFef2I@neo> (raw)
In-Reply-To: <tencent_724FCBD5632726B8DB9644CD5FA0024DB107@qq.com>
[-- Attachment #1.1: Type: text/plain, Size: 4270 bytes --]
Hi Zhao
On Tue, Dec 30, 2025 at 12:46:24AM +0800, Zhao Zhili via ffmpeg-devel wrote:
>
>
> > On Dec 24, 2025, at 11:30, nyh163925 <code@ffmpeg.org> wrote:
> >
> >
> > Hello FFmpeg community, I am from Xiaomi Vela, and we have built the Vela multimedia system using FFmpeg. Thank you for the invaluable work you do—FFmpeg is the cornerstone of many of our modules.
> >
> > ISSUE: -fshort-enum ABI problem
> >
> > In the process of application, we found that some embedded platforms (such as ARM Cortex-m) have enabled -fshort-enum optimization by default in their compilers, which leads to ABI in the cross passing of some enum * and int * in FFmpeg. For example, when passing enum AVSampleFormat * as int * in ff_det_common_fformats_for_list2(), it will cause check_fformat() error.
> >
> > Context
> >
> > C language Standard undefined behavior:
> > The underlying type and size of an enum are implementation-defined. Many toolchains can use the smallest integer type that fits the values (e.g., with -fshort-enums), so sizeof(enum) can be less than sizeof(int), and alignment may differ.
> > Casting enum* to int* and accessing through the int pointer runs into strict-aliasing and effective-type rules; it is not portable and may be undefined.
> >
> > FFmpeg defaults to the equality of sizeof(enum) and sizeof(int):
> > We have seen code patterns that implicitly assume “enum is a 4-byte int” and interchange enum* with int*. Typical examples include:
> >
> > BufferSinkContext {
> > enum AVSampleFormat *sample_formats
> > ...
> > }
> >
> > int ff_set_common_formats_from_list2(const AVFilterContext *ctx,
> > AVFilterFormatsConfig **cfg_in,
> > AVFilterFormatsConfig **cfg_out,
> > const int *fmts)
> >
> > static int asink_query_formats(const AVFilterContext *ctx,
> > AVFilterFormatsConfig **cfg_in,
> > AVFilterFormatsConfig **cfg_out)
> > {
> > const BufferSinkContext *buf = ctx->priv;
> > if (buf->nb_sample_formats) {
> > ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->sample_formats);
> > if (ret < 0)
> > return ret;
> > }
> > ...
> > }
> > We are facing a conflict dilemma:
> > We found that many ARM-based embedded compilers and third-party libraries default to -fshort-enums, which conflicts with FFmpeg's ABI (compiled with -fno-short-enums). However, if we enable the '-fshort-enums' in FFMPEG, the above ABI causes format negotiation and matching failures in our modules.
> > Proposed paths forward
> >
> > Change “assume 4 bytes” to “force 4 bytes”.
> > Adopt a fixed 32-bit representation for enums at API/ABI boundaries
> > vulkan for example, uses *_MAX_ENUM = 0x7FFFFFFF as last value for each enum, to avoid any and all problems with size
> >
> > Stop assuming sizeof(enum) == 4.
> > Gradually fix code to avoid enum* ↔ int* aliasing; use value-level conversions or memcpy where needed.
> > Pros: preserves the size benefits where compilers choose smaller enums.
> > Cons: requires auditing and incremental code changes.
> >
> > We’re seeking the community’s guidance on which direction is preferable for FFmpeg: Should we standardize on a fixed 32-bit enum representation for ABI stability? Or should we remove the “enum == int” assumption and accept smaller enums, with code cleanup to avoid aliasing and stride errors?
> > We’re ready to contribute patches in the direction the project prefers and to align with FFmpeg’s coding guidelines. Thanks again for your time and feedback.
> >
>
> I think the issue is common and better be discussed on the mailing list. It's a big decision.
The way we mix enums and int currently is not good, so iam in favor of some
solution.
Which solution, i dont have a strong oppinion about.
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Homeopathy is like voting while filling the ballot out with transparent ink.
Sometimes the outcome one wanted occurs. Rarely its worse than filling out
a ballot properly.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 163 bytes --]
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
next prev parent reply other threads:[~2025-12-30 20:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <FFmpeg/FFmpeg/issues/21289@code.ffmpeg.org>
[not found] ` <reply-AIBQIAAKCMFAAEA4TQPGZGSRJPMJVXS6SIZSC3WSDYFAAGYHAQAPZVSZEO7AGBQAAEHAUAALAEBQMAAAAUCAB7QOOA@code.ffmpeg.org>
2025-12-29 16:46 ` Zhao Zhili via ffmpeg-devel
2025-12-30 20:44 ` Michael Niedermayer via ffmpeg-devel [this message]
2025-12-31 2:31 ` Zhao Zhili via ffmpeg-devel
2025-12-31 14:09 ` Michael Niedermayer via ffmpeg-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aVQ5mefYSYfFef2I@neo \
--to=ffmpeg-devel@ffmpeg.org \
--cc=michael@niedermayer.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git