unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH v3 09/32] Do not export <alloc_buffer.h> functions from libc
Date: Thu, 07 Dec 2023 11:31:39 +0100	[thread overview]
Message-ID: <1d318df83797ca520244a075ecdc52c7e0827fd3.1701944612.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1701944612.git.fweimer@redhat.com>

With the merge of NSS service modules into libc, external users are
gone except in tests.

To enable tests that use these functions (and the unit tests in
malloc/tst-alloc_buffer.h), add a copy of these functions to
libsupport.
---
 include/alloc_buffer.h               | 26 ++++++--------------------
 malloc/Makefile                      |  6 ++++--
 malloc/Versions                      |  7 -------
 malloc/alloc_buffer_alloc_array.c    |  1 -
 malloc/alloc_buffer_allocate.c       |  1 -
 malloc/alloc_buffer_copy_bytes.c     |  1 -
 malloc/alloc_buffer_copy_string.c    |  1 -
 malloc/alloc_buffer_create_failure.c |  1 -
 malloc/tst-alloc_buffer.c            |  4 ++++
 nss/Makefile                         |  4 ++--
 support/Makefile                     |  1 +
 support/support-alloc_buffer.c       | 26 ++++++++++++++++++++++++++
 12 files changed, 43 insertions(+), 36 deletions(-)
 create mode 100644 support/support-alloc_buffer.c

diff --git a/include/alloc_buffer.h b/include/alloc_buffer.h
index 5dcd009405..17acada715 100644
--- a/include/alloc_buffer.h
+++ b/include/alloc_buffer.h
@@ -113,10 +113,8 @@ enum
   };
 
 /* Internal function.  Terminate the process using __libc_fatal.  */
-void __libc_alloc_buffer_create_failure (void *start, size_t size);
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_alloc_buffer_create_failure)
-#endif
+void __libc_alloc_buffer_create_failure (void *start, size_t size)
+  attribute_hidden;
 
 /* Create a new allocation buffer.  The byte range from START to START
    + SIZE - 1 must be valid, and the allocation buffer allocates
@@ -134,10 +132,7 @@ alloc_buffer_create (void *start, size_t size)
 
 /* Internal function.  See alloc_buffer_allocate below.  */
 struct alloc_buffer __libc_alloc_buffer_allocate (size_t size, void **pptr)
-  __attribute__ ((nonnull (2)));
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_alloc_buffer_allocate)
-#endif
+  attribute_hidden __attribute__ ((nonnull (2)));
 
 /* Allocate a buffer of SIZE bytes using malloc.  The returned buffer
    is in a failed state if malloc fails.  *PPTR points to the start of
@@ -338,10 +333,7 @@ __alloc_buffer_next (struct alloc_buffer *buf, size_t align)
 void * __libc_alloc_buffer_alloc_array (struct alloc_buffer *buf,
 					size_t size, size_t align,
 					size_t count)
-  __attribute__ ((nonnull (1)));
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_alloc_buffer_alloc_array)
-#endif
+  attribute_hidden __attribute__ ((nonnull (1)));
 
 /* Obtain a TYPE * pointer to an array of COUNT objects in BUF of
    TYPE.  Consume these bytes from the buffer.  Return NULL and mark
@@ -357,10 +349,7 @@ libc_hidden_proto (__libc_alloc_buffer_alloc_array)
 /* Internal function.  See alloc_buffer_copy_bytes below.  */
 struct alloc_buffer __libc_alloc_buffer_copy_bytes (struct alloc_buffer,
 						    const void *, size_t)
-  __attribute__ ((nonnull (2)));
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_alloc_buffer_copy_bytes)
-#endif
+  attribute_hidden __attribute__ ((nonnull (2)));
 
 /* Copy SIZE bytes starting at SRC into the buffer.  If there is not
    enough room in the buffer, the buffer is marked as failed.  No
@@ -374,10 +363,7 @@ alloc_buffer_copy_bytes (struct alloc_buffer *buf, const void *src, size_t size)
 /* Internal function.  See alloc_buffer_copy_string below.  */
 struct alloc_buffer __libc_alloc_buffer_copy_string (struct alloc_buffer,
 						     const char *)
