Does every .so file have a PLT/GOT?

334 Views Asked by At

I've been thinking about this for a while because I've observed that even really fundamental libraries like libc have a GOT/PLT, consisting of important functionality such as malloc() and its friends.

Is it even possible to create a shared library that has no GOT/PLT? Would such a library ever crop up in the wild, outside of an academic exercise? (If it helps, consider exclusively the x86 platform)

My gut tells me the answers to those questions are "no" and "yes" respectively, but I'm not 100% certain on either.

Is it possible that a .so file that just contains a list of C types won't have a GOT/PLT? Maybe, but I can't understand why that would occur in practice when you can just #include a .h file to do that!

1

There are 1 best solutions below

1
On

I wound up finding an answer to the second part of the question, and it seems to be "no". I have just under 5500 .so files in my /lib directory, and I ran the following shell script, called sotest.sh:

#!/bin/bash
for i in $( ls /lib ); do
  objdump -d -j .plt /lib/$i &> /tmp/tmpfile.txt;
  a=`grep "File format not recognized" /tmp/tmpfile.txt`
  b=`grep "not an ordinary file" /tmp/tmpfile.txt`
  c=`grep "not found in any input file" /tmp/tmpfile.txt`
  if [ -n "$a" ]; then
    echo "Invalid";
  elif [ -n "$b" ]; then
    echo "Invalid";
  elif [ -n "$c" ]; then
    echo "$i HAS NO PLT SECTION";
  else
    echo "$i has plt section";
  fi
  rm /tmp/tmpfile.txt;
done
echo "Done"

I then ran ./sotest.sh | grep "HAS NO PLT SECTION". I did have some results, but all were .a files and none were .so files.

So, in practice, it doesn't seem like you will ever run across a .so file without a PLT/GOT in the wild. I'm still curious if it's possible in theory, but I found the answer to the practical side of my question, so I thought it could help others who were wondering the same thing!