mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-25 07:46:01 +03:00
[PR #625] [MERGED] Force PIE usage on linux #1674
Labels
No labels
Bloodborne
bug
contributor wanted
documentation
enhancement
frontend
good first issue
help wanted
linux
pull-request
question
release
verification progress
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/shadPS4#1674
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/shadps4-emu/shadPS4/pull/625
Author: @Random06457
Created: 8/28/2024
Status: ✅ Merged
Merged: 9/1/2024
Merged by: @raphaelthegreat
Base:
main← Head:pie📝 Commits (5)
ccd9b5dforce PIE usage on linux65b107aget rid of explicit -pie linker flag1fef188change UNIX with UNIX AND NOT APPLE in CMakeLists.txt24bf84acmake: add proper check for PIE support at link time4541a74Merge pull request #1 from Mixaill/pie📊 Changes
1 file changed (+15 additions, -3 deletions)
View changed files
📝
CMakeLists.txt(+15 -3)📄 Description
It seems the project currently has an implicit requirement that emulator code be located at an address > 40 bits. Otherwise the code gets overwritten when the PS4 memory is allocated, resulting in memory corruptions.
Some linux distributions (e.g. NixOS and fedora(?)) come with a GCC binary built without the
--enable-default-pieconfiguration enabled, which means binaries produces by such systems do not have ASLR support by default.This causes the compiler to emit relocations which aren't compatible with a high base address (e.g.
R_X86_64_32) and the linker to map the base address at a fixed address, which happens to be0x400000according to GNU's default linker script.To address this issue, this PR forces GCC to produce a PIE executable via the
CMAKE_POSITION_INDEPENDENT_CODEcmake variable and adds the-pielinker flag toUNIXtargets.Note that I am not 100% sure that enabling PIE guarantees that the base address is going to be > 40 bits. I only looked at the linux source tree briefly and it seems to be very configuration-dependant. However in practice the 40 bit assumption seems to hold so far, so I guess worst case scenario it only happens once and relaunching the emulator will do just fine. And if it happens too frequently, a proper linker script can be added to force the base address.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.