]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[arm] Avoid instruction references to symbols defined via ".equ"
authorMichael Brown <mcb30@ipxe.org>
Sat, 7 May 2016 22:55:28 +0000 (23:55 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sat, 7 May 2016 23:08:48 +0000 (00:08 +0100)
When building for 64-bit ARM, some symbol references may be resolved
via an "adrp" instruction (to obtain the start of the 4kB page
containing the symbol) and a separate 12-bit offset.  For example
(taken from the GNU assembler documentation):

  adrp x0, foo
  ldr  x0, [x0, #:lo12:foo]

We occasionally refer to symbols defined via mechanisms that are not
directly visible to gcc.  For example:

  extern char some_magic_symbol[];
  __asm__ ( ".equ some_magic_symbol, some_magic_expression" );

The subsequent use of the ":lo12:" prefix on such magically-defined
symbols triggers an assertion failure in the assembler.

This problem seems to affect only "private_key_len" in the current
codebase.  Fix by storing this value as static data; this avoids the
need to provide the value as a literal within the instruction stream,
and so avoids the problematic use of the ":lo12:" prefix.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/privkey.c

index 0b10e9cf84545230b00838829eb45bb7172606a3..7ef04880f67d2151c2afd98245ccc00fea7fad96 100644 (file)
@@ -69,6 +69,12 @@ struct asn1_cursor private_key = {
        .len = ( ( size_t ) private_key_len ),
 };
 
+/** Default private key */
+static struct asn1_cursor default_private_key = {
+       .data = private_key_data,
+       .len = ( ( size_t ) private_key_len ),
+};
+
 /** Private key setting */
 static struct setting privkey_setting __setting ( SETTING_CRYPTO, privkey ) = {
        .name = "privkey",
@@ -92,8 +98,8 @@ static int privkey_apply_settings ( void ) {
        if ( ALLOW_KEY_OVERRIDE ) {
 
                /* Restore default private key */
-               private_key.data = private_key_data;
-               private_key.len = ( ( size_t ) private_key_len );
+               memcpy ( &private_key, &default_private_key,
+                        sizeof ( private_key ) );
 
                /* Fetch new private key, if any */
                free ( key_data );