https://sourceware.org/bugzilla/show_bug.cgi?id=34844

            Bug ID: 34844
           Summary: GNU ld RISC-V R_RISCV_ALIGN addend with the top bit
                    set never terminates
           Product: binutils
           Version: 2.46
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: basavesh.shivakumar at wsu dot edu
  Target Milestone: ---

Created attachment 17164
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17164&action=edit
repro

I'm reporting this bug on behalf of my team: Ananta Srikar Puranam, Emily West,
Dr. Swarn Priya, Dr. Peng Gao and Dr. Basavesh Ammanaghatta Shivakumar.

Summary
=======

A valid RISC-V relocatable object whose R_RISCV_ALIGN relocation carries an
addend with its top bit set (e.g. -1, 0x8000000000000000 on RV64, or 0x80000000
sign-extended on RV32) makes _bfd_riscv_relax_align loop forever: alignment
doubles to 2^63, stays <= the unsigned addend, then wraps to 0 and never
exceeds it (bfd/elfnn-riscv.c:5253 released 2.46, :5555 current 85f5ea68, :5562
instrumented build 3d45f46c, :5555 master 17d606a601f4). The mandatory ALIGN
pass runs even with --no-relax, so static, PIE and shared links all hang; only
-r links are skipped. Released GNU ld 2.46, the Ubuntu riscv64-linux-gnu-ld
2.46, current 2.47.50.20261016 plain, and both sanitizer builds time out while
the addend-6 controls link; no sanitizer memory diagnostic is produced because
the loop variable is unsigned.

Reproduction
============

1. Download and extract
`bfd-riscv-align-negative-addend-nonterminating-relaxation-reproducer.tar.gz`.
2. Run the following command with an ld.bfd or all-target `ld-new` binary that
   supports the emulation used by the reproducer:

       LD=/path/to/ld-new sh repro.sh

The archive contains the fixed input files, independent controls, helper
scripts needed by `repro.sh`, and their checksums. The script uses a temporary
directory and does not modify the source tree.

Observed result
===============

A valid RISC-V relocatable object whose R_RISCV_ALIGN relocation carries an
addend with its top bit set (e.g. -1, 0x8000000000000000 on RV64, or 0x80000000
sign-extended on RV32) makes _bfd_riscv_relax_align loop forever: alignment
doubles to 2^63, stays <= the unsigned addend, then wraps to 0 and never
exceeds it (bfd/elfnn-riscv.c:5253 released 2.46, :5555 current 85f5ea68, :5562
instrumented build 3d45f46c, :5555 master 17d606a601f4). The mandatory ALIGN
pass runs even with --no-relax, so static, PIE and shared links all hang; only
-r links are skipped. Released GNU ld 2.46, the Ubuntu riscv64-linux-gnu-ld
2.46, current 2.47.50.20261016 plain, and both sanitizer builds time out while
the addend-6 controls link; no sanitizer memory diagnostic is produced because
the loop variable is unsigned.

Expected result
===============

GNU ld should either produce the correct output or reject the input with a
normal diagnostic. It should not crash, hang, execute undefined behavior, read
outside an input-derived allocation, or produce the described malformed
output.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to