From: SourceForge.net <no...@so...> - 2007-11-15 20:24:25
|
Bugs item #1057171, was opened at 2004-10-30 06:27 Message generated for change (Comment added) made by maartenbrock You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1057171&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: linker Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Akiya ISHIDA (akiya-i) Assigned to: Nobody/Anonymous (nobody) >Summary: Linker problem on multiple defined global variable Initial Comment: Attached source files, aa.c and bb.c, are intended to share global variables. I should put 'extern' keyword on ether one of the two, but I forgot. When I link two object modules into one executable, z80- linker doesn't say any error and assign different address to each of those global variables. If I put 'extern' on ether one, it's OK. ============ aa.c Page 1 char a,b; char c=10; void aa() { a = b + c; } void main() { void bb(); bb(); } ============ bb.c Page 1 char a,b,c; void bb() { c = a+ b; } ============ compile.sh Page 1 sdcc -mz80 -c aa.c sdcc -mz80 -c bb.c sdcc -mz80 -o xx aa.o bb.o ============ disassenble Page 1 aa: 0x020a 21 02 80 LD HL,#0x8002 <-- linker assiend different address from bb.o 0x020d d5 PUSH DE 0x020e fd 21 00 80 LD IY,#0x8000 <-- 0x0212 fd e5 PUSH IY 0x0214 d1 POP DE 0x0215 fd 21 01 80 LD IY,#0x8001 <-- 0x0219 fd 7e 00 LD A,(IY+#0) 0x021c 86 ADD A,(HL) 0x021d 12 LD (DE),A 0x021e d1 POP DE 0x021f c9 RET main: 0x0220 cd 24 02 CALL #0x0224 0x0223 c9 RET bb: 0x0224 21 04 80 LD HL,#0x8004 <-- 0x0227 d5 PUSH DE 0x0228 fd 21 05 80 LD IY,#0x8005 <-- 0x022c fd e5 PUSH IY 0x022e d1 POP DE 0x022f fd 21 03 80 LD IY,#0x8003 <-- 0x0233 fd 7e 00 LD A,(IY+#0) 0x0236 86 ADD A,(HL) 0x0237 12 LD (DE),A 0x0238 d1 POP DE 0x0239 c9 RET SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/ TININative/xa51/ds400/hc08 2.4.4 #849 (Sep 25 2004) (UNIX) ---------------------------------------------------------------------- >Comment By: Maarten Brock (maartenbrock) Date: 2007-11-15 21:24 Message: Logged In: YES user_id=888171 Originator: NO I just looked at this and it is not restricted to the z80 linker. The mcs51 has the same problem. When a variable is defined more than once but in different modules it is treated as if the definitions were static. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1057171&group_id=599 |