Repository navigation
Relic 1.1.4
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 doubleget that type.
Stepping through an array moves by whole elements (12 bytes on x86, 16 on x86-64). - Parameters and results. A
long doubleparameter takes its 12- or 16-byte stack slot as
one parameter, not two or three integers. Along doubleresult comes back on the x87 stack,
and on x86-64 that is how Relic tells it apart from adoubleinxmm0. On 32-bit x86, a
float, adoubleand along doubleall 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%Lconversions take onelong doubleargument from
the stack. Arguments that unoptimized code copies over word by word (push qwordtwice, or
push dwordthree times) become a single argument. A parameter that a function only passes
on to another function is still recognized as along double. - Math and constants.
sqrtl,fabsland the otherlfunctions, 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.