Skip to content

RandomX fails to build as shared library on AArch64 due to non-PIC assembly symbol (ADR relocation error) #321

@coffnix

Description

@coffnix

Environment

  • OS: Macaroni OS MARK
  • Distribution family: Gentoo-based
  • Kernel: Linux 6.19.11 PREEMPT
  • Architecture: aarch64
  • libc: glibc 2.40

CPU

  • SoC: CIX P1 CD8160
  • Vendor: Cix Technology Group Co., Ltd.
  • CPUs: 12
  • Topology: 8x Cortex-A720 + 4x Cortex-A520
  • Features include: AES, PMULL, SHA1, SHA2, SHA3, SM3, SM4, SVE, SVE2, BF16, I8MM

Memory

  • RAM: 30 GiB
  • Swap: 15 GiB

Compiler

  • GCC: 14.3.0
  • Target: aarch64-unknown-linux-gnu
  • Thread model: posix
  • Default PIE enabled
  • Default SSP enabled
  • Configured with --with-arch=armv9.2-a --with-tune=cortex-a720

Toolchain

  • CMake
  • Ninja
  • GCC-based Gentoo toolchain

Build context

  • Building RandomX as a shared library (librandomx.so)
  • Compiler flags include -march=armv8-a+crypto
  • Issue reproduced on AArch64 during shared library build
  • Build mode: shared library (BUILD_SHARED_LIBS=ON)

Describe the bug

Building RandomX as a shared library on AArch64 fails with a linker error related to non-PIC assembly code.

The issue is caused by the use of adr with a globally exported symbol in jit_compiler_a64_static.S, which results in an invalid relocation type when building a shared object.


Error

relocation R_AARCH64_ADR_PREL_LO21 against symbol `randomx_program_aarch64_aes_lut_pointers' which may bind externally can not be used when making a shared object

Root cause

The symbol randomx_program_aarch64_aes_lut_pointers is declared as global and accessed via adr:

adr x19, DECL(randomx_program_aarch64_aes_lut_pointers)

This generates a PC-relative relocation that is not valid for externally visible symbols in shared libraries.

At the same time, the symbol is referenced from C++:

(uint8_t*)randomx_program_aarch64_aes_lut_pointers

Fix

Marking the symbol as hidden resolves the issue while preserving functionality:

.global DECL(randomx_program_aarch64_aes_lut_pointers)
.hidden DECL(randomx_program_aarch64_aes_lut_pointers)

This keeps the symbol usable internally while preventing problematic relocations when linking as a shared object.


Notes

Removing .global entirely avoids the relocation error but breaks linkage from C++.

Using .hidden is the correct fix, as it preserves symbol visibility where needed while ensuring compatibility with shared library builds.

Patch

This patch marks the symbol randomx_program_aarch64_aes_lut_pointers as hidden while keeping it global, ensuring compatibility with shared library builds on AArch64 without breaking internal references.

opi6plus /var/overlay/overlay-local/dev-libs/randomx # cat files/randomx-aarch64-shared-fix.patch
--- a/src/jit_compiler_a64_static.S
+++ b/src/jit_compiler_a64_static.S
@@ -44,6 +44,7 @@
 	.global DECL(randomx_program_aarch64_v2_FE_mix)
 	.global DECL(randomx_program_aarch64_v1_FE_mix)
 	.global DECL(randomx_program_aarch64_v2_FE_mix_soft_aes)
+	.hidden DECL(randomx_program_aarch64_aes_lut_pointers)
 	.global DECL(randomx_program_aarch64_aes_lut_pointers)
 	.global DECL(randomx_program_aarch64_vm_instructions_end_light)
 	.global DECL(randomx_program_aarch64_vm_instructions_end_light_tweak)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions