diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c
index c8b83681ed7e8fbb86b1a2f15a205a23945c63d7..f22233987ca5c3d11ec388094329892ec75394ca 100644
--- a/libgcc/config/aarch64/heap-trampoline.c
+++ b/libgcc/config/aarch64/heap-trampoline.c
@@ -1,5 +1,8 @@
 /* Copyright The GNU Toolchain Authors. */
 
+/* libc is required to allocate trampolines.  */
+#ifndef inhibit_libc
+
 #include <unistd.h>
 #include <sys/mman.h>
 #include <stdint.h>
@@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
       tramp_ctrl_curr = prev;
     }
 }
+
+#endif /* !inhibit_libc */
diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i386/heap-trampoline.c
index 96e13bf828eaf42ecc0dd113c2ad6bb60f13fd9e..4b9f436586890eff866ef8c99812a0694cd75efa 100644
--- a/libgcc/config/i386/heap-trampoline.c
+++ b/libgcc/config/i386/heap-trampoline.c
@@ -1,5 +1,8 @@
 /* Copyright The GNU Toolchain Authors. */
 
+/* libc is required to allocate trampolines.  */
+#ifndef inhibit_libc
+
 #include <unistd.h>
 #include <sys/mman.h>
 #include <stdint.h>
@@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
       tramp_ctrl_curr = prev;
     }
 }
+
+#endif /* !inhibit_libc */