Skip to content

Commit

Permalink
Merge pull request #242 from illusion0001/patch-2
Browse files Browse the repository at this point in the history
Fix build for llvm 14+
  • Loading branch information
kiwidoggie authored Jul 6, 2023
2 parents 368f830 + 2931a94 commit 3f75068
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 49 deletions.
122 changes: 108 additions & 14 deletions .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,48 @@ on:

jobs:
build:
strategy:
fail-fast: false
matrix:
llvm: [ '10', '11', '12', '13', '14', '15', '16' ]
runs-on: ubuntu-latest
steps:

- name: Checkout
- name: Checkout OOSDK
uses: actions/checkout@v3

- name: Checkout musl
uses: actions/checkout@v3
with:
repository: OpenOrbis/musl
path: musl

- name: Checkout create-fself
uses: actions/checkout@v3
with:
repository: OpenOrbis/create-fself
path: create-fself

- name: Checkout orbis-lib-gen
uses: actions/checkout@v3
with:
repository: OpenOrbis/orbis-lib-gen
path: orbis-lib-gen

- name: Checkout ps4libdoc
uses: actions/checkout@v3
with:
repository: idc/ps4libdoc
path: orbis-lib-gen/ps4libdoc
ref: '5.05'

- name: Set environment variables
run: |
echo "OO_PS4_TOOLCHAIN=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo llvm_ver=12.0 >> $GITHUB_ENV
echo "llvm_path=$RUNNER_TOOL_CACHE/llvm" >> $GITHUB_ENV
echo llvm_ver=${{ matrix.llvm }} >> $GITHUB_ENV
echo "llvm_path=${{ runner.tool_cache }}/llvm" >> $GITHUB_ENV
# llvm 13 fix for ci
sudo apt install libncurses5
- name: Cache LLVM and Clang (${{ env.llvm_ver }})
id: cache-llvm
Expand All @@ -33,24 +64,77 @@ jobs:
key: llvm-${{ env.llvm_ver }}

- name: Install LLVM and Clang (${{ env.llvm_ver }})
uses: KyleMayes/install-llvm-action@v1
uses: KyleMayes/install-llvm-action@master
with:
version: ${{ env.llvm_ver }}
directory: ${{ env.llvm_path }}
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- name: Set up musl environment
working-directory: musl
run: |
mkdir ps4
clang -v
./configure --target=x86_64-scei-ps4 --disable-shared CC="clang" \
CFLAGS="-fPIC -DPS4 -D_LIBUNWIND_IS_BAREMETAL=1" \
--prefix=./ps4
- name: Build musl
working-directory: musl
run: make

