[FFmpeg-devel] [PATCH 1/2] libavutil: Add av_visibility_hidden for setting hidden symbol visibility

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Jul 11 17:26:49 EEST 2022


Henrik Gramner:
> On Mon, Jul 11, 2022 at 11:19 AM Martin Storsjö <martin at martin.st> wrote:
>> +#if (AV_GCC_VERSION_AT_LEAST(4,0) || defined(__clang__)) && (defined(__ELF__) || defined(__MACH__))
>> +#    define av_visibility_hidden __attribute__((visibility("hidden")))
>> +#else
>> +#    define av_visibility_hidden
>> +#endif
> 
> The usual approach is to compile with -fvisibility=hidden and
> explicitly flag exported API symbols.
> 
> Is there a reason for doing this the other way around?

-fvisibility=hidden only affects the visibility of symbols defined in
the currently compiled translation unit. It does not allow the compiler
to make assumptions about external declarations that are used in this
translation unit (in other words, it has to presume the worst: That it
comes from a different DSO). E.g. this is ff_rdft_end on 32bit x86 if
ff_fft_end is declared with an explicit hidden attribute:

000000bb <ff_rdft_end>:

  bb:	83 44 24 04 18       	addl   $0x18,0x4(%esp)

  c0:	e9 fc ff ff ff       	jmp    c1 <ff_rdft_end+0x6>

			c1: R_386_PC32	ff_fft_end


And this is the same function if one uses -fvisibility=hidden instead of
the attribute:

000000bb <ff_rdft_end>:

  bb:	53                   	push   %ebx

  bc:	e8 fc ff ff ff       	call   bd <ff_rdft_end+0x2>

			bd: R_386_PC32	__x86.get_pc_thunk.bx

  c1:	81 c3 02 00 00 00    	add    $0x2,%ebx

			c3: R_386_GOTPC	_GLOBAL_OFFSET_TABLE_

  c7:	83 ec 14             	sub    $0x14,%esp

  ca:	8b 44 24 1c          	mov    0x1c(%esp),%eax

  ce:	83 c0 18             	add    $0x18,%eax

  d1:	50                   	push   %eax

  d2:	e8 fc ff ff ff       	call   d3 <ff_rdft_end+0x18>

			d3: R_386_PLT32	ff_fft_end

  d7:	83 c4 18             	add    $0x18,%esp

  da:	5b                   	pop    %ebx

  db:	c3                   	ret


The code is the same as if one had not used -fvisibility=hidden at all.

Of course, adding the attribute to every function/object is way too much
effort; that's why the pragma exists.

- Andreas


More information about the ffmpeg-devel mailing list