Skip to content

Weak references not working correctly under Windows with MinGW #523

Open
@Ensber

Description

@Ensber

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions