[FFmpeg-devel] [PATCH 2/2] libavcodec: Set hidden visibility on global symbols accessed from x86_64 assembly

Thomas Guillem thomas at gllm.fr
Wed Jul 27 15:00:00 EEST 2022


ld: error: relocation R_X86_64_PC32 cannot be used against symbol 'ff_h264_cabac_tables'; recompile with -fPIC
>>> defined in /home/tom/work/git/vlc-android/vlc/contrib/x86_64-linux-android/lib/libavcodec.a(cabac.o)
>>> referenced by cabac.h:187 (libavcodec/x86/cabac.h:187)
>>>               h264_cabac.o:(ff_h264_decode_mb_cabac) in archive /home/tom/work/git/vlc-android/vlc/contrib/x86_64-linux-android/lib/libavcodec.a
 libavcodec/ac3dsp.h        |  3 +-
 libavcodec/cabac.h         |  3 +-
 libavcodec/h263dsp.h       |  3 +-
 libavcodec/x86/constants.h | 81 +++++++++++++++++++-------------------
 libavutil/mem.h            |  6 +--
 libswscale/x86/rgb2rgb.c   |  2 +-
 6 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h
index a23b11526e..f8c03a7c23 100644
--- a/libavcodec/ac3dsp.h
+++ b/libavcodec/ac3dsp.h
@@ -23,12 +23,13 @@
 #include <stdint.h>
+#include "libavutil/internal.h"
  * Number of mantissa bits written for each bap value.
  * bap values with fractional bits are set to 0 and are calculated separately.
-extern const uint16_t ff_ac3_bap_bits[16];
+extern const uint16_t attribute_visibility_hidden ff_ac3_bap_bits[16];
 typedef struct AC3DSPContext {
diff --git a/libavcodec/cabac.h b/libavcodec/cabac.h
index 38d06b2842..356aa368d0 100644
--- a/libavcodec/cabac.h
+++ b/libavcodec/cabac.h
@@ -28,8 +28,9 @@
 #include <stdint.h>
+#include "libavutil/internal.h"
-extern const uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63];
+extern const uint8_t attribute_visibility_hidden ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63];
 #define H264_NORM_SHIFT_OFFSET 0
 #define H264_LPS_RANGE_OFFSET 512
 #define H264_MLPS_STATE_OFFSET 1024
diff --git a/libavcodec/h263dsp.h b/libavcodec/h263dsp.h
index 1abea3ca8c..514a148fb1 100644
--- a/libavcodec/h263dsp.h
+++ b/libavcodec/h263dsp.h
@@ -20,8 +20,9 @@
 #define AVCODEC_H263DSP_H
 #include <stdint.h>
+#include "libavutil/internal.h"
-extern const uint8_t ff_h263_loop_filter_strength[32];
+extern const uint8_t attribute_visibility_hidden ff_h263_loop_filter_strength[32];
 typedef struct H263DSPContext {
     void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale);
diff --git a/libavcodec/x86/constants.h b/libavcodec/x86/constants.h
index 85da38b7b9..c84b0d4324 100644
--- a/libavcodec/x86/constants.h
+++ b/libavcodec/x86/constants.h
@@ -22,51 +22,52 @@
 #include <stdint.h>
+#include "libavutil/internal.h"
 #include "libavutil/x86/asm.h"