- name: Install musl
working-directory: musl
run: |
make install
cp -r ps4/include/* ../include/
cp -r ps4/lib/* ../lib/
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: Build create-fself
working-directory: create-fself/cmd/create-fself
run: |
GOOS=windows go build -o ${{ github.workspace }}/bin/windows/create-fself.exe -modfile=go-linux.mod
go build -o ${{ github.workspace }}/bin/linux/create-fself -modfile=go-linux.mod
GOOS=darwin go build -o ${{ github.workspace }}/bin/macos/create-fself-macos -modfile=go-linux.mod
- name: Generate library stub sources
working-directory: orbis-lib-gen
run: python generate.py ps4libdoc/system/common/lib

- name: Generate makefile
working-directory: orbis-lib-gen
run: python gen_makefile.py

- name: Build library stubs
working-directory: orbis-lib-gen/build
run: make

- name: Install library stubs
working-directory: orbis-lib-gen
run: |
rm build/out/libc.so
cp -r build/out/* ../lib/
- name: Remove built dependencies
run: |
rm -rf create-fself
rm -rf musl
rm -rf orbis-lib-gen
- name: Download and extract dependencies
run: |
curl -sL https://github.com/OpenOrbis/musl/releases/latest/download/musl.tar.gz | tar xz -C ./
curl -sL https://github.com/OpenOrbis/llvm-project/releases/latest/download/libcxx-full.tar.gz | tar xz -C ./
curl -sL https://github.com/OpenOrbis/SDL-PS4/releases/latest/download/SDL2.tar.gz | tar xz -C ./
curl -sL https://github.com/OpenOrbis/orbis-lib-gen/releases/latest/download/lib.tar.gz | tar xz -C ./
curl -sL https://github.com/OpenOrbis/create-fself/releases/latest/download/binaries.tar.gz | tar xz -C ./
curl -sL https://github.com/OpenOrbis/create-gp4/releases/latest/download/binaries.tar.gz | tar xz -C ./
curl -sL https://github.com/OpenOrbis/readoelf/releases/latest/download/binaries.tar.gz | tar xz -C ./
# Get maxton's publishing tools <3
- name: Download and extract maxton's Publishing Tools
- name: "Download and extract maxton's Publishing Tools"
run: |
BASE_URL="https://github.com/maxton/LibOrbisPkg/releases/latest/download"
curl -sL $BASE_URL/PkgEditor-0.2.231.zip | busybox unzip - -o -d bin/windows
Expand Down Expand Up @@ -79,8 +163,8 @@ jobs:
working-directory: src/modules
run: bash build-and-copy.sh

- name: Create tarball
run: tar -czf toolchain.tar.gz --transform 's,^,OpenOrbis/PS4Toolchain/,' *
- name: Create toolchain tarball
run: tar -czf toolchain-llvm-${{ env.llvm_ver }}.tar.gz --transform 's,^,OpenOrbis/PS4Toolchain/,' *

- name: Build samples
working-directory: samples
Expand All @@ -89,12 +173,22 @@ jobs:
- name: Upload toolchain
uses: actions/upload-artifact@v3
with:
name: toolchain
path: toolchain.tar.gz
name: toolchain-llvm-${{ env.llvm_ver }}
path: toolchain-llvm-${{ env.llvm_ver }}.tar.gz
if-no-files-found: error

- name: Upload samples
- name: Upload samples packages
uses: actions/upload-artifact@v3
with:
name: samples
name: samples-pkg-llvm-${{ env.llvm_ver }}
path: samples/**/*.pkg

- name: Upload samples binaries
uses: actions/upload-artifact@v3
with:
name: samples-elf-llvm-${{ env.llvm_ver }}
path: |
samples/**/*.elf
samples/**/*.so
src/**/*.elf
src/**/*.so
16 changes: 11 additions & 5 deletions src/crt/crtlib.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdint.h>

void(*__init_array_start[])(void);
void(*__init_array_end[])(void);

Expand Down Expand Up @@ -28,23 +30,27 @@ __asm__(
".att_syntax prefix \n"
);

int __attribute__((visibility("hidden"))) module_start(unsigned long long args, const void* argp)
int32_t __attribute__((visibility("hidden"))) module_start(int64_t args, const void* argp)
{
// Iterate init array and initialize all objects
for(void(**i)(void) = __init_array_start; i != __init_array_end; i++)
i[0]();
{
i[0]();
}
return 0;
}

int __attribute__((visibility("hidden"))) module_stop(unsigned long long args, const void* argp)
int32_t __attribute__((visibility("hidden"))) module_stop(int64_t args, const void* argp)
{
return 0;
}

int _init()
int32_t _init()
{
return 0;
}

int _fini()
int32_t _fini()
{
return 0;
}
3 changes: 0 additions & 3 deletions src/modules/build-and-copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
cd libc/
make clean && make
cp libc.prx ../libc.prx
make clean

cd ../libSceFios2
make clean && make
cp libSceFios2.prx ../libSceFios2.prx
make clean

cd ../right
make clean && make
cp right.sprx ../right.sprx
make clean

# Copy into samples
cd ..
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int __dummy__sce_fios2_func()
{
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int __dummy__libc_func()
{
return 0;
}
}
18 changes: 11 additions & 7 deletions src/modules/right/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ LIBS := -lSceLibcInternal -lkernel

