Skip to content

Commit e0b2e4d

Browse files
committed
LLEXT: Xtensa: add a Kconfig option to enable -fPIC
Currently when building LLEXT for Xtensa we use the -fPIC compiler option, but this cannot be used when using detached sections in extensions. Add a Kconfig option to switch between the two compilation modes and switch -fPIC off when building relocatable (partially linked) ELF binaries. Signed-off-by: Guennadi Liakhovetski <[email protected]>
1 parent eb3009d commit e0b2e4d

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

cmake/compiler/gcc/target_xtensa.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Flags not supported by llext linker
44
# (regexps are supported and match whole word)
55
set(LLEXT_REMOVE_FLAGS
6-
-fno-pic
7-
-fno-pie
86
-ffunction-sections
97
-fdata-sections
108
-g.*
@@ -14,7 +12,20 @@ set(LLEXT_REMOVE_FLAGS
1412

1513
# Flags to be added to llext code compilation
1614
set(LLEXT_APPEND_FLAGS
17-
-fPIC
1815
-nostdlib
1916
-nodefaultlibs
2017
)
18+
19+
if(CONFIG_LLEXT_BUILD_PIC)
20+
set(LLEXT_REMOVE_FLAGS ${LLEXT_REMOVE_FLAGS}
21+
-fno-pic
22+
-fno-pie
23+
)
24+
set(LLEXT_APPEND_FLAGS ${LLEXT_APPEND_FLAGS}
25+
-fPIC
26+
)
27+
else()
28+
set(LLEXT_APPEND_FLAGS ${LLEXT_APPEND_FLAGS}
29+
-ffreestanding
30+
)
31+
endif()

cmake/compiler/xt-clang/target.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ include(${ZEPHYR_BASE}/cmake/compiler/xcc/target.cmake)
55
# Flags not supported by llext linker
66
# (regexps are supported and match whole word)
77
set(LLEXT_REMOVE_FLAGS
8-
-fno-pic
9-
-fno-pie
108
-ffunction-sections
119
-fdata-sections
1210
-g.*
@@ -16,7 +14,20 @@ set(LLEXT_REMOVE_FLAGS
1614

1715
# Flags to be added to llext code compilation
1816
set(LLEXT_APPEND_FLAGS
19-
-fPIC
2017
-nostdlib
2118
-nodefaultlibs
2219
)
20+
21+
if(CONFIG_LLEXT_BUILD_PIC)
22+
set(LLEXT_REMOVE_FLAGS ${LLEXT_REMOVE_FLAGS}
23+
-fno-pic
24+
-fno-pie
25+
)
26+
set(LLEXT_APPEND_FLAGS ${LLEXT_APPEND_FLAGS}
27+
-fPIC
28+
)
29+
else()
30+
set(LLEXT_APPEND_FLAGS ${LLEXT_APPEND_FLAGS}
31+
-ffreestanding
32+
)
33+
endif()

subsys/llext/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ config LLEXT_HEAP_SIZE
4949
help
5050
Heap size in kilobytes available to llext for dynamic allocation
5151

52+
config LLEXT_BUILD_PIC
53+
bool "Use -fPIC when building LLEXT"
54+
depends on XTENSA
55+
default y if LLEXT_TYPE_ELF_SHAREDLIB
56+
help
57+
By default LLEXT compilation is performed with -fno-pic -fno-pie compiler
58+
flags. Some platforms can benefit from using -fPIC instead, in which case
59+
most internal linking is performed by the linker at build time. Select "y"
60+
to make use of that advantage.
61+
5262
config LLEXT_SHELL
5363
bool "llext shell commands"
5464
depends on SHELL

0 commit comments

Comments
 (0)