Skip to content

Core fails to load on glibc 2.41+: "cannot enable executable stack as shared object requires" #217

Description

@veralvx

melonds_libretro.so is linked with an executable stack. glibc 2.41 stopped granting that at dlopen time, so on any distribution shipping that glibc or newer, RetroArch cannot load the core.

Log:

[INFO] [Core] Loading dynamic libretro core from: ".../melonds_libretro.so".
[ERROR] [Core] Failed to open libretro core: ".../melonds_libretro.so"
[ERROR] [Core] Error(s): .../melonds_libretro.so: cannot enable executable
        stack as shared object requires: Invalid argument

RetroArch 1.22.2, x86_64, glibc 2.41+.

Cause

src/ARMJIT_x64/ARMJIT_Linkage.S and src/ARMJIT_A64/ARMJIT_Linkage.S are assembled without a .note.GNU-stack section. Given an input object without that note, the linker assumes an executable stack is needed and marks the whole shared object RWE. Makefile:548 builds these files through $(CC) -x assembler-with-cpp, so the mark lands in the core.

Assembling the current:

$ gcc -fPIC -x assembler-with-cpp -c -o before.o src/ARMJIT_x64/ARMJIT_Linkage.S
$ gcc -shared -fPIC -o libbefore.so before.o stub.c
/usr/bin/ld: warning: before.o: missing .note.GNU-stack section implies
executable stack
$ readelf -lW libbefore.so | grep GNU_STACK
  GNU_STACK  0x000000 0x0000000000000000 0x0000000000000000 ... RWE 0x10

glibc 2.41's release notes describe the change.

Fix

PR: #218

Upstream melonDS added the note to both files in 3ab752b (2023-10-22) and refined the platform guards in 2a86ee7 and 63e4b68. Here, ARMJIT_Linkage.S has not changed since 436b3c4 (2021-03-12), so the fix never arrived.

Adding the same four lines to each file produces GNU_STACK RW, and the core loads. Patch and test procedure are in the pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions