From cad6d32144e374381d39134d7defecb9e2116da9 Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Wed, 7 Jun 2023 13:34:15 -0400 Subject: [PATCH 1/5] CMake: Bump to 3.4, and set vars properly. - CMake 3.4 is the bare minimum recommended, 3.1 enables pkg-config to search in CMAKE_PREFIX_PATH. - TOOLCHAIN_DEPS_DIR should be a cache variable since it's provided by the commandline. - Set the CMAKE_PREFIX_PATH instead of PKG_CONFIG_PATH. --- CMakeLists.txt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2968a04..77ae432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,9 @@ -cmake_minimum_required(VERSION 2.6) -project(vita-toolchain) +cmake_minimum_required(VERSION 3.4) +project(vita-toolchain LANGUAGES C) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -if (NOT TOOLCHAIN_DEPS_DIR) - set(TOOLCHAIN_DEPS_DIR "${CMAKE_SOURCE_DIR}/builds/deps_build") -endif() -set(ENV{PKG_CONFIG_PATH} "${TOOLCHAIN_DEPS_DIR}/lib/pkgconfig:${TOOLCHAIN_DEPS_DIR}/share/pkgconfig") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/") +set(TOOLCHAIN_DEPS_DIR "${CMAKE_SOURCE_DIR}/builds/deps_build" CACHE PATH "Prefix to search for dependencies in.") +list(APPEND CMAKE_PREFIX_PATH "${TOOLCHAIN_DEPS_DIR}") add_subdirectory(src) add_subdirectory(psp2rela) From 0bfe10c2ed0b4c17fb7d54418c439001b58229d7 Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Wed, 7 Jun 2023 16:37:58 -0400 Subject: [PATCH 2/5] Add a strndup fallback implementation for Windows. --- src/CMakeLists.txt | 21 ++++++++++++++++++++- src/dupstring.c | 24 ++++++++++++++++++++++++ src/dupstring.h | 9 +++++++++ src/elf-create-argp.c | 4 +++- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/dupstring.c create mode 100644 src/dupstring.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 910b559..021c0d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,25 @@ else() set(runtime_destination lib) endif() +# Check if strndup is available, Windows toolchains typically don't provide it +include(CheckCSourceCompiles) +check_c_source_compiles(" +#include +#include +int main() { + free(strndup(\"foo\", 4)); +}" +HAVE_STRNDUP) + +if(HAVE_STRNDUP) + set(STRNDUP_DEF "HAVE_STRNDUP=1") +else() + set(STRNDUP_DEF "HAVE_STRNDUP=0") +endif() + +set_source_files_properties(dupstring.c PROPERTIES + COMPILE_DEFINITIONS ${STRNDUP_DEF}) + add_library(vita-yaml yamltree.c yamltreeutil.c) add_library(vita-export vita-export-parse.c sha256.c) add_library(vita-import vita-import.c vita-import-parse.c) @@ -53,7 +72,7 @@ target_include_directories(vita-import PUBLIC $) add_executable(vita-libs-gen vita-libs-gen.c) -add_executable(vita-elf-create vita-elf-create.c elf-create-argp.c vita-elf.c elf-defs.c sce-elf.c varray.c elf-utils.c yamlemitter.c) +add_executable(vita-elf-create vita-elf-create.c elf-create-argp.c vita-elf.c elf-defs.c sce-elf.c varray.c elf-utils.c yamlemitter.c dupstring.c) add_executable(vita-mksfoex vita-mksfoex.c getopt_long.c) add_executable(vita-make-fself vita-make-fself.c) add_executable(vita-pack-vpk vita-pack-vpk.c) diff --git a/src/dupstring.c b/src/dupstring.c new file mode 100644 index 0000000..0145702 --- /dev/null +++ b/src/dupstring.c @@ -0,0 +1,24 @@ +#include "dupstring.h" + +#include + +#if defined(HAVE_STRNDUP) && HAVE_STRNDUP + +char *dupstring(const char *source, size_t maxlen) { + return strndup(source, maxlen); +} + +#else /* Fallback implementation */ +#include + +char *dupstring(const char *source, size_t maxlen) { + size_t dest_size = strnlen(source, maxlen); + char *dest = malloc(dest_size + 1); + if (dest == NULL) { + return NULL; + } + memcmp(dest, source, dest_size); + dest[dest_size] = '\0'; + return dest; +} +#endif diff --git a/src/dupstring.h b/src/dupstring.h new file mode 100644 index 0000000..2bd5ed1 --- /dev/null +++ b/src/dupstring.h @@ -0,0 +1,9 @@ +#ifndef DUPSTRING_H +#define DUPSTRING_H + +#include + +/* Wrapper around strndup */ +char *dupstring(const char *source, size_t maxlen); + +#endif /* DUPSTRING_H */ diff --git a/src/elf-create-argp.c b/src/elf-create-argp.c index 2c91834..e8d86c0 100644 --- a/src/elf-create-argp.c +++ b/src/elf-create-argp.c @@ -5,6 +5,8 @@ #include #include +#include "dupstring.h" + int parse_arguments(int argc, char *argv[], elf_create_args *arguments) { int c; @@ -76,7 +78,7 @@ int parse_arguments(int argc, char *argv[], elf_create_args *arguments) } size_t entrypoint_length = (size_t)(entrypoint_end - entrypoint); if (entrypoint_length > 0) - arguments->entrypoint_funcs[i] = strndup(entrypoint, entrypoint_length); + arguments->entrypoint_funcs[i] = dupstring(entrypoint, entrypoint_length); i++; entrypoint = entrypoint_end + 1; From a9221c02f1b1c21f7af21d5a2657c8fc5bda6549 Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Wed, 7 Jun 2023 20:32:34 -0400 Subject: [PATCH 3/5] libs-gen: Prefer using response file. This allows building on Windows through Msys. --- src/vita-libs-gen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vita-libs-gen.c b/src/vita-libs-gen.c index 8ced47e..36585b4 100644 --- a/src/vita-libs-gen.c +++ b/src/vita-libs-gen.c @@ -494,7 +494,8 @@ int generate_makefile(vita_imports_t **imports, int imports_count) "clean:\n" "\trm -f $(TARGETS) $(TARGETS_WEAK) $(ALL_OBJS)\n\n" "$(TARGETS) $(TARGETS_WEAK):\n" - "\t$(AR) cru $@ $?\n" + "\t@echo \"$?\" > $@-objs\n" + "\t$(AR) cru $@ @$@-objs\n" "\t$(RANLIB) $@\n\n" "%.o: %.S\n" "\t$(AS) --defsym GEN_WEAK_EXPORTS=0 $< -o $@\n\n" From f37a0c295aa31f703755c0c113262b43c357ce6b Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Thu, 8 Jun 2023 18:05:01 -0400 Subject: [PATCH 4/5] Avoid using a wrapper for strndup. --- src/CMakeLists.txt | 15 +++++---------- src/dupstring.h | 9 --------- src/elf-create-argp.c | 6 ++++-- src/{dupstring.c => strndup.c} | 15 ++++----------- src/strndup.h | 8 ++++++++ 5 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 src/dupstring.h rename src/{dupstring.c => strndup.c} (50%) create mode 100644 src/strndup.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 021c0d8..030ba0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,15 +37,6 @@ int main() { }" HAVE_STRNDUP) -if(HAVE_STRNDUP) - set(STRNDUP_DEF "HAVE_STRNDUP=1") -else() - set(STRNDUP_DEF "HAVE_STRNDUP=0") -endif() - -set_source_files_properties(dupstring.c PROPERTIES - COMPILE_DEFINITIONS ${STRNDUP_DEF}) - add_library(vita-yaml yamltree.c yamltreeutil.c) add_library(vita-export vita-export-parse.c sha256.c) add_library(vita-import vita-import.c vita-import-parse.c) @@ -72,12 +63,16 @@ target_include_directories(vita-import PUBLIC $) add_executable(vita-libs-gen vita-libs-gen.c) -add_executable(vita-elf-create vita-elf-create.c elf-create-argp.c vita-elf.c elf-defs.c sce-elf.c varray.c elf-utils.c yamlemitter.c dupstring.c) +add_executable(vita-elf-create vita-elf-create.c elf-create-argp.c vita-elf.c elf-defs.c sce-elf.c varray.c elf-utils.c yamlemitter.c strndup.c) add_executable(vita-mksfoex vita-mksfoex.c getopt_long.c) add_executable(vita-make-fself vita-make-fself.c) add_executable(vita-pack-vpk vita-pack-vpk.c) add_executable(vita-elf-export vita-elf-export.c yamlemitter.c) +if(HAVE_STRNDUP) + target_compile_definitions(vita-elf-create PRIVATE "HAVE_STRNDUP") +endif() + target_link_libraries(vita-yaml ${libyaml_LIBRARIES}) target_link_libraries(vita-import vita-yaml) target_link_libraries(vita-export vita-yaml) diff --git a/src/dupstring.h b/src/dupstring.h deleted file mode 100644 index 2bd5ed1..0000000 --- a/src/dupstring.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef DUPSTRING_H -#define DUPSTRING_H - -#include - -/* Wrapper around strndup */ -char *dupstring(const char *source, size_t maxlen); - -#endif /* DUPSTRING_H */ diff --git a/src/elf-create-argp.c b/src/elf-create-argp.c index e8d86c0..b796da7 100644 --- a/src/elf-create-argp.c +++ b/src/elf-create-argp.c @@ -5,7 +5,9 @@ #include #include -#include "dupstring.h" +#ifndef HAVE_STRNDUP +#include "strndup.h" +#endif int parse_arguments(int argc, char *argv[], elf_create_args *arguments) { @@ -78,7 +80,7 @@ int parse_arguments(int argc, char *argv[], elf_create_args *arguments) } size_t entrypoint_length = (size_t)(entrypoint_end - entrypoint); if (entrypoint_length > 0) - arguments->entrypoint_funcs[i] = dupstring(entrypoint, entrypoint_length); + arguments->entrypoint_funcs[i] = strndup(entrypoint, entrypoint_length); i++; entrypoint = entrypoint_end + 1; diff --git a/src/dupstring.c b/src/strndup.c similarity index 50% rename from src/dupstring.c rename to src/strndup.c index 0145702..5e942e6 100644 --- a/src/dupstring.c +++ b/src/strndup.c @@ -1,17 +1,10 @@ -#include "dupstring.h" +#ifndef HAVE_STRNDUP +#include "strndup.h" -#include - -#if defined(HAVE_STRNDUP) && HAVE_STRNDUP - -char *dupstring(const char *source, size_t maxlen) { - return strndup(source, maxlen); -} - -#else /* Fallback implementation */ #include +#include -char *dupstring(const char *source, size_t maxlen) { +char *strndup(const char *source, size_t maxlen) { size_t dest_size = strnlen(source, maxlen); char *dest = malloc(dest_size + 1); if (dest == NULL) { diff --git a/src/strndup.h b/src/strndup.h new file mode 100644 index 0000000..0e57db2 --- /dev/null +++ b/src/strndup.h @@ -0,0 +1,8 @@ +#ifndef STRNDUP_H +#define STRNDUP_H + +#include + +char *strndup(const char *source, size_t maxlen); + +#endif /* STRNDUP_H */ From 51a21426638b2421563721798b3a5fa7b87b0c18 Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Mon, 12 Jun 2023 09:00:23 -0400 Subject: [PATCH 5/5] CI: Checkout submodules. --- .github/workflows/compilation.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml index 29edb9e..3bd139a 100644 --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + submodules: true - name: Get Information Variables id: core