1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
{
Copyright (c) 2008 by the Free Pascal Compiler team
This unit implements common support for import,export,link routines
for unix target
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit expunix;
{$i fpcdefs.inc}
interface
uses
cutils,cclasses,
systems,
export,
symtype,symdef,symsym,
aasmbase;
type
texportlibunix=class(texportlib)
private
fexportedsymnames: TCmdStrList;
public
constructor Create; override;
destructor destroy; override;
procedure preparelib(const s : string);override;
procedure exportprocedure(hp : texported_item);override;
procedure exportvar(hp : texported_item);override;
procedure generatelib;override;
property exportedsymnames: TCmdStrList read fexportedsymnames;
end;
implementation
{****************************************************************************
TExportLibUnix
****************************************************************************}
uses
symconst,
globtype,globals,
aasmdata,aasmtai,aasmcpu,
fmodule,
cgbase,cgutils,cpubase,cgobj,
cgcpu,hlcgobj,hlcgcpu,
ncgutil,
verbose;
constructor texportlibunix.create;
begin
inherited create;
fexportedsymnames:=tcmdstrlist.create_no_double;
end;
destructor texportlibunix.destroy;
begin
fexportedsymnames.free;
inherited destroy;
end;
procedure texportlibunix.preparelib(const s:string);
begin
end;
procedure texportlibunix.exportprocedure(hp : texported_item);
var
hp2 : texported_item;
begin
{ first test the index value }
if (hp.options and eo_index)<>0 then
begin
Message1(parser_e_no_export_with_index_for_target,target_info.shortname);
exit;
end;
{ now place in correct order }
hp2:=texported_item(current_module._exports.first);
while assigned(hp2) and
(hp.name^>hp2.name^) do
hp2:=texported_item(hp2.next);
{ insert hp there !! }
if assigned(hp2) and (hp2.name^=hp.name^) then
begin
{ this is not allowed !! }
Message1(parser_e_export_name_double,hp.name^);
exit;
end;
if hp2=texported_item(current_module._exports.first) then
current_module._exports.concat(hp)
else if assigned(hp2) then
begin
hp.next:=hp2;
hp.previous:=hp2.previous;
if assigned(hp2.previous) then
hp2.previous.next:=hp;
hp2.previous:=hp;
end
else
current_module._exports.concat(hp);
end;
procedure texportlibunix.exportvar(hp : texported_item);
begin
hp.is_var:=true;
exportprocedure(hp);
end;
procedure texportlibunix.generatelib; // straight t_linux copy for now.
var
hp2 : texported_item;
pd : tprocdef;
{$ifdef x86}
sym : tasmsymbol;
r : treference;
{$endif x86}
begin
create_hlcodegen;
new_section(current_asmdata.asmlists[al_procedures],sec_code,'',0);
hp2:=texported_item(current_module._exports.first);
while assigned(hp2) do
begin
if (not hp2.is_var) and
(hp2.sym.typ=procsym) then
begin
{ the manglednames can already be the same when the procedure
is declared with cdecl }
pd:=tprocdef(tprocsym(hp2.sym).ProcdefList[0]);
if not has_alias_name(pd,hp2.name^) then
begin
{ place jump in al_procedures }
current_asmdata.asmlists[al_procedures].concat(tai_align.create(target_info.alignment.procalign));
current_asmdata.asmlists[al_procedures].concat(Tai_symbol.Createname_global(hp2.name^,AT_FUNCTION,0));
if (cs_create_pic in current_settings.moduleswitches) and
{ other targets need to be checked how it works }
(target_info.system in [system_i386_freebsd,system_x86_64_freebsd,system_x86_64_linux,system_i386_linux,system_x86_64_solaris,system_i386_solaris,system_i386_android,system_x86_64_dragonfly]) then
begin
{$ifdef x86}
sym:=current_asmdata.RefAsmSymbol(pd.mangledname);
reference_reset_symbol(r,sym,0,sizeof(pint));
if cs_create_pic in current_settings.moduleswitches then
r.refaddr:=addr_pic
else
r.refaddr:=addr_full;
current_asmdata.asmlists[al_procedures].concat(taicpu.op_ref(A_JMP,S_NO,r));
{$endif x86}
end
else
cg.g_external_wrapper(current_asmdata.asmlists[al_procedures],pd,pd.mangledname);
current_asmdata.asmlists[al_procedures].concat(Tai_symbol_end.Createname(hp2.name^));
end;
exportedsymnames.insert(hp2.name^);
end
else
begin
if assigned(hp2.sym) and
(hp2.name^<>hp2.sym.mangledname) then
Message2(parser_e_cant_export_var_different_name,hp2.sym.realname,hp2.sym.mangledname)
else
exportedsymnames.insert(hp2.name^);
end;
hp2:=texported_item(hp2.next);
end;
destroy_hlcodegen;
end;
end.
|