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

Weak references not working correctly under Windows with MinGW #523

Open
Ensber opened this issue May 31, 2022 · 1 comment
Open

Weak references not working correctly under Windows with MinGW #523

Ensber opened this issue May 31, 2022 · 1 comment

Comments

@Ensber
Copy link

Ensber commented May 31, 2022

I was compiling a littele test project. Under Linux it compiled without a problem, but under Windows I always got a error that it could not find 'pico_rand_feed' and 'pico_rand'. After not knowing how I could possibly fix this, i went to Google and Stack Overflow to find nothing. Next I did was to ask a detailed Question on Stack Overflow here. Today I had the idea to inspect the .a archive with objdump, wich got me this:

$ objdump -t libpicotcp.a | grep pico_rand
[ 94](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[149](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 86](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 80](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 98](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[148](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[123](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[163](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[103](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 62](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 36](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[184](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 57](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 65](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand_feed
[156](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 80](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000012d .weak._pico_rand_feed._pico_tick
[ 81](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000169 .weak._pico_rand._pico_tick
[ 82](sec  0)(fl 0x00)(ty  20)(scl 105) (nx 1) 0x00000000 _pico_rand_feed
[ 84](sec  0)(fl 0x00)(ty  20)(scl 105) (nx 1) 0x00000000 _pico_rand

and after I commented out the weak references in pico_config.h, I got this:

$ objdump -t libpicotcp.a | grep pico_rand
[ 94](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[149](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 86](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 80](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 98](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[148](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[123](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[163](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[103](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 62](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 36](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[184](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 57](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[ 65](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand_feed
[156](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 _pico_rand
[  7](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x0000012d _pico_rand_feed
[  8](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000169 _pico_rand

wich was ok to compile.
I found that, the WEAK define is not configurable, so my suggestion would be to just make a config entry, to toggle this behaviour.

Alternatively I beleve, that by implementing a 'uint32_t pico_rand(void)' and 'void pico_rand_feed(uint32_t feed)' could also have solved the problem, if you didn't want to change the source.

@danielinux
Copy link
Contributor

You should not use the default pico_rand/pico_rand_feed mechanism, because it's just demo code, and it's PRNG, causing security issues in TCP and other protocols.

Please note that this project looks abandoned/dead. In our free branch, we do not provide a pico_rand() function any more, and you are specifically required to write one of your own, which do not pose this kind of security risks (e.g. predictable sequence numbers, side-channel attacks, etc.).

Please see https://github.com/virtualsquare/picotcp/ for a newer GPL-only fork that's still relatively active and maintained.

Thanks,

--
picoTCP original author

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

No branches or pull requests

2 participants