OpenOrbis / create-fself

Golang based tools for taking PC-compatible ELFs and generating fake SELFs that run on the PlayStation 4.
GNU General Public License v3.0
11 stars 3 forks source link

`create-fself` crashes with SIGSEGV when linking with `--gc-sections --as-needed` #6

Open glebm opened 2 years ago

glebm commented 2 years ago

After linking with --gc-sections --as-needed, create-fself crashes with SIGSEGV at OELFGenProgramHeaders.go:116:

FAILED: devilutionx.self /home/gleb/devilutionX/build-ps4/devilutionx.self 
cd /home/gleb/devilutionX/build-ps4 && /usr/bin/cmake -E env OO_PS4_TOOLCHAIN=/opt/pacbrew/ps4/openorbis /opt/pacbrew/ps4/openorbis/bin/create-fself -in=devilutionx -out=devilutionx.oelf --eboot eboot.bin --paid 0x3800000000000035 --authinfo 000000000000000000000000001C004000FF000000000080000000000000000000000000000000000000008000400040000000000000008000000000000000080040FFFF000000F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x4bd64b]

goroutine 1 [running]:
github.com/OpenOrbis/create-fself/pkg/oelf.(*OrbisElf).GenerateProgramHeaders(0xc000185680)
    /home/cpasjuste/dev/pacbrew-packages/ps4-openorbis/create-fself/src/create-fself-30d2e10507f55124cf21e85e19825482e4f93c87/pkg/oelf/OELFGenProgramHeaders.go:116 +0x3ab
main.main()
    /home/cpasjuste/dev/pacbrew-packages/ps4-openorbis/create-fself/src/create-fself-30d2e10507f55124cf21e85e19825482e4f93c87/cmd/create-fself/main.go:94 +0x517
ninja: build stopped: subcommand failed.

The crash happens here:

https://github.com/OpenOrbis/create-fself/blob/30d2e10507f55124cf21e85e19825482e4f93c87/pkg/oelf/OELFGenProgramHeaders.go#L116

More log: https://gist.githubusercontent.com/glebm/49a29bfc641ea3c844cadd08ef18df68/raw/c2ac2268dba8f3c6ec4b69fca7ec4eecf8dbbc33/gistfile1.txt

glebm commented 2 years ago

Steps to reproduce this crash:

# Install system packages and prepare the PS4 toolchain:
sudo apt-get install -y wget cmake git gettext smpq
wget https://github.com/PacBrew/pacbrew-pacman/releases/download/v1.1/pacbrew-pacman-1.1.deb
sudo dpkg -i pacbrew-pacman-1.1.deb
sudo pacbrew-pacman -Sy
sudo pacbrew-pacman --noconfirm -S ps4-openorbis ps4-openorbis-portlibs
echo "#include <endian.h>" | sudo tee /opt/pacbrew/ps4/openorbis/include/sys/endian.h

# Clone DevilutionX
git clone https://github.com/diasurgical/devilutionX.git
cd devilutionX

# Disable the workaround that prevents the crash:
sed -i 's/ AND NOT PS4//' CMakeLists.txt

# Build, will crash here:
Packaging/ps4/build.sh

For the above to work, the changes in https://github.com/PacBrew/ps4-openorbis/pull/7 need to be released