Skip to content

Relic 1.1.4

Choose a tag to compare

@github-actions github-actions released this 01 Nov 03:56
17815a8

Relic 1.1.4

This release adds long double, which until now was the one gap in the decompiler's x87
support. Code that uses long double, on 32-bit x86 or on x86-64, used to come out as
__asm("fld xword ptr [...]") lines. On x86-64 a function returning a long double could even
come out empty. Now you get C you can read and compile again.

Download

System File
Windows (x86-64) relic-1.1.4-windows-x86_64.exe
Linux (x86-64) relic-1.1.4-linux-x86_64.tar.gz: one file, relic
macOS, Apple silicon relic-1.1.4-macos-arm64.zip: Relic.app
macOS, Intel relic-1.1.4-macos-x86_64.zip: Relic.app

The macOS app isn't signed, so right-click it and choose Open the first time. The wheel is
attached too, for pip (Python 3.10+).

long double

long double ld_scale(long double x, int k) { return x * k + g_ld; }

compiled for 32-bit x86 used to decompile to

double scale(int a1, int a2, int a3, int a4)
{
    double v1;

    v1 = (double)a4;
    __asm("fld xword ptr [esp + 4]");
    __asm("fld xword ptr [eax + 0x38]");
    return v1 * x87_1 + x87_1;
}

and now decompiles to

long double ld_scale(long double a1, int a2)
{
    return (double)a2 * a1 + g_ld;
}

What's covered, on both x86 and x86-64:

  • Values in memory. Globals, locals, pointers and arrays of long double get that type.
    Stepping through an array moves by whole elements (12 bytes on x86, 16 on x86-64).
  • Parameters and results. A long double parameter takes its 12- or 16-byte stack slot as
    one parameter, not two or three integers. A long double result comes back on the x87 stack,
    and on x86-64 that is how Relic tells it apart from a double in xmm0. On 32-bit x86, a
    float, a double and a long double all come back on the x87 stack, so the type is worked
    out from how callers store the result and from the function's own code.
  • Calls. printf("%Lf", x) and other %L conversions take one long double argument from
    the stack. Arguments that unoptimized code copies over word by word (push qword twice, or
    push dword three times) become a single argument. A parameter that a function only passes
    on to another function is still recognized as a long double.
  • Math and constants. sqrtl, fabsl and the other l functions, and constants like
    0.25L.

The test sample, built at -O0 and -O2 for both x86 and x86-64, recompiles from its
pseudocode and gives the same results as the original.

One limit: when the decompiler simplifies constant expressions itself, it works with double
precision. In practice this matters only for constants that a double can't represent exactly.

Fixed

x86-64: calls returning a double were taken to leave it on the x87 stack. That only
mattered in functions that also use the x87 (that is, long double code), where it threw off
everything that came after such a call.