Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:05:25+00:00 2026-06-15T12:05:25+00:00

I’ve got libraries that do no expose any function except say CreateObject. Nevertheless all

  • 0

I’ve got libraries that do no expose any function except say “CreateObject”. Nevertheless all their functions are called indirectly, so I see in the perf report that up to 1.65% of time is spent in __i686.get_pc_thunk.bx. The functions (class methods) are called 160 million times and they are internal to the shared library, i.e. not exposed.

I wonder if it’s possible to compile internal methods without relocations – i.e. using relative offsets or something like that.

gcc is 4.5.2

UPDATE: Actually I think that was because of -O0 left in the makefile. So it’s not a big deal now, but I would still like to do the same with -O0, too, as it keeps less “garbage” for profiler. I wonder what is the -O2 “real” option that does this.

UPDATE2: hm, it wasn’t -O2, it was probably –dynamic-list that lower the pc_thunk performance hit a bit, but it’s still there… so not even sure if –dynamic-list really helps. Should hidden symbols still include indirection thunks, is it correct?

UPDATE3: I created a test project, for internal library function I set attribute visibility hidden, I compile with gcc 4.7 and -O2 and LTO enabled, I pass –dynamic-list to linker without the internal function in there, and nevertheless the call to get_pc_thunk is still there.

This is the code in the test shared library:

#include <stdio.h>

__attribute__((visibility("hidden"), noinline)) void lib1f2()
{
    puts("I should have PLT disabled");
}

void lib1f()
{
    puts("I'm lib1");
    lib1f2();
}

In gdb I still see thunk inside lib1f2.

What’s funny is that with -fwhole-program lib1f2 is inlined into the main executable but still contains this call to the thunk.

UPDATE4: OK I’m getting close (to realize me being dumb), the program (and code above) uses data even if it’s just a const string, so it needs GOT calls. So the question now is:

  1. Still, can I avoid thunks for GOT?
  2. (related) via, maybe, compiling without -fPIC – what will be drawbacks?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:05:26+00:00Added an answer on June 15, 2026 at 12:05 pm

    1) Still, can I avoid thunks for GOT?

    I think not. Not on i686 at least. The problem is that code can automagically do relative jumps… or rather all the jumps on x86 are relative, beside indirect jump IIRC. On the other hand there is no way to index data relative to the current program counter. This problem is actually solved in x86_64, since there is a new instruction pointer relative addressing that can be used exactly for this cases.

    Your test, compiled with gcc -fPIC -shared -O2 -flto

    On 32 bit:

    00000530 <lib1f2.2321>:
    push   %ebx
    call   52b <__x86.get_pc_thunk.bx>
    add    $0x1aca,%ebx
    sub    $0x18,%esp
    lea    -0x1a67(%ebx),%eax
    mov    %eax,(%esp)
    call   3f0 <puts@plt>
    add    $0x18,%esp
    pop    %ebx
    ret
    00000560 <lib1f>:
    push   %ebx
    call   52b <__x86.get_pc_thunk.bx>
    add    $0x1a9a,%ebx
    sub    $0x18,%esp
    lea    -0x1a4c(%ebx),%eax
    mov    %eax,(%esp)
    call   3f0 <puts@plt>
    add    $0x18,%esp
    pop    %ebx
    jmp    530 <lib1f2.2321>
    nop
    

    On 64 bit

    00000000000006b0 <lib1f2.2352>:
    lea    0x2a(%rip),%rdi
    jmpq   590 <puts@plt>
    
    00000000000006c0 <lib1f>:
    lea    0x35(%rip),%rdi
    sub    $0x8,%rsp
    callq  590 <puts@plt>
    xor    %eax,%eax
    add    $0x8,%rsp
    jmp    6b0 <lib1f2.2352>
    

    2) (related) via, maybe, compiling without -fPIC – what will be drawbacks?

    Well, although it’s embarrassing I have to admit I’m slightly confused here. At first sight I would have said that a shared library bust be compiled with -fPIC. Instead, the following two commands both works

    gcc -fPIC -m32 -shared -O2 -flto test.c -o test.so
    gcc -m32 -shared -O2 -flto test.c -o test.so
    

    In the non -fPIC case the code does also not need any call to get_pc_thunk. The trick is that the dynamic loader fixes the library code at runtime with the right address to the data.

    This is a problem though, since you gained some speed avoiding the thunks, but you lost the ability to actually share the shared library since the operating system must create a new copy for every code page of the library which contains a relocation. On the other hand, when a GOT is used only the GOT page(s) must be duplicated, greatly reducing the memory footprint when many applications link to the same library.

    Interestingly enough, in 64bit mode is not possible to compile a library in non pic mode, the following command fails

    gcc -m64 -shared -O2 -flto test.c -o test.so
    

    Still, since there is processor provided support for code relative addressing this is not a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.