-  __attribute__ ((nonnull (2)));
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_alloc_buffer_copy_string)
-#endif
+  attribute_hidden __attribute__ ((nonnull (2)));
 
 /* Copy the string at SRC into the buffer, including its null
    terminator.  If there is not enough room in the buffer, the buffer
diff --git a/malloc/Makefile b/malloc/Makefile
index f6cdf7bf0b..234bb8f6d9 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -34,7 +34,6 @@ tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
 	 tst-mallocfork3 \
 	 tst-interpose-nothread \
 	 tst-interpose-thread \
-	 tst-alloc_buffer \
 	 tst-free-errno \
 	 tst-malloc-tcache-leak \
 	 tst-malloc_info tst-mallinfo2 \
@@ -57,7 +56,10 @@ ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes)
 tests += tst-mallocstate tst-compathooks-off tst-compathooks-on
 endif
 
-tests-internal := tst-scratch_buffer
+tests-internal := \
+  tst-alloc_buffer \
+  tst-scratch_buffer \
+  # tests-internal
 
 # The dynarray framework is only available inside glibc.
 tests-internal += \
diff --git a/malloc/Versions b/malloc/Versions
index c763395c6d..011b6a5a85 100644
--- a/malloc/Versions
+++ b/malloc/Versions
@@ -88,13 +88,6 @@ libc {
     __libc_dynarray_finalize;
     __libc_dynarray_resize;
     __libc_dynarray_resize_clear;
-
-    # struct alloc_buffer support
-    __libc_alloc_buffer_alloc_array;
-    __libc_alloc_buffer_allocate;
-    __libc_alloc_buffer_copy_bytes;
-    __libc_alloc_buffer_copy_string;
-    __libc_alloc_buffer_create_failure;
   }
 }
 
diff --git a/malloc/alloc_buffer_alloc_array.c b/malloc/alloc_buffer_alloc_array.c
index 018d07061a..739934d9fd 100644
--- a/malloc/alloc_buffer_alloc_array.c
+++ b/malloc/alloc_buffer_alloc_array.c
@@ -43,4 +43,3 @@ __libc_alloc_buffer_alloc_array (struct alloc_buffer *buf, size_t element_size,
       return NULL;
     }
 }
-libc_hidden_def (__libc_alloc_buffer_alloc_array)
diff --git a/malloc/alloc_buffer_allocate.c b/malloc/alloc_buffer_allocate.c
index 7f1e083a7c..8b05f55a3d 100644
--- a/malloc/alloc_buffer_allocate.c
+++ b/malloc/alloc_buffer_allocate.c
@@ -33,4 +33,3 @@ __libc_alloc_buffer_allocate (size_t size, void **pptr)
   else
     return alloc_buffer_create (*pptr, size);
 }
-libc_hidden_def (__libc_alloc_buffer_allocate)
diff --git a/malloc/alloc_buffer_copy_bytes.c b/malloc/alloc_buffer_copy_bytes.c
index 397f6a734f..2e261da02e 100644
--- a/malloc/alloc_buffer_copy_bytes.c
+++ b/malloc/alloc_buffer_copy_bytes.c
@@ -31,4 +31,3 @@ __libc_alloc_buffer_copy_bytes (struct alloc_buffer buf,
     memcpy (ptr, src, len);
   return buf;
 }
-libc_hidden_def (__libc_alloc_buffer_copy_bytes)
diff --git a/malloc/alloc_buffer_copy_string.c b/malloc/alloc_buffer_copy_string.c
index a334bd359d..711fbcf695 100644
--- a/malloc/alloc_buffer_copy_string.c
+++ b/malloc/alloc_buffer_copy_string.c
@@ -27,4 +27,3 @@ __libc_alloc_buffer_copy_string (struct alloc_buffer buf, const char *src)
 {
   return __libc_alloc_buffer_copy_bytes (buf, src, strlen (src) + 1);
 }
-libc_hidden_def (__libc_alloc_buffer_copy_string)
diff --git a/malloc/alloc_buffer_create_failure.c b/malloc/alloc_buffer_create_failure.c
index 77ce9378ce..c9557cae5b 100644
--- a/malloc/alloc_buffer_create_failure.c
+++ b/malloc/alloc_buffer_create_failure.c
@@ -28,4 +28,3 @@ __libc_alloc_buffer_create_failure (void *start, size_t size)
               size);
   __libc_fatal (buf);
 }
-libc_hidden_def (__libc_alloc_buffer_create_failure)
diff --git a/malloc/tst-alloc_buffer.c b/malloc/tst-alloc_buffer.c
index 567cb1b172..5e06b5e91c 100644
--- a/malloc/tst-alloc_buffer.c
+++ b/malloc/tst-alloc_buffer.c
@@ -16,6 +16,10 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+/* Note: This test exercises the (identical) copy of the
+   <alloc_buffer.h> in libsupport, not libc.so, because the latter has
+   hidden visibility and cannot be tested from the outside.  */
+
 #include <arpa/inet.h>
 #include <alloc_buffer.h>
 #include <stdio.h>
