Bug 37139 - DEP prevents using Ada tasking
Summary: DEP prevents using Ada tasking
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.1.3
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-16 15:50 UTC by Silas Parker
Modified: 2016-10-16 20:16 UTC (History)
2 users (show)

See Also:
Host: pentium-mingw32msv
Target: pentium-mingw32msv
Build: pentium-mingw32msv
Known to work:
Known to fail:
Last reconfirmed: 2009-03-08 09:18:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Silas Parker 2008-08-16 15:50:38 UTC
When DEP (Data Execution Prevention) is enabled for an Ada program using tasks, an exception is raised.

Actual behaviour: Exception PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION raised
Expected behaviour: Program executes correctly

Operating System: Microsoft Windows Vista (64 bit)

Minimal program:
task_test.adb
procedure Task_Test is
	task Test;
	task body Test is
	begin
		null;
	end Test;
begin
	null;
end Task_Test;

Observed output:

>gcc -v
Using built-in specs.
Target: pentium-mingw32msv
Configured with: /pristina.a/gnatmail/release-gpl/build-pristina/src/configure --prefix=/gnat-prefix --target=pentium-mingw32msv --host=pentium-mingw32msv --build=pentium-mingw32msv --enable-languages=c,ada --disable-nls --disable-libada --enable-checking=release --enable-threads=win32 --disable-sjlj-exceptions
Thread model: win32
gcc version 4.1.3 20080522 for GNAT GPL 2008 (20080521)

>gnatmake task_test.adb
gcc -c task_test.adb
gnatbind -x task_test.ali
gnatlink task_test.ali

>task_test.exe

raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION


Under gdb the following is observed:
Program received signal SIGSEGV, Segmentation fault.
[Switching to thread 6852.0x1510]
0x0027ff02 in ?? ()
(gdb) bt
#0  0x0027ff02 in ?? ()
#1  0x00404f01 in system.tasking.stages.task_wrapper ()
(gdb) info tasks
  ID       TID P-ID Pri State                  Name
   1    3225d8    0  15 Child Activation Wait  main_task
*  2    322df8    1  15 Running                test

This problem can be prevented by excluding the program from DEP by adding it to the excluded programs list, but DEP is a useful security feature.  The exclusion list can be accessed by opening 'System' in control panel, clicking 'Advanced system settings', then the 'Advanced' tab, the 'Settings' button next to 'Performance', then the 'Data Execution Prevention' tab, clicking the 'Add' button allows an exclusion to be made when DEP is enabled for all programs.
Comment 1 Eric Botcazou 2009-03-08 09:18:46 UTC
The stack must be executable because of trampolines.
Comment 2 Eric Botcazou 2016-10-16 20:14:04 UTC
Author: ebotcazou
Date: Sun Oct 16 20:13:32 2016
New Revision: 241222