-extern const ymm_reg  ff_pw_1;
-extern const ymm_reg  ff_pw_2;
-extern const xmm_reg  ff_pw_3;
-extern const ymm_reg  ff_pw_4;
-extern const xmm_reg  ff_pw_5;
-extern const xmm_reg  ff_pw_8;
-extern const xmm_reg  ff_pw_9;
-extern const uint64_t ff_pw_15;
-extern const xmm_reg  ff_pw_16;
-extern const xmm_reg  ff_pw_18;
-extern const xmm_reg  ff_pw_20;
-extern const xmm_reg  ff_pw_32;
-extern const uint64_t ff_pw_42;
-extern const uint64_t ff_pw_53;
-extern const xmm_reg  ff_pw_64;
-extern const uint64_t ff_pw_96;
-extern const uint64_t ff_pw_128;
-extern const ymm_reg  ff_pw_255;
-extern const ymm_reg  ff_pw_256;
-extern const ymm_reg  ff_pw_512;
-extern const ymm_reg  ff_pw_1023;
-extern const ymm_reg  ff_pw_1024;
-extern const ymm_reg  ff_pw_2048;
-extern const ymm_reg  ff_pw_4095;
-extern const ymm_reg  ff_pw_4096;
-extern const ymm_reg  ff_pw_8192;
-extern const ymm_reg  ff_pw_m1;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_1;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_2;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_3;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_4;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_5;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_8;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_9;
+extern const uint64_t attribute_visibility_hidden ff_pw_15;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_16;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_18;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_20;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_32;
+extern const uint64_t attribute_visibility_hidden ff_pw_42;
+extern const uint64_t attribute_visibility_hidden ff_pw_53;
+extern const xmm_reg attribute_visibility_hidden  ff_pw_64;
+extern const uint64_t attribute_visibility_hidden ff_pw_96;
+extern const uint64_t attribute_visibility_hidden ff_pw_128;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_255;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_256;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_512;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_1023;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_1024;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_2048;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_4095;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_4096;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_8192;
+extern const ymm_reg attribute_visibility_hidden  ff_pw_m1;
-extern const ymm_reg  ff_pb_0;
-extern const ymm_reg  ff_pb_1;
-extern const ymm_reg  ff_pb_2;
-extern const ymm_reg  ff_pb_3;
-extern const ymm_reg  ff_pb_80;
-extern const ymm_reg  ff_pb_FE;
-extern const uint64_t ff_pb_FC;
+extern const ymm_reg attribute_visibility_hidden  ff_pb_0;
+extern const ymm_reg attribute_visibility_hidden  ff_pb_1;
+extern const ymm_reg attribute_visibility_hidden  ff_pb_2;
+extern const ymm_reg attribute_visibility_hidden  ff_pb_3;
+extern const ymm_reg attribute_visibility_hidden  ff_pb_80;
+extern const ymm_reg attribute_visibility_hidden  ff_pb_FE;
+extern const uint64_t attribute_visibility_hidden ff_pb_FC;
-extern const xmm_reg  ff_ps_neg;
+extern const xmm_reg attribute_visibility_hidden  ff_ps_neg;
-extern const ymm_reg  ff_pd_1;
-extern const ymm_reg  ff_pd_16;
-extern const ymm_reg  ff_pd_32;
-extern const ymm_reg  ff_pd_8192;
-extern const ymm_reg  ff_pd_65535;
+extern const ymm_reg attribute_visibility_hidden  ff_pd_1;
+extern const ymm_reg attribute_visibility_hidden  ff_pd_16;
+extern const ymm_reg attribute_visibility_hidden  ff_pd_32;
+extern const ymm_reg attribute_visibility_hidden  ff_pd_8192;
+extern const ymm_reg attribute_visibility_hidden  ff_pd_65535;
 #endif /* AVCODEC_X86_CONSTANTS_H */
diff --git a/libavutil/mem.h b/libavutil/mem.h
index d91174196c..88fea4bfe7 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -113,9 +113,9 @@
     #define DECLARE_ASM_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
-    #define DECLARE_ASM_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
+    #define DECLARE_ALIGNED(n,t,v)      attribute_visibility_hidden t __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_ALIGNED(n,t,v)  attribute_visibility_hidden t av_used __attribute__ ((aligned (n))) v
+    #define DECLARE_ASM_CONST(n,t,v)    attribute_visibility_hidden static const t av_used __attribute__ ((aligned (n))) v
 #elif defined(_MSC_VER)
     #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
     #define DECLARE_ASM_ALIGNED(n,t,v)  __declspec(align(n)) t v
diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c
index b325e5dbd5..100f608d04 100644
--- a/libswscale/x86/rgb2rgb.c
+++ b/libswscale/x86/rgb2rgb.c
@@ -70,7 +70,7 @@ DECLARE_ASM_CONST(8, uint64_t, mul15_hi)     = 0x0210021002100210ULL;
 DECLARE_ASM_CONST(8, uint64_t, mul16_mid)    = 0x2080208020802080ULL;
 DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset);
-DECLARE_ALIGNED(8, extern const uint64_t, ff_w1111);
+attribute_visibility_hidden DECLARE_ALIGNED(8, extern const uint64_t, ff_w1111);
 DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2UVOffset);
 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))

More information about the ffmpeg-devel mailing list