Invalid class member offset address

I have a problem: when I try to access a member of a class in a specific file, it doesn't get the actual value of that element. But when I try to access it elsewhere, I do it.

File A:

find_func_wrapper ( Func_Container * rules, char * func_name ) {
    ulong count = rules->function_count;
    cout << "A count: " << count << endl;
    B::find_func( rules, func_name );
}

main () {
    Func_Container *rules = get_rules();
    find_func_wrapper( rules, func_name );
}

      

File B:

B::find_func ( Func_Container * rules, char * func_name ) {
    ulong count = rules->function_count;
    cout << "B count: " << count << endl;
}

      

When I run this I get:

A count: 2
B count: 0

      

When the account member is set to 2. Running the code with gdb in both A and B, when I use print rules->function_count

I get 2.

Parsing code in find_func_wrapper.

1885            ulong count = rules->function_count;
=> 0x0000000006004be5 <+294>:   mov    -0xa8(%rbp),%rax
   0x0000000006004bec <+301>:   mov    0x60a8(%rax),%rax
   0x0000000006004bf3 <+308>:   mov    %rax,-0x38(%rbp)

      

Also, print &rules->function_count = 0x11684158

and print rules = 0x1167e0b0


In B :: find_func

2652        ulong count = rules->function_count;
   0x00000000062494a1 <+75>:    mov    -0x4f8(%rbp),%rax
   0x00000000062494a8 <+82>:    mov    0x60e8(%rax),%rax
   0x00000000062494af <+89>:    mov    %rax,-0x50(%rbp)

      

Printing the addresses of the rules and -> function_count returns the same addresses as expected. To me it looks like the culprit is in the second instruction mov

where the offset used in B, 0x60e8, is not correct. Why is this happening?

get_rules () returns a pointer to a global object that was previously initialized and maintained until the program terminates.

This is compiling with gcc 4.4.7. The project is extremely large. Also, this only happens in debug builds, release failures, or non-optimized builds, it doesn't seem to be.

Sizeof in find_func_wrapper: 24968
    Offset: 3093
Sizeof in B::find_func: 25032
    Offset: 3101

      

Offset calculated for ((&rules->function_count) - rules)

+3


source to share


1 answer


I was able to narrow down the source of my problem, including header reordering. Putting #include "Func_Container.h"

before others included in file B, I found that the container became correct. I kept moving other headers Func_Container

until I found what was causing the problem. I found that the offending header has a flag _GLIBCXX_DEBUG

. This caused additional debug members on certain std types that resized them, so when my definition for Func_Container was loaded at later addresses, it changed as a result of the larger types.



An example of this issue is available on this mailing list: https://gcc.gnu.org/ml/libstdc++/2012-10/msg00077.html

+1


source







All Articles