Why is function's length information of other shared lib in ELF?

Posted by minastaros on Stack Overflow See other posts from Stack Overflow or by minastaros
Published on 2012-11-29T14:47:50Z Indexed on 2012/11/29 17:04 UTC
Read the original article Hit count: 159

Filed under:
|
|
|

Our project (C++, Linux, gcc, PowerPC) consists of several shared libraries. When releasing a new version of the package, only those libs should change whose source code was actually affected. With "change" I mean absolute binary identity (the checksum over the file is compared. Different checksum -> different version according to the policy). (I should mention that the whole project is always built at once, no matter if any code has changed or not per library).

Usually this can by achieved by hiding private parts of the included Header files and not changing the public ones.

However, there was a case where just a delete was added to the destructor of a class TableManager (in the TableManager.cpp file!) of library libTableManager.so, and yet the binary/checksum of library libB.so (which uses class TableManager ) has changed.

TableManager.h:

class TableManager 
{
public:
    TableManager();
    ~TableManager();
private:
    int* myPtr;
}

TableManager.cpp:

TableManager::~TableManager()
{
    doSomeCleanup();
    delete myPtr;     // this delete has been added
}

By inspecting libB.so with readelf --all libB.so, looking at the .dynsym section, it turned out that the length of all functions, even the dynamically used ones from other libraries, are stored in libB! It looks like this (length is the 668 in the 3rd column):

527: 00000000 668 FUNC GLOBAL DEFAULT UND _ZN12TableManagerD1Ev

So my questions are:

  1. Why is the length of a function actually stored in the client lib? Wouldn't a start address be sufficient?
  2. Can this be suppressed somehow when compiling/linking of libB.so (kind of "stripping")? We would really like to reduce this degree of dependency...

© Stack Overflow or respective owner

Related posts about c++

Related posts about linux