Eliminating redundant loads of GOT register?


I'm dealing with some code that's getting 70-80% slower when compiled as PIC (position independent code), and looking for ways to alleviate the problem. A big part of the problem is that gcc insists on inserting the following in every single function:

call __i686.get_pc_thunk.bx addl $_GLOBAL_OFFSET_TABLE_,%ebx

even if that ends up being 20% of the content of the function. Now, ebx is a call-preserved register, and <strong>every</strong> function in the relevant translation unit (source file) is loading it with the address of the GOT, and it's easily detectable that the static functions cannot be called from outside the translation unit (their addresses are never taken). So why can't gcc just load ebx once at the beginning of the big external-linkage functions, and generate the static-linkage functions so that they assume ebx has already been loaded with the address of the GOT? Is there any optimization flag I can use to force gcc to make this obvious and massive optimization, short of turning the inline limits up sky-high so everything gets inlined into the external functions?


There is probably no generic cure for this, but you could try to play around with inlining options. I'd guess that static functions in a compilation unit don't have too many callers, so the overhead in code replication wouldn't be too bad.

The easiest way to force such things with gcc would be to set an attribute((always_inline)). You could play around with a gcc dependent macro to ensure portability.

If you don't want to modify the code (but static inline would be good anyhow) you could use the -finline-limit option to fine tune that.


Not really a solution, but: if the functions in question do not reference file-scope variables, you could put them all together in a single translation unit and compile it without -fPIC flag. Then you link them together with other files in the final SO as usual.


  • XML/XSD validation for a Word doc
  • Xamarin in Visual Studio packaging failed | mono-symbolicate error -1073740791
  • Magento form validation only works on the last checkbox in a group
  • Is there any practical use for ContiguousIterator?
  • WPF: Get MouseEnter Event When IsEnabled=false
  • iOS 9 UIPasteboard won't work in the background
  • SIlverStripe - No data written onBeforeWrite
  • How to get EF POCOs from System.Data.Entities.DynamicProxies
  • How to generate all the permutations of elements in a list one at a time in Lisp?
  • Copying/using Python files from S3 to Amazon Elastic MapReduce at bootstrap time
  • How to resolve org.springframework.web.util.NestedServletException: Request processing failed; with
  • VBA Paste Value into new sheet below last row
  • Create DAX to count number of occupied rooms per calendar date in Power BI
  • Generically overloading operator new while considering alignment requirements
  • GC.start has no effect in Pry, but does in IRB
  • How to reset git pushed first commit into wrong new repo?
  • Sending Objects over Java Socket really slow
  • Test an application behind a proxy server using Robot Framework and Selenium2Library
  • Putting multiple films in a circle in Raphael/Joint.js
  • Jquery Skill bar effect starts when you scroll to the section
  • Adding items to an already existing jlist from another class
  • How to add blur effect into UIImage with Swift? [duplicate]
  • Jasmine unit testing observable subscribe does not trigger
  • Saving CLLocation error: Mutating method sent to immutable object
  • Laravel 5 - Cache remember doesn't work
  • Getting/building the SQL (with parameters) from NHibernate 3.2
  • How to organize this layout with overflows?
  • yii rewrite url with many sub categories
  • SQL query for game rental website - game delivery report
  • Draw 9 patch dotted /dashed line on Android
  • internal javascript not works in angular2
  • Getting Microsoft Calibri font on Amazon EC2 ubuntu
  • How to make Rss News Reader application in android …? [closed]
  • SQL Server 2012 not showing unicode character in results
  • Create an average of multiple excel chart without the data source
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • Change cell value based on cell color in google spreadsheet
  • jQuery scrollTop if URL has hash
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?