Inline asm code assumes these DECLARE_ASM_ALIGNED declared global
constants are non-preemptive, e.g.

libavcodec/x86/cabac.h
        "lea    "MANGLE(ff_h264_cabac_tables)", %0      \n\t"

These constants are currently defined in C files with default
visibility. Such object files require either -Wl,-Bsymbolic or
-Wl,--version-script,libavcodec/libavcodec.ver to link into a shared
object. However, there are good reasons that the user wants to specify
neither option:

* -Bsymbolic is dangerous as it breaks C++ semantics about address
  uniqueness of inline functions, type_info, ...
* --version-script applies to all exported symbols and can thus affect
  program code. If the program code doesn't want all of its symbols to be
  marked local, it needs to define its own version script combining
  FFmpeg's version scripts. This is cumbersome.

If neither -Bsymbolic nor --version-script is specified, there will be
linker errors like:

    ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 
ff_h264_cabac_tables; recompile with -fPIC

It is better to express the intention explicitly and mark such global
constants hidden. This patch marks a large number of such constants
(accessible from assembly) hidden.

Signed-off-by: Fangrui Song <mask...@google.com>
---
Changes in v2:
* Rewrote description
* Used av_ prefixed av_visibility_hidden
* The patch is a re-send of 
http://ffmpeg.org/pipermail/ffmpeg-devel/2019-March/241054.html
---
 libavutil/mem.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02dd9..98a14b826b 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -100,6 +100,12 @@
  * @param v Name of the variable
  */
 
+#if defined(__GNUC__) && !(defined(_WIN32) || defined(__CYGWIN__))
+    #define av_visibility_hidden __attribute__ ((visibility ("hidden")))
+#else
+    #define av_visibility_hidden
+#endif
+
 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
     #define DECLARE_ASM_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
@@ -110,7 +116,7 @@
     #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_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned 
(n))) av_visibility_hidden 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.28.0.297.g1956fa8f8d-goog

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to