mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 14:29:14 +02:00
* Partial fix for i386 linux PIC code generation
git-svn-id: trunk@16080 -
This commit is contained in:
parent
6cc206ac77
commit
292e85a59a
@ -449,6 +449,10 @@ implementation
|
|||||||
|
|
||||||
procedure TAsmData.getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
|
procedure TAsmData.getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
|
||||||
begin
|
begin
|
||||||
|
if (cs_link_smart in current_settings.globalswitches) and
|
||||||
|
(alt = alt_dbgline) then
|
||||||
|
l:=TAsmLabel.createglobal(AsmSymbolDict,name,FNextLabelNr[alt],alt)
|
||||||
|
else
|
||||||
l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt],alt);
|
l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt],alt);
|
||||||
inc(FNextLabelNr[alt]);
|
inc(FNextLabelNr[alt]);
|
||||||
end;
|
end;
|
||||||
|
@ -59,6 +59,12 @@ interface
|
|||||||
RELOC_GOTPCREL,
|
RELOC_GOTPCREL,
|
||||||
RELOC_PLT32,
|
RELOC_PLT32,
|
||||||
{$endif x86_64}
|
{$endif x86_64}
|
||||||
|
{$ifdef i386}
|
||||||
|
{ PIC }
|
||||||
|
RELOC_GOTPC,
|
||||||
|
RELOC_GOT32,
|
||||||
|
RELOC_PLT32,
|
||||||
|
{$endif i386}
|
||||||
{$ifdef arm}
|
{$ifdef arm}
|
||||||
RELOC_RELATIVE_24,
|
RELOC_RELATIVE_24,
|
||||||
{$endif arm}
|
{$endif arm}
|
||||||
|
@ -546,13 +546,28 @@ implementation
|
|||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
|
||||||
constructor TElfObjData.create(const n:string);
|
constructor TElfObjData.create(const n:string);
|
||||||
|
var
|
||||||
|
need_datarel : boolean;
|
||||||
begin
|
begin
|
||||||
inherited create(n);
|
inherited create(n);
|
||||||
CObjSection:=TElfObjSection;
|
CObjSection:=TElfObjSection;
|
||||||
{ we need at least the following sections }
|
{ we need at least the following sections }
|
||||||
createsection(sec_code);
|
createsection(sec_code);
|
||||||
|
if (cs_create_pic in current_settings.moduleswitches) and
|
||||||
|
not(target_info.system in systems_darwin) then
|
||||||
|
begin
|
||||||
|
{ We still need an empty data section }
|
||||||
|
system.exclude(current_settings.moduleswitches,cs_create_pic);
|
||||||
|
need_datarel:=true;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
need_datarel:=false;
|
||||||
createsection(sec_data);
|
createsection(sec_data);
|
||||||
|
if need_datarel then
|
||||||
|
system.include(current_settings.moduleswitches,cs_create_pic);
|
||||||
createsection(sec_bss);
|
createsection(sec_bss);
|
||||||
|
if need_datarel then
|
||||||
|
createsection(sec_data);
|
||||||
if tf_section_threadvars in target_info.flags then
|
if tf_section_threadvars in target_info.flags then
|
||||||
createsection(sec_threadvar);
|
createsection(sec_threadvar);
|
||||||
if (tf_needs_dwarf_cfi in target_info.flags) and
|
if (tf_needs_dwarf_cfi in target_info.flags) and
|
||||||
@ -753,9 +768,23 @@ implementation
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
{$ifdef i386}
|
||||||
|
{ Hack for _GLOBAL_OFFSET_TABLE_ which needs a special
|
||||||
|
relocation type R_386_GOTPC, found by trial/error PM }
|
||||||
|
if p.name='_GLOBAL_OFFSET_TABLE_' then
|
||||||
|
begin
|
||||||
|
reltype:=RELOC_GOTPC;
|
||||||
|
{ This value comes from the offset of the relocation
|
||||||
|
of _GLOBAL_OFFSET_TABLE symbol within the instruction
|
||||||
|
movl $_GLOBAL_OFFSET_TABLE_,%ebx
|
||||||
|
It might be wrong if the symbol is used
|
||||||
|
in some other instruction having a bigger offset }
|
||||||
|
inc(data,2);
|
||||||
|
end;
|
||||||
|
{$endif i386}
|
||||||
CurrObjSec.addsymreloc(CurrObjSec.Size,p,reltype);
|
CurrObjSec.addsymreloc(CurrObjSec.Size,p,reltype);
|
||||||
{$ifndef x86_64}
|
{$ifndef x86_64}
|
||||||
if reltype=RELOC_RELATIVE then
|
if (reltype=RELOC_RELATIVE) or (reltype=RELOC_PLT32) then
|
||||||
dec(data,len);
|
dec(data,len);
|
||||||
{$endif x86_64}
|
{$endif x86_64}
|
||||||
end;
|
end;
|
||||||
@ -822,6 +851,14 @@ implementation
|
|||||||
reltyp:=R_386_PC32;
|
reltyp:=R_386_PC32;
|
||||||
RELOC_ABSOLUTE :
|
RELOC_ABSOLUTE :
|
||||||
reltyp:=R_386_32;
|
reltyp:=R_386_32;
|
||||||
|
RELOC_GOT32 :
|
||||||
|
reltyp:=R_386_GOT32;
|
||||||
|
RELOC_GOTPC :
|
||||||
|
reltyp:=R_386_GOTPC;
|
||||||
|
RELOC_PLT32 :
|
||||||
|
begin
|
||||||
|
reltyp:=R_386_PLT32;
|
||||||
|
end;
|
||||||
{$endif i386}
|
{$endif i386}
|
||||||
{$ifdef sparc}
|
{$ifdef sparc}
|
||||||
RELOC_ABSOLUTE :
|
RELOC_ABSOLUTE :
|
||||||
|
@ -274,6 +274,7 @@ implementation
|
|||||||
uses
|
uses
|
||||||
cutils,
|
cutils,
|
||||||
globals,
|
globals,
|
||||||
|
systems,
|
||||||
itcpugas,
|
itcpugas,
|
||||||
symsym;
|
symsym;
|
||||||
|
|
||||||
@ -929,6 +930,12 @@ implementation
|
|||||||
top_ref :
|
top_ref :
|
||||||
begin
|
begin
|
||||||
if (ref^.refaddr=addr_no)
|
if (ref^.refaddr=addr_no)
|
||||||
|
{$ifdef i386}
|
||||||
|
or (
|
||||||
|
(ref^.refaddr in [addr_pic]) and
|
||||||
|
(ref^.base=NR_EBX)
|
||||||
|
)
|
||||||
|
{$endif i386}
|
||||||
{$ifdef x86_64}
|
{$ifdef x86_64}
|
||||||
or (
|
or (
|
||||||
(ref^.refaddr in [addr_pic,addr_pic_no_got]) and
|
(ref^.refaddr in [addr_pic,addr_pic_no_got]) and
|
||||||
@ -1918,6 +1925,16 @@ implementation
|
|||||||
begin
|
begin
|
||||||
currval:=oper[opidx]^.ref^.offset;
|
currval:=oper[opidx]^.ref^.offset;
|
||||||
currsym:=ObjData.symbolref(oper[opidx]^.ref^.symbol);
|
currsym:=ObjData.symbolref(oper[opidx]^.ref^.symbol);
|
||||||
|
{$ifdef i386}
|
||||||
|
if (oper[opidx]^.ref^.refaddr=addr_pic) and
|
||||||
|
(tf_pic_uses_got in target_info.flags) then
|
||||||
|
begin
|
||||||
|
currrelreloc:=RELOC_PLT32;
|
||||||
|
currabsreloc:=RELOC_GOT32;
|
||||||
|
currabsreloc32:=RELOC_GOT32;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{$endif i386}
|
||||||
{$ifdef x86_64}
|
{$ifdef x86_64}
|
||||||
if oper[opidx]^.ref^.refaddr=addr_pic then
|
if oper[opidx]^.ref^.refaddr=addr_pic then
|
||||||
begin
|
begin
|
||||||
@ -2265,6 +2282,12 @@ implementation
|
|||||||
if (oper[opidx]^.ot and OT_MEMORY)=OT_MEMORY then
|
if (oper[opidx]^.ot and OT_MEMORY)=OT_MEMORY then
|
||||||
begin
|
begin
|
||||||
currsym:=objdata.symbolref(oper[opidx]^.ref^.symbol);
|
currsym:=objdata.symbolref(oper[opidx]^.ref^.symbol);
|
||||||
|
{$ifdef i386}
|
||||||
|
if (oper[opidx]^.ref^.refaddr=addr_pic) and
|
||||||
|
(tf_pic_uses_got in target_info.flags) then
|
||||||
|
currabsreloc:=RELOC_GOT32
|
||||||
|
else
|
||||||
|
{$endif i386}
|
||||||
{$ifdef x86_64}
|
{$ifdef x86_64}
|
||||||
if oper[opidx]^.ref^.refaddr=addr_pic then
|
if oper[opidx]^.ref^.refaddr=addr_pic then
|
||||||
currabsreloc:=RELOC_GOTPCREL
|
currabsreloc:=RELOC_GOTPCREL
|
||||||
@ -2303,6 +2326,12 @@ implementation
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
{$endif x86_64}
|
{$endif x86_64}
|
||||||
|
{$ifdef i386}
|
||||||
|
if (oper[opidx]^.ref^.refaddr=addr_pic) and
|
||||||
|
(tf_pic_uses_got in target_info.flags) then
|
||||||
|
currabsreloc:=RELOC_GOT32
|
||||||
|
else
|
||||||
|
{$endif i386}
|
||||||
currabsreloc:=RELOC_ABSOLUTE32;
|
currabsreloc:=RELOC_ABSOLUTE32;
|
||||||
|
|
||||||
if (currabsreloc=RELOC_ABSOLUTE32) and
|
if (currabsreloc=RELOC_ABSOLUTE32) and
|
||||||
|
Loading…
Reference in New Issue
Block a user