4

So right now I'm trying to resolve function calls and their names in my reversing tool

the problem I'm having is that library functions such as printf and fwrite and such do not have a corresponding address in symbol table unlike functions inside the actual program which do contain a virtual address in the symbol table and therefore i can resolve their name when they are called statically

basically i want to resolve the name of functions even static library functions like printf just like how readelf does (i tried readelf and indeed it does resolve the name of printf even tho it says the address value of printf inside symbol table is 0 unlike other functions so not sure how does it realize the offset of printf inside plt)

so i have these questions :

  1. how to find the index or address of printf in the PLT so i can resolve its name when i see a "Call address"

  2. why doesn't the symbol table contain the virtual address of these functions unlike functions inside the code? considering these are static libraries and are statically linked in that program, shouldn't they have a fixed address just like other functions?

  3. the program is only a printf function inside main and only included stdio.h, now my understanding is that i included the stdio.h statically considering i included it in the beginning and didnt use any specific option while compiling. so why is it going into PLT instead of .text section and having a static address? i thought when i include a library in the beginning it basically copy and pastes it into my .text section?

1 Answer 1

1

how to find the index or address of printf in the PLT so i can resolve its name when i see a "Call address"

When a function is present in PLT (Procedure Linkage Table) section, that means its address isn't known at compilation time and has to be resolved by dynamic linker at the runtime. However, just to know that a certain function is called at some point in the program you may use a tool like objdump, which will show you the function name followed by @plt like so:

call   720 <printf@plt>

why doesn't the symbol table contain the virtual address of these functions unlike functions inside the code? considering these are static libraries and are statically linked in that program, shouldn't they have a fixed address just like other functions?

Because they are not statically linked (see first sentence of the answer for the first question). They don't have fixed addresses, since these will be resolved during the runtime.

so why is it going into PLT instead of .text section and having a static address? i thought when i include a library in the beginning it basically copy and pastes it into my .text section?

It would be the waste of space if every executable contained copy of the same library. The .h files are included and they often contain just the declarations. So you don't include compiled definitions of functions declared in .h - just the prototypes. The linker is responsible for linking the program with the libraries used in it. They still may be linked either statically or dynamically and since dynamic linking avoids copying entire libraries' code into every single executable, it's often used instead of static one.

See this question for further reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.