Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
agrandi opened this issue Sep 13, 2021 · 8 comments

Comments

@agrandi
Copy link

agrandi commented Sep 13, 2021

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
Copy link

linuxhw commented Sep 13, 2021

Hello!

Is it optimized out from the binary by the compiler?

@agrandi
Copy link
Author

agrandi commented Sep 13, 2021

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
Copy link

linuxhw commented Sep 14, 2021

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
Copy link

linuxhw commented Sep 14, 2021

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
Copy link
Author

agrandi commented Sep 14, 2021

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
Copy link
Author

agrandi commented Sep 14, 2021

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
Copy link

linuxhw commented Sep 15, 2021

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

@Muffo
Copy link

Muffo commented Oct 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants