This is the mail archive of the binutils@sources.redhat.com 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]

Using __bss_start to write relocatable code?


I am using m68k-elf binutils, trying to make a position independent reference
to .bss data.  The .bss section is being interpreted as the layout of the data,
but some other process will actually allocate a section of size __bss_size
and place it into %a5.

Now, I want to use .bss symbols to access the data in a PIC way, without
having to modify the assembler/linker from the default.  I need to reference
as a literal the offset of a symbol from the beginning of the .bss section.

For example, with the simple code:

   .section     .rodata
   .text
   .globl       foo
   .extern      __bss_start
   .globl       test
   .align       2
test:
        link.w %a6,#-28
        move.l #foo-__bss_start,%d0
        add.l %a5,%d0
        rts

   .section     .bss
   .align       2
foo:
   .zero        4

The significant instruction is the move.l, leading to the add to
get the actual address into %d0.

This gives me a compiler error because apparently __bss_start has
been defined absolute instead of relative to .bss even though it
identifies the start of .bss.

If, instead, I move.l #foo or #__bss_start, everything is fine, but
the result is not what I want.

Is there a better way to get the offset as a literal?

I suppose I could do two move.l instructions followed by a subtract,
but that is getting rather lengthy and uses more registers than I
had hoped.  Is there any other way to reference, as a literal, the
offset to a symbol from the .bss section start?

Thanks,

Ray


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