common symbols and GNU ld
Sat May 14 08:03:00 GMT 2011
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.
I used the word, space, because the manual used that word. My example
showed that if I specify FORCE_COMMON_ALLOCATION or not, it makes no
difference and the space is reserved and only once for the resulted
linked program. I repeat my example:
.comm dovom, 10
movl %edx, 32(%edi)
.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
asm2: file format elf32-i386
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.
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?
On Wed, May 11, 2011 at 3:36 PM, Andreas Schwab <firstname.lastname@example.org> wrote:
> ali hagigat <email@example.com> writes:
>> "FORCE_COMMON_ALLOCATION" of ld seems not working!
> As documented, this statement has no effect except for relocatable
>> 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
>> Why two different spaces are not considered for "dovom"?
> What do you mean with "spaces are not considered"? Both objects
> allocate 10 bytes for the common symbol dovom, and the linker has
> allocated a single 10 byte space for them, as expected.
> Andreas Schwab, firstname.lastname@example.org
> GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
> "And now for something completely different."
More information about the Binutils