This is the mail archive of the
mailing list for the binutils project.
Re: common symbols and GNU ld
ali hagigat <email@example.com> writes:
> FORCE_COMMON_ALLOCATION is not only for relocatable linking but also
> for other types of linking. The document says that:
> "This command has the same effect as the â-dâ command-line option: to
> make ld assign space to common symbols even if a relocatable output
> file is specified(â-râ)."
> The document says that even if a relocatable output file is specified,
> it means that if you specify other types of file it works too.
FORCE_COMMON_ALLOCATION is the default when not using -r.
> .comm dovom, 10
> movl %edx, 32(%edi)
> .section .text
> .comm dovom, 10
> movl $26, %eax
> as asm2.s -o asm2.o
> as asm3.s -o asm3.o
> ld asm2.o asm3.o -T asm2.ld -o asm2
> The result:
> asm2: file format elf32-i386
> SYMBOL TABLE:
> 00000000 l d .text 00000000 .text
> 00000010 l d .bss 00000000 .bss
> 00000000 l .text 00000000 aval
> 00000004 l .text 00000000 aval
> 00000010 g O .bss 0000000a dovom
> In this example if I create, asm2.ld, as an empty file, it means if
> the content of this file is empty and nothing has been written, the
> resulted symbol table is the same.
> The manual says that FORCE_COMMON_ALLOCATION forces 'space to be
> considered for symbols' but this command has no effect as the above
> shows and space is considered no matter if I use
> FORCE_COMMON_ALLOCATION or not.
Yes. That is how it works.
> and my last question is that I have defined "dovom" two times as a
> common symbol and forced the linker to consider space for it, so the
> linker should consider the space for this variable two times for each
> file and I should see two lines for "dovom" in the resulted final
> symbol table. But why i see only one line?
Because you've said that dovom is a common symbol. The definition of a
common symbol is that all instances of the symbol are combined into
one. A linker common symbol implements the semantics of a FORTRAN