[FFmpeg-devel] [PATCH] Fix missing used attribute for inline assembly variables

Thomas Köppe tkoeppe at google.com
Mon Oct 30 22:31:50 EET 2017


Please find below the actual patch:
==============

Variables used in inline assembly need to be marked with attribute((used)).
Static constants already were, via the define of DECLARE_ASM_CONST.
But DECLARE_ALIGNED does not add this attribute, and some of the variables
defined with it are const only used in inline assembly, and therefore
appeared dead.

This change makes FFMPEG linkable with Clang's ThinLTO.
---
 libavcodec/cabac.c | 2 +-
 libavutil/mem.h    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
index dd2b057c6d..7321b48901 100644
--- a/libavcodec/cabac.c
+++ b/libavcodec/cabac.c
@@ -32,7 +32,7 @@
 #include "cabac.h"
 #include "cabac_functions.h"

-const uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63] = {
+DECLARE_ALIGNED(1, const uint8_t, ff_h264_cabac_tables)[512 + 4*2*64 +
4*64 + 63] = {
     9,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5,
     4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
     3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 527cd03191..c4ee11af58 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -101,7 +101,7 @@
     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned
(FFMIN(n, 16)))) v
     #define DECLARE_ASM_CONST(n,t,v)    static const t av_used
__attribute__ ((aligned (FFMIN(n, 16)))) v
 #elif defined(__GNUC__) || defined(__clang__)
-    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
+    #define DECLARE_ALIGNED(n,t,v)      t av_used __attribute__ ((aligned
(n))) v
     #define DECLARE_ASM_CONST(n,t,v)    static const t av_used
__attribute__ ((aligned (n))) v
 #elif defined(_MSC_VER)
     #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
-- 
2.15.0.rc2.357.g7e34df9404-goog


On 30 October 2017 at 20:25, Thomas Köppe <tkoeppe at google.com> wrote:

> (I must have forgotten to rebase first!)
>
> On 30 October 2017 at 20:14, Thomas Köppe <tkoeppe at google.com> wrote:
>
>> It should be under __GNUC__ -- something went wrong with the patch! I'll
>> make a new one. Sorry about that!
>>
>> On 30 October 2017 at 19:31, James Almer <jamrial at gmail.com> wrote:
>>
>>> On 10/30/2017 4:17 PM, Thomas Köppe wrote:
>>> > Variables used in inline assembly need to be marked with
>>> attribute((used)).
>>> > Static constants already were, via the define of DECLARE_ASM_CONST.
>>> > But DECLARE_ALIGNED does not add this attribute, and some of the
>>> variables
>>> > defined with it are const only used in inline assembly, and therefore
>>> > appeared dead.
>>> >
>>> > This change makes FFMPEG linkable with Clang's ThinLTO.
>>> >
>>> > ---
>>> >  libavcodec/cabac.c | 2 +-
>>> >  libavutil/mem.h    | 2 +-
>>> >  2 files changed, 2 insertions(+), 2 deletions(-)
>>> >
>>> > diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
>>> > index dd2b057c6d..7321b48901 100644
>>> > --- a/libavcodec/cabac.c
>>> > +++ b/libavcodec/cabac.c
>>> > @@ -32,7 +32,7 @@
>>> >  #include "cabac.h"
>>> >  #include "cabac_functions.h"
>>> >
>>> > -const uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63] = {
>>> > +DECLARE_ALIGNED(1, const uint8_t, ff_h264_cabac_tables)[512 + 4*2*64 +
>>> > 4*64 + 63] = {
>>> >      9,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5,
>>> >      4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
>>> >      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
>>> > diff --git a/libavutil/mem.h b/libavutil/mem.h
>>> > index 527cd03191..db06e109be 100644
>>> > --- a/libavutil/mem.h
>>> > +++ b/libavutil/mem.h
>>> > @@ -98,7 +98,7 @@
>>> >          AV_PRAGMA(DATA_ALIGN(v,n))                      \
>>> >          static const t __attribute__((aligned(n))) v
>>> >  #elif defined(__DJGPP__)
>>>
>>> Is your intention to change the DJGPP path, or the gnuc/clang path?
>>>
>>> > -    #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned
>>> > (FFMIN(n, 16)))) v
>>> > +    #define DECLARE_ALIGNED(n,t,v)      t av_used __attribute__
>>> ((aligned
>>> > (FFMIN(n, 16)))) v
>>> >      #define DECLARE_ASM_CONST(n,t,v)    static const t av_used
>>> > __attribute__ ((aligned (FFMIN(n, 16)))) v
>>> >  #elif defined(__GNUC__) || defined(__clang__)
>>> >      #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned
>>> (n))) v
>>> >
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>
>>
>


More information about the ffmpeg-devel mailing list