Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-01

-Cg and x86_64-linux

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Florian Klaempfl

As of revision 5831, I've enabled -Cg for x86_64-linux building. This means all code is built with PIC so you can build libraries without recompiling the fpc rtl etc. However, this might have some downsides: first, pic'ed code is slightly slower, second, pic support still might contain bugs so please share your findings and opinions.

Reply by email

Daniël Mantione
to Florian Klaempfl

Op Sat, 6 Jan 2007, schreef Florian Klaempfl:

Show quoted text 5 lines
As of revision 5831, I've enabled -Cg for x86_64-linux building. This means all code is built with PIC so you can build libraries without recompiling the fpc rtl etc. However, this might have some downsides: first, pic'ed code is slightly slower, second, pic support still might contain bugs so please share your findings and opinions.

How difficult do you think it is to use RIP relative addresses to access global variables? That way there should be no speed difference, allowing us to remove the -Cg switch on x64-64.

Daniël

Reply by email

Florian Klaempfl
to Daniël Mantione
Show quoted text 10 lines
Op Sat, 6 Jan 2007, schreef Florian Klaempfl: > As of revision 5831, I've enabled -Cg for x86_64-linux building. This means > all code is built with PIC so you can build libraries without recompiling the > fpc rtl etc. However, this might have some downsides: first, pic'ed code is > slightly slower, second, pic support still might contain bugs so please share > your findings and opinions. How difficult do you think it is to use RIP relative addresses to access

How should this look like?

global variables? That way there should be no speed difference, allowing us to remove the -Cg switch on x64-64.

Reply by email

Daniël Mantione
to Florian Klaempfl

Op Sat, 6 Jan 2007, schreef Florian Klaempfl:

Show quoted text 17 lines
Daniël Mantione schrieb: > > Op Sat, 6 Jan 2007, schreef Florian Klaempfl: > > > As of revision 5831, I've enabled -Cg for x86_64-linux building. This > > means > > all code is built with PIC so you can build libraries without > > recompiling the > > fpc rtl etc. However, this might have some downsides: first, pic'ed > > code is > > slightly slower, second, pic support still might contain bugs so > > please share > > your findings and opinions. > > How difficult do you think it is to use RIP relative addresses to access How should this look like?

Assume we have:

var global:byte;
procedure z;
begin
  global:=1;
end;

Referencing to z without PIC would be an absolute memory access, preventing us to place z in memory where we want without breaking the code. Normally with -Cg we do something like:

call FPC_GETEIPINEBX
add rbx,dword global_offset_table
mov [rbx + offset_of_global_in_datasegment].byte,1

... to get access to the variable. With x64_64 you can do:

mov [global wrt rip].byte,1

The assembler must translate this to:

mov [rip-data_segment_distance+offset_of_global_in_datasegment].byte,1

... where offset_of_global_in_datasegment is a constant and data_segment_distance symbol that is resolved by the linker.

RIP relative addresses are more efficient than absolute addresses, because an absolute address is always stored as 64 bit, while the RIP offset is encoded as a 32 bit signed value (8 bit in x86 tradition possible as well, but usually the datasegment is further away than 128 bytes), the processor can decode them faster.

Daniël

Reply by email

Florian Klaempfl
to Daniël Mantione
Show quoted text 31 lines
Op Sat, 6 Jan 2007, schreef Florian Klaempfl: > Daniël Mantione schrieb: >> Op Sat, 6 Jan 2007, schreef Florian Klaempfl: >> >>> As of revision 5831, I've enabled -Cg for x86_64-linux building. This >>> means >>> all code is built with PIC so you can build libraries without >>> recompiling the >>> fpc rtl etc. However, this might have some downsides: first, pic'ed >>> code is >>> slightly slower, second, pic support still might contain bugs so >>> please share >>> your findings and opinions. >> How difficult do you think it is to use RIP relative addresses to access > How should this look like? Assume we have: var global:byte; procedure z; begin global:=1; end; Referencing to z without PIC would be an absolute memory access, preventing us to place z in memory where we want without breaking the code.

Well, to be correct it allows to map physical pages with code at different virtual address in different processes. Without PIC they could be only relocated for one address.

Show quoted text 16 lines
Normally with -Cg we do something like: call FPC_GETEIPINEBX add rbx,dword global_offset_table mov [rbx + offset_of_global_in_datasegment].byte,1 ... to get access to the variable. With x64_64 you can do: mov [global wrt rip].byte,1 The assembler must translate this to: mov [rip-data_segment_distance+offset_of_global_in_datasegment].byte,1 ... where offset_of_global_in_datasegment is a constant and data_segment_distance symbol that is resolved by the linker.

Well, amd64 does this basically but it stores only the address to the actual data rip relative so you need an additional redirection. This point is stored in the got section. I wonder indeed if one could abuse the got to actually store data :)

Reply by email