lvc / abi-dumper

Dump ABI of an ELF object containing DWARF debug info
GNU Lesser General Public License v2.1
178 stars 35 forks source link

Dumping and checking struct definitions that are not directly used as function arguments #31

Open agrandi opened 3 years ago

agrandi commented 3 years ago

Hello and thanks a lot for developing this great set of tools!

I am using this to check a C library that exposes a large number of symbols in its public interface. Some of these symbols are struct definitions that are not directly used in any of the public functions.

For example, in one of my header files I have the following:

#define SIZE 16

struct data {
    int data[SIZE];
    char flag;
};

int set_value(int type, void *o);

The type of void *o depends on the value of the first argument type. The struct data is one of the possible argument types and it will be casted inside the function.

The problem is that non-backward compatible changes to struct data are not detected and flagged as error by the tool. In fact, it looks like struct data is not even part of the dump. So far I tried to add the options -all -dump-static to the abi-dumper as well as -ext to the abi-compliance-checker. However these do not seem to work.

The only way to detect these changes is to add a dummy function that explicitly takes an argument of type struct data.

int foo(struct data *o);

This is not very friendly and convenient to use. Is there any other option that I should try?

Thanks!

linuxhw commented 3 years ago

Hello!

Is it optimized out from the binary by the compiler?

agrandi commented 3 years ago

Good question! I am not even sure if the struct definition will appear in the binary. From my understanding, the information about the struct members should come from the struct definition in the header file, right?

linuxhw commented 3 years ago

It is not part of the stripped binary. But I mean the binary with debug-info (extra .debug_info section).

Let's check this by:

abi-dumper ./your_library.so --extra-info=./DEBUG_DUMP
grep -nR your_struct_type_name ./DEBUG_DUMP
linuxhw commented 3 years ago

If it's not part of the debug-info then abi-dumper cannot extract it. Probably the compiler (GCC, Clang, etc.) can have an option to include such data types to the debug-info (see -fkeep-inline-functions for example).

agrandi commented 3 years ago

Thanks! I think we are on the right track. I checked the content of the DEBUG_DUMP and the struct that is passed as void * is not included. On the other hand, I confirmed that other structs that are explicitly passed as arguments to my functions are included, for example:

DEBUG_DUMP/debug_info:72:             name                 (strp) "stats_data"

I'll investigate the gcc options to see if there is anything useful there.

agrandi commented 3 years ago

This looks promising: -fno-eliminate-unused-debug-types

Source: https://stackoverflow.com/questions/35324109/gdb-see-unused-struct-typedef

Let me run some test and I'll get back to you.

linuxhw commented 3 years ago

It works for me. Probably we need to add this option to abi-dumper documentation near the -g -Og.

Muffo commented 3 years ago

Good idea! That would be very useful for future reference.