oasislinux / oasis

a small statically-linked linux system
Other
2.75k stars 84 forks source link

cproc has problem with cast from double to unsigned int #63

Closed xphung closed 5 months ago

xphung commented 1 year ago

cproc seems to have a problem with the cast from double to unsigned int (needed by Lua).

I came across the error originally compiling lua v5.2.4 (oasis r0) using cproc (commit #995d5b48b1), but the following c program demonstrates the error more clearly (save source below to a file 'llimit.c', and compile to a.out as shown below):

` DEMO SOURCE CODE:

include

include

define LUA_INT32 int

define LUA_UNSIGNED unsigned LUA_INT32

typedef LUA_UNSIGNED lua_Unsigned;

int main(int arg, char *argv[]) { double u = (1lu<<32) - 0x1234 + arg - arg; //4294962636.0; printf("u = %f, long u = %lx, unsigned u = %x\n", u, (long)u, (lua_Unsigned)u); return 0; }

COMPILE AND EXECUTE:

gcc llimits.c ./a.out u = 4294962636.000000, long u = ffffedcc, unsigned u = ffffedcc cproc -static -nostdinc -isystem out/pkg/musl/include -L out/pkg/musl llimits.c ./a.out u = 4294962636.000000, long u = ffffedcc, unsigned u = 80000000 `

As you can see above, a.out compiled with gcc gives the correct result, whereas the result is incorrect when compiled with cproc

mpu commented 10 months ago

I suggest you flag the issue on the mailing list, if not already done. https://lists.sr.ht/~mcf/cproc

michaelforney commented 10 months ago

Thanks for the bug report! I think this is an issue with qbe's ftoui/dtoui instructions, and I've reported it (along with a patch) here: https://lists.sr.ht/~mpu/qbe/%3C20220128010618.18922-1-bor.groseljsimic%40telemach.net%3E#%3C2WHWJ00ELR8ZM.2DGF0BPWK4MDE@mforney.org%3E

xphung commented 10 months ago

Thanks for the patch :smiley: I will incorporate it into my oasis/cproc build and report back if any problems.

mpu commented 10 months ago

Hi all, qbe master should now have a fix for this issue.

michaelforney commented 5 months ago

qbe is now updated to latest master in oasis