From patchwork Thu Dec 7 10:31:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 81638 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6857D385E45D for ; Thu, 7 Dec 2023 10:32:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B04BC385C6F0 for ; Thu, 7 Dec 2023 10:31:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B04BC385C6F0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B04BC385C6F0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945105; cv=none; b=ha1rJVSlbYKPDYUtAD1UHC7TCJmQPYYTozwsyqN4bRUjFIfRGIqiLr8xnxhshTd1PjWpCL9+TzIK5Yk68uxM4JJB2Unz86XitT3idaVeh8wQbY0l5zllxEj++mPVhTsl4RgdBJRHALe9X6xTldVy3slJTh9Gw5cpKOW79SQm3zM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945105; c=relaxed/simple; bh=dg+tE57pYSb1X1Pg7tZ2XFKqO0ZGNMwQdI+cmI+N3eQ=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=ceg/9tq/ogfqaYylWzZK0r4c8BEYODaR7G0AeYkuWD7ZJgE5JbOsQRAav3Qarm2hUUKE/4aNN2WUXM54WyFl/pKUEVddi9sqXyr7an5utrZ42l/acCAh8WxPnORyp7f0doGTdAZ+BS9+uZ/hNV8Z8n+H2DJP+3HvefWIP+Fg31Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701945103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=V27Yk3f2OAcpakt2vVWVfpID3ebSZlC4SlH9DmeZEmc=; b=EQ87/57WrVRBYJjcTCCs32XwJ/n2T6Fy9ZUbTK7n7pUrvzbGE5nEuk/tos/RLrdVtIoYt5 7uFZa+LAg7U60AcxY+P20ufm1OVm3PJbGRus7qPpglaposhUWLYTNBDrjy4h8zQHo6cWdp G2kVGMP8kild8i38X3CJOhogH9m7Jcc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-8S-jri0gOZWS2SHnrYYE9w-1; Thu, 07 Dec 2023 05:31:42 -0500 X-MC-Unique: 8S-jri0gOZWS2SHnrYYE9w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAD052803609 for ; Thu, 7 Dec 2023 10:31:41 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04B66492BCE for ; Thu, 7 Dec 2023 10:31:40 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v3 09/32] Do not export functions from libc In-Reply-To: Message-ID: <1d318df83797ca520244a075ecdc52c7e0827fd3.1701944612.git.fweimer@redhat.com> References: X-From-Line: 1d318df83797ca520244a075ecdc52c7e0827fd3 Mon Sep 17 00:00:00 2001 Date: Thu, 07 Dec 2023 11:31:39 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org 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 . */ +/* Note: This test exercises the (identical) copy of the + in libsupport, not libc.so, because the latter has + hidden visibility and cannot be tested from the outside. */ + #include #include #include 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 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 + . */ + +/* The implementation in libc.so has hidden visibility and is + therefore not usable. */ + +#include +#include +#include +#include +#include