Skip to content

Conversation

@Ericson2314
Copy link

With Clang 21 at least, we start to get warnings like:

rtld.c:333:58: error: initializer-string for character array is too long, array size is 4 but initializer has size 5 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Werror,-Wunterminated-string-initialization]
  333 |         static const char rtld_utrace_sig[RTLD_UTRACE_SIG_SZ] = RTLD_UTRACE_SIG;
      |                                                                 ^~~~~~~~~~~~~~~
./rtld_utrace.h:49:27: note: expanded from macro 'RTLD_UTRACE_SIG'
   49 | #define RTLD_UTRACE_SIG                 "RTLD"
      |

Looking up the nonstring attribute 1, it does seem to be the correct thing --- indicating a char array which should not have a null terminator byte --- to use in these two cases.

Note: I discovered this when fixing Nixpkgs's FreeBSD cross compilation support. I understand that FreeBSD may not officially support this version of Clang yet, but I am hoping the attribute still works with the version of Clang it does support (even if it not yet needed on that version to fix -Werror errors). I am hoping thus that this patch is accessible, as just early readiness for when FreeBSD does upgrade to that version of Clang.

@github-actions
Copy link

github-actions bot commented Oct 27, 2025

Thank you for taking the time to contribute to FreeBSD!
All issues resolved.

@Ericson2314
Copy link
Author

llvm/llvm-project#137705 ah interesting, it is an old GCC feature, but new in Clang. I will add some CPP compat magic for this accordingly.

With Clang 21 at least, we start to get warnings like:

```
rtld.c:333:58: error: initializer-string for character array is too long, array size is 4 but initializer has size 5 (including the null terminating character); did you mean to use the 'nonstring' attribute? [-Werror,-Wunterminated-string-initialization]
  333 |         static const char rtld_utrace_sig[RTLD_UTRACE_SIG_SZ] = RTLD_UTRACE_SIG;
      |                                                                 ^~~~~~~~~~~~~~~
./rtld_utrace.h:49:27: note: expanded from macro 'RTLD_UTRACE_SIG'
   49 | #define RTLD_UTRACE_SIG                 "RTLD"
      |
```

Looking up the `nonstring` attribute [1], it does seem to be the correct
thing --- indicating a char array which should not have a null
terminator byte --- to use in these two cases.

Note: I discovered this when fixing Nixpkgs's FreeBSD cross compilation
support. I understand that FreeBSD may not officially support this
version of Clang yet, and so the CPP that is needed is a bit annoying.
But it still hopefully will make things easier once it comes time to
bump the supported version of Clang to one with this attribute.

I am hoping thus that this patch is acceptable, as just early readiness
for when FreeBSD does upgrade to that version of Clang.

[1]: https://clang.llvm.org/docs/AttributeReference.html#nonstring

Signed-off-by: John Ericson <[email protected]>
@Ericson2314
Copy link
Author

OK this only uses the attribute when it exists, now.

github-merge-queue bot pushed a commit to NixOS/nixpkgs that referenced this pull request Nov 1, 2025
It looks like upgrading to newer clang has caused some `-Werror`
problems. We should probably disable `-Werror` entirely, but for now,
I've done the more targetted fix of disabling one specific warning, and
sending freebsd/freebsd-src#1882 upstream.
@VexedUXR
Copy link
Member

VexedUXR commented Nov 1, 2025

Thank you, but I think #1847 should cover this.

@Ericson2314
Copy link
Author

Ah ok good that exists. Hope it is merged soon.

@Ericson2314 Ericson2314 closed this Nov 1, 2025
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