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 8, 2023
1 parent ccd62fe commit 5b0e469
Show file tree
Hide file tree
Showing 5 changed files with 85 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)
41 changes: 41 additions & 0 deletions arch/armv7a/tls.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* tls access function
*
* Copyright 2023 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


/* NOTE:
* 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. */


/* typedef struct {
* unsigned long ti_moduleid;
* unsigned long ti_tlsoffset;
* } TLS_index;
*
* void *__tls_get_addr(TLS_index *ti) */
.globl __tls_get_addr;
.type __tls_get_addr, %function;
__tls_get_addr:
/* Access ti_tlsoffset. */
ldr r0, [r0, #4]
/* Get thread pointer. */
mrc p15, #0, r1, cr13, cr0, #3
/* GCC expects that TLS block has 8 byte TCB pointer at the begging. */
add r1, r1, #8
add r0, r0, r1
bx lr
.size __tls_get_addr, .-__tls_get_addr
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)
39 changes: 39 additions & 0 deletions arch/riscv64/tls.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* tls access function
*
* Copyright 2023 Phoenix Systems
* Author: Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

/* NOTE:
* 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. */


/* typedef struct {
* unsigned long ti_moduleid;
* unsigned long ti_tlsoffset;
* } TLS_index;
*
* void *__tls_get_addr(TLS_index *ti) */
.globl __tls_get_addr;
.type __tls_get_addr, %function;
__tls_get_addr:
/* Access ti_tlsoffset. */
ld a0, 8(a0)
/* GCC expects that Dynamic Thread Vector pointer points at TLS block start + 0x800 */
li t0, 0x800
add a0, a0, t0
add a0, a0, tp
ret
.size __tls_get_addr, .-__tls_get_addr

0 comments on commit 5b0e469

Please sign in to comment.