gcc-8-riscv64-linux-gnu produces binaries with executable stack by default

Bug #1853740 reported by Wladimir J. van der Laan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-8-cross-ports (Ubuntu)
New
Undecided
Unassigned

Bug Description

The gcc 8 RISC-V cross-compiler on Ubuntu 18.04, in contrast to other architectures such as ARM and x86, does not use noexecstack by default.

$ riscv64-linux-gnu-gcc-8 --version
'riscv64-linux-gnu-gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ echo "int main() { return 0; }" > test.c
$ riscv64-linux-gnu-gcc-8 test.c -o test
$ readelf -lW test|grep GNU_STACK
(no output)

Expected output:

  GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10

$ riscv64-linux-gnu-gcc-8 test.c -c -o test.o
$ scanelf -e test.o
 TYPE STK/REL/PTL FILE
ET_REL !WX --- --- test.o

Expected output:

 TYPE STK/REL/PTL FILE
ET_REL --- --- --- test.o

$ riscv64-linux-gnu-gcc-8 test.c -o test

I've checked with the RISC-V toolchain on Fedora, and that does set the correct GNU_STACK permissions.

So I don't think this is expected behavior, and might result in cross-compiled executables being less hardened than expected.

As a workaround, `-Wl,-z,noexecstack` can be passed to the linker, or `-Wa,-noexecstack` to gcc.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.