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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
http://bugs.gentoo.org/show_bug.cgi?id=228867
http://mantis.freepascal.org/view.php?id=11563
--- fpcbuild-2.2.2/fpcsrc/compiler/aggas.pas
+++ fpcbuild-2.2.2/fpcsrc/compiler/aggas.pas
@@ -1074,6 +1074,13 @@
(target_info.system in systems_darwin) then
AsmWriteLn(#9'.subsections_via_symbols');
+ { "no executable stack" marker for Linux }
+ if (target_info.system in system_linux) and
+ not(cs_executable_stack in current_settings.moduleswitches) then
+ begin
+ AsmWriteLn('.section .note.GNU-stack,"",%progbits');
+ end;
+
AsmLn;
{$ifdef EXTDEBUG}
if assigned(current_module.mainsource) then
--- fpcbuild-2.2.2/fpcsrc/compiler/globtype.pas
+++ fpcbuild-2.2.2/fpcsrc/compiler/globtype.pas
@@ -109,7 +109,9 @@
{ linking }
cs_create_smart,cs_create_dynamic,cs_create_pic,
{ browser switches are back }
- cs_browser,cs_local_browser
+ cs_browser,cs_local_browser,
+ { target specific }
+ cs_executable_stack
);
tmoduleswitches = set of tmoduleswitch;
--- fpcbuild-2.2.2/fpcsrc/compiler/msg/errore.msg
+++ fpcbuild-2.2.2/fpcsrc/compiler/msg/errore.msg
@@ -2704,6 +2704,7 @@
3*1W<x>_Target-specific options (targets)
A*1W<x>_Target-specific options (targets)
P*1W<x>_Target-specific options (targets)
+p*1W<x>_Target-specific options (targets)
3*2Wb_Create a bundle instead of a library (Darwin)
P*2Wb_Create a bundle instead of a library (Darwin)
p*2Wb_Create a bundle instead of a library (Darwin)
@@ -2723,6 +2724,10 @@
3*2WR_Generate relocation code (Windows)
A*2WR_Generate relocation code (Windows)
P*2WT_Specify MPW tool type application (Classic Mac OS)
+3*2WX_Enable executable stack (Linux)
+A*2WX_Enable executable stack (Linux)
+p*2WX_Enable executable stack (Linux)
+P*2WX_Enable executable stack (Linux)
**1X_Executable options:
**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Linux)
**2Xd_Do not use standard library search path (needed for cross compile)
--- fpcbuild-2.2.2/fpcsrc/compiler/msgidx.inc
+++ fpcbuild-2.2.2/fpcsrc/compiler/msgidx.inc
@@ -740,7 +740,7 @@
option_info=11024;
option_help_pages=11025;
- MsgTxtSize = 46171;
+ MsgTxtSize = 46365;
MsgIdxMax : array[1..20] of longint=(
24,87,250,84,63,50,108,22,135,61,
--- fpcbuild-2.2.2/fpcsrc/compiler/msgtxt.inc
+++ fpcbuild-2.2.2/fpcsrc/compiler/msgtxt.inc
@@ -1,7 +1,7 @@
{$ifdef Delphi}
-const msgtxt : array[0..000192] of string[240]=(
+const msgtxt : array[0..000193] of string[240]=(
{$else Delphi}
-const msgtxt : array[0..000192,1..240] of char=(
+const msgtxt : array[0..000193,1..240] of char=(
{$endif Delphi}
'01000_T_Compiler: $1'#000+
'01001_D_Compiler OS: $1'#000+
@@ -1055,48 +1055,53 @@
'3*1W<x>_Target-specific options (targets)'#010+
'A*1W<x>_Target-specific options (targets)'#010+
'P*1W<x>_Target-specific options (targets)'#010+
- '3*2Wb_Create a bundle instead of a ','library (Darwin)'#010+
+ 'p*1W<x>_Target-specific options (ta','rgets)'#010+
+ '3*2Wb_Create a bundle instead of a library (Darwin)'#010+
'P*2Wb_Create a bundle instead of a library (Darwin)'#010+
'p*2Wb_Create a bundle instead of a library (Darwin)'#010+
'3*2WB_Create a relocatable image (Windows)'#010+
- 'A*2WB_Create a relocatable image (Windows, Symbian)'#010+
- '3*2WC_Specify console ty','pe application (EMX, OS/2, Windows)'#010+
+ 'A*2WB_Create a relocatable image (','Windows, Symbian)'#010+
+ '3*2WC_Specify console type application (EMX, OS/2, Windows)'#010+
'A*2WC_Specify console type application (Windows)'#010+
'P*2WC_Specify console type application (Classic Mac OS)'#010+
- '3*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
- 'A*2WD_Use DEFFILE to export functions',' of DLL or EXE (Windows)'#010+
+ '3*2WD_Use DEFFILE to export functions of DLL or EXE (Wind','ows)'#010+
+ 'A*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
'3*2WF_Specify full-screen type application (EMX, OS/2)'#010+
'3*2WG_Specify graphic type application (EMX, OS/2, Windows)'#010+
'A*2WG_Specify graphic type application (Windows)'#010+
- 'P*2WG_Specify graphic type application (Classic Mac',' OS)'#010+
+ 'P*2WG_Spe','cify graphic type application (Classic Mac OS)'#010+
'3*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
'A*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
'3*2WR_Generate relocation code (Windows)'#010+
- 'A*2WR_Generate relocation code (Windows)'#010+
- 'P*2WT_Specify',' MPW tool type application (Classic Mac OS)'#010+
- '**1X_Executable options:'#010+
+ 'A*2WR_Genera','te relocation code (Windows)'#010+
+ 'P*2WT_Specify MPW tool type application (Classic Mac OS)'#010+
+ '3*2WX_Enable executable stack (Linux)'#010+
+ 'A*2WX_Enable executable stack (Linux)'#010+
+ 'p*2WX_Enable executable stack (Linux)'#010+
+ 'P*2WX_Enable executable stack (Linux)'#010+
+ '**','1X_Executable options:'#010+
'**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Lin'+
'ux)'#010+
'**2Xd_Do not use standard library search path (needed for cross compil'+
'e)'#010+
- '**2Xe_Use external linke','r'#010+
- '**2Xg_Create debuginfo in a separate file and add a debuglink section '+
- 'to executable'#010+
+ '**2Xe_Use external linker'#010+
+ '**2Xg_Create debuginfo in a separate file an','d add a debuglink sectio'+
+ 'n to executable'#010+
'**2XD_Try to link units dynamically (defines FPC_LINK_DYNAMIC)'#010+
'**2Xi_Use internal linker'#010+
'**2Xm_Generate link map'#010+
- '**2XM<x>_Set the name of the '#039'main'#039' ','program routine (default'+
- ' is '#039'main'#039')'#010+
- '**2XP<x>_Prepend the binutils names with the prefix <x>'#010+
+ '**2XM<x>_Set the name of the '#039'main'#039' program routine (default i'+
+ 's '#039'main'#039')'#010+
+ '**2XP<x>_P','repend the binutils names with the prefix <x>'#010+
'**2Xr<x>_Set library search path to <x> (needed for cross compile) (Be'+
'OS, Linux)'#010+
- '**2XR<x>_Prepend <x> to all linker search paths (BeOS, Darwin, Free','B'+
- 'SD, Linux, Mac OS, Solaris)'#010+
- '**2Xs_Strip all symbols from executable'#010+
+ '**2XR<x>_Prepend <x> to all linker search paths (BeOS, Darwin, FreeBSD'+
+ ', Linux, Mac OS, Solaris)'#010+
+ '**2Xs_Strip all s','ymbols from executable'#010+
'**2XS_Try to link units statically (default, defines FPC_LINK_STATIC)'#010+
'**2Xt_Link with static libraries (-static is passed to linker)'#010+
- '**2XX_Try to smartlink units ',' (defines FPC_LINK_SMART)'#010+
+ '**2XX_Try to smartlink units (defines FPC_LINK_SMART)'#010+
'**1*_'#010+
- '**1?_Show this help'#010+
+ '**1?_Show th','is help'#010+
'**1h_Shows this help without waiting'#000
);
--- fpcbuild-2.2.2/fpcsrc/compiler/ogelf.pas
+++ fpcbuild-2.2.2/fpcsrc/compiler/ogelf.pas
@@ -1021,6 +1021,10 @@
symtabsect:=TElfObjSection.create_ext(ObjSectionList,'.symtab',SHT_SYMTAB,0,0,0,4,sizeof(telfsymbol));
strtabsect:=TElfObjSection.create_ext(ObjSectionList,'.strtab',SHT_STRTAB,0,0,0,1,0);
shstrtabsect:=TElfObjSection.create_ext(ObjSectionList,'.shstrtab',SHT_STRTAB,0,0,0,1,0);
+ { "no executable stack" marker for Linux }
+ if (target_info.system in system_linux) and
+ not(cs_executable_stack in current_settings.moduleswitches) then
+ TElfObjSection.create_ext(ObjSectionList,'.note.GNU-stack',SHT_PROGBITS,0,0,0,1,0);
{ insert the empty and filename as first in strtab }
strtabsect.writestr(#0);
strtabsect.writestr(ExtractFileName(current_module.mainsource^)+#0);
--- fpcbuild-2.2.2/fpcsrc/compiler/options.pas
+++ fpcbuild-2.2.2/fpcsrc/compiler/options.pas
@@ -1357,6 +1357,18 @@
else
apptype:=app_tool;
end;
+ 'X':
+ begin
+ if (target_info.system in system_linux) then
+ begin
+ if UnsetBool(More, j) then
+ exclude(init_settings.moduleswitches,cs_executable_stack)
+ else
+ include(init_settings.moduleswitches,cs_executable_stack)
+ end
+ else
+ IllegalPara(opt);
+ end
else
IllegalPara(opt);
end;
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/cprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/cprt0.as
@@ -135,3 +135,5 @@
2: .long 0
.long 2,0,0
3: .align 4
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/gprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/gprt0.as
@@ -90,3 +90,4 @@
.long 2,0,0
3: .align 4
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/prt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/prt0.as
@@ -108,3 +108,5 @@
2: .long 0
.long 2,0,0
3: .align 4
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/ucprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/arm/ucprt0.as
@@ -178,3 +178,5 @@
2: .long 0
.long 2,0,0
3: .align 4
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/cprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/cprt0.as
@@ -105,3 +105,5 @@
.set operatingsystem_parameter_envp,operatingsystem_parameters+0
.set operatingsystem_parameter_argc,operatingsystem_parameters+4
.set operatingsystem_parameter_argv,operatingsystem_parameters+8
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/cprt21.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/cprt21.as
@@ -122,3 +122,5 @@
.set operatingsystem_parameter_envp,operatingsystem_parameters+0
.set operatingsystem_parameter_argc,operatingsystem_parameters+4
.set operatingsystem_parameter_argv,operatingsystem_parameters+8
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/dllprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/dllprt0.as
@@ -72,3 +72,4 @@
.set operatingsystem_parameter_argc,operatingsystem_parameters+4
.set operatingsystem_parameter_argv,operatingsystem_parameters+8
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/gprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/gprt0.as
@@ -87,3 +87,5 @@
.set operatingsystem_parameter_envp,operatingsystem_parameters+0
.set operatingsystem_parameter_argc,operatingsystem_parameters+4
.set operatingsystem_parameter_argv,operatingsystem_parameters+8
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/gprt21.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/gprt21.as
@@ -136,3 +136,4 @@
.set operatingsystem_parameter_argc,operatingsystem_parameters+4
.set operatingsystem_parameter_argv,operatingsystem_parameters+8
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/prt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/i386/prt0.as
@@ -109,3 +109,4 @@
//.section .threadvar,"aw",@nobits
.comm ___fpc_threadvar_offset,4
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc/cprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc/cprt0.as
@@ -117,3 +117,4 @@
.comm operatingsystem_parameter_argc, 4
.comm operatingsystem_parameter_argv, 4
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc/prt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc/prt0.as
@@ -67,3 +67,5 @@
.comm operatingsystem_parameter_envp,4
.comm operatingsystem_parameter_argc,4
.comm operatingsystem_parameter_argv,4
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc64/cprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc64/cprt0.as
@@ -433,3 +433,5 @@
.comm operatingsystem_parameter_argc, 4
.comm operatingsystem_parameter_argv, 8
.comm operatingsystem_parameter_envp, 8
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc64/gprt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc64/gprt0.as
@@ -439,3 +439,5 @@
.comm operatingsystem_parameter_argc, 4
.comm operatingsystem_parameter_argv, 8
.comm operatingsystem_parameter_envp, 8
+
+.section .note.GNU-stack,"",%progbits
--- fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc64/prt0.as
+++ fpcbuild-2.2.2/fpcsrc/rtl/linux/powerpc64/prt0.as
@@ -376,3 +376,4 @@
.comm operatingsystem_parameter_argv, 8
.comm operatingsystem_parameter_envp, 8
+.section .note.GNU-stack,"",%progbits
--- /dev/null
+++ fpcbuild-2.2.2/fpcsrc/tests/webtbs/tw11563.pp
@@ -0,0 +1,40 @@
+{ %target=linux}
+{ %result=216 }
+
+program ExecStack;
+ procedure DoIt;
+ type
+ proc = procedure;
+ var
+{$if defined(cpupowerpc) or defined(cpupowerpc64)}
+ ret: longint;
+{$endif}
+{$if defined(cpui386) or defined(cpux86_64)}
+ ret: Byte;
+{$endif}
+{$ifdef cpuarm}
+ 'add arm code to test stack execution'
+{$endif}
+ DoNothing: proc;
+
+ begin
+{$if defined(cpupowerpc) or defined(cpupowerpc64)}
+ { can't use proc(@ret) because linux/ppc64 always expects some kind of
+ trampoline
+ }
+ ret := ($4e shl 24) or ($80 shl 16) or ($00 shl 8) or $20;
+ asm
+ la r0, ret
+ mtctr r0
+ bctrl
+ end;
+{$endif}
+{$if defined(cpui386) or defined(cpux86_64)}
+ ret := $C3;
+ DoNothing := proc(@ret);
+ DoNothing;
+{$endif}
+ end;
+begin
+ DoIt;
+end.
|