[Sorry! Meant to send this to the list, not just to Ian!] On Dec 17, 2010, at 11:36 AM, Ian Lance Taylor wrote: > Amittai Aviram <amittai.aviram@xxxxxxxx> writes: > >> Thank you very much! But I just tried linking with the -v option, and >> the output looks as if the linker does in fact put head.o immediately >> before hello.o and tail.o immediately after it. (Output below. The >> relevant bit is near the bottom.) Why doesn't that give me the >> results I was expecting in the finished executable binary? > > I don't know, you would have to provide more details about exactly what > input you used, what you expected to see, exactly what you saw, and why > you expected it to be different. > > One specific issue is that common symbols don't match your scheme, since > they are not defined in the .bss section in a .o file but are placed > there later by the linker. > > Ian On Dec 17, 2010, at 11:36 AM, Ian Lance Taylor wrote: > Amittai Aviram <amittai.aviram@xxxxxxxx> writes: > >> Thank you very much! But I just tried linking with the -v option, and >> the output looks as if the linker does in fact put head.o immediately >> before hello.o and tail.o immediately after it. (Output below. The >> relevant bit is near the bottom.) Why doesn't that give me the >> results I was expecting in the finished executable binary? > > I don't know, you would have to provide more details about exactly what > input you used, what you expected to see, exactly what you saw, and why > you expected it to be different. > > One specific issue is that common symbols don't match your scheme, since > they are not defined in the .bss section in a .o file but are placed > there later by the linker. > > Ian I start with three source code files, head.s, hello.c, and tail.s. Here is their source code in that order. // head.s .section .rodata .globl my_data_start my_data_start: .section .bss .global my_bss_start my_bss_start: // end head.s // hello.c #include <stdio.h> #include <stdlib.h> int global_a, global_b; int main(void) { global_a = 3; global_b = 4; printf("Hello! %d %d\n", global_a, global_b); return EXIT_SUCCESS; } // end hello.c // tail.s .section .bss .globl my_bss_end my_bss_end: // end tail.s And here is my Makefile: all: l1 l1: head.o hello.o tail.o gcc -Wall -static -g -v -o $@ $^ head.o: head.s gcc -c -o $@ $< tail.o: tail.s gcc -c -o $@ $< hello.o: hello.c gcc -c -o $@ $< clean: rm -f l1 *.o Here is what I was expecting to see in the output from objdump -D l1, somewhere after "Disassembly of section .bss" (where the three dots actually appear in the output, but any [text] is my shorthand notation): [Some address] <my_data_start>: ... [Next address 1] <global_b>: [Next address 1]: 00 00 add %al,(%rax) ... [Next address 2] <global_a>: [Next address 2]: 00 00 add %al,(%rax) ... [Next address 3] <my_data_end>: ... But here is what I get instead: Disassembly of section .bss: 00000000006a1cc0 <completed.6885>: ... 00000000006a1cc8 <dtor_idx.6887>: ... 00000000006a1ce0 <object.6911>: ... 00000000006a1d10 <my_bss_end>: ... 00000000006a1d20 <static_dtv>: ... 00000000006a2120 <static_slotinfo>: ... [... snip ...] 00000000006a49e0 <frame_hdr_cache_head>: ... 00000000006a49e8 <global_b>: 6a49e8: 00 00 add %al,(%rax) ... 00000000006a49ec <global_a>: 6a49ec: 00 00 add %al,(%rax) ... 00000000006a49f0 <_dl_tls_static_used>: ... [...snip...] So note two things: (a) my_data_start is missing, only my_data_end appears. (If, however, I only include head.o in my Makefile,rule, then my_data_start appears in the location where my_data_end appears in the above extract.) (b) my_data_end is separated from global_a and global_b and seems to be in an arbitrary location in relation to them. Thanks! Amittai Amittai Aviram PhD Student in Computer Science Yale University 646 483 2639 amittai.aviram@xxxxxxxx http://www.amittai.com