Re: How a linker works (continued)

jacob navia <jacob@xxxxxxxxxx> writes:
This can be tested, for instance, with the following two files:
file t1.c
int tab[12];

File t2.c
int tab[256];
int main(void){return 0;}

Linking t1.c and t2.c with MSVC 8 we obtain an executable *without any
warnings* not even at the highest warning level.

In the linker of lcc-win I added a warning:
in t1.obj warning: '_tab' (defined with size 48)
is redefined in t2.obj with size 1024

The linker of gnu doesn't emit any warning:
root@ubuntu:/tmp# gcc -Wall t1.c t2.c

*Please* post these articles in comp.programming. I'd join in a lot
more if I could do so and be topical. However, you are dead set on
knocking gcc without understanding it so...

gcc uses the GNU linker ld. ld merges the common blocks to make tab
the larger of the two size regardless of the linking order. In this
case, I can't see why you'd want a diagnostic[1]. When a compilation
unit initialises the table (so it can't be merged) the GNU linker
*does* produce a warning:

/usr/bin/ld: Warning: size of symbol `tab' changed from 1024 in t1.o
to 16 in t2.o

Next installment will treat the object libraries

Please post it where it belongs.

[1] OK, a case can be made for a diagnostic in all such cases, but you
are suggesting the gcc leads the programmer silently into a trap.


Relevant Pages

  • xemacs installation problems
    ... checking for gcc... ... checking whether we are using GNU C... ... checking size of int... ... configure: warning: No OffiX without generic Drag'n'Drop support ...
  • Re: gcc bug? Openoffice port impossibel to compile on 4.8
    ... remove this silly "bitten by the Linux bug" and the red-herring of gcc ... struct bar {int a; int b;} dapper; ... The *warning* emitted by gcc when enough analysis is done (e.g. ...
  • Re: How a linker works (continued)
    ... int tab; ... warnings* not even at the highest warning level. ... In the linker of lcc-win I added a warning: ... t1.c: Info 830: Location cited in prior message ...
  • Re: How to check if same partition
    ... GCC will bitch when you get this wrong. ... function(int b, int c, int something) ... The gcc version I am using is clever enough not to give this warning ... I covered all cases for argc. ...
  • Help needed in solving C-errors in Linux (gcc)
    ... i'm trying to make I got the following messages from gcc. ... main.c:22: warning: comparison is always false due to limited range of data type ... int conv_inch2feet; ... int convert(int unit, const char *,const char *,const char *); ...