Help with linking and symbol resolution

David Brown david@westcontrol.com
Mon Jan 30 09:46:00 GMT 2017


On 28/01/17 16:10, Lakshay Garg wrote:
>> I do this:
>>
>>  $ gcc f1.c f2.c -Wall
>> /usr/local/bin/ld: Warning: alignment 4 of symbol `c' in f2.o is smaller than 8 in f1.o
>> /usr/local/bin/ld: Warning: size of symbol `c' changed from 8 in f1.o to 4 in f2.o
>>
>> You should always use -Wall when gcc does anything unexpected.
>>
> 
> Hi Andrew
> 
> Yes, I get this warning too. But what I want to understand is why do
> we get the size of c as 8 when it should be 4 because the linker will
> find that there are multiple declarations of c and will keep the
> strong one which is the declaration with int.
> 
> Please see slides 22,23,24 from here:
> https://www.cs.cmu.edu/afs/cs/academic/class/15213-f10/www/lectures/11-linking.pdf
> 
> Lakshay G.
> 

Others have already explained how the slides are incorrect regarding
common symbols, tentative declarations, and weak symbols.

Looking further in the slides, I see some very questionable style in the
"Role of .h Files", incorrect terms in "Global Variables", and other bad
advice.  Unless these slides are accompanied by notes saying "this is
how /not/ to do it", I'd recommend you be sceptical to the course.  This
is not the right place to discuss details, since it is nothing to do
with the gcc compiler - the comp.lang.c newsgroup might be a better
choice.

Be wary of posting a direct link to the lecture slides - check that you
are allowed to do so before posting it in public again.



More information about the Gcc-help mailing list