Skip to content

Commit ed80427

Browse files
committed
add TLS support.
1 parent 59b83da commit ed80427

File tree

8 files changed

+82
-9
lines changed

8 files changed

+82
-9
lines changed

cafe/coreinit.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ __PPCHalt
12001200
//__ghs_mtx_lock
12011201
//__ghs_mtx_unlock
12021202
__os_snprintf
1203-
//__tls_get_addr
1203+
__tls_get_addr
12041204
bspGetConsoleTypeRaw
12051205
bspGetEntityVersion
12061206
bspGetHardwareVersion

samples/cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_subdirectory(helloworld)
1010
add_subdirectory(helloworld_cpp)
1111
add_subdirectory(my_first_rpl)
1212
add_subdirectory(swkbd)
13+
add_subdirectory(tls_test)
1314

1415
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/content/"
1516
DESTINATION "${CMAKE_INSTALL_PREFIX}/content")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.2)
2+
project(helloworld C)
3+
include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED)
4+
5+
add_executable(tls_test
6+
main.cpp)
7+
8+
wut_create_rpx(tls_test)
9+
10+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tls_test.rpx"
11+
DESTINATION "${CMAKE_INSTALL_PREFIX}")

samples/cmake/tls_test/main.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <coreinit/thread.h>
2+
#include <coreinit/time.h>
3+
4+
#include <whb/proc.h>
5+
#include <whb/log.h>
6+
#include <whb/log_console.h>
7+
8+
#include <thread>
9+
10+
__thread
11+
__attribute((tls_model("global-dynamic")))
12+
const char* thread_name = "";
13+
14+
int
15+
thread1_entry(void)
16+
{
17+
thread_name = "Thread1";
18+
WHBLogPrintf("Hello from %-20s (thread_name@0x%08X)\n", thread_name, &thread_name);
19+
return 0;
20+
}
21+
22+
int
23+
main(int argc, char **argv)
24+
{
25+
WHBProcInit();
26+
WHBLogConsoleInit();
27+
28+
thread_name = "Main Thread";
29+
WHBLogPrintf("Hello from %-20s (thread_name@0x%08X)\n", thread_name, &thread_name);
30+
31+
std::thread th1 = std::thread(thread1_entry);
32+
th1.join();
33+
34+
WHBLogPrintf("Hello from %-20s (thread_name@0x%08X)\n", thread_name, &thread_name);
35+
WHBLogConsoleDraw();
36+
37+
while(WHBProcIsRunning()) {
38+
OSSleepTicks(OSMillisecondsToTicks(1000));
39+
}
40+
41+
WHBLogPrintf("Exiting... good bye.");
42+
WHBLogConsoleDraw();
43+
OSSleepTicks(OSMillisecondsToTicks(1000));
44+
45+
WHBLogConsoleFree();
46+
WHBProcShutdown();
47+
return 0;
48+
}

share/wut.ld

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ SECTIONS
2525
*(.text.*)
2626
*(.gnu.warning)
2727
*(.gnu.linkonce.t.*)
28+
*(.got)
29+
*(.got1)
30+
*(.got2)
31+
*(.got.plt)
32+
*(.plt)
2833

2934
KEEP (*(.fini))
3035
} > codemem
@@ -56,11 +61,6 @@ SECTIONS
5661
*(.fixup)
5762
*(.gcc_except_table)
5863
*(.gcc_except_table.*)
59-
*(.got)
60-
*(.got1)
61-
*(.got2)
62-
*(.got.plt)
63-
*(.plt)
6464
*(.tm_clone_table)
6565
} > datamem
6666

@@ -107,6 +107,19 @@ SECTIONS
107107
} > datamem
108108
__bss_end = .;
109109

110+
.thrdata : {
111+
*(.tdata)
112+
*(.tdata.*)
113+
*(.gnu.linkonce.td.*)
114+
} > datamem
115+
116+
.thrbss : {
117+
*(.tbss)
118+
*(.tbss.*)
119+
*(.gnu.linkonce.tb.*)
120+
*(.tcommon)
121+
} > datamem
122+
110123
. = ORIGIN(relmem);
111124
.rela.text ALIGN(4) : {
112125
*(.rela.text)

share/wut.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ DEPSEXT ?= d
4646
# There's some default wut flags, they need to be added
4747

4848
# cpu type and hardware flags, keep all relocations (for elf2rpl), wut includes
49-
WUT_CFLAGS := -mcpu=750 -meabi -mhard-float -isystem $(WUT_ROOT)/include
49+
WUT_CFLAGS := -mcpu=750 -meabi -mhard-float -ftls-model=global-dynamic -isystem $(WUT_ROOT)/include
5050
# Defines to tell code about this environment
5151
WUT_CFLAGS += -D__WIIU__ -D__WUT__ -D__WUT_MAKEFILE__
5252
# keep relocations, use wut linker script

share/wut.specs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
%rename link old_link
22

33
*link:
4-
%(old_link) -T %:getenv(DEVKITPRO /wut/share/wut.ld) --gc-sections --emit-relocs -z nocopyreloc %(wut_entry)
4+
%(old_link) -T %:getenv(DEVKITPRO /wut/share/wut.ld) --gc-sections --emit-relocs -z nocopyreloc --no-tls-optimize %(wut_entry)

share/wut.toolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ set(CMAKE_LINKER "${DEVKITPPC_LD}" CACHE PATH "")
7676
set(CMAKE_AR "${DEVKITPPC_AR}" CACHE PATH "")
7777
set(CMAKE_STRIP "${DEVKITPPC_STRIP}" CACHE PATH "")
7878

79-
set(WUT_C_FLAGS "-mcpu=750 -meabi -mhard-float -Wl,-q -D__WIIU__ -D__WUT__")
79+
set(WUT_C_FLAGS "-mcpu=750 -meabi -mhard-float -ftls-model=global-dynamic -Wl,-q -D__WIIU__ -D__WUT__")
8080
set(CMAKE_C_FLAGS "${WUT_C_FLAGS}" CACHE STRING "")
8181
set(CMAKE_CXX_FLAGS "${WUT_C_FLAGS}" CACHE STRING "")
8282
set(CMAKE_ASM_FLAGS "${WUT_C_FLAGS}" CACHE STRING "")

0 commit comments

Comments
 (0)