Skip to content

Conversation

@kr-t
Copy link
Contributor

@kr-t kr-t commented Oct 6, 2025

This PR is intended to remove following warnings, when build in Zephyr application:

wasm-micro-runtime/core/shared/platform/zephyr/platform_internal.h:293: warning: "CLOCK_MONOTONIC" redefined
  293 | #define CLOCK_MONOTONIC 4
wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c: In function 'zephyr_fs_alloc_obj':
wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c:123:25: warning: implicit declaration of function 'bh_strdup' [-Wimplicit-function-declaration]
  123 |             ptr->path = bh_strdup(path);
      |                         ^~~~~~~~~
wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c:123:23: warning: assignment to 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  123 |             ptr->path = bh_strdup(path);
      |                       ^
wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c: In function 'os_renameat':
wasm-micro-runtime/core/shared/platform/zephyr/zephyr_file.c:853:35: warning: initialization of 'char *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  853 |             char *new_path_copy = bh_strdup(new_path);
      |                                   ^~~~~~~~~
[45/462] Building C object CMakeFiles/app.dir/wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c.obj
wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c: In function 'wasmtime_ssp_poll_oneoff':
wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2216:42: warning: initialization of 'os_file_handle' {aka 'struct zephyr_handle *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
 2216 |                     os_file_handle tfd = fos[i]->file_handle->fd;
      |                                          ^~~
wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2222:31: warning: initialization of 'int' from 'os_file_handle' {aka 'struct zephyr_handle *'} makes integer from pointer without a cast [-Wint-conversion]
 2222 |                         .fd = tfd,
      |                               ^~~
wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2222:31: note: (near initialization for '(anonymous).fd')

Result - no warnings.

Tested in ocre as a zephyr application.

Updates:
there have been updates and changes after the initial commit and initial description. Please check those below in my follow-up comments.

@kr-t kr-t changed the title Remove warnings relevant to Zephyr platform Reduce warnings relevant to Zephyr platform Oct 6, 2025
@kr-t kr-t force-pushed the remove-zephyr-warnings branch 2 times, most recently from e79ae4b to 7639ed9 Compare October 6, 2025 11:36
@kr-t
Copy link
Contributor Author

kr-t commented Oct 6, 2025

Update after the initial commit:

Apparently, the CI doesn't like that in Zephyr's case I used int instead of os_file_handle. I have tried another way of refactoring the logic of how we abstract the os_file_handle tfd variable, but each time I have successfully removed warnings, the CI was unhappy with my changes and I couldn't pass all checks. Therefore, the changes in this PR in its current state leaves us with following - a successful CI, reduced amount of warnings and following warnings left:

wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2216:42: warning: initialization of 'os_file_handle' {aka 'struct zephyr_handle *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
 2216 |                     os_file_handle tfd = fos[i]->file_handle->fd;
      |                                          ^~~
wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2222:31: warning: initialization of 'int' from 'os_file_handle' {aka 'struct zephyr_handle *'} makes integer from pointer without a cast [-Wint-conversion]
 2222 |                         .fd = tfd,
      |                               ^~~
wasm-micro-runtime/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c:2222:31: note: (near initialization for '(anonymous).fd')

Fixing temporary workaround which was made in PR#4377 will probably help with these remaining warnings as well.

@kr-t kr-t force-pushed the remove-zephyr-warnings branch from 7639ed9 to bdfd724 Compare October 6, 2025 12:29
@lum1n0us
Copy link
Collaborator

IMM, a better approach is to avoid using bh_xxx() functions in zephyr/zephyr_file.c. Instead, opt for a specific version that is compatible with Zephyr

@kr-t
Copy link
Contributor Author

kr-t commented Oct 16, 2025

Noted, will check out the alternatives.

@kr-t
Copy link
Contributor Author

kr-t commented Oct 21, 2025

Removed bh_strdup() function, therefore reducing the undeclared warning.
Since zephyr supports strdup() only when CONFIG_POSIX_C_LIB_EXT is selected, I didn't want to force users to use this, so I replaced strdup() with more generic strcpy().

struct zephyr_fs_desc *ptr = &desc_array[i];
if (ptr->used && ptr->path && strcmp(ptr->path, abs_old_path) == 0) {
char *new_path_copy = bh_strdup(new_path);
size_t new_path_len = strlen(abs_new_path) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems there is another modification to store the absolute path instead of the relative path, which might be better to split into a new PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR was intended to fix two warning, redefinition of CLOCK_MONOTONIC and implicit declaration of function 'bh_strdup'. With first one parallelly being committed by @TianlongLiang in #4668 , this PR can't be further split anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or if you mean that I replaced bh_strdup in two places and it would be better to split them in two separate PRs, or I missed something, please let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

new_path -> abs_new_path.

The modified version stores absolute paths instead of relative paths in desc_array, which looks good. It would be better to build absolute paths in os_open_preopendir() to ensure all paths are absolute.

If this is intentional, it should be mentioned in the PR description. It's your decision whether to split this into another PR or keep it in the current one. I am okay with both options.

kr-t added 4 commits October 28, 2025 07:33
Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
@kr-t kr-t force-pushed the remove-zephyr-warnings branch from 986174b to 50d92d3 Compare October 28, 2025 06:48
@lum1n0us lum1n0us added the bug-fix Determine if this PR addresses a bug. It will be used by scripts to classify PRs. label Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix Determine if this PR addresses a bug. It will be used by scripts to classify PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants