LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2009, 07:57 PM   #1
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Rep: Reputation: 51
How to get rid of __i686.get_pc_thunk.bx?


I tried to compile simple hello world program using such flags as -finline-functions, -finline-functions-called-once, but they don't seem to inline __i686.get_pc_thunk.bx. How can i force gcc do this?
 
Old 01-01-2010, 04:27 PM   #2
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Hey 10110111 ;-),

you can't force gcc to inline this "function", because it is added by the program linker (ld). The purpose of this thunk is to determine the IP (instruction pointer) value of the following instruction and it is usually used for position-independent code.

Though, if you have the following assembly snipped:

0x00 call <i686.get_pc_thunk.bx>
0x04 add $0x1191,%ebx

Then, after calling the thunk, the register ebx will contain the IP value 0x04. For the sake of completeness, this is how this thunk is implemented:

080483ca <__i686.get_pc_thunk.bx>:
80483ca: 8b 1c 24 mov (%esp),%ebx
80483cd: c3 ret


For the case you are interested in this position-independent code issue, please check this very good explanation: http://www.airs.com/blog/archives/41

- Andi -
 
Old 01-01-2010, 11:13 PM   #3
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Original Poster
Rep: Reputation: 51
Yes, i know how it is implemented. I came across this function while looking at disassembly. And just because i know this, i thought that it would be more efficient to replace function call with "mov (%esp),%ebx". It's just strange why linker can't optimize it this way...
 
Old 01-02-2010, 11:11 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by 10110111 View Post
i thought that it would be more efficient to replace function call with "mov (%esp),%ebx". It's just strange why linker can't optimize it this way...
That wouldn't work, the call instruction is needed to put the program counter on the stack.
 
Old 01-03-2010, 06:24 AM   #5
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Original Poster
Rep: Reputation: 51
Heh.. haven't thought about this

Still, a bit more efficient to inline:
;intel syntax
call next
next:
pop ebx


Though, as all this is being done by linker, i guess, linker can't change already existing code, so the result is a function...

Last edited by 10110111; 01-03-2010 at 06:43 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Rid Of Xp ihatewindows Linux - Software 1 01-24-2007 06:59 PM
Should I get rid of XP? NCC-1701&NCC-1701-D Linux - Newbie 12 06-13-2005 08:41 AM
where did it come from, and how do i get rid of it? scarryharry Slackware - Installation 2 10-08-2004 01:10 PM
What can I get rid of? NKYG Linux - Software 6 06-17-2004 02:19 PM
Getting a rid of X AnyoneEB Linux - Software 4 09-24-2002 06:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration