Communication debug warning "character type does not match original declaration"

I am trying to systematically debug the following problem:

% gcc -fPIC -flto -o try1.o -c try1.c
% gcc -fPIC -flto -o try2.o -c try2.c
% gcc -shared -flto -fPIC -o try.so try1.o try2.o
try2.c:1:14: warning: type of 'aaaaaaaa' does not match original declaration [enabled by default]
try1.c:1:5: note: previously declared here

I am this synthetic test, I know for sure that the problem is aaaaaaaadefined inthere, but shortthere. In my real problem, the relationship brings together many objects that are the result of a complex assembly process, and I don't know which two objects contain conflicting definitions.

I want to solve it by examining each of the related object files, see how a character is defined in each, and find a pair with mismatched definitions. Then I will track the build process to see how they are built and get the root cause. But I do not know how to determine the way to determine the object.

I tried nm -Aand objdump -t, but they do not show the type / size of the character:

% nm -A try1.o
try1.o:00000001 C __gnu_lto_v1
try1.o:00000000 D aaaaaaaa
% nm -A try2.o
try2.o:00000001 C __gnu_lto_v1
try2.o:         U aaaaaaaa
try2.o:00000000 T foo
% objdump -t try1.o | grep aaa
00000000 g     O .data  00000004 aaaaaaaa
% objdump -t try2.o | grep aaa
00000000         *UND*  00000000 aaaaaaaa

My compiler:

% gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+4
source share
1 answer

Use nm --print-size. GNU nmuses the BSD format by default, which displays only values. This does not display the character sizes of undefined, as this information is not required for binding and is not stored anywhere.

When compiling with -flto, GCC adds a pair of .gnu.lto_.section , which, among others, contain the expected size of undefined characters. I do not know if there is an available tool to analyze them.

You can show hexdump with:

F=try2.o; objdump -h $F | grep -o '\.gnu.lto_\S*' | xargs -I% readelf -x % $F
+2
source

Source: https://habr.com/ru/post/1650908/


All Articles