[FFmpeg-devel] Visibility implementation

Uoti Urpala uoti.urpala
Wed Jul 30 17:24:11 CEST 2008


On Wed, 2008-07-30 at 15:40 +0100, M?ns Rullg?rd wrote:
> Uoti Urpala wrote:
> > On Wed, 2008-07-30 at 08:16 +0200, matthieu castet wrote:
> >> Did you see any code change with your attribute patch ?
> >
> > Yes, if compiling with -fPIC.
> 
> On which architecture?  How did it compare to vanilla code without -fPIC?

I think it should change the resulting code on any architecture, but
exactly how differs.

On AMD64 hidden visibility should make most code identical to the
version without -fPIC; as accesses are PC-relative anyway using -fPIC
adds no indirection overhead when you know that the symbol will be in
the same library, at a constant offset from the current position.

On x86 -fPIC will still add overhead as there are no PC-relative
addressing modes and it reserves one of the few registers. Hidden
visibility does reduce the amount of indirection required however.

Here's an example of gcc-4.3 output with and without hidden visibility.
Program:
-----
void g(int i);
extern int ii;
void f(int a) { g(a + ii); }
-----

x86, no -fPIC:
	movl	4(%esp), %eax
	addl	ii, %eax
	movl	%eax, 4(%esp)
	jmp	g

x86, -fPIC with g and ii marked hidden:
	call	__i686.get_pc_thunk.cx
	addl	$_GLOBAL_OFFSET_TABLE_, %ecx
	movl	4(%esp), %eax
	addl	ii at GOTOFF(%ecx), %eax
	movl	%eax, 4(%esp)
	jmp	g

x86, -fPIC without visibility:
	pushl	%ebx
	call	__i686.get_pc_thunk.bx
	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
	subl	$8, %esp
	movl	16(%esp), %eax
	movl	ii at GOT(%ebx), %edx
	addl	(%edx), %eax
	movl	%eax, (%esp)
	call	g at PLT
	addl	$8, %esp
	popl	%ebx
	ret

AMD64, -fPIC with g and ii marked hidden: (same as without -fPIC)
	addl	ii(%rip), %edi
	jmp	g

AMD64, -fPIC without visibility:
	movq	ii at GOTPCREL(%rip), %rax
	addl	(%rax), %edi
	jmp	g at PLT






More information about the ffmpeg-devel mailing list