picotcp
picotcp copied to clipboard
Weak references not working correctly under Windows with MinGW
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.
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