Inline assembler in padlock.c is incompatible with LTO #312

Closed
opened 2019-11-01 14:54:50 -05:00 by StefanBruens · 1 comment
StefanBruens commented 2019-11-01 14:54:50 -05:00 (Migrated from github.com)

Description

When using LTO, the non-local label 'unsupported' may be instantiated several times in the traslation unit (which is the whole program with LTO typically). This leads to an error during linking:

[ 212s] ../../contrib/mbedtls/library/padlock.c: Assembler messages:
[ 212s] ../../contrib/mbedtls/library/padlock.c:64: Error: symbol `unsupported' is already defined
[ 212s] lto-wrapper: fatal error: cc returned 1 exit status
[ 212s] compilation terminated.
[ 212s] /usr/lib/gcc/i586-suse-linux/9/../../../../i586-suse-linux/bin/ld: error: lto-wrapper failed

github.com/ARMmbed/mbed-crypto@08c674dfe3/library/padlock.c (L61-L64)

This happens when compiling premake5, which statically links to a bundled mbedtls.

Only ix86 (32bit) is affected, as the padlock code is left out otherwise.

The problem can probably avoided by using local labels in the asm code, e.g.

jb 1f
movl  $0xC0000001, %%eax
cpuid
1:

or assembler templates, unsupported_%=:. A local label likely is the better option, as it avoids generating a globally visible symbol in the firs place.

Issue request type

[ ] Question
[ ] Enhancement
[X] Bug
<!-- ************************************** WARNING ************************************** The ciarcom bot parses this header automatically. Any deviation from the template may cause the bot to automatically correct this header or may result in a warning message, requesting updates. Please ensure that nothing follows the Issue request type section, all issue details are within the Description section and no changes are made to the template format (as detailed below). ************************************************************************************* --> ### Description When using LTO, the non-local label 'unsupported' may be instantiated several times in the traslation unit (which is the whole program with LTO typically). This leads to an error during linking: [ 212s] ../../contrib/mbedtls/library/padlock.c: Assembler messages: [ 212s] ../../contrib/mbedtls/library/padlock.c:64: Error: symbol `unsupported' is already defined [ 212s] lto-wrapper: fatal error: cc returned 1 exit status [ 212s] compilation terminated. [ 212s] /usr/lib/gcc/i586-suse-linux/9/../../../../i586-suse-linux/bin/ld: error: lto-wrapper failed https://github.com/ARMmbed/mbed-crypto/blob/08c674dfe3e57932fe21e3feb3aebed680759c37/library/padlock.c#L61-L64 This happens when compiling premake5, which statically links to a bundled mbedtls. Only ix86 (32bit) is affected, as the padlock code is left out otherwise. The problem can probably avoided by using local labels in the asm code, e.g. ``` jb 1f movl $0xC0000001, %%eax cpuid 1: ``` or [assembler templates](https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#AssemblerTemplate), `unsupported_%=:`. A local label likely is the better option, as it avoids generating a globally visible symbol in the firs place. <!-- Required Add detailed description of what you are reporting. Good example: https://os.mbed.com/docs/latest/reference/workflow.html Things to consider sharing: - What target does this relate to? - What toolchain (name + version) are you using? - What tools (name + version - is it mbed-cli, online compiler or IDE) are you using? - What is the SHA of Mbed OS (git log -n1 --oneline)? - Steps to reproduce. (Did you publish code or a test case that exhibits the problem?) --> ### Issue request type <!-- Required Please add only one X to one of the following types. Do not fill multiple types (split the issue otherwise.) Please note this is not a GitHub task list, indenting the boxes or changing the format to add a '.' or '*' in front of them would change the meaning incorrectly. The only changes to be made are to add a description text under the description heading and to add a 'x' to the correct box. --> [ ] Question [ ] Enhancement [X] Bug
gilles-peskine-arm commented 2023-05-24 14:00:51 -05:00 (Migrated from github.com)

This has also been raised against Mbed TLS at https://github.com/Mbed-TLS/mbedtls/issues/3451 and has been fixed in Mbed TLS by https://github.com/Mbed-TLS/mbedtls/pull/3452.

This has also been raised against Mbed TLS at https://github.com/Mbed-TLS/mbedtls/issues/3451 and has been fixed in Mbed TLS by https://github.com/Mbed-TLS/mbedtls/pull/3452.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-ARMmbed/mbed-crypto#312
No description provided.