[llvm] [JITLink] Include target addend in out-of-range error (PR #145423)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 23 18:02:59 PDT 2025


lhames wrote:

This is a nice improvement.

With the proposed message the reader still needs to do the target-symbol + addend arithmetic to arrive at the actual out-of-
range address. What if we changed the message to:

```c++
    ErrStream << "In graph " << G.getName() << ", section " << Sec.getName()
              << ": relocation target "
              << formatv("{0:x}", E.getTarget().getAddress() + E.getAddend())
              <<  "(";
    if (E.getTarget().hasName())
      ErrStream << E.getTarget().getName();
    else
      ErrStream << "<anonymous symbol>";
    if (E.getAddend()) {
      // Target address includes non-zero added, so break down the arithmetic.
      ErrStream << formatv(":{0:x}", E.getTarget().getAddress()) << " + addend"
                << formatv(":{0:x}", E.getAddend());
    }
    ErrStream << ") is out of range of " << G.getEdgeKindName(E.getKind())
              << " at address " << formatv("{0:x}", E.getTarget().getAddress());
```

So error messages would look like:

"In graph foo.o, section __text: relocation target 0x10000000 (main) is out of range..."
"In graph foo.o, section __text: relocation target 0x20000000 (<anonymous symbol>) is out of range..."
"In graph foo.o, section __text: relocation target 0x10001000 (main:0x1000000 + addend:0x1000) is out of range..."
"In graph foo.o, section __text: relocation target 0x20002000 (<anonymous symbol>:0x20000000 + addend:0x2000) is out of range..."

https://github.com/llvm/llvm-project/pull/145423


More information about the llvm-commits mailing list