<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/88163>88163</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            MSan missing sysconf() interceptor on FreeBSD
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tavianator
      </td>
    </tr>
</table>

<pre>
    I can get spurious errors by calling sysconf() after some stack is marked uninitialized:

```console
tavianator@muon $ cat foo.c
#include <stdio.h>
#include <unistd.h>

__attribute__((noinline))
void foo(void) {
        int uninit[1024];
        printf("[%p, %p)\n", (void *)&uninit, (void *)(&uninit + 1));
}

int main(void) {
 foo();

        long arg_max = (sysconf)(_SC_ARG_MAX);
 printf("%ld\n", arg_max);
        return 0;
}
tavianator@muon $ clang18 -g -fsanitize=memory -fsanitize-memory-track-origins foo.c -o foo
tavianator@muon $ ./foo
[0x7fffffffc5b0, 0x7fffffffd5b0)
Uninitialized bytes in sysctl at offset 0 inside [0x7fffffffd580, 8)
==51927==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x800442766 in sysconf /usr/src/lib/libc/gen/sysconf.c:613:6
    #1 0x2b719d in main /usr/home/tavianator/code/foo.c:13:17
    #2 0x800413af9 in __libc_start1 /usr/src/lib/libc/csu/libc_start1.c:157:7
    #3 0x24d5bf in _start /usr/src/lib/csu/amd64/crt1_s.S:83

  Uninitialized value was created by an allocation of 'uninit' in the stack frame
    #0 0x2b7062 in foo /usr/home/tavianator/code/foo.c:6:2

SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/src/lib/libc/gen/sysconf.c:613:6 in sysconf
Exiting
tavianator@muon $ clang18 -v
clang version 18.1.2
Target: x86_64-portbld-freebsd14.0
Thread model: posix
InstalledDir: /usr/local/llvm18/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/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