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

    <tr>
        <th>Summary</th>
        <td>
            [libc] exposes internal implementations in symbol table
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

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

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

<pre>
    running `llvm-readelf -sW` on `libc.a` shows that the namespaced symbols are exported with STB_GLOBAL binding and STV_DEFAULT visbility:

```
$ llvm-readelf -sW projects/libc/lib/libc.a | llvm-cxxfilt | grep select
File: projects/libc/lib/libc.a(select.cpp.o)
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS select.cpp
     2: 0000000000000000    16 OBJECT  LOCAL  DEFAULT    5 .L__const.select.pss
 3: 0000000000000000   187 FUNC    GLOBAL DEFAULT    3 select
     6: 0000000000000000   187 FUNC    GLOBAL DEFAULT    3 __llvm_libc_18_0_0_git::select(int, fd_set*, fd_set*, fd_set*, timeval*)
```
ideally `_ZN22__llvm_libc_18_0_0_git6selectEiP6fd_setS1_S1_P7timeval` would not be accessible to folks linking against libc.a.

```diff
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index 53951dc131c2..e7902f96b617 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -22,10 +22,10 @@
 
 // MacOS needs to be excluded because it does not support aliasing.
 #if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
-#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
-  LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
-      __##name##_impl__ __asm__(#name); \
-  decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]];                   \
+#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
+  LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
+      __##name##_impl__ __asm__(#name); \
+  decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name),gnu::visibility("hidden")]];  \
   type __##name##_impl__ arglist
 #else
 #define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) type name arglist
 ```
 will at least produce
```
 6: 0000000000000000   187 FUNC    GLOBAL HIDDEN     3 __llvm_libc_18_0_0_git::select(int, fd_set*, fd_set*, fd_set*, timeval*)
```
but I think even better would be:
```
     6: 0000000000000000   187 FUNC    LOCAL DEFAULT     3 __llvm_libc_18_0_0_git::select(int, fd_set*, fd_set*, fd_set*, timeval*)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVt2P4jYQ_2vMy4gocUKABx5CgCttdhcV7ir1xXLiCbhrHBQ7-_HfV04C-3F7173eqrWs2M7Yv_nwjGe4MXKvEWdkNCejxYA39lDVMy2LW4GGN0pLrM0gr8TjrG60lnoPJPaVujsOa-QCVQlD8weJfah0S5F54XG3Nofq3oA9cAv2gKD5Ec2JFyjAPB7zShngNQI-nKraooB7aQ-w3c3Zp-xmnmSQSy0cN64FbHdf2GK5Sj5nO7iTJpdK2kcSJsRfEP_8jf2-d0sawWsp4VRXf2FhDaErJ2c39AuPAxmn3Zni4aGUyrY_9jWewKDCwnbIK6mQhMk_gBE66Q55xenkVYROu9PgWuDO-69aS_Fhtc6WbpbdpEkGcFYbkvkWnhCfgdFvgQUx3Mx_Xaa7r8EARuBljBWVNtbrYU_G9LDhNyCDyRhWn69TB9Bf0zPI8IWZWtnifwnEmLsH5kzJggnzmc_20robD5OeCZ1IbQlNoRTMoCU0-f7CyiPecdWupm-6jBTIlXp0Xsz-vKb0bSHijv9SbuIOfxuwbcA24zOD2If7qlECdGUhR-BFgcbIXCHYCspK3RpQUt-2zr3nUhsLnc94b_qzkGXZ_XIzGA730gJ_8jpTuy9jpjm5UCJ0VVTHY6W9A-Tv2dUrrwU-wCicjgJRBGFQUM_D8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