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

Incorrect size assumption for size_t on 16-bit target (msp430). #168

Closed
geurtv opened this issue Nov 20, 2023 · 7 comments
Closed

Incorrect size assumption for size_t on 16-bit target (msp430). #168

geurtv opened this issue Nov 20, 2023 · 7 comments
Assignees
Labels
platform-incompatibility The library is making assumptions causing it to fail on platforms where they do not hold. resolved-on-develop A changeset fixing this issue has been commiutted to the development branch

Comments

@geurtv
Copy link

geurtv commented Nov 20, 2023

As noted in README.md:

The implementation currently assumes each of intmax_t, signed size_t, and ptrdiff_t has the same size as long int or as long long int. If this is not the case for your platform, please open an issue.

With msp430-elf-gcc for the 16-bit msp430 microcontroller sizeof(size_t) == 2, which is the same as int and not as long (sizeof(long) == 4). A change like this should be portable and fixes the issue (intmax_t and ptrdiff_t will need similar changes):

flags |= sizeof(size_t) <= sizeof(int) ? FLAGS_INT : sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG;
@eyalroz
Copy link
Owner

eyalroz commented Nov 20, 2023

So, you're saying long is not representable in a single machine register? Are you 100% sure this is the case? That's a very weird choice for a platform's C ABI.

@eyalroz eyalroz added the platform-incompatibility The library is making assumptions causing it to fail on platforms where they do not hold. label Nov 20, 2023
@geurtv
Copy link
Author

geurtv commented Nov 20, 2023

Yes, that's exactly how it is, and I wouldn't expect this to be too uncommon for 16-bit microcontrollers. int (and short) will be the same size as the cpu register size, so 16-bit. Then long will be 32-bit and long long 64-bit (which gcc actually supports). For msp430 gcc has two addressing mode options: -msmall and -mlarge. With -msmall it uses 16-bit pointers and 16-bit size_t, with -mlarge it uses 20-bit pointers and 32-bit size_t (which should already work). The msp430 variant I'm using has 16k flash and 4k ram, so I use -msmall.

Btw, intmax_t already works as it's long long. For -msmall it's (only) size_t and ptrdiff_t that don't work.

@eyalroz
Copy link
Owner

eyalroz commented Nov 20, 2023

Ok, if you say so... I'll try to find the time to consider your suggestion and check the code for potential impact of this situation.

However, as you may know, there's war now, and demonstrations against it, and I've already been arrested at one of those, and there are some personal issues, and my job etc., so it may take a bit of time. If I haven't done anything within... 3 weeks from now, please ping me.

eyalroz added a commit that referenced this issue Nov 21, 2023
… than `long` (e.g. for the msp430-elf-gcc target)
@eyalroz
Copy link
Owner

eyalroz commented Nov 21, 2023

Please check out the development branch and let me know if everything works for you.

@geurtv
Copy link
Author

geurtv commented Nov 22, 2023

That does the trick, thanks! Note that ptrdiff_t needs similar treatment.

eyalroz added a commit that referenced this issue Nov 22, 2023
… of smaller size than `long` (e.g. for the msp430-elf-gcc target)
eyalroz added a commit that referenced this issue Nov 22, 2023
… of smaller size than `long` (e.g. for the msp430-elf-gcc target)
@eyalroz
Copy link
Owner

eyalroz commented Nov 22, 2023

Right... can you recheck?

@geurtv
Copy link
Author

geurtv commented Nov 23, 2023

Yes, that now works for both size_t and ptrdiff_t.

@eyalroz eyalroz self-assigned this Nov 23, 2023
@eyalroz eyalroz added the resolved-on-develop A changeset fixing this issue has been commiutted to the development branch label Nov 23, 2023
eyalroz added a commit that referenced this issue Jul 19, 2024
… of smaller size than `long` (e.g. for the msp430-elf-gcc target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-incompatibility The library is making assumptions causing it to fail on platforms where they do not hold. resolved-on-develop A changeset fixing this issue has been commiutted to the development branch
Projects
None yet
Development

No branches or pull requests

2 participants