Issue 243548
Summary [llvm-jitlink] --show-relocated-section-contents loops forever when two symbols share an address
Labels jitlink
Assignees
Reporter AnantaSrikar
    `dumpSectionContents` in `llvm-jitlink` sorts a section's symbols by address and then walks them with a `NextAddr` cursor. After rendering the first symbol, `NextAddr` is at that symbol's end. If the next symbol starts at the same address, or anywhere before that end, the padding loop `while (NextAddr != SymStart) ++NextAddr;` never meets `SymStart` until the 64-bit address wraps. So `--show-relocated-section-contents` prints empty rows without end for an ordinary object with two function symbols at the same offset. An x86-64 ELF object that uses the GOT hits the same loop through the synthesized `$__GOT` symbols, but only on some runs (two of three here), because the order of equal-address symbols after the sort isn't fixed.

**Version**: main at c7014922f582 (2026-11-16), built from the Git repository with `-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON`, on x86_64 Linux.

### Reproducer

```sh
cat > eq.yaml <<'YAML'
--- !COFF
header:
  Machine:         IMAGE_FILE_MACHINE_AMD64
 Characteristics: [ ]
sections:
  - Name:            .text
 Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
    Alignment:       16
    SectionData: C3
symbols:
  - Name:            f
    Value:           0
 SectionNumber:   1
    SimpleType:      IMAGE_SYM_TYPE_NULL
 ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
    StorageClass: IMAGE_SYM_CLASS_EXTERNAL
  - Name:            g
    Value:           0
 SectionNumber:   1
    SimpleType:      IMAGE_SYM_TYPE_NULL
 ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
    StorageClass: IMAGE_SYM_CLASS_EXTERNAL
YAML
yaml2obj eq.yaml -o eq.obj
llvm-jitlink --noexec --entry=f --show-relocated-section-contents eq.obj | head -6
```

Without `--show-relocated-section-contents`, it exits 0. With only `f`, it prints the one row and exits.

### Observed

```
Relocated section contents for eq.obj:
.text content:
0x7fad18000000: c3
0x7fad18000010:
0x7fad18000020:
0x7fad18000030:
```

and so on: it filled a 1 MB output cap within 10 seconds.

### Expected

One row with `c3`, as with a single symbol.

### Analysis

https://github.com/llvm/llvm-project/blob/c7014922f5829426952a38d079220c21b0a8ebe8/llvm/tools/llvm-jitlink/llvm-jitlink.cpp#L610-L645

Skipping a symbol whose start is below `NextAddr` (or starting its render at `max(SymStart, NextAddr)`), and making the padding loop `while (NextAddr < SymStart)`, would fix it. A secondary sort key (for example size, then name) would also make the output deterministic for symbols at the same address.

This report was drafted with help from an AI assistant (Claude); I reviewed it and reproduced it myself.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to