Skip to content

[libc] exposes internal implementations in symbol table #74881

Open
@nickdesaulniers

Description

@nickdesaulniers

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 --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*)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions