llvm / llvm/llvm-project

[compiler-rt] Missing .note.GNU-stack can produce an executable stack with legacy ld.bfd

Open
#220,866 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Problem

Several ELF compiler-rt assembly sources on LLVM main do not emit
`.note.GNU-stack`, and compiler-rt does not pass a common
`-Wa,--noexecstack` flag to these targets. For example,
`compiler-rt/lib/orc/elfnix_tls.x86-64.S` assembles without the section.

With GNU `ld.bfd` 2.38, linking that object with a normal marked compiler-rt
object produces an executable `PT_GNU_STACK`. Current `ld.lld` produces a
non-executable stack for the same inputs.

### Reproducer

[reproduction.zip](https://github.com/user-attachments/files/31786544/reproduction.zip)

The attached `verify.sh` requires only an LLVM source checkout and existing
LLVM tools; no full LLVM build is needed:

```sh
LLVM_SRC=/path/to/llvm-project \
LLVM_BIN=/path/to/llvm/bin \
OUT=./output \
bash verify.sh
```

Key output:

```text
unmarked representative objects: .note.GNU-stack sections = 0
marked control/-Wa,--noexecstack objects: .note.GNU-stack sections = 1
ld.bfd 2.38 mixed link: PT_GNU_STACK = RWE
ld.lld 24.0.0 mixed link: PT_GNU_STACK = RW
result=still_present
```

### Expected

Every selected ELF compiler-rt assembly object that does not intentionally
execute code from the stack should carry a non-executable `.note.GNU-stack`
section, and a normal link should produce `PT_GNU_STACK` with `RW` rather
than `RWE`.

### Scope

The affected assembly uses the stack for ordinary register/frame data and
does not require executing code from it. The verified impact is limited to
links that select an affected object and use legacy GNU linker behavior;
current LLD did not reproduce it.

### Suggested fix

Propagate an ELF-gated `-Wa,--noexecstack` option through the compiler-rt
assembler target flags, or add the marker to affected ELF assembly sources.
Document and test any genuine executable-stack exception explicitly.

LLVM HEAD: `303475a57c121e13b3363a4ef0e3fcd52523457c`

Contributor guide

Open the contributing guide

Research direction

Start with compiler-rt/lib/orc/elfnix_tls.x86-64.S and run the supplied verify.sh using an LLVM source checkout and existing LLVM tools. Inspect the compiler-rt assembler target flags and the affected ELF assembly sources to determine the applicable scope. Done means affected objects carry a non-executable .note.GNU-stack marker and the mixed GNU ld.bfd link reports PT_GNU_STACK as RW rather than RWE.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.