Skip to content

Commit

Permalink
libphoenix: compile with FPIC by default
Browse files Browse the repository at this point in the history
JIRA: RTOS-664
  • Loading branch information
badochov committed Dec 7, 2023
1 parent ccd62fe commit 4790fa3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ endif

CFLAGS += -Iinclude -fno-builtin-malloc

ifneq ($(LIBPHOENIX_NOPIC), y)
CFLAGS += -fpic
endif

OBJS :=
# crt0.o should have all necessary initialization + call to main()
Expand Down
2 changes: 1 addition & 1 deletion arch/armv7a/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# Author: Pawel Pisarczyk
#

OBJS += $(addprefix $(PREFIX_O)arch/armv7a/, syscalls.o jmp.o signal.o string.o reboot.o)
OBJS += $(addprefix $(PREFIX_O)arch/armv7a/, syscalls.o jmp.o signal.o string.o reboot.o tls.o)
CRT0_OBJS += $(addprefix $(PREFIX_O)arch/armv7a/, _start.o)
36 changes: 36 additions & 0 deletions arch/armv7a/tls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* tls access function
*
* Copyright 2023 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#define TLS_TCB_SIZE 8


typedef struct {
unsigned long ti_moduleid;
unsigned long ti_tlsoffset;
} TLS_index;


/* When libphoenix is compiled as a PIC, even when linked into a static NOPIC binary,
* compiler generates accesses to TLS as calls to this function.
* This functions is simple version just for static binaries purposes,
* in dynamic binaries dynamic linker handles TLS accesses. */
void *__tls_get_addr(TLS_index *ti)
{
void *ptr;
__asm__ volatile ("mrc p15, 0, %0, cr13, cr0, 3"
: "=r"(ptr));
return ((char *)ptr) + TLS_TCB_SIZE + ti->ti_tlsoffset;
}
2 changes: 1 addition & 1 deletion arch/riscv64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# Author: Pawel Pisarczyk
#

OBJS += $(addprefix $(PREFIX_O)arch/riscv64/, syscalls.o string.o signal.o reboot.o jmp.o)
OBJS += $(addprefix $(PREFIX_O)arch/riscv64/, syscalls.o string.o signal.o reboot.o jmp.o tls.o)
CRT0_OBJS += $(addprefix $(PREFIX_O)arch/riscv64/, _start.o)
34 changes: 34 additions & 0 deletions arch/riscv64/tls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* tls access function
*
* Copyright 2023 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


typedef struct {
unsigned long ti_moduleid;
unsigned long ti_tlsoffset;
} TLS_index;


/* When libphoenix is compiled as a PIC, even when linked into a static NOPIC binary,
* compiler generates accesses to TLS as calls to this function.
* This functions is simple version just for static binaries purposes,
* in dynamic binaries dynamic linker handles TLS accesses. */
void *__tls_get_addr(TLS_index *ti)
{
void *ptr;
__asm__ volatile ("mv %0, tp"
: "=r"(ptr));

return ((char *)ptr) + ti->ti_tlsoffset;
}

0 comments on commit 4790fa3

Please sign in to comment.