diff --git a/nss/Makefile b/nss/Makefile
index 213b68720b..fef617454d 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -475,9 +475,9 @@ libof-nss_test1 = extramodules
 libof-nss_test2 = extramodules
 libof-nss_test_errno = extramodules
 libof-nss_test_gai_hv2_canonname = extramodules
-$(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(link-libc-deps)
+$(objpfx)/libnss_test1.so: $(objpfx)nss_test1.os $(libsupport) $(link-libc-deps)
 	$(build-module)
-$(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(link-libc-deps)
+$(objpfx)/libnss_test2.so: $(objpfx)nss_test2.os $(libsupport) $(link-libc-deps)
 	$(build-module)
 $(objpfx)/libnss_test_errno.so: $(objpfx)nss_test_errno.os $(link-libc-deps)
 	$(build-module)
diff --git a/support/Makefile b/support/Makefile
index 556281121d..2adef004c8 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -41,6 +41,7 @@ libsupport-routines = \
   resolv_response_context_free \
   resolv_test \
   set_fortify_handler \
+  support-alloc_buffer \
   support-open-dev-null-range \
   support-xfstat \
   support-xfstat-time64 \
diff --git a/support/support-alloc_buffer.c b/support/support-alloc_buffer.c
new file mode 100644
index 0000000000..11f967295c
--- /dev/null
+++ b/support/support-alloc_buffer.c
@@ -0,0 +1,26 @@
+/* Make <alloc_buffer.h> available to tests.
+   Copyright (C) 2023 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* The implementation in libc.so has hidden visibility and is
+   therefore not usable.  */
+
+#include <malloc/alloc_buffer_alloc_array.c>
+#include <malloc/alloc_buffer_allocate.c>
+#include <malloc/alloc_buffer_copy_bytes.c>
+#include <malloc/alloc_buffer_copy_string.c>
+#include <malloc/alloc_buffer_create_failure.c>
-- 
2.43.0



  parent reply	other threads:[~2023-12-07 10:32 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 10:30 [PATCH v3 00/32] RELRO linkmaps Florian Weimer
2023-12-07 10:30 ` [PATCH v3 01/32] support: Add <support/memprobe.h> for protection flags probing Florian Weimer
2024-02-22 22:39   ` Joseph Myers
2023-12-07 10:30 ` [PATCH v3 02/32] misc: Enable internal use of memory protection keys Florian Weimer
2024-02-22  1:06   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 03/32] elf: Remove _dl_sysdep_open_object hook function Florian Weimer
2024-01-31 13:10   ` Joseph Myers
2024-03-11 17:19     ` Florian Weimer
2024-03-11 17:33       ` Joseph Myers
2024-03-11 17:46         ` Florian Weimer
2024-03-11 18:02           ` Joseph Myers
2024-03-11 18:16             ` Florian Weimer
2023-12-07 10:31 ` [PATCH v3 04/32] elf: Eliminate second loop in find_version in dl-version.c Florian Weimer
2024-02-19 22:17   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 05/32] elf: In rtld_setup_main_map, assume ld.so has a DYNAMIC segment Florian Weimer
2024-02-19 22:18   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 06/32] elf: Remove version assert in check_match in elf/dl-lookup.c Florian Weimer
2024-03-04 23:22   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 07/32] elf: Disambiguate some failures in _dl_load_cache_lookup Florian Weimer
2024-02-19 23:07   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 08/32] elf: Eliminate alloca in open_verify Florian Weimer
2024-02-19 23:26   ` Joseph Myers
2023-12-07 10:31 ` Florian Weimer [this message]
2024-02-21 17:13   ` [PATCH v3 09/32] Do not export <alloc_buffer.h> functions from libc Joseph Myers
2023-12-07 10:31 ` [PATCH v3 10/32] elf: Make <alloc_buffer.h> usable in ld.so Florian Weimer
2024-02-21 17:19   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 11/32] elf: Merge the three implementations of _dl_dst_substitute Florian Weimer
2024-02-28 17:52   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 12/32] elf: Move __rtld_malloc_init_stubs call into _dl_start_final Florian Weimer
2024-02-22 22:30   ` Joseph Myers
2024-02-22 23:06   ` Andreas Schwab
2023-12-07 10:31 ` [PATCH v3 13/32] elf: Merge __dl_libc_freemem into __rtld_libc_freeres Florian Weimer
2024-02-22 23:23   ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 14/32] elf: Use struct link_map_private for the internal link map Florian Weimer
2024-02-22 23:36   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 15/32] elf: Remove run-time-writable fields from struct link_map_private Florian Weimer
2024-02-23  0:09   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 16/32] elf: Move l_tls_offset into read-write part of link map Florian Weimer
2024-02-26 21:57   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 17/32] elf: Allocate auditor state after read-write " Florian Weimer
2024-02-26 22:01   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 18/32] elf: Move link map fields used by dependency sorting to writable part Florian Weimer
2024-02-27 17:51   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 19/32] elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object Florian Weimer
2024-02-27 17:56   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 20/32] elf: Add l_soname accessor function for DT_SONAME values Florian Weimer
2024-02-27 22:14   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 21/32] elf: _dl_rtld_map should not exist in static builds Florian Weimer
2024-02-28 12:38   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 22/32] elf: Introduce GLPM accessor for the protected memory area Florian Weimer
2024-02-28 12:44   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 23/32] elf: Bootstrap allocation for future protected memory allocator Florian Weimer
2024-02-28 15:04   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 24/32] elf: Implement a basic " Florian Weimer
2024-02-28 18:46   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 25/32] elf: Move most of the _dl_find_object data to the protected heap Florian Weimer
2024-02-28 19:06   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 26/32] elf: Switch to a region-based protected memory allocator Florian Weimer
2024-03-05 23:36   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 27/32] elf: Determine the caller link map in _dl_open Florian Weimer
2024-02-28 19:23   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 28/32] elf: Add fast path to dlopen for fully-opened maps Florian Weimer
2024-02-28 19:26   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 29/32] elf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen Florian Weimer
2024-02-28 19:27   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 30/32] elf: Put critical _dl_find_object pointers into protected memory area Florian Weimer
2024-03-04 21:39   ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 31/32] elf: Add hash tables to speed up DT_NEEDED, dlopen lookups Florian Weimer
2024-03-06  0:04   ` Joseph Myers
2023-12-07 10:33 ` [PATCH v3 32/32] elf: Use memory protection keys for the protected memory allocator Florian Weimer
2024-03-06  0:11   ` Joseph Myers
2023-12-07 10:53 ` [PATCH v3 00/32] RELRO linkmaps Andreas Schwab
2023-12-07 10:56   ` Florian Weimer
2023-12-07 11:34     ` Andreas Schwab
2024-03-01 14:45     ` Adhemerval Zanella Netto
2024-03-11 17:24       ` Florian Weimer
2024-03-12 12:51         ` Adhemerval Zanella Netto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1d318df83797ca520244a075ecdc52c7e0827fd3.1701944612.git.fweimer@redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).