|
@@ -47,6 +47,41 @@ unit og386elf;
|
|
SHF_EXECINSTR = 4;
|
|
SHF_EXECINSTR = 4;
|
|
|
|
|
|
type
|
|
type
|
|
|
|
+ telf32header=packed record
|
|
|
|
+ magic0123 : longint;
|
|
|
|
+ file_class : byte;
|
|
|
|
+ data_encoding : byte;
|
|
|
|
+ file_version : byte;
|
|
|
|
+ padding : array[$07..$0f] of byte;
|
|
|
|
+ e_type : word;
|
|
|
|
+ e_machine : word;
|
|
|
|
+ e_version : longint;
|
|
|
|
+ e_entry : longint; // entrypoint
|
|
|
|
+ e_phoff : longint; // program header offset
|
|
|
|
+ e_shoff : longint; // sections header offset
|
|
|
|
+ e_flags : longint;
|
|
|
|
+ e_ehsize : word; // elf header size in bytes
|
|
|
|
+ e_phentsize : word; // size of an entry in the program header array
|
|
|
|
+ e_phnum : word; // 0..e_phnum-1 of entrys
|
|
|
|
+ e_shentsize : word; // size of an entry in sections header array
|
|
|
|
+ e_shnum : word; // 0..e_shnum-1 of entrys
|
|
|
|
+ e_shstrndx : word; // index of string section header
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ telf32sechdr=packed record
|
|
|
|
+ sh_name : longint;
|
|
|
|
+ sh_type : longint;
|
|
|
|
+ sh_flags : longint;
|
|
|
|
+ sh_addr : longint;
|
|
|
|
+ sh_offset : longint;
|
|
|
|
+ sh_size : longint;
|
|
|
|
+ sh_link : longint;
|
|
|
|
+ sh_info : longint;
|
|
|
|
+ sh_addralign : longint;
|
|
|
|
+ sh_entsize : longint;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
preloc = ^treloc;
|
|
preloc = ^treloc;
|
|
treloc = packed record
|
|
treloc = packed record
|
|
next : preloc;
|
|
next : preloc;
|
|
@@ -71,18 +106,22 @@ unit og386elf;
|
|
pelfsection = ^telfsection;
|
|
pelfsection = ^telfsection;
|
|
telfsection = object
|
|
telfsection = object
|
|
index : tsection;
|
|
index : tsection;
|
|
|
|
+ name : string[16];
|
|
|
|
+ elftype,
|
|
|
|
+ elfflags,
|
|
|
|
+ align : longint;
|
|
data : PDynamicArray;
|
|
data : PDynamicArray;
|
|
len,
|
|
len,
|
|
pos,
|
|
pos,
|
|
- nrelocs,
|
|
|
|
- flags : longint;
|
|
|
|
|
|
+ nrelocs : longint;
|
|
relochead : PReloc;
|
|
relochead : PReloc;
|
|
reloctail : ^PReloc;
|
|
reloctail : ^PReloc;
|
|
|
|
|
|
rel : PDynamicArray;
|
|
rel : PDynamicArray;
|
|
gsyms : PSymbol;
|
|
gsyms : PSymbol;
|
|
|
|
|
|
- constructor init(sec:TSection;Aflags:longint);
|
|
|
|
|
|
+ constructor init(sec:TSection;Atype,Aflags,Aalign:longint);
|
|
|
|
+ constructor initname(const Aname:string;Atype,Aflags,Aalign:longint);
|
|
destructor done;
|
|
destructor done;
|
|
procedure write(var d;l:longint);
|
|
procedure write(var d;l:longint);
|
|
procedure alloc(l:longint);
|
|
procedure alloc(l:longint);
|
|
@@ -93,11 +132,14 @@ unit og386elf;
|
|
pelfoutput = ^telfoutput;
|
|
pelfoutput = ^telfoutput;
|
|
telfoutput = object(tobjectoutput)
|
|
telfoutput = object(tobjectoutput)
|
|
sects : array[TSection] of PElfSection;
|
|
sects : array[TSection] of PElfSection;
|
|
- elf_gotpc_sect,
|
|
|
|
- elf_gotoff_sect,
|
|
|
|
- elf_got_sect,
|
|
|
|
- elf_plt_sect,
|
|
|
|
- elf_sym_sect : PElfSection;
|
|
|
|
|
|
+ symtab_sect,
|
|
|
|
+ strtab_sect,
|
|
|
|
+ shstrtab_sect,
|
|
|
|
+ gotpc_sect,
|
|
|
|
+ gotoff_sect,
|
|
|
|
+ got_sect,
|
|
|
|
+ plt_sect,
|
|
|
|
+ sym_sect : PElfSection;
|
|
strs,
|
|
strs,
|
|
syms : Pdynamicarray;
|
|
syms : Pdynamicarray;
|
|
initsym : longint;
|
|
initsym : longint;
|
|
@@ -111,7 +153,7 @@ unit og386elf;
|
|
procedure writesymbol(p:pasmsymbol);virtual;
|
|
procedure writesymbol(p:pasmsymbol);virtual;
|
|
procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
|
|
procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
|
|
private
|
|
private
|
|
- procedure createsection(sec:tsection);
|
|
|
|
|
|
+ procedure createsection(sec:tsection;const name:string);
|
|
procedure write_relocs(s:pcoffsection);
|
|
procedure write_relocs(s:pcoffsection);
|
|
procedure write_symbol(const name:string;strpos,value,section,typ,aux:longint);
|
|
procedure write_symbol(const name:string;strpos,value,section,typ,aux:longint);
|
|
procedure write_symbols;
|
|
procedure write_symbols;
|
|
@@ -142,29 +184,54 @@ unit og386elf;
|
|
TSection
|
|
TSection
|
|
****************************************************************************}
|
|
****************************************************************************}
|
|
|
|
|
|
- constructor tcoffsection.init(sec:TSection;Aflags:longint);
|
|
|
|
|
|
+ constructor telfsection.init(sec:TSection;Atype,Aflags,Aalign:longint);
|
|
begin
|
|
begin
|
|
index:=sec;
|
|
index:=sec;
|
|
- flags:=AFlags;
|
|
|
|
|
|
+ name:=sec_2_str[sec];
|
|
|
|
+ elftype:=AType;
|
|
|
|
+ elfflags:=AFlags;
|
|
|
|
+ align:=Aalign;
|
|
relocHead:=nil;
|
|
relocHead:=nil;
|
|
relocTail:=@relocHead;
|
|
relocTail:=@relocHead;
|
|
Len:=0;
|
|
Len:=0;
|
|
|
|
+ Pos:=0;
|
|
NRelocs:=0;
|
|
NRelocs:=0;
|
|
if sec=sec_bss then
|
|
if sec=sec_bss then
|
|
data:=nil
|
|
data:=nil
|
|
else
|
|
else
|
|
new(Data,Init(1,8192));
|
|
new(Data,Init(1,8192));
|
|
|
|
+ new(rel,Init(1,8192));
|
|
|
|
+ gsyms:=nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- destructor tcoffsection.done;
|
|
|
|
|
|
+ constructor initname(const Aname:string;Atype,Aflags,Aalign:longint);
|
|
|
|
+ begin
|
|
|
|
+ index:=sec_none;
|
|
|
|
+ name:=Aname;
|
|
|
|
+ elftype:=AType;
|
|
|
|
+ elfflags:=AFlags;
|
|
|
|
+ align:=Aalign;
|
|
|
|
+ relocHead:=nil;
|
|
|
|
+ relocTail:=@relocHead;
|
|
|
|
+ Len:=0;
|
|
|
|
+ Pos:=0;
|
|
|
|
+ NRelocs:=0;
|
|
|
|
+ new(Data,Init(1,8192));
|
|
|
|
+ new(rel,Init(1,8192));
|
|
|
|
+ gsyms:=nil;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ destructor telfsection.done;
|
|
begin
|
|
begin
|
|
if assigned(Data) then
|
|
if assigned(Data) then
|
|
dispose(Data,done);
|
|
dispose(Data,done);
|
|
|
|
+ if assigned(rel) then
|
|
|
|
+ dispose(rel,done);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tcoffsection.write(var d;l:longint);
|
|
|
|
|
|
+ procedure telfsection.write(var d;l:longint);
|
|
begin
|
|
begin
|
|
if not assigned(Data) then
|
|
if not assigned(Data) then
|
|
Internalerror(3334441);
|
|
Internalerror(3334441);
|
|
@@ -173,7 +240,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tcoffsection.alloc(l:longint);
|
|
|
|
|
|
+ procedure telfsection.alloc(l:longint);
|
|
begin
|
|
begin
|
|
if assigned(Data) then
|
|
if assigned(Data) then
|
|
Internalerror(3334442);
|
|
Internalerror(3334442);
|
|
@@ -181,7 +248,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tcoffsection.addsymreloc(ofs:longint;p:pasmsymbol;relative:relative_type);
|
|
|
|
|
|
+ procedure telfsection.addsymreloc(ofs:longint;p:pasmsymbol;typ:byte);
|
|
var
|
|
var
|
|
r : PReloc;
|
|
r : PReloc;
|
|
begin
|
|
begin
|
|
@@ -191,13 +258,13 @@ unit og386elf;
|
|
r^.next:=nil;
|
|
r^.next:=nil;
|
|
r^.address:=ofs;
|
|
r^.address:=ofs;
|
|
r^.symbol:=p;
|
|
r^.symbol:=p;
|
|
- r^.section:=sec_none;
|
|
|
|
- r^.relative:=relative;
|
|
|
|
|
|
+ {r^.section:=sec_none;}
|
|
|
|
+ r^.typ:=typ;
|
|
inc(nrelocs);
|
|
inc(nrelocs);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tcoffsection.addsectionreloc(ofs:longint;sec:tsection);
|
|
|
|
|
|
+{ procedure telfsection.addsectionreloc(ofs:longint;sec:tsection);
|
|
var
|
|
var
|
|
r : PReloc;
|
|
r : PReloc;
|
|
begin
|
|
begin
|
|
@@ -210,7 +277,7 @@ unit og386elf;
|
|
r^.section:=sec;
|
|
r^.section:=sec;
|
|
r^.relative:=relative_false;
|
|
r^.relative:=relative_false;
|
|
inc(nrelocs);
|
|
inc(nrelocs);
|
|
- end;
|
|
|
|
|
|
+ end; }
|
|
|
|
|
|
|
|
|
|
{****************************************************************************
|
|
{****************************************************************************
|
|
@@ -226,19 +293,19 @@ unit og386elf;
|
|
strsresize = 8192;
|
|
strsresize = 8192;
|
|
{$endif}
|
|
{$endif}
|
|
|
|
|
|
- constructor tgenericcoffoutput.init;
|
|
|
|
|
|
+ constructor telfoutputput.init;
|
|
begin
|
|
begin
|
|
inherited init;
|
|
inherited init;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- destructor tgenericcoffoutput.done;
|
|
|
|
|
|
+ destructor telfoutputput.done;
|
|
begin
|
|
begin
|
|
inherited done;
|
|
inherited done;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.initwriting;
|
|
|
|
|
|
+ procedure telfoutputput.initwriting;
|
|
var
|
|
var
|
|
s : string;
|
|
s : string;
|
|
begin
|
|
begin
|
|
@@ -246,12 +313,16 @@ unit og386elf;
|
|
{ reset }
|
|
{ reset }
|
|
initsym:=0;
|
|
initsym:=0;
|
|
new(syms,init(sizeof(TSymbol),symbolresize));
|
|
new(syms,init(sizeof(TSymbol),symbolresize));
|
|
- new(strs,init(1,strsresize));
|
|
|
|
FillChar(Sects,sizeof(Sects),0);
|
|
FillChar(Sects,sizeof(Sects),0);
|
|
- { we need at least the following 3 sections }
|
|
|
|
|
|
+ { default sections }
|
|
|
|
+ new(symtab_sect,initname('.symtab',2,4));
|
|
|
|
+ new(strtab_sect,initname('.strtab',3,1));
|
|
|
|
+ new(shstrtab_sect,initname('.shstrtab',3,1));
|
|
|
|
+ { we need at least the following sections }
|
|
createsection(sec_code);
|
|
createsection(sec_code);
|
|
createsection(sec_data);
|
|
createsection(sec_data);
|
|
createsection(sec_bss);
|
|
createsection(sec_bss);
|
|
|
|
+ { create stabs sections if debugging }
|
|
if (cs_debuginfo in aktmoduleswitches) then
|
|
if (cs_debuginfo in aktmoduleswitches) then
|
|
begin
|
|
begin
|
|
createsection(sec_stab);
|
|
createsection(sec_stab);
|
|
@@ -264,7 +335,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.donewriting;
|
|
|
|
|
|
+ procedure telfoutputput.donewriting;
|
|
var
|
|
var
|
|
sec : tsection;
|
|
sec : tsection;
|
|
begin
|
|
begin
|
|
@@ -278,49 +349,37 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- function tgenericcoffoutput.text_flags : longint;
|
|
|
|
- begin
|
|
|
|
- text_flags:=0;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- function tgenericcoffoutput.data_flags : longint;
|
|
|
|
- begin
|
|
|
|
- data_flags:=0;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- function tgenericcoffoutput.bss_flags : longint;
|
|
|
|
- begin
|
|
|
|
- bss_flags:=0;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
- function tgenericcoffoutput.info_flags : longint;
|
|
|
|
- begin
|
|
|
|
- info_flags:=0;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- procedure tgenericcoffoutput.createsection(sec:TSection);
|
|
|
|
|
|
+ procedure telfoutputput.createsection(sec:tsection);
|
|
var
|
|
var
|
|
- Aflags : longint;
|
|
|
|
|
|
+ Aflags,AType,AAlign : longint;
|
|
begin
|
|
begin
|
|
Aflags:=0;
|
|
Aflags:=0;
|
|
|
|
+ Atype:=0;
|
|
case sec of
|
|
case sec of
|
|
sec_code :
|
|
sec_code :
|
|
- Aflags:=text_flags;
|
|
|
|
|
|
+ begin
|
|
|
|
+ Aflags:=SHF_ALLOC or SHF_EXECINSTR;
|
|
|
|
+ AType:=SHT_PROGBITS;
|
|
|
|
+ AAlign:=16;
|
|
|
|
+ end;
|
|
sec_data :
|
|
sec_data :
|
|
- Aflags:=data_flags;
|
|
|
|
|
|
+ begin
|
|
|
|
+ Aflags:=SHF_ALLOC or SHF_WRITE;
|
|
|
|
+ AType:=SHT_PROGBITS;
|
|
|
|
+ AAlign:=4;
|
|
|
|
+ end;
|
|
sec_bss :
|
|
sec_bss :
|
|
- Aflags:=bss_flags;
|
|
|
|
- { sec_info :
|
|
|
|
- Aflags:=info_flags; }
|
|
|
|
- else
|
|
|
|
- Aflags:=0;
|
|
|
|
|
|
+ begin
|
|
|
|
+ Aflags:=SHF_ALLOC or SHF_WRITE;
|
|
|
|
+ AType:=SHT_NOBITS;
|
|
|
|
+ AAlign:=4;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
- sects[sec]:=new(PcoffSection,init(Sec,Aflags));
|
|
|
|
|
|
+ sects[sec]:=new(PElfSection,init(Sec,AType,Aflags,AAlign));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.writesymbol(p:pasmsymbol);
|
|
|
|
|
|
+ procedure telfoutputput.writesymbol(p:pasmsymbol);
|
|
var
|
|
var
|
|
pos : longint;
|
|
pos : longint;
|
|
sym : tsymbol;
|
|
sym : tsymbol;
|
|
@@ -371,7 +430,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.writebytes(var data;len:longint);
|
|
|
|
|
|
+ procedure telfoutputput.writebytes(var data;len:longint);
|
|
begin
|
|
begin
|
|
if not assigned(sects[currsec]) then
|
|
if not assigned(sects[currsec]) then
|
|
createsection(currsec);
|
|
createsection(currsec);
|
|
@@ -379,7 +438,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.writealloc(len:longint);
|
|
|
|
|
|
+ procedure telfoutputput.writealloc(len:longint);
|
|
begin
|
|
begin
|
|
if not assigned(sects[currsec]) then
|
|
if not assigned(sects[currsec]) then
|
|
createsection(currsec);
|
|
createsection(currsec);
|
|
@@ -387,7 +446,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
|
|
|
|
|
|
+ procedure telfoutputput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
|
|
begin
|
|
begin
|
|
if not assigned(sects[currsec]) then
|
|
if not assigned(sects[currsec]) then
|
|
createsection(currsec);
|
|
createsection(currsec);
|
|
@@ -448,7 +507,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean);
|
|
|
|
|
|
+ procedure telfoutputput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc : boolean);
|
|
var
|
|
var
|
|
stab : coffstab;
|
|
stab : coffstab;
|
|
s : tsection;
|
|
s : tsection;
|
|
@@ -483,7 +542,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.write_relocs(s:pcoffsection);
|
|
|
|
|
|
+ procedure telfoutputput.write_relocs(s:pcoffsection);
|
|
var
|
|
var
|
|
rel : coffreloc;
|
|
rel : coffreloc;
|
|
hr,r : preloc;
|
|
hr,r : preloc;
|
|
@@ -515,7 +574,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.write_symbol(const name:string;strpos,value,section,typ,aux:longint);
|
|
|
|
|
|
+ procedure telfoutputput.write_symbol(const name:string;strpos,value,section,typ,aux:longint);
|
|
var
|
|
var
|
|
sym : coffsymbol;
|
|
sym : coffsymbol;
|
|
begin
|
|
begin
|
|
@@ -532,7 +591,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.write_symbols;
|
|
|
|
|
|
+ procedure telfoutputput.write_symbols;
|
|
var
|
|
var
|
|
filename : string[18];
|
|
filename : string[18];
|
|
sec : tsection;
|
|
sec : tsection;
|
|
@@ -572,7 +631,7 @@ unit og386elf;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
- procedure tgenericcoffoutput.writetodisk;
|
|
|
|
|
|
+ procedure telfoutputput.writetodisk;
|
|
var
|
|
var
|
|
datapos,
|
|
datapos,
|
|
nsects,pos,sympos,i,fillsize : longint;
|
|
nsects,pos,sympos,i,fillsize : longint;
|
|
@@ -753,7 +812,10 @@ unit og386elf;
|
|
end.
|
|
end.
|
|
{
|
|
{
|
|
$Log$
|
|
$Log$
|
|
- Revision 1.5 2000-03-19 18:46:50 peter
|
|
|
|
|
|
+ Revision 1.6 2000-03-21 21:36:05 peter
|
|
|
|
+ * some more updates
|
|
|
|
+
|
|
|
|
+ Revision 1.5 2000/03/19 18:46:50 peter
|
|
* some beginning
|
|
* some beginning
|
|
|
|
|
|
}
|
|
}
|