Skip to contentSkip to conversation

openssl: aarch64: configure with no-asm

PATCH In review [email protected] 4 participants 4 messages May 6, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 openssl: aarch64: configure with no-asm

From: Max Krummenacher <[email protected]>

openssl has a couple of functionalities which use optimized assembler code. With no-asm these are replaced by generic C code implementation.

With GCC 15 OE by default uses the new AARCH64 specific GCS feature. However the object files produced by the assembler are not marked to provide the feature and consequently the produced shared objects containing them also not.
The linker will warn when linking against such shared objects files and, with all warnings are errors set linking will fail. Without this patch systemd e.g. fails do_compile as it links against libcrypto.so from openssl.

To test what features an object file (or .so, .a file) has use readelf -ln and check the content of .note.gnu.property, e.g. libcrypto-shlib-md5-aarch64.o build from assembler source, libcrypto-shlib-md5_one.o build from C source:

$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5-aarch64.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC

$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5_one.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC, GCS

---
 meta/recipes-connectivity/openssl/openssl_3.5.0.bb | 2 ++
 1 file changed, 2 insertions(+)

For reference also refer to this thread:
https://lore.kernel.org/all/aBilFkr4HF-MSBd6@toolbox/

meta/recipes-connectivity/openssl/openssl_3.5.0.bb +2 -0
index 865e04deb220..d025fc3ff100 100644
@@ -36,6 +36,8 @@ B = "${WORKDIR}/build"
 do_configure[cleandirs] = "${B}"
 
 EXTRA_OECONF = "${@bb.utils.contains('PTEST_ENABLED', '1', '', 'no-tests', d)}"
+# aarch64 'as' doesn't mark objects to have the GCS feature, resulting *.so then produces linker warnings
+EXTRA_OECONF:append:aarch64 = " no-asm"
 
 #| ./libcrypto.so: undefined reference to `getcontext'
 #| ./libcrypto.so: undefined reference to `setcontext'
Signature · 1 line
2.42.0
#1 lore raw
Quoted 30 lines · Max Krummenacher via lists.openembedded.org

From: Max Krummenacher <[email protected]>

openssl has a couple of functionalities which use optimized assembler code. With no-asm these are replaced by generic C code implementation.

With GCC 15 OE by default uses the new AARCH64 specific GCS feature. However the object files produced by the assembler are not marked to provide the feature and consequently the produced shared objects containing them also not.
The linker will warn when linking against such shared objects files and, with all warnings are errors set linking will fail. Without this patch systemd e.g. fails do_compile as it links against libcrypto.so from openssl.

To test what features an object file (or .so, .a file) has use readelf -ln and check the content of .note.gnu.property, e.g. libcrypto-shlib-md5-aarch64.o build from assembler source, libcrypto-shlib-md5_one.o build from C source:

$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5-aarch64.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC

Quoted 8 lines
$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5_one.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC, GCS

Good find. I was suspecting something like that, what happens if we use compiler driver to invoke as assembler ?
another way might be to add CFI directives in asm files, maybe just start and end
foo:
.cfi_startproc
...
.cfi_endproc

Quoted 14 lines
---
 meta/recipes-connectivity/openssl/openssl_3.5.0.bb | 2 ++
 1 file changed, 2 insertions(+)

For reference also refer to this thread:
https://lore.kernel.org/all/aBilFkr4HF-MSBd6@toolbox/

meta/recipes-connectivity/openssl/openssl_3.5.0.bb +0 -0
index 865e04deb220..d025fc3ff100 100644

meta/recipes-connectivity/openssl/openssl_3.5.0.bb B = "${WORKDIR}/build" · line 40

Quoted 5 lines
meta/recipes-connectivity/openssl/openssl_3.5.0.bb +2 -0
@@ -36,6 +36,8 @@ B = "${WORKDIR}/build"
 do_configure[cleandirs] = "${B}"
 
 EXTRA_OECONF = "${@bb.utils.contains('PTEST_ENABLED', '1', '', 'no-tests', d)}"
+# aarch64 'as' doesn't mark objects to have the GCS feature, resulting *.so then produces linker warnings
+EXTRA_OECONF:append:aarch64 = " no-asm"

Does this disable assembly ? if so there might be a performance impact, it would be good to find that out.

Quoted 15 lines
meta/recipes-connectivity/openssl/openssl_3.5.0.bb +0 -1
 #| ./libcrypto.so: undefined reference to `getcontext'
 #| ./libcrypto.so: undefined reference to `setcontext'
