From patchwork Sat Aug 22 05:36:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 21812 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EDD3F44AA23 for ; Sat, 22 Aug 2020 08:37:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D340068B5E0; Sat, 22 Aug 2020 08:37:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA45D68B55B for ; Sat, 22 Aug 2020 08:37:05 +0300 (EEST) Received: by mail-pg1-f201.google.com with SMTP id f18so2158052pgl.1 for ; Fri, 21 Aug 2020 22:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=yV63tahuKe+NbqfCq0zrqF0dhTyJNyjci94lAIoGNSc=; b=fAto4Kxw3ohUTQ9cOrh+CO132PZRP9nEn3v9HzjRBr8H/2QcbrL8aq7mmDi4gcUuzE aNjwgW+z0CsF733p/YgVnMP3nyxap+MhB9cYBxKVQT5RkryweLJZmP7dgjo+khcZhwB0 XfiHGbp8xeKEi1j6LJ8q2x9wI5qpSvF4ByZElw1IWAJhmycIUf7L6z6sT6qA6KyKmGod N6buUpWIbEh16vTGg4W8+KUMl+9z7zfklsn/8BX7cfHjGBNuEvVixCuHa9uIFDw7awjw qW44bsmOZ633BRiNlBPAozIZqRm77wFaqr3ox7xS2cpUvrBw+t6PCblsHzcJysd7JFUZ ybJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=yV63tahuKe+NbqfCq0zrqF0dhTyJNyjci94lAIoGNSc=; b=UGUiZcU+dHwuA+jEEsDpOoWMfHlkNk//lzwvH/pAbfofnX+bLQ+1xHXWPImSSRbiae +J1UlIzDmX8RJL98ah9w3avJ78oFrzrB+RpwApjx4S7TYmXZKfJlxKHRlQiVDL81GxUn lDadDwXbI9zEthWhUU2/jyVfhEdjHJFGOujvGEzOLoT1WDkQipDOgMFVel6JBQqo6CbM QsE+VM3WP6blIBrPyqkCIyw28E95emTpPVBJynMXtj6TRy2Py5F65n7E+sCOTFnGHQEY BRo7PeOpYMt6VzmU1WyQ/fCY+5O2HxjI8eaRfeQaWgv3I0DzErs/K3A/L/opENzfH4Hs NadQ== X-Gm-Message-State: AOAM532ARPlM4qrusiFxsjMemSHctHsu45vb1pQXlBseqGcJXcIBi8HI i10if4Hbi8elwcrX3uujAzn1YCG6kG9GJ0AnWGYDeOVSSk1oRaBrBKp2xZun3p9pBKa99Wmh7qg VBBzQ7tYhlmk3Frec94WTNbUhzdx4FTM+rEwcHFTuz188RLr1vRmm8J5ZBlRqe8sC4A== X-Google-Smtp-Source: ABdhPJyYhvZXYJIatk7hDhhy4AjypLWtJv4GuMucpfP3eLJFdn9FDHbnngTuOgzBC5+5hKKM4E3v+44qFGCV X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) (user=maskray job=sendgmr) by 2002:aa7:8e8d:: with SMTP id a13mr5222570pfr.250.1598074623354; Fri, 21 Aug 2020 22:37:03 -0700 (PDT) Date: Fri, 21 Aug 2020 22:36:54 -0700 Message-Id: <20200822053654.2653426-1-maskray@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog From: Fangrui Song To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__ X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Fangrui Song Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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