diff mbox series

[FFmpeg-devel,v2] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__

Message ID 20200822053654.2653426-1-maskray@google.com
State New
Headers show
Series [FFmpeg-devel,v2] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__ | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Fangrui Song Aug. 22, 2020, 5:36 a.m. UTC
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 <maskray@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 mbox series

Patch

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