I just have a question about potential problem of multiple weak symbols, this question is from my textbook:
One module A:
int x;
int y;
p1() {...}
the other module B:
double x;
p2() {...}
and my textbook says that 'write to x in p2 might overwrite y' I can kind of get the idea of the textbook( double x is twice the size of int x, and int y is placed right after int x, here comes the problem), but still lost in details, I know when there are multiple weak symbols, the linker will just randomly pick one, so my question is, which x of module that the linker choose will result in writing to x in p2 will overwrite y.
This is my understanding :if the linker choose the int x of module A will result in the consequence, because in that way x,y are both 4 bytes and the p2(image after compilation there is one assembly code movq
compared by movl
in p1 )will change 8 bytes therefore overwrite y.
But my instructor said if only the linker choose double x of module B, that will result in overwriting y, how come, am I correct or my instructor is correct?
See Question&Answers more detail:os