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

wasi-libc: compile emmalloc.c without strict aliasing #16157

Merged
merged 3 commits into from
Jun 25, 2023

Conversation

jedisct1
Copy link
Contributor

emmalloc.c does a fair amount of type punning in order to access the size of memory regions and traverse them.

Unfortunately, that can lead to unwanted optimizations.

This simple test case currently triggers a memory fault:

int main(void) {
    char * volatile p = malloc(1);
    p = realloc(p, 12);
    p = malloc(1);
    printf("%p\n", p);
}

Work around this by adding "-fno-strict-aliasing" when compiling that file.

emmalloc.c does a fair amount of type punning in order to access
the size of memory regions and traverse them.

Unfortunately, that can lead to unwanted optimizations.

This simple test case currently triggers a memory fault:

int main(void) {
    char * volatile p = malloc(1);
    p = realloc(p, 12);
    p = malloc(1);
    printf("%p\n", p);
}

Work around this by adding "-fno-strict-aliasing" when compiling
that file.
@jedisct1
Copy link
Contributor Author

Fixes WebAssembly/wasi-libc#421

Copy link
Member

@Luukdegram Luukdegram left a comment

Choose a reason for hiding this comment

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

LGTM

@jedisct1 jedisct1 merged commit e7f872c into ziglang:master Jun 25, 2023
@jedisct1 jedisct1 deleted the wasi-libc-aliasing branch June 25, 2023 09:25
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