[libc] [llvm] [libc][hdr] Add poll and socket overlay headers for GCC overlay builds. (PR #227961)

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 04:45:34 PDT 2026


================
@@ -0,0 +1,69 @@
+//===-- Including poll.h in overlay mode ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_POLL_OVERLAY_H
+#define LLVM_LIBC_HDR_POLL_OVERLAY_H
+
+#ifdef LIBC_FULL_BUILD
+#error "This header should only be included in overlay mode"
+#endif
+
+// Overlay mode
+
+// glibc <poll.h> header might provide extern inline definitions for few
+// functions, causing external alias errors.  They are guarded by
+// `__USE_EXTERN_INLINES` macro.  We temporarily disable `__USE_EXTERN_INLINES`
+// macro by defining `__NO_INLINE__` before including <poll.h>.
+// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
+// with `_FORTIFY_SOURCE`.
+
+#ifdef _FORTIFY_SOURCE
+#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
+#undef _FORTIFY_SOURCE
+#endif
+
+#ifndef __NO_INLINE__
+#define __NO_INLINE__ 1
+#define LIBC_SET_NO_INLINE
+#endif
+
+#ifdef __USE_EXTERN_INLINES
+#define LIBC_OLD_USE_EXTERN_INLINES
+#undef __USE_EXTERN_INLINES
+#endif
+
+#ifdef __USE_FORTIFY_LEVEL
+#define LIBC_OLD_USE_FORTIFY_LEVEL __USE_FORTIFY_LEVEL
+#undef __USE_FORTIFY_LEVEL
+#define __USE_FORTIFY_LEVEL 0
+#endif
----------------
labath wrote:

Actually, this doesn't do what it seems to be doing. C(++) does not expand macros when they are defined. This only happens when they are used. IOW, this does not assign the "old" value of __USE_FORTIFY_LEVEL. It assigns the literal token "__USE_FORTIFY_LEVEL". Likewise, at the end of this file __USE_FORTIFY_LEVEL is defined to a literal "LIBC_OLD_USE_FORTIFY_LEVEL" (and it stays that because that macro is undefined).

I'm keeping the LGTM because this is consistent with what the other files are doing, but I have to note this pattern is completely broken. I don't think there's a standard way to do the thing we're doing here, though it could be achieved with `#pragma push_macro`, which seems to be implemented in the major compilers.

https://github.com/llvm/llvm-project/pull/227961


More information about the llvm-commits mailing list