Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #5703

Re: efficient function call

From Edek <edek.pieITAKNIECZYTAM@gmail.com>
Newsgroups comp.lang.c++
Subject Re: efficient function call
Date 2011-05-27 16:39 +0200
Organization ATMAN - ATM S.A.
Message-ID <4DDFB789.2080107@gmail.com> (permalink)
References (2 earlier) <irim81$v8d$1@dont-email.me> <579f855a-ff3b-4e65-a977-9773fb58a07c@e35g2000yqc.googlegroups.com> <irleec$po3$1@dont-email.me> <irllnn$hdq$1@node2.news.atman.pl> <slrnitvaoc.gtj.grahn+nntp@frailea.sa.invalid>

Show all headers | View raw


> So you're saying a file
>
>    static int foo() { return 42; }
>    int bar() { return 69+foo(); }
>
> will never inline foo() if I use g++ with the -fpic option?
> That sounds wrong -- and I cannot repeat it on my system.
>
> tuva:/tmp>  g++ -W -Wall -ansi -fpic -O3 -c foo.cc
> tuva:/tmp>  nm -C foo.o
> 00000000 V DW.ref.__gxx_personality_v0
> 00000000 T bar()
>           U __gxx_personality_v0
>

To check that I am not lying to you:
------------------------------------------------------
int answer () { return 42; };

int bar () { return 69|answer(); }
-------------------------------------------------
gcc -O3 -S test.cpp

	.type	_Z3barv, @function
_Z3barv:
.LFB1:
	.cfi_startproc
	movl	$111, %eax
	ret
------------------------------------------------------
gcc -O3 -S -fPIC test.cpp

	.type	_Z3barv, @function
_Z3barv:
.LFB1:
	.cfi_startproc
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	call	_Z6answerv@PLT
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	orl	$69, %eax
	ret

And the working thing:
-------------------------------------------------------------------------
  [devel@marvin preload]$ LD_LIBRARY_PATH=. ./main
bar gives111
  [devel@marvin preload]$ LD_LIBRARY_PATH=. LD_PRELOAD=./mylib.so ./main
bar gives1093
  [devel@marvin preload]$
----------------------------------------------------------------------

where main is

#include <iostream>

extern int bar();

int main () {
     std::cout << "bar gives" << bar () <<std::endl;
}

Edek

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

efficient function call hamze <hamze60@gmail.com> - 2011-05-24 05:52 -0700
  Re: efficient function call Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-24 09:52 -0400
    Re: efficient function call yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-05-24 18:28 +0000
    Re: efficient function call hamze <hamze60@gmail.com> - 2011-05-24 11:49 -0700
      Re: efficient function call Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-24 15:07 -0400
        Re: efficient function call hamze <hamze60@gmail.com> - 2011-05-25 00:37 -0700
          Re: efficient function call yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-05-25 10:38 +0000
            Re: efficient function call hamze <hamze60@gmail.com> - 2011-05-25 11:08 -0700
              Re: efficient function call Dombo <dombo@disposable.invalid> - 2011-05-25 21:38 +0200
              Re: efficient function call yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-05-26 11:44 +0000
                Re: efficient function call Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-26 15:53 +0200
                Re: efficient function call yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-05-27 08:31 +0000
                Re: efficient function call Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-27 13:45 +0000
                Re: efficient function call Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-27 16:17 +0200
                Re: efficient function call Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-27 22:38 +0000
                Re: efficient function call Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-27 16:39 +0200
      Re: efficient function call Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-24 14:30 -0700
        Re: efficient function call hamze <hamze60@gmail.com> - 2011-05-25 00:39 -0700
      Re: efficient function call hamze <hamze60@gmail.com> - 2011-05-25 00:20 -0700

csiph-web