# Compiler options. You likely won't need to touch these.
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)
CC := clang++
LD := ld.lld
CDIR := linux
CC := clang
CCX := clang++
LD := ld.lld
CDIR := linux
endif
ifeq ($(UNAME_S),Darwin)
CC := /usr/local/opt/llvm/bin/clang++
LD := /usr/local/opt/llvm/bin/ld.lld
CDIR := macos
CC := /usr/local/opt/llvm/bin/clang
CCX := /usr/local/opt/llvm/bin/clang++
LD := /usr/local/opt/llvm/bin/ld.lld
CDIR := macos
endif

ODIR := $(INTDIR)
SDIR := $(PROJDIR)
IDIRS := -I$(TOOLCHAIN)/include
LDIRS := -L$(TOOLCHAIN)/lib
CFLAGS := -cc1 -triple x86_64-scei-ps4-elf -munwind-tables $(IDIRS) -emit-obj
CFLAGS := -cc1 -triple x86_64-scei-ps4-elf $(IDIRS) -emit-obj
LFLAGS := -m elf_x86_64 -pie --version-script="right/right.version" --script $(TOOLCHAIN)/link.x --eh-frame-hdr $(LDIRS) $(LIBS) $(TOOLCHAIN)/lib/crtlib.o

CFILES := $(wildcard $(SDIR)/*.c)
Expand Down
10 changes: 5 additions & 5 deletions src/modules/right/right/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ uint32_t sceGameRightGetVersion()
return 1;
}

void* sceGameRightGetString()
const char* sceGameRightGetString()
{
return string_data;
}

int32_t sceGameRightGetStringSizeInBytes()
{
return (int32_t)size_string_data;
return (int32_t)sizeof(string_data);
}

void* sceGameRightGetLogoPngImage()
{
return logo_data;
return (void*)logo_data;
}

int32_t sceGameRightGetLogoPngImageSizeInBytes()
{
return (int32_t)size_logo_data;
}
return (int32_t)sizeof(logo_data);
}
1 change: 0 additions & 1 deletion src/modules/right/right/logo_data.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef __logo_data__
#define __logo_data__

static const size_t size_logo_data = 25095;
static uint8_t logo_data[] __attribute__((aligned(16))) =
{
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/right/right/right.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sceGameRight {
global: sceGameRight*;
local: *;
};
};
12 changes: 1 addition & 11 deletions src/modules/right/right/string_data.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#ifndef __string_data__
#define __string_data__

static const size_t size_string_data = 108;
static uint8_t string_data[] __attribute__((aligned(16))) =
{
0x48, 0x6F, 0x6D, 0x65, 0x62, 0x72, 0x65, 0x77, 0x20, 0x77, 0x61, 0x73, 0x20, 0x62, 0x75, 0x69,
0x6C, 0x74, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x4F, 0x70, 0x65, 0x6E,
0x4F, 0x72, 0x62, 0x69, 0x73, 0x20, 0x50, 0x53, 0x34, 0x20, 0x54, 0x6F, 0x6F, 0x6C, 0x63, 0x68,
0x61, 0x69, 0x6E, 0x2E, 0x0D, 0x0A, 0x0D, 0x0A, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x4F, 0x70, 0x65, 0x6E, 0x4F,
0x72, 0x62, 0x69, 0x73, 0x2F, 0x4F, 0x70, 0x65, 0x6E, 0x4F, 0x72, 0x62, 0x69, 0x73, 0x2D, 0x50,
0x53, 0x34, 0x2D, 0x54, 0x6F, 0x6F, 0x6C, 0x63, 0x68, 0x61, 0x69, 0x6E,
};
static const char string_data[] __attribute__((aligned(16))) = "Homebrew was built with the OpenOrbis PS4 Toolchain.\n\nhttps://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain";

#endif

0 comments on commit 3f75068

Please sign in to comment.