Page MenuHome GnuPG

aarch64 assembly code for chacha20 should use local symbols for internal data
Closed, ResolvedPublic

Description

I just got around to upgrading a copy of libgcrypt--something I haven't done in a while, clearly :(--and I started getting link errors in my project, specifically only on aarch64 for Android, due to an impossible relocation to a couple symbols in the new-as-of-January-2023 chacha20 assembly code. I compared this file to the other algorithms--such as camellia--which were not experiencing the problem, and tracked down a very simple fix: the symbols that are being used for GET_DATA_POINTER should not be marked .globl.

The trivial patch, which I hope you will be willing to consider, is as follows:

diff --git a/cipher/chacha20-aarch64.S b/cipher/chacha20-aarch64.S
index d9745909..692f0f6a 100644
--- a/cipher/chacha20-aarch64.S
+++ b/cipher/chacha20-aarch64.S
@@ -182,13 +182,11 @@ SECTION_RODATA
 
 .align 4
 ELF(.type _gcry_chacha20_aarch64_blocks4_data_inc_counter,%object;)
-.globl _gcry_chacha20_aarch64_blocks4_data_inc_counter
 _gcry_chacha20_aarch64_blocks4_data_inc_counter:
        .long 0,1,2,3
 
 .align 4
 ELF(.type _gcry_chacha20_aarch64_blocks4_data_rot8,%object;)
-.globl _gcry_chacha20_aarch64_blocks4_data_rot8
 _gcry_chacha20_aarch64_blocks4_data_rot8:
        .byte 3,0,1,2
        .byte 7,4,5,6

For reference, the link errors I was getting were:

ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_rot8'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:213 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:213)
>>>               chacha20-aarch64.o:(_gcry_chacha20_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_rot8'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:213 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:213)
>>>               chacha20-aarch64.o:(_gcry_chacha20_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_inc_counter'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:216 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:216)
>>>               chacha20-aarch64.o:(_gcry_chacha20_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_inc_counter'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:216 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:216)
>>>               chacha20-aarch64.o:(_gcry_chacha20_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_rot8'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:390 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:390)
>>>               chacha20-aarch64.o:(_gcry_chacha20_poly1305_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_rot8'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:390 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:390)
>>>               chacha20-aarch64.o:(_gcry_chacha20_poly1305_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_inc_counter'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:393 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:393)
>>>               chacha20-aarch64.o:(_gcry_chacha20_poly1305_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol '_gcry_chacha20_aarch64_blocks4_data_inc_counter'; recompile with -fPIC
>>> defined in out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a(chacha20-aarch64.o)
>>> referenced by chacha20-aarch64.S:393 (./vpn/shared/wsk/libgcrypt/cipher/chacha20-aarch64.S:393)
>>>               chacha20-aarch64.o:(_gcry_chacha20_poly1305_aarch64_blocks4) in archive out-and/arm64-v8a/./vpn/shared/wsk/libgcrypt/src/.libs/libgcrypt.a
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)

(And yes: my entire project--as well as libgcrypt--were definitely being compiled using -fPIC.)

Details

Version
5a653a9129d7cc2f203ab9ad37ccdbcb832337d1