This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: common symbols and GNU ld


Hello Andreas,

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:

--------------------------------------------
asm2.s
.comm dovom, 10
aval:
movl %edx, 32(%edi)

asm3.s
.section .text
.comm dovom, 10
aval:
movl $26, %eax

asm2.ld
FORCE_COMMON_ALLOCATION

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.
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?

Regards


On Wed, May 11, 2011 at 3:36 PM, Andreas Schwab <schwab@redhat.com> wrote:
> ali hagigat <hagigatali@gmail.com> writes:
>
>> "FORCE_COMMON_ALLOCATION" of ld seems not working!
>
> As documented, this statement has no effect except for relocatable
> linking.
>
>> 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.
>
> --
> Andreas Schwab, schwab@redhat.com
> GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 ?5EC7 45C6 250E 6F00 984E
> "And now for something completely different."
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]