abi-dumper icon indicating copy to clipboard operation
abi-dumper copied to clipboard

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

Open agrandi opened this issue 4 years ago • 8 comments

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!

agrandi avatar Sep 13 '21 17:09 agrandi

Hello!

Is it optimized out from the binary by the compiler?

linuxhw avatar Sep 13 '21 19:09 linuxhw

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?

agrandi avatar Sep 13 '21 21:09 agrandi

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 avatar Sep 14 '21 10:09 linuxhw

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).

linuxhw avatar Sep 14 '21 10:09 linuxhw

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 avatar Sep 14 '21 16:09 agrandi

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.

agrandi avatar Sep 14 '21 16:09 agrandi

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

linuxhw avatar Sep 15 '21 08:09 linuxhw

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

Muffo avatar Oct 21 '21 15:10 Muffo