-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Structs with same name in different compilation units #4421
Comments
There is a another scenario though: /* header.h */
struct A {
int a;
int b;
} #include "header.h"
/* main.c */
struct A a;
int main() {
return 0;
} #include "header.h"
/* other.c */
struct A b; so both compilation units This example shows we can't just name those structs differently or create a local storage within a compilation unit or name the respectively to compilation units like |
100% bugIf you use the
rizin is using incorrect type for variable So this is clearly a bug and can not be skipped. |
Okay so here is my main point:
There are 2 different causes of the same struct name in 2 different compilation units:
The dwarf DOES contain the file info from which the struct came from (where struct was declared). So in 1st case those structs will have Probably it is the solution. I will release the PR soon. |
Hey @rockrid3r, I also had a look at it in the meantime. I would suggest using the compile unit offset and name, defined here: rizin/librz/include/rz_bin_dwarf.h Lines 1075 to 1091 in 73d85d2
This is because of the One Definition Rule (a.k. ODR). There can only be one definition of a struct/union/enum type inside a single compilation/translation unit. So it makes more sense to use that to classify types. Also, If I were to go about it, I would create a new type as follows. typedef struct rz_base_type_with_metadata_t {
RzBaseType *base_type;
ut64 cu_offset;
char *cu_name;
} RzBaseTypeWithMetadata; Here
I would advise you to go ahead with solution 2 and open a draft PR, so that the maintainers can track the changes. Since solution 2 will be a big overhaul, it'd be nice to be on the same page since the starting changes itself. |
@DMaroo respect. Good research. Most probably will proceed with 2. |
@DMaroo it looks like |
Work environment
rizin -v
full output, not truncated (mandatory)Consider this example:
and
Now consider compiling it with
and opening it in rizin:
Then the
tp
command (tp
prints the type)results in
so clearly it uses the definition of
struct A
frommain.c
without complaining/warning that it is also defined inother.c
.Steps to reproduce the behavior
Additional Logs, screenshots, source code, configuration dump, ...
a.out.tar.gz
The text was updated successfully, but these errors were encountered: