From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 7ED3F4DB11 for ; Tue, 30 Dec 2025 20:44:51 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'h8fpHbPNFTiG5h4PFM6ngQDMOUgrzQa90N2qcSoFvHk=', expected b'VJpbJ7+Zua9SMK+JVW+XQmlAzJZWhQ3lOqeCkpRHy1w=')) header.d=niedermayer.cc header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1767127476; h=date : to : message-id : references : mime-version : in-reply-to : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : from; bh=D5xSNEMP6bYdarg9xSHunW1V3gi4YsVsmOoDL60ULXk=; b=VeAo72MRBi457KMwC3PglqLw6da6LIWO0nxTDgC7hbCkNsXPGb7o9Oc7UiPds+dTs4TUL qCkgWjMKtTX1cjphZC8yw7ecTB+RNVudQ+GnUN3OYf7ARVdfC0KCH8LiCK7ZZjN4f0RtVfc EXE1EHbsVN3nMUqJc1T5hULnKEYCwBHFm9vFkiG8PtfHjHyHYJiIWSy6gxlF5OaHrR08gJ4 hWRa5PnXeZkTh0zh1jSUhNNZsDzftw+oI5FNHKVvV5Q+VRlGVbwScVw85C540kl2tw+jmV9 Pn64ZdFztcHeoK7miYNhjk0t3d5F0ODhtLXidWLDaSBcQ1Ml/1Z8yHtatT1A== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id CD62F690C69; Tue, 30 Dec 2025 22:44:36 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1767127462; b=mn9i8/qg3WOmdw+8i3q3eRtr0Jer4RiB33aXS+Ovr/kVVlmCEYBtMinVvdbOaEz8Hd1Eh amfB9E3nIQW58zwAt7nbnZ/qt61JivPLwPgtL71SY8DEgcaF/tzWqr3Y+ahfgidxny38PCW V2bDh1PRX7saOFM83zkwyZCZJuVrHzbCOclAyL7008ZqrJBsHyXv9St8CFObCJKRVWYuq0H aVRl/h9hknpb7FaiE41NjrBhHBfWUVFbFnZWsSbSnIkssF/huL1BNHU+Ht7RbTbyvZ/K2Bb 1quJvggEXXOBr97/RuiQMlQ/EUTyFg9OWl3V/6K9lNjt7hAIahRDlO72y3sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1767127462; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=h8fpHbPNFTiG5h4PFM6ngQDMOUgrzQa90N2qcSoFvHk=; b=QvVfP+wUbJ+AfGUJgR0uqs+LNDKBAUphr6G3gg+wrdyYUu3hsagjsh5ccg+rpWSxH1+mg a+qeq5abPbZu4fL8p3cQxhO+35OJ4ZXifhYeIAfvKMit/NU4Q4d9aQ3iv9ZRzDYJpSbra75 F3CsPA/c8hA2lkx47YFbLigpuvMJiPqG7h2jZ7eyyZqF/KJ/8C8ZEGD3cPEQclOvESfWuL4 SrDwH94xq6jXS0J2VjEMEngrd/l/7e+wn1sww/RMTkRThhiezb6r2vxti6sFC42HkPm8SxL soo/YXZxfd+OPmKQwOERpvlmpcrg6o5rgaV7+hcoQ2DgAImivbIvf77keJzw== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=niedermayer.cc; arc=none; dmarc=none Authentication-Results: ffmpeg.org; dkim=pass header.d=niedermayer.cc; arc=none (Message is not ARC signed); dmarc=none Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id DD10B6909E5 for ; Tue, 30 Dec 2025 22:44:10 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 15F8344524 for ; Tue, 30 Dec 2025 20:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1767127450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VJpbJ7+Zua9SMK+JVW+XQmlAzJZWhQ3lOqeCkpRHy1w=; b=fRDffaZwT/4qai3MXtFHVE6CdgWEm7XMAY2wkWHQaV2J8ehfv0UI3WHlaYQx7wwG/KjEFj YAbS5g1Un3K0xAnx1zbyGDIB0Wf30Sv9U42oeMf7xp2zDDZPcFWKRlfM0DFr7RT+7Wt/Iq mw1jPT3x6Tgxu58o0FWIlLoKZgWDKj9r2N6oKZcrYJdM7OE/1lI+h9Iw26Q7ffH0xQmmkL m1PKb7bSy20curTLWy0MhglBZL7Cfq5jdiLQUjtjWMRPDWPZLN6GTmTnC87T+lIeUrnc91 pIWK6iaZuSFfxxcDIEDn3QrlXqYQ5tG4xFbrfMGabAhyGsZYc1NH3UnN8HXRHQ== Date: Tue, 30 Dec 2025 21:44:09 +0100 To: FFmpeg development discussions and patches Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-GND-Sasl: michael@niedermayer.cc X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdekuddtudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrhhlucfvnfffucdludehmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddtjeenucfhrhhomhepofhitghhrggvlhcupfhivgguvghrmhgrhigvrhcuoehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgeqnecuggftrfgrthhtvghrnhepleekgefgffeiudefjeeuffejudehtddtudeltdehveevvedtieeulefhtdeutdeknecukfhppeeguddrieeirdeiiedrhedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieeirdehtddphhgvlhhopehlohgtrghlhhhoshhtpdhmrghilhhfrhhomhepmhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtpdhqihgupeduhefhkeefgeeghedvgedpmhhouggvpehsmhhtphhouhhtpdhnsggprhgtphhtthhopedupdhrtghpthhtohepfhhfmhhpvghgqdguvghvvghlsehffhhmphgvghdrohhrgh Message-ID-Hash: FQIHARD4TODDHBKJHJXM24ISFX6RVEIU X-Message-ID-Hash: FQIHARD4TODDHBKJHJXM24ISFX6RVEIU X-MailFrom: SRS0=zUKs=7E=niedermayer.cc=michael@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] Re: [FFFjo] [FFmpeg/FFmpeg] -fshort-enum breaks ABI compatibility and enum/int pointer conversions (Issue #21289) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michael Niedermayer via ffmpeg-devel Cc: Michael Niedermayer Content-Type: multipart/mixed; boundary="===============7938018316672403528==" Archived-At: List-Archive: List-Post: --===============7938018316672403528== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vcodkZz8emJPLK0C" Content-Disposition: inline --vcodkZz8emJPLK0C Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Zhao On Tue, Dec 30, 2025 at 12:46:24AM +0800, Zhao Zhili via ffmpeg-devel wrote: >=20 >=20 > > On Dec 24, 2025, at 11:30, nyh163925 wrote: > >=20 > >=20 > > Hello FFmpeg community, I am from Xiaomi Vela, and we have built the Ve= la multimedia system using FFmpeg. Thank you for the invaluable work you do= =E2=80=94FFmpeg is the cornerstone of many of our modules. > >=20 > > ISSUE: -fshort-enum ABI problem > >=20 > > In the process of application, we found that some embedded platforms (s= uch as ARM Cortex-m) have enabled -fshort-enum optimization by default in t= heir compilers, which leads to ABI in the cross passing of some enum * and = int * in FFmpeg. For example, when passing enum AVSampleFormat * as int * i= n ff_det_common_fformats_for_list2(), it will cause check_fformat() error. > >=20 > > Context > >=20 > > C language Standard undefined behavior: > > The underlying type and size of an enum are implementation-defined. Man= y 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 alig= nment may differ. > > Casting enum* to int* and accessing through the int pointer runs into s= trict-aliasing and effective-type rules; it is not portable and may be unde= fined. > >=20 > > FFmpeg defaults to the equality of sizeof(enum) and sizeof(int): > > We have seen code patterns that implicitly assume =E2=80=9Cenum is a 4-= byte int=E2=80=9D and interchange enum* with int*. Typical examples include: > >=20 > > BufferSinkContext { > > enum AVSampleFormat *sample_formats > > ... > > } > >=20 > > int ff_set_common_formats_from_list2(const AVFilterContext *ctx, > > AVFilterFormatsConfig **cfg_in, > > AVFilterFormatsConfig **cfg_out, > > const int *fmts) > >=20 > > static int asink_query_formats(const AVFilterContext *ctx, > > AVFilterFormatsConfig **cfg_in, > > AVFilterFormatsConfig **cfg_out) > > { > > const BufferSinkContext *buf =3D ctx->priv; > > if (buf->nb_sample_formats) { > > ret =3D ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, b= uf->sample_formats); > > if (ret < 0) > > return ret; > > } > > ... > > } > > We are facing a conflict dilemma: > > We found that many ARM-based embedded compilers and third-party librari= es default to -fshort-enums, which conflicts with FFmpeg's ABI (compiled wi= th -fno-short-enums). However, if we enable the '-fshort-enums' in FFMPEG, = the above ABI causes format negotiation and matching failures in our module= s. > > Proposed paths forward > >=20 > > Change =E2=80=9Cassume 4 bytes=E2=80=9D to =E2=80=9Cforce 4 bytes=E2=80= =9D. > > Adopt a fixed 32-bit representation for enums at API/ABI boundaries > > vulkan for example, uses *_MAX_ENUM =3D 0x7FFFFFFF as last value for ea= ch enum, to avoid any and all problems with size > >=20 > > Stop assuming sizeof(enum) =3D=3D 4. > > Gradually fix code to avoid enum* =E2=86=94 int* aliasing; use value-le= vel conversions or memcpy where needed. > > Pros: preserves the size benefits where compilers choose smaller enums. > > Cons: requires auditing and incremental code changes. > >=20 > > We=E2=80=99re seeking the community=E2=80=99s guidance on which directi= on is preferable for FFmpeg: Should we standardize on a fixed 32-bit enum r= epresentation for ABI stability? Or should we remove the =E2=80=9Cenum =3D= =3D int=E2=80=9D assumption and accept smaller enums, with code cleanup to = avoid aliasing and stride errors? > > We=E2=80=99re ready to contribute patches in the direction the project = prefers and to align with FFmpeg=E2=80=99s coding guidelines. Thanks again = for your time and feedback. > >=20 >=20 > 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 [...] --=20 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. --vcodkZz8emJPLK0C Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaVQ5lQAKCRBhHseHBAsP q+bQAJ4ynONC5a0JfR8VkU1SWV0NeXhoWwCfRtSSEG9Px5G6zRZlBFhZ9w6GzHw= =QYA5 -----END PGP SIGNATURE----- --vcodkZz8emJPLK0C-- --===============7938018316672403528== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org --===============7938018316672403528==--