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

Use MUSL's weak* feature in bottom half #306

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

abrown
Copy link
Collaborator

@abrown abrown commented Jul 25, 2022

This change extracts the weak*-related parts of #303 as a separate PR.
Note that this is slightly strange in that it uses some top-half MUSL
headers in the bottom-half code, but discussion around this led me to
believe that the advantages of, e.g., LOCK made this worthwhile.
Beyond just changing uses of weak to __weak__, we also MUSL's weak
and weak_alias macros in a few more places.

This change extracts the `weak*`-related parts of WebAssembly#303 as a separate PR.
Note that this is slightly strange in that it uses some top-half MUSL
headers in the bottom-half code, but discussion around this led me to
believe that the advantages of, e.g., `LOCK` made this worthwhile.
Beyond just changing uses of `weak` to `__weak__`, we also MUSL's `weak`
and `weak_alias` macros in a few more places.
@@ -70,7 +70,7 @@ int __wasilibc_find_relpath_alloc(
char **relative,
size_t *relative_len,
int can_realloc
) __attribute__((weak));
) __attribute__((__weak__));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is a place that I could have used just weak but when I do the build fails:

#
# Test that it compiles.
#
clang -O2 -DNDEBUG --target=wasm32-wasi -fno-trapping-math -Wall -Wextra -Werror -Wno-null-pointer-arithmetic -Wno-unused-parameter -Wno-sign-compare -Wno-unused-variable -Wno-unused-function -Wno-ignored-attributes -Wno-missing-braces -Wno-ignored-pragmas -Wno-unused-but-set-variable -Wno-unknown-warning-option -mthread-model single -isystem "/home/abrown/Code/wasi-libc/sysroot/include" -fsyntax-only "/home/abrown/Code/wasi-libc/sysroot/share/wasm32-wasi/include-all.c" -Wno-\#warnings
In file included from /home/abrown/Code/wasi-libc/sysroot/share/wasm32-wasi/include-all.c:166:
/home/abrown/Code/wasi-libc/sysroot/include/wasi/libc-find-relpath.h:73:3: error: expected function body after function declarator
) weak;
  ^
1 error generated.

I guess there is some other place to add an include path if we want to use weak everywhere. (Not sure I'm fully convinced that weak is better than __attribute((__weak__)), though... Just trying to be consistent.)

Copy link
Member

@sbc100 sbc100 Jul 25, 2022

Choose a reason for hiding this comment

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

Adding #include <features.h> to this file should do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That seemed like the right thing to do so I tried it but it blew up with the same error...

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Nice!

@sunfishcode sunfishcode merged commit 87c2aa0 into WebAssembly:main Jul 26, 2022
@sunfishcode
Copy link
Member

LGTM!

@@ -11,7 +11,7 @@
/// Statically-initialize it to an invalid pointer value so that we can
/// detect if it's been explicitly initialized (we can't use `NULL` because
/// `clearenv` sets it to NULL.
char **__wasilibc_environ __attribute__((weak)) = (char **)-1;
char **__wasilibc_environ weak = (char **)-1;
Copy link
Member

Choose a reason for hiding this comment

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

I think this reads way easier with weak at the start of the line.. and I think that seems to be how musl uses it.

@@ -87,7 +87,7 @@ void __wasilibc_deinitialize_environ(void) {
}

// See the comments in libc-environ.h.
__attribute__((weak))
weak
void __wasilibc_maybe_reinitialize_environ_eagerly(void) {
Copy link
Member

Choose a reason for hiding this comment

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

Combine these onto one line?

@abrown abrown deleted the weak-alias branch July 26, 2022 22:23
abrown added a commit to abrown/wasi-libc that referenced this pull request Jul 26, 2022
This is a follow-up based on @sbc100's comments in WebAssembly#306.
sbc100 pushed a commit that referenced this pull request Jul 26, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This is a follow-up based on @sbc100's comments in #306.
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.

None yet

3 participants