1818# along with this program; if not, write to the Free Software
1919# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2020
21+ .ONESHELL :
2122SHELL =bash
2223
2324ifeq "$(WOLFSSL_OBJ_FILES ) " ""
@@ -158,30 +159,30 @@ rename-pie-text-and-data-sections:
158159ifneq "$(quiet ) " "silent_"
159160 @echo -n ' Checking wolfCrypt for unresolved symbols and forbidden relocations... '
160161endif
161- @cd "$(obj)" || exit $$?; \
162- $(LD) -relocatable -o wolfcrypt_test_link.o $(WOLFCRYPT_PIE_FILES) || exit $$?; \
163- undefined=$$($(NM) --undefined-only wolfcrypt_test_link.o) || exit $$?; \
164- GOT_relocs=$$($(READELF) --relocs --wide wolfcrypt_test_link.o | egrep '^[^ ]+ +[^ ]+ +[^ ]*GOT[^ ]* ') || [ $$? = 1 ] || exit 2; \
165- rm wolfcrypt_test_link.o; \
166- if [ -n "$$undefined" ]; then \
167- echo "wolfCrypt container has unresolved symbols:" 1>&2; \
168- echo "$$undefined" 1>&2; \
169- exit 1; \
170- fi; \
171- if [ -n "$$GOT_relocs" ]; then \
172- echo "wolfCrypt container has GOT relocations (non-local function address used as operand?):" 1>&2; \
173- echo "$$GOT_relocs" 1>&2; \
174- exit 1; \
162+ @cd "$(obj)" || exit $$?
163+ $(LD) -relocatable -o wolfcrypt_test_link.o $(WOLFCRYPT_PIE_FILES) || exit $$?
164+ undefined=$$($(NM) --undefined-only wolfcrypt_test_link.o) || exit $$?
165+ GOT_relocs=$$($(READELF) --relocs --wide wolfcrypt_test_link.o | egrep '^[^ ]+ +[^ ]+ +[^ ]*GOT[^ ]* ') || [ $$? = 1 ] || exit 2
166+ rm wolfcrypt_test_link.o
167+ if [ -n "$$undefined" ]; then
168+ echo "wolfCrypt container has unresolved symbols:" 1>&2
169+ echo "$$undefined" 1>&2
170+ exit 1
171+ fi
172+ if [ -n "$$GOT_relocs" ]; then
173+ echo "wolfCrypt container has GOT relocations (non-local function address used as operand?):" 1>&2
174+ echo "$$GOT_relocs" 1>&2
175+ exit 1
175176 fi
176177ifneq "$(quiet ) " "silent_"
177- @ echo 'OK.'
178+ echo 'OK.'
178179endif
179- @ cd "$(obj)" || exit $$?; \
180- for file in $(WOLFCRYPT_PIE_FILES); do \
181- $(OBJCOPY) --rename-section .text=.text.wolfcrypt --rename-section .data=.data.wolfcrypt --rename-section .rodata=.rodata.wolfcrypt "$$file" || exit $$?; \
180+ cd "$(obj)" || exit $$?
181+ for file in $(WOLFCRYPT_PIE_FILES); do
182+ $(OBJCOPY) --rename-section .text=.text.wolfcrypt --rename-section .data=.data.wolfcrypt --rename-section .rodata=.rodata.wolfcrypt "$$file" || exit $$?
182183 done
183184ifneq "$(quiet ) " "silent_"
184- @ echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'
185+ echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'
185186endif
186187
187188$(obj ) /linuxkm/module_exports.c : rename-pie-text-and-data-sections
@@ -192,14 +193,20 @@ endif
192193# auto-generate the exported symbol list, leveraging the WOLFSSL_API visibility tags.
193194# exclude symbols that don't match wc_* or wolf*.
194195$(obj ) /linuxkm/module_exports.c : $(src ) /module_exports.c.template $(WOLFSSL_OBJ_TARGETS )
195- @cp $< $@
196- @$(READELF ) --symbols --wide $(WOLFSSL_OBJ_TARGETS ) | \
197- $(AWK ) ' /^ *[0-9]+: / { \
198- if ($$ 8 ! ~ /^(wc_| wolf| WOLF| TLSX_)/){next; } \
199- if (( $$ 4 == "FUNC") && ($$ 5 == "GLOBAL") && ($$ 6 == "DEFAULT")) { \
200- print " EXPORT_SYMBOL_NS_GPL(" $$ 8 " , EXPORT_SYMBOL_NS_Q(WOLFSSL));" ; \
201- } \
202- }' >> $@
203- @echo -e ' #ifndef NO_CRYPT_TEST\nEXPORT_SYMBOL_NS_GPL(wolfcrypt_test, EXPORT_SYMBOL_NS_Q(WOLFSSL));\n#endif' >> $@
196+ @cp $< $@ || exit $$?
197+ if [[ " $$ {VERSION}" -gt 6 || (" $$ {VERSION}" -eq 6 && " $$ {PATCHLEVEL}" -ge 13) ]]; then
198+ # use ASCII octal escape to avoid syntax disruption in the awk script.
199+ ns=' \042WOLFSSL\042'
200+ else
201+ ns=' WOLFSSL'
202+ fi
203+ $(READELF ) --symbols --wide $(WOLFSSL_OBJ_TARGETS ) |
204+ $(AWK ) ' /^ *[0-9]+: / {
205+ if ($$ 8 ! ~ /^(wc_| wolf| WOLF| TLSX_)/){next; }
206+ if (( $$ 4 == "FUNC") && ($$ 5 == "GLOBAL") && ($$ 6 == "DEFAULT")) {
207+ print " EXPORT_SYMBOL_NS_GPL(" $$ 8 " , '" $$ ns" ');" ;
208+ }
209+ }' >> $@ || exit $$?
210+ echo -e " #ifndef NO_CRYPT_TEST\nEXPORT_SYMBOL_NS_GPL(wolfcrypt_test, $$ {ns});\n#endif" >> $@
204211
205212clean-files := linuxkm src wolfcrypt
0 commit comments