URL: https://gcc.gnu.org/viewcvs?rev=241222&root=gcc&view=rev
Log:
	PR ada/37139
	PR ada/67205
	* common.opt (-ftrampolines): New option.
	* doc/invoke.texi (Code Gen Options): Document it.
	* doc/tm.texi.in (Trampolines): Add TARGET_CUSTOM_FUNCTION_DESCRIPTORS.
	* doc/tm.texi: Regenerate.
	* builtins.def: Add init_descriptor and adjust_descriptor.
	* builtins.c (expand_builtin_init_trampoline): Do not issue a warning
	on platforms with descriptors.
	(expand_builtin_init_descriptor): New function.
	(expand_builtin_adjust_descriptor): Likewise.
	(expand_builtin) <BUILT_IN_INIT_DESCRIPTOR>: New case.
	<BUILT_IN_ADJUST_DESCRIPTOR>: Likewise.
	* calls.c (prepare_call_address): Remove SIBCALLP parameter and add
	FLAGS parameter.  Deal with indirect calls by descriptor and adjust.
	Set STATIC_CHAIN_REG_P on the static chain register, if any.
	(call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by descriptor.
	(expand_call): Likewise.  Move around call to prepare_call_address
	and pass all flags to it.
	* cfgexpand.c (expand_call_stmt): Reinstate CALL_EXPR_BY_DESCRIPTOR.
	* gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
	(gimple_call_set_by_descriptor): New setter.
	(gimple_call_by_descriptor_p): New getter.
	* gimple.c (gimple_build_call_from_tree): SetCALL_EXPR_BY_DESCRIPTOR.
	(gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
	* langhooks.h (struct lang_hooks): Add custom_function_descriptors.
	* langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS): Define.
	(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
	* rtl.h (STATIC_CHAIN_REG_P): New macro.
	* rtlanal.c (find_first_parameter_load): Skip static chain registers.
	* target.def (custom_function_descriptors): New POD hook.
	* tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
	(CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
	* tree-core.h (ECF_BY_DESCRIPTOR): New mask.
	Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
	* tree.c (make_node_stat) <tcc_declaration>: Use FUNCTION_ALIGNMENT.
	(build_common_builtin_nodes): Initialize init_descriptor and
	adjust_descriptor.
	* tree-nested.c: Include target.h.
	(struct nesting_info): Add 'any_descr_created' field.
	(get_descriptor_type): New function.
	(lookup_element_for_decl): New function extracted from...
	(create_field_for_decl): Likewise.
	(lookup_tramp_for_decl): ...here.  Adjust.
	(lookup_descr_for_decl): New function.
	(convert_tramp_reference_op): Deal with descriptors.
	(build_init_call_stmt): New function extracted from...
	(finalize_nesting_tree_1): ...here.  Adjust and deal withdescriptors.
	* defaults.h (FUNCTION_ALIGNMENT): Define.
	(TRAMPOLINE_ALIGNMENT): Set to above instead of FUNCTION_BOUNDARY.
	* config/i386/i386.h (TARGET_CUSTOM_FUNCTION_DESCRIPTORS): Define.
	* config/ia64/ia64.h (TARGET_CUSTOM_FUNCTION_DESCRIPTORS): Likewise.
	* config/rs6000/rs6000.h (TARGET_CUSTOM_FUNCTION_DESCRIPTORS):Likewise.
	* config/sparc/sparc.h (TARGET_CUSTOM_FUNCTION_DESCRIPTORS): Likewise.
ada/
	* gcc-interface/misc.c (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS):Define.
	* gcc-interface/trans.c (Attribute_to_gnu) <Attr_Access>: Deal with
	a zero TARGET_CUSTOM_FUNCTION_DESCRIPTORS specially for Code_Address.
	Otherwise, if TARGET_CUSTOM_FUNCTION_DESCRIPTORS is positive, set
	FUNC_ADDR_BY_DESCRIPTOR for 'Access/'Unrestricted_Access of nested
	subprograms if the type can use an internal representation.
	(call_to_gnu): Likewise, but set CALL_EXPR_BY_DESCRIPTOR on indirect
	calls if the type can use an internal representation.

Added:
    trunk/gcc/testsuite/gnat.dg/trampoline3.adb
    trunk/gcc/testsuite/gnat.dg/trampoline4.adb
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/gcc-interface/misc.c
    trunk/gcc/ada/gcc-interface/trans.c
    trunk/gcc/builtins.c
    trunk/gcc/builtins.def
    trunk/gcc/calls.c
    trunk/gcc/cfgexpand.c
    trunk/gcc/common.opt
    trunk/gcc/config/i386/i386.h
    trunk/gcc/config/ia64/ia64.h
    trunk/gcc/config/rs6000/rs6000.h
    trunk/gcc/config/sparc/sparc.h
    trunk/gcc/defaults.h
    trunk/gcc/doc/invoke.texi
    trunk/gcc/doc/tm.texi
    trunk/gcc/doc/tm.texi.in
    trunk/gcc/gimple.c
    trunk/gcc/gimple.h
    trunk/gcc/langhooks-def.h
    trunk/gcc/langhooks.h
    trunk/gcc/rtl.h
    trunk/gcc/rtlanal.c
    trunk/gcc/target.def
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-core.h
    trunk/gcc/tree-nested.c
    trunk/gcc/tree.c
    trunk/gcc/tree.h
Comment 3 Eric Botcazou 2016-10-16 20:16:06 UTC
At last.