Skip to content

Commit 20449bc

Browse files
yus3710-fjtarunprabhuDavidSpickett
authored
[flang][docs] Add an FAQ about an executable stack (#171241)
Co-authored-by: Tarun Prabhu <[email protected]> Co-authored-by: David Spickett <[email protected]>
1 parent c9df272 commit 20449bc

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

flang/docs/FAQ.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--===- docs/FAQ.md
2+
3+
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
See https://llvm.org/LICENSE.txt for license information.
5+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
-->
8+
9+
# Frequently Asked Questions (FAQ)
10+
11+
```{contents}
12+
---
13+
local:
14+
---
15+
```
16+
17+
## Driver
18+
19+
### Why do I get a warning or an error about an executable stack?
20+
21+
This occurs because Flang's implementation of pointers to internal procedures requires an executable stack.
22+
23+
An internal procedure has a "host scope", which is the scope in which it is contained.
24+
It can access variables defined in that host scope.
25+
When an internal procedure is referenced from outside its host scope (for example, via a procedure pointer), the implementation must ensure that it can still access variables from the host scope.
26+
To achieve this, the current implementation of Flang generates a small piece of code, called a "trampoline", on the stack.
27+
When the procedure is called, this trampoline is executed.
28+
The trampoline is on the stack, so the stack itself must be executable.
29+
For a more detailed explanation of trampolines, please refer to the [design document](InternalProcedureTrampolines.md).
30+
31+
An executable stack increases the risk and impact of certain classes of security vulnerabilities, such as [stack buffer overflows](https://llsoftsec.github.io/llsoftsecbook/#stack-buffer-overflows).
32+
Therefore, modern linkers often issue a warning or an error if an executable stack is not explicitly requested by the developer.
33+
For instance, the GNU Linker (`ld`) issues a warning while the LLVM Linker (`lld`) emits an error.
34+
35+
```{note}
36+
The trampoline code generated by Flang is not itself a security risk.
37+
The risk comes from the possibility of executing malicious code that an attacker has placed on the stack.
38+
You should determine whether such risks are appropriate for your software.
39+
```
40+
41+
When you use the Flang driver (the `flang` command) to generate executables, you can instruct the linker to enable an executable stack with the `-Wl,-z,execstack` or `-Xlinker -zexecstack` flag.
42+
43+
```console
44+
$ flang src.f90 -fuse-ld=ld
45+
/path/to/ld: warning: src.o: requires executable stack (because the .note.GNU-stack section is executable)
46+
$ flang src.f90 -fuse-ld=ld -Wl,-z,execstack
47+
48+
$ flang src.f90 -fuse-ld=lld
49+
ld.lld: error: src.o: requires an executable stack, but -z execstack is not specified
50+
flang-22: error: linker command failed with exit code 1 (use -v to see invocation)
51+
$ flang src.f90 -fuse-ld=lld -Wl,-z,execstack
52+
```

flang/docs/FortranStandardsSupport.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ All features except those listed in the following table are supported.
9595
|------------------------------------------------------------|--------|---------------------------------------------------------|
9696
| Coarrays | N | Lowering and runtime support is not implemented |
9797
| do concurrent | P | Sequential execution works. Parallel support in progress|
98-
| Internal procedure as an actual argument or pointer target | Y | Current implementation requires stack to be executable. See [Proposal](InternalProcedureTrampolines.md) |
98+
| Internal procedure as an actual argument or pointer target | Y | Current implementation requires stack to be executable. See [FAQ](FAQ.md#why-do-i-get-a-warning-or-an-error-about-an-executable-stack) and [Proposal](InternalProcedureTrampolines.md) |
9999

100100
## Fortran 2003
101101
All features except those listed in the following table are supported.

flang/docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on how to get in touch with us and to learn more about the current status.
3030
OpenMPSupport
3131
Real16MathSupport
3232
Unsigned
33+
FAQ
3334
```
3435

3536
# Contributing to Flang

0 commit comments

Comments
 (0)