Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply patches when used in radare2 #569

Closed
wants to merge 14 commits into from
Closed

Conversation

satk0
Copy link
Contributor

@satk0 satk0 commented Oct 2, 2024

I've made a PR that fixes all the issues we found in r2 as I said I would do in issue #559

Based on the following commits:

Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I left a couple of comments.

cutils.c Outdated
@@ -1129,7 +1129,7 @@ void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)

/*---- Portable time functions ----*/

#if defined(_MSC_VER)
#if defined(_MSC_VER) || __MINGW32__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Is it to support the old mingw32 aka not mingw-w64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yea, that's @trufae's commit, here:
radareorg/radare2@86529d7
and sheesh its failing all the mingw checks, idk why :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mingw32 is really old and no longer maintained AFAIK, mingw-w64 (which also has a 32bit version, despite the name) has been the de facto MinGW for a while I think.

@trufae ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can either of you confirm which version of MinGW you're using?

My fear is we'd break mingw32 support since we don't run tests on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMG_20241005_142544

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's mingw-w64 which we already support, I don't think those changes are necessary.

Any chance you can try to build radare without them?

quickjs.c Show resolved Hide resolved
quickjs.c Outdated
@@ -34561,7 +34561,7 @@ static JSString *JS_ReadString(BCReaderState *s)
}
#ifdef DUMP_READ_OBJECT
if (check_dump_flag(s->ctx->rt, DUMP_READ_OBJECT)) {
bc_read_trace(s, ""); // hex dump and indentation
bc_read_trace(s, "%s", ""); // hex dump and indentation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, nice! Can you please remove the silencer flag I added to CMake then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@satk0
Copy link
Contributor Author

satk0 commented Oct 2, 2024

Done, maybe this time mingw-w64 will pass, I added a check for only mingw32, excluding w64 🙏

@satk0
Copy link
Contributor Author

satk0 commented Oct 2, 2024

Btw, thanks a lot for being so responsive, it is really motivating!

@@ -1710,6 +1710,11 @@ static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
slimb_t d;

na = n + nb;

if (na >= (SIZE_MAX / sizeof(limb_t)) - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on Windows, since IIRC the limb bits are fewer there.

D:/a/quickjs/quickjs/libbf.c:1714:16: error: comparison is always false due to limited range of data type [-Werror=type-limits]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's rough, will try to play with it more

cutils.c Outdated
@@ -1129,7 +1129,7 @@ void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)

/*---- Portable time functions ----*/

#if defined(_MSC_VER)
#if defined(_MSC_VER) || (__MINGW32__ && !defined(__MINGW64__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come to think of it, we could use this everywhere on windows, perhaps that's a simpler thing, let's try it please.

Copy link
Contributor Author

@satk0 satk0 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I need to find a macro that distinguish mingw32 from Mingw-w64

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking on the opposite direction, as in, to use this implementation also in MinGW, if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, allright, I could try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw can you plz give me any hint about the limb bits on windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

#if INTPTR_MAX >= INT64_MAX && !defined(_WIN32) && !defined(__TINYC__)
the size of limb_t is platform dependent, so perhaps an extra if-def is necessary to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I will try this today as well as your __MINGW32__ idea

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@satk0
Copy link
Contributor Author

satk0 commented Oct 4, 2024

Done, letme know if that's what you expected. Sorry for pushing it so late 😓

libbf.c Outdated
@@ -1710,6 +1710,11 @@ static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec,
slimb_t d;

na = n + nb;

if (na >= (SIZE_MAX / sizeof(limb_t)) - 1) && !defined(_WIN32) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check should be surrounded by some ifdef sizeof (limb_t) > sizeof(uint64_t) instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W8, I haven't closed the brackets here, that's why its all failing, sorry. I will fix it

cutils.c Outdated
@@ -1129,7 +1129,7 @@ void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque)

/*---- Portable time functions ----*/

#if defined(_MSC_VER)
#if defined(_MSC_VER) || __MINGW32__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can either of you confirm which version of MinGW you're using?

My fear is we'd break mingw32 support since we don't run tests on it.

@satk0
Copy link
Contributor Author

satk0 commented Oct 5, 2024

Chck now, sry for this obv mistake I've made

@satk0
Copy link
Contributor Author

satk0 commented Oct 6, 2024

Allright, some checks are still failing, I think that changing this comparison back to a simple !defined(_WIN32) would solve it.

@saghul
Copy link
Contributor

saghul commented Oct 6, 2024

Allright, some checks are still failing, I think that changing this comparison back to a simple !defined(_WIN32) would solve it.

I think so too!

@satk0
Copy link
Contributor Author

satk0 commented Oct 6, 2024

Ok, letsee how it goes ❗

@saghul
Copy link
Contributor

saghul commented Oct 6, 2024

Ah I thought you meant something else.

I think what you want to check for then is if LIMB_LOG2_BITS is 6 or not.

@satk0
Copy link
Contributor Author

satk0 commented Oct 6, 2024

Oh, ok so I'd check for if LIMB_LOG2_BITS == 6 instead of _WIN32

Thanks for the quick review btw 😃

@satk0
Copy link
Contributor Author

satk0 commented Oct 6, 2024

Another thing is that I should check if defined(__MINGW32__) instead of only if __MINGW32__

@saghul
Copy link
Contributor

saghul commented Oct 6, 2024

Another thing is that I should check if defined(__MINGW32__) instead of only if __MINGW32__

I'd rather see it gone. I think it's not necessary since both us and radars are using mingw-w64.

@satk0
Copy link
Contributor Author

satk0 commented Oct 6, 2024

Ok, So I contacted pancake on it and he said this:
IMG_20241006_203533

So yea, we use mingw32 in r2, I just asked pancake on mingw version, not mingw32 (I wasn't precise enough). So he answered with the mingw-w64 one XD.

But nevertheless, I'll go with your suggestion to omit this and see what happens with mingw32 on ubuntu24, thanks!

@saghul
Copy link
Contributor

saghul commented Oct 6, 2024

Sounds good!

@satk0
Copy link
Contributor Author

satk0 commented Oct 6, 2024

OK done, hopefully nothing will break 🙏

@saghul
Copy link
Contributor

saghul commented Oct 7, 2024

Looks good! Let's see if the CI is green!

@satk0
Copy link
Contributor Author

satk0 commented Oct 7, 2024

Hmm, seems I have to put this limb thing inside #if LIMB_LOG2_BITS == 6 cuz C is still calculating it cuz operator precedence 😖

@satk0
Copy link
Contributor Author

satk0 commented Oct 7, 2024

Ok done, chck it now

@saghul
Copy link
Contributor

saghul commented Oct 7, 2024

Squash - rebased them and landed! #582

@saghul saghul closed this Oct 7, 2024
@saghul
Copy link
Contributor

saghul commented Oct 7, 2024

Thanks for persevering! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants