@@ -179,8 +179,6 @@ ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
179179
180180LDFLAGS_libwolfssl.o += -T $(src ) /wolfcrypt.lds
181181
182- rename-pie-text-and-data-sections : $(WOLFSSL_OBJ_TARGETS )
183-
184182ifndef NM
185183 NM := nm
186184endif
@@ -189,31 +187,30 @@ ifndef OBJCOPY
189187 OBJCOPY := objcopy
190188endif
191189
192- .PHONY : rename-pie-text-and-data-sections
193- rename-pie-text-and-data-sections :
194- ifneq "$(quiet ) " "silent_"
195- @echo -n ' Checking wolfCrypt for unresolved symbols and forbidden relocations... '
196- endif
197- @cd "$(obj)" || exit $$?
198- $(LD) -relocatable -o wolfcrypt_test_link.o $(WOLFCRYPT_PIE_FILES) || exit $$?
199- undefined=$$($(NM) --undefined-only wolfcrypt_test_link.o) || exit $$?
200- GOT_relocs=$$($(READELF) --relocs --wide wolfcrypt_test_link.o | grep -E '^[^ ]+ +[^ ]+ +[^ ]*GOT[^ ]* ') || [ $$? = 1 ] || exit 2
201- rm wolfcrypt_test_link.o
202- if [ -n "$$undefined" ]; then
203- echo "wolfCrypt container has unresolved symbols:" 1>&2
204- echo "$$undefined" 1>&2
205- exit 1
206- fi
207- if [ -n "$$GOT_relocs" ]; then
208- echo "wolfCrypt container has GOT relocations (non-local function address used as operand?):" 1>&2
209- echo "$$GOT_relocs" 1>&2
210- exit 1
211- fi
212- ifneq "$(quiet ) " "silent_"
213- echo 'OK.'
214- endif
215- cd "$(obj)" || exit $$?
216- for file in $(WOLFCRYPT_PIE_FILES); do
190+ RENAME_PIE_TEXT_AND_DATA_SECTIONS := \
191+ if [[ "$(quiet ) " != "silent_" ]]; then \
192+ echo -n ' Checking wolfCrypt for unresolved symbols and forbidden relocations... '; \
193+ fi; \
194+ cd "$(obj ) " || exit $$? ; \
195+ $(LD ) -relocatable -o wolfcrypt_test_link.o $(WOLFCRYPT_PIE_FILES ) || exit $$? ; \
196+ undefined=$$($(NM ) --undefined-only wolfcrypt_test_link.o) || exit $$? ; \
197+ GOT_relocs=$$($(READELF ) --relocs --wide wolfcrypt_test_link.o | grep -E '^[^ ]+ +[^ ]+ +[^ ]*GOT[^ ]* ') || [ $$? = 1 ] || exit 2; \
198+ rm wolfcrypt_test_link.o; \
199+ if [ -n "$$undefined" ]; then \
200+ echo "wolfCrypt container has unresolved symbols:" 1>&2; \
201+ echo "$$undefined" 1>&2; \
202+ exit 1; \
203+ fi; \
204+ if [ -n "$$GOT_relocs" ]; then \
205+ echo "wolfCrypt container has GOT relocations (non-local function address used as operand?):" 1>&2; \
206+ echo "$$GOT_relocs" 1>&2; \
207+ exit 1; \
208+ fi; \
209+ if [[ "$(quiet ) " != "silent_" ]]; then \
210+ echo 'OK.'; \
211+ fi; \
212+ cd "$(obj ) " || exit $$? ; \
213+ for file in $(WOLFCRYPT_PIE_FILES ) ; do \
217214 $(OBJCOPY ) --rename-section .text=.text.wolfcrypt \
218215 --rename-section .text.unlikely=.text.wolfcrypt \
219216 --rename-section .rodata=.rodata.wolfcrypt \
@@ -223,8 +220,8 @@ endif
223220 --rename-section .rodata.cst32=.rodata.wolfcrypt \
224221 --rename-section .data=.data.wolfcrypt \
225222 --rename-section .data.rel.local=.data.wolfcrypt \
226- --rename-section .bss=.bss.wolfcrypt "$$file" || exit $$?
227- done
223+ --rename-section .bss=.bss.wolfcrypt "$$file" || exit $$? ; \
224+ done; \
228225 [ "$(KERNEL_ARCH_X86 ) " != "yes" ] || \
229226 { $(READELF ) --sections --syms --wide $(WOLFCRYPT_PIE_FILES ) | \
230227 $(AWK ) -v obj="$(obj ) " ' \
@@ -298,19 +295,16 @@ endif
298295 } else { \
299296 exit(0); \
300297 }}'; } || \
301- { echo 'Error: symbol(s) missed by containerization.' >&2; exit 1; }
302- ifneq "$(quiet ) " "silent_"
303- echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'
304- endif
305-
306- $(obj ) /linuxkm/module_exports.c : rename-pie-text-and-data-sections
307-
298+ { echo 'Error: symbol(s) missed by containerization.' >&2; exit 1; }; \
299+ if [[ "$(quiet ) " != "silent_" ]]; then \
300+ echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'; \
301+ fi
308302endif
309303
310-
311304# auto-generate the exported symbol list, leveraging the WOLFSSL_API visibility tags.
312305# exclude symbols that don't match wc_* or wolf*.
313306$(obj ) /linuxkm/module_exports.c : $(src ) /module_exports.c.template $(WOLFSSL_OBJ_TARGETS ) $(obj ) /linuxkm/module_hooks.o
307+ @$(RENAME_PIE_TEXT_AND_DATA_SECTIONS )
314308 @cp $< $@ || exit $$?
315309 if [[ " $$ {VERSION}" -gt 6 || (" $$ {VERSION}" -eq 6 && " $$ {PATCHLEVEL}" -ge 13) ]]; then
316310 # use ASCII octal escape to avoid syntax disruption in the awk script.
0 commit comments