--

2.42.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#216050): https://lists.openembedded.org/g/openembedded-core/message/216050
Mute This Topic: https://lists.openembedded.org/mt/112649627/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

Hi,

Quoted 42 lines · Khem Raj via lists.openembedded.org
Quoted 30 lines · Max Krummenacher via lists.openembedded.org

From: Max Krummenacher <[email protected]>

openssl has a couple of functionalities which use optimized assembler code. With no-asm these are replaced by generic C code implementation.

With GCC 15 OE by default uses the new AARCH64 specific GCS feature. However the object files produced by the assembler are not marked to provide the feature and consequently the produced shared objects containing them also not.
The linker will warn when linking against such shared objects files and, with all warnings are errors set linking will fail. Without this patch systemd e.g. fails do_compile as it links against libcrypto.so from openssl.

To test what features an object file (or .so, .a file) has use readelf -ln and check the content of .note.gnu.property, e.g. libcrypto-shlib-md5-aarch64.o build from assembler source, libcrypto-shlib-md5_one.o build from C source:

$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5-aarch64.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC

Quoted 8 lines
$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5_one.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC, GCS

Quoted 8 lines

Good find. I was suspecting something like that, what happens if we use compiler driver to invoke as assembler ?
another way might be to add CFI directives in asm files, maybe just start and end
foo:
.cfi_startproc
...
.cfi_endproc

This may be needed in a lot of places...

Quoted 16 lines
Quoted 16 lines
---
 meta/recipes-connectivity/openssl/openssl_3.5.0.bb | 2 ++
 1 file changed, 2 insertions(+)

For reference also refer to this thread:
https://lore.kernel.org/all/aBilFkr4HF-MSBd6@toolbox/

meta/recipes-connectivity/openssl/openssl_3.5.0.bb +0 -0
index 865e04deb220..d025fc3ff100 100644
@@ -36,6 +36,8 @@ B = "${WORKDIR}/build"
 do_configure[cleandirs] = "${B}"
 
Quoted 6 lines

meta/recipes-connectivity/openssl/openssl_3.5.0.bb B = "${WORKDIR}/build" · line 40

Quoted 3 lines
meta/recipes-connectivity/openssl/openssl_3.5.0.bb +2 -0
 EXTRA_OECONF = "${@bb.utils.contains('PTEST_ENABLED', '1', '', 'no-tests', d)}"
+# aarch64 'as' doesn't mark objects to have the GCS feature, resulting *.so then produces linker warnings
+EXTRA_OECONF:append:aarch64 = " no-asm"

Does this disable assembly ? if so there might be a performance impact, it would be good to find that out.

Or security win? What does upstream recommend?

This GCS is now enabled with -mbranch-protection=standard. There may be more places which need similar fixes/workarounds so getting this working automatically would be better. Bug report to gcc?

I wonder if GCS should be disabled for now and use "bti" instead?

https://gcc.gnu.org/onlinedocs/gcc-15.1.0/gcc/AArch64-Options.html#index-mbranch-protection

Cheers,

-Mikko

#3 lore raw
In reply to [email protected]
Quoted 9 lines · Max Krummenacher via lists.openembedded.org
$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5-aarch64.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

 Owner                Data size        Description
 GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC

Quoted 8 lines
$ aarch64-poky-linux-readelf -ln ./crypto/md5/libcrypto-shlib-md5_one.o

There are no program headers in this file.

Displaying notes found in: .note.gnu.property

 Owner                Data size        Description
 GNU                  0x00000010       NT_GNU_PROPERTY_TYPE_0

Properties: AArch64 feature: BTI, PAC, GCS

Some context here: openssl has some assembler code that has PAC and BTI hints but not GCS. The systemd recipe then links to libcrypto from openssl with GCS enabled (as that is a distro-wide setting) and it - correctly - warns that it’s being told to use GCS but one of the inputs doesn’t have GCS. This wouldn’t be a problem but systemd also links with —fatal-warnings, so the build explodes.

I’m asking people internally who know more about this than me, but it’s possible that the proper fix here is to just add the GCS tag. Alternatively, relaxing the systemd build so that it doesn’t have fatal warnings (or consider GCS issues a warning) would be a fallback. Disabling the assembler fast-paths because of this is an incredibly blunt hammer.

Ross