Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!news-2.dfn.de!news.dfn.de!news.uni-stuttgart.de!news.nask.pl!news.nask.org.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Edek Newsgroups: comp.lang.c++ Subject: Re: efficient function call Date: Fri, 27 May 2011 16:39:05 +0200 Organization: ATMAN - ATM S.A. Lines: 65 Message-ID: <4DDFB789.2080107@gmail.com> References: <5b9040f8-e35b-4cb0-95c8-1b89838f1da9@s14g2000vbi.googlegroups.com> <579f855a-ff3b-4e65-a977-9773fb58a07c@e35g2000yqc.googlegroups.com> NNTP-Posting-Host: 81.219.115.2 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: node2.news.atman.pl 1306506837 6501 81.219.115.2 (27 May 2011 14:33:57 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Fri, 27 May 2011 14:33:57 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Linux/3.1.0-15 Thunderbird/3.1.0 To: Jorgen Grahn In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:5703 > 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 extern int bar(); int main () { std::cout << "bar gives" << bar () <