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]

Relocating section at virtual address 0


Hi,

I'm coding a more efficient way of threadvar handling for Free Pascal
compiler. To do that I'm using the gs: register, which I make point to the
threadvar area of the current thread by means of the modify_ldt syscall of
the Linux kernel.

So, to access a threadvar, the compiler only needs to issue an instruction
like 'mov eax,[gs:variableoffset]'.

I have modified the compiler to put all threadvars into their own section,
.threadvars, now I need to make sure the linker relocates addresses inside
that section from the virtual address 0.

I took the default linker script and added this after the .bss section:

  _save = .;
  . = 0;
  .threadvar _save : AT (0) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }
  . = _save;

However, when I disassemble a test program, of which the source code is:

program tv1;

threadvar x:word;
var y:word;

begin
  x:=2;
  writeln(stderr,x);
end.

... the disassembly is:

08048438 <PASCALMAIN>:
 8048438:       55                      push   %ebp
 8048439:       89 e5                   mov    %esp,%ebp
 804843b:       e8 fc c7 00 00          call   8054c3c
<FPC_INITIALIZEUNITS>
 8048440:       65 66 c7 05 94 19 06    movw   $0x2,%gs:0x8061994
 8048447:       08 02 00
 804844a:       65 0f b7 0d 94 19 06    movzwl %gs:0x8061994,%ecx
 8048451:       08
 8048452:       65                      gs
 8048453:       ba 90 14 06 08          mov    $0x8061490,%edx
 8048458:       65 03 15 c4 0c 06 08    add    %gs:0x8060cc4,%edx
 804845f:       b8 00 00 00 00          mov    $0x0,%eax
 8048464:       e8 03 1b 01 00          call   8059f6c
<FPC_WRITE_TEXT_UINT>
 8048469:       e8 ee c6 00 00          call   8054b5c <FPC_IOCHECK>
 804846e:       65                      gs
 804846f:       b8 90 14 06 08          mov    $0x8061490,%eax
 8048474:       65 03 05 c4 0c 06 08    add    %gs:0x8060cc4,%eax
 804847b:       e8 2c 16 01 00          call   8059aac <FPC_WRITELN_END>
 8048480:       e8 d7 c6 00 00          call   8054b5c <FPC_IOCHECK>
 8048485:       e8 d2 c9 00 00          call   8054e5c <FPC_DO_EXIT>
 804848a:       c9                      leave
 804848b:       c3                      ret

In other words, variables in the .threadvar section are still relocated
according to the program text.

This changes if I use:

  .threadvar 0 : AT (0) { *(.threadvar .threadvar.* .gnu.linkonce.tv.*) }

... but then the section is loaded at address 0 in memory, which is not
what I want.

How should I do this?

I'm not subscribed to this mailinglist. While I will monitor the archives
it would be usefull if you replied to my address as well.

Daniël Mantione


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