Skip to content

UI test sanitize/hwaddress.rs fails with linker error on aarch64 when executed with 1 CGU #83989

Closed

Description

@the8472

This was discovered in #81942 (comment) which lowers the UI test default CGU count to 1. The test was modified to explicitly request a higher CGU count to make it pass, but the underlying issue remains.

Steps to reproduce:

  1. add the compile flag -C codegen-units=1 to src/test/ui/sanitize/hwaddress.rs
  2. run test on an aarch64 target, e.g. via aarch64-gnu CI job

Output:

failures:

---- [ui] ui/sanitize/hwaddress.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/sanitize/hwaddress.rs" "-Zthreads=1" "--target=aarch64-unknown-linux-gnu" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/sanitize/hwaddress/a" "-A" "unused" "-Crpath" "-Zunstable-options" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "sanitizer=hwaddress" "-O" "-g" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/sanitize/hwaddress/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error: linking with `cc` failed: exit status: 1
   |
   = note: "cc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,--as-needed" "-Wl,-Bstatic" "-Wl,--whole-archive" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc-nightly_rt.hwasan.a" "-Wl,--no-whole-archive" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/sanitize/hwaddress/a.hwaddress.7rcbfp3g-cgu.0.rcgu.o" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/sanitize/hwaddress/a" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/sanitize/hwaddress/auxiliary" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,--start-group" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lstd-2e601f8d612d905c" "-Wl,--end-group" "-Wl,-Bstatic" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-6725377457b1bda4.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,-rpath,$ORIGIN/../../../../stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-rpath,/checkout/obj/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,--enable-new-dtags"
   = note: /checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/sanitize/hwaddress/a.hwaddress.7rcbfp3g-cgu.0.rcgu.o: in function `main':
           hwaddress.7rcbfp3g-cgu.0:(.text.main+0x7c): relocation truncated to fit: R_AARCH64_ADR_PREL_PG_HI21 against `.data.rel.ro..L.hwasan'
           collect2: error: ld returned 1 exit status
Some tests failed in compiletest suite=ui mode=ui host=aarch64-unknown-linux-gnu target=aarch64-unknown-linux-gnu

error: aborting due to previous error

---
test result: FAILED. 11605 passed; 1 failed; 136 ignored; 0 measured; 0 filtered out; finished in 342.80s



command did not execute successfully: "/checkout/obj/build/aarch64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/lib/rustlib/aarch64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-aarch64-unknown-linux-gnu" "--suite" "ui" "--mode" "ui" "--target" "aarch64-unknown-linux-gnu" "--host" "aarch64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/aarch64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--llvm-version" "12.0.0-rust-1.53.0-nightly" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter cfguard codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver dwarflinker engine executionengine extensions filecheck frontendopenacc frontendopenmp fuzzmutate globalisel hellonew hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interfacestub interpreter ipo irreader jitlink libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit orcshared orctargetprocess passes powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info xray" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test
Build completed unsuccessfully in 0:48:15

@rustbot label A-testsuite C-bug

Activity

  1. added
    A-testsuiteArea: The testsuite used to check the correctness of rustc
    C-bugCategory: This is a bug.
    on Apr 8, 2021
  2. changed the title [-]UI test `sanitize/hwaddress.rs` fails on aarch64 when executed with 1 CGU[/-] [+]UI test `sanitize/hwaddress.rs` fails with linker error on aarch64 when executed with 1 CGU[/+] on Apr 8, 2021
  3. pnkfelix commented on Jun 3, 2022

    @pnkfelix
    Contributor

    is this an instance of #49845, which we had thought had quietly gone away?

  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    O-AArch64Armv8-A or later processors in AArch64 mode
    on Mar 19, 2024
  5. Enselic commented on Oct 23, 2025

    @Enselic
    Member

    We get the error also with 16 CGUs if we disable LTO:

    $ rustc +nightly -Clinker=aarch64-linux-gnu-gcc --target=aarch64-unknown-linux-gnu tests/ui/sanitizer/hwaddress.rs -Z sanitizer=hwaddress -O -g -C codegen-units=16 -C unsafe-allow-abi-mismatch=sanitizer -Clto=no
    error: linking with `aarch64-linux-gnu-gcc` failed: exit status: 1
      |
      = note: hwaddress.hwaddress.71eeac658309bde7-cgu.2.rcgu.o: in function `std::rt::lang_start':
              /home/martin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:(.text._ZN3std2rt10lang_start17hae1e7d092f980101E+0x38): relocation truncated to fit: R_AARCH64_ADR_PREL_PG_HI21 against `.data.rel.ro..L.hwasan'
              collect2: error: ld returned 1 exit status
    
    error: aborting due to 1 previous error

    So it seems like with 16 CGUs the thin linker optimizations hide a real bug. I think I found the bug. At least my LLVM patch tested ok for the Rust test we have.

    I will soon open an LLVM PR (Edit: llvm/llvm-project#164876) with the fix and see what they say.

    @rustbot claim

  6. rustbot commented on Oct 23, 2025

    @rustbot
  7. added 3 commits that reference this issue on Oct 28, 2025
    df98447
    c4747ea
    78526e4
  8. added a commit that references this issue on Oct 28, 2025
    46a48f5
  9. added a commit that references this issue on Nov 3, 2025
    fea02f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-testsuiteArea: The testsuite used to check the correctness of rustcC-bugCategory: This is a bug.O-AArch64Armv8-A or later processors in AArch64 modeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions