Building libgc / bdwgc

Problems with installing the SDK? Errors building? Non-code specific questions go here. Please check out https://vitasdk.org/ for instructions on setting up the SDK.
Post Reply
soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Building libgc / bdwgc

Post by soywiz » Sun May 21, 2017 9:15 am

I'm trying to build Boehm's GC library:
https://github.com/ivmai/bdwgc

But I'm having trouble even using this tips: https://github.com/vitasdk/vita-headers ... ur-project

Has anyone tried to build it already?

---

I'm trying to add support to jtransc for vitasdk, in order to be able to use Java/Kotlin/Scala code to build apps for the vita: https://github.com/jtransc/jtransc-exam ... k.java#L59
That example already works since it has the GC disabled in line 59. You just have to git clone the repo, go to vitasdk folder and execute `./gradlew distcpp`. That will build `build/jtransc-cpp/program.vpk`.

I did it almost a year ago: https://github.com/jmedialayer/jmedialayer but it was painfully slow due to the refcounting approach. Now we are reaching near native speeds ( https://github.com/jtransc/jtransc/pull ... -302695967 ), but using a garbage collector; that now is pseudo precise, and will promote to mostly precise soon. But for it to work we need bdwgc support. That's why I'm asking if someone built it already to save some time on this :)

Thanks in advance!

xyz
Posts: 8
Joined: Sun Jan 01, 2017 12:51 pm

Re: Building libgc / bdwgc

Post by xyz » Sun May 21, 2017 5:04 pm

I don't think anybody tried building it, what's your problem?

xyz
Posts: 8
Joined: Sun Jan 01, 2017 12:51 pm

Re: Building libgc / bdwgc

Post by xyz » Sun May 21, 2017 5:09 pm

I was able to build it with:

Code: Select all

git clone git://github.com/ivmai/bdwgc.git
cd bdwgc
git clone git://github.com/ivmai/libatomic_ops.git
./autogen.sh
./configure --host arm-vita-eabi --disable-shared --enable-static --disable-threads
make
You might have to modify configure script if you want to use threads (we do have a pthreads port: https://github.com/vitasdk/pthread-embedded), should be installed by default with the toolchain.

soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Re: Building libgc / bdwgc

Post by soywiz » Mon May 22, 2017 8:18 pm

Woops. Didn't notice. I though the forum was sending emails by default.
Thanks for the help! I'm trying it already.

We are using c++11 threads.

soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Re: Building libgc / bdwgc

Post by soywiz » Mon May 22, 2017 8:23 pm

__stack_base__ should be defined in arm/crt?
https://github.com/eblot/newlib/blob/9a ... rt0.S#L481

Code: Select all

root@MSI:/projects/jtransc-examples/vitasdk# ./gradlew distcpp
Starting a Gradle Daemon (subsequent builds will be faster)
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:test NO-SOURCE
:check UP-TO-DATE
:build
:distCpp
java.util.Set
/mnt/c/Users/soywiz/projects/jtransc-examples/vitasdk/build/jtransc-cpp/program.cpp
/usr/bin/cmake --build . --config Release
Execute command /usr/bin/cmake --build . --config Release
:distCpp FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':distCpp'.
> success=false exitCode=2 output='-- Configuring done
  -- Generating done
  -- Build files have been written to: /projects/jtransc-examples/vitasdk/build/jtransc-cpp
  Scanning dependencies of target program
  [ 16%] Building CXX object CMakeFiles/program.dir/program.cpp.obj
  [ 33%] Linking CXX executable program
  CMakeFiles/program.dir/build.make:94: recipe for target 'program' failed
  CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/program.dir/all' failed
  Makefile:83: recipe for target 'all' failed' error='/projects/jtransc-examples/vitasdk/build/jtransc-cpp/program.cpp:15312:32: warning: integer constant is so large that it is unsigned
    if (((N::lcmp(lJ0, (int64_t)(-9223372036854775808ll)) != 0))) goto label_2;
                                  ^~~~~~~~~~~~~~~~~~~~~
  /usr/local/vitasdk/lib/libgc.a(os_dep.o): In function `GC_get_main_stack_base':
  /projects/vita1/bdwgc/os_dep.c:1170: undefined reference to `__stack_base__'
  /projects/vita1/bdwgc/os_dep.c:1170: undefined reference to `__stack_base__'
  /projects/vita1/bdwgc/os_dep.c:1170: undefined reference to `__stack_base__'
  /projects/vita1/bdwgc/os_dep.c:1170: undefined reference to `__stack_base__'
  collect2: error: ld returned 1 exit status
  make[2]: *** [program] Error 1
  make[1]: *** [CMakeFiles/program.dir/all] Error 2
  make: *** [all] Error 2' folder=/mnt/c/Users/soywiz/projects/jtransc-examples/vitasdk/build/jtransc-cpp command='/usr/bin/cmake --build . --config Release'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 15.52 secs

soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Re: Building libgc / bdwgc

Post by soywiz » Mon May 22, 2017 9:08 pm

It is strange, it seems to be defined here: https://github.com/vitasdk/newlib/blob/ ... rt0.S#L514
I'm missing any link?

Code: Select all

cmake_minimum_required(VERSION 3.1)

set (CMAKE_CXX_STANDARD 11)
#add_compile_options(-std=c++11)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})


if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)

   if(DEFINED ENV{VITASDK})

       set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")

   else()

       message(FATAL_ERROR "Please define VITASDK to point to your SDK path!")

   endif()

endif()


project (program)


include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)

include_directories(/usr/local/vitasdk/include/)

include_directories(/usr/local/vitasdk/arm-vita-eabi/include)

link_directories(/usr/local/vitasdk/lib/)

link_directories(/usr/local/vitasdk/arm-vita-eabi/lib/)

set(VITA_APP_NAME "Hello World")

set(VITA_TITLEID  "VSDK00006")

set(VITA_VERSION  "01.00")

vita_create_self(program.self program)

vita_create_vpk(program.vpk ${VITA_TITLEID} program.self

   VERSION ${VITA_VERSION}

   NAME ${VITA_APP_NAME}

)



include_directories(/root/.jtransc/cpp/0_6_1/bdwgc/include)

include_directories(/root/.jtransc/cpp/0_6_1/jni-headers)

include_directories(/root/.jtransc/cpp/0_6_1/jni-headers/linux)



link_directories(/root/.jtransc/cpp/0_6_1/bdwgc/.libs)



add_definitions(-DGC_NOT_DLL=1)

add_definitions(-DUSE_BOEHM_GC=1)


add_executable(program program.cpp)


target_link_libraries(program gc)

target_link_libraries(program pthread)

target_link_libraries(program SceDisplay_stub)
But can't find references to `stack_base` (outside libgc in vitasdk):
stack_base_references.png
stack_base_references.png (171.9 KiB) Viewed 314 times

soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Re: Building libgc / bdwgc

Post by soywiz » Mon May 22, 2017 11:17 pm

I have tried this too:
https://devkitpro.org/viewtopic.php?f=2&t=1418#p2830

Replacing this:

Code: Select all

      /* __data_start is usually defined in the target linker script.  */
      extern int __data_start[];
#     define DATASTART ((ptr_t)(__data_start))
	/* __stack_base__ is set in newlib/libc/sys/arm/crt0.S  */
      extern void *__stack_base__;
#     define STACKBOTTOM ((ptr_t)(__stack_base__))
But it says:

Code: Select all

/usr/local/vitasdk/lib/libgc.a(os_dep.o): In function `GC_get_main_stack_base':
  /projects/vita1/bdwgc/os_dep.c:1171: undefined reference to `_sp_usr'
  /projects/vita1/bdwgc/os_dep.c:1171: undefined reference to `_sp_usr'
  /usr/local/vitasdk/lib/libgc.a(os_dep.o): In function `GC_get_stack_base':
  /projects/vita1/bdwgc/os_dep.c:1451: undefined reference to `_sp_usr'
  /projects/vita1/bdwgc/os_dep.c:1451: undefined reference to `_sp_usr'
  collect2: error: ld returned 1 exit status
So I suspect this should be specific to vita. So I will need help with this :)

soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Re: Building libgc / bdwgc

Post by soywiz » Tue May 23, 2017 9:25 pm

I tried this, but it crashes at startup:

Code: Select all

./autogen.sh
./configure --host arm-vita-eabi --disable-shared --enable-static --disable-threads --prefix=/usr/local/vitasdk

Code: Select all

include/private/gcconfig.h

      extern void *__stack_base__;
#     define STACKBOTTOM ((ptr_t)__stack_base__)

--->

#include <psp2/kernel/threadmgr.h>
extern SceKernelThreadInfo __myThreadInfo;
#     define STACKBOTTOM (sceKernelGetThreadInfo(sceKernelGetThreadId(), &__myThreadInfo), (ptr_t)(&__myThreadInfo.stack))

Code: Select all

os_dep.c (add to the end)

#include <psp2/kernel/threadmgr.h>
SceKernelThreadInfo __myThreadInfo = {0};


Also tried this other approach with the same result (crash at startup):

-------------

misc.c

Code: Select all

#include <psp2/kernel/threadmgr.h>

void *__stack_base__ = NULL;

GC_API void GC_CALL GC_init(void)
{
    /* LOCK(); -- no longer does anything this early. */
    word initial_heap_sz;
	
	SceKernelThreadInfo __myThreadInfo = {0};
	sceKernelGetThreadInfo(sceKernelGetThreadId(), &__myThreadInfo);
	__stack_base__ = (void*)(&__myThreadInfo.stack);
Is there a way to explore psp2dmp files and find out what's happening / or a vita emulator in the works for homebrew to debug?

soywiz
Posts: 7
Joined: Sun May 21, 2017 9:04 am

Re: Building libgc / bdwgc

Post by soywiz » Wed May 24, 2017 8:57 am

Continuing with this story:

Yesterday I tried to compile tinygc instead https://github.com/ivmai/tinygc and replaced it. And it compiled without crashing. Then did some memory tests to check if GC was working. And didn't seems to work. At least properly or without further investigation.

Also noticed that the malloc heap is limited to 32MB, then searched for malloc in vita's newlib. And found this: https://github.com/vitasdk/newlib/blob/ ... sbrk.c#L37
So I suspect I should implement my own malloc for this (using vita's sceKernelAllocMemBlock or other facilities for allocating memory). Right? In order to be able to use as much memory as possible.

For the record. I changed the test to this. And crashed after 8 steps, so since I was allocating in 4MB chunks I suspected it was limited to 32 MB. For the games I want to port I will need more memory:

Code: Select all

Global.psvDebugScreenInit();

for (int m = 0; m < 2000; m++) {
    GlobalTools.psvDebugScreenPrintf("Welcome to the psvDebugScreen showcase in JAVA! " + m);
    int[] ints = new int[1024 * 1024];
    final int len = ints.length;
    for (int n = 0; n < len; n++) ints[n]++;
}
Global.sceKernelDelayThread(1000 * 1000);

xyz
Posts: 8
Joined: Sun Jan 01, 2017 12:51 pm

Re: Building libgc / bdwgc

Post by xyz » Wed May 24, 2017 9:18 pm

You can change the heap size like this, just make a global variable anywhere in your C code:

Code: Select all

int _newlib_heap_size_user = 128 * 1024 * 1024; // 128 MB
I suggest that you join #vitasdk:matrix.org / or freenode to discuss stuff in real time.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest