From patchwork Mon Mar 6 19:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 659267 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1988168wrb; Mon, 6 Mar 2023 11:18:25 -0800 (PST) X-Google-Smtp-Source: AK7set/Gy4XFUECrV2zmpFI5BzXA6v1M+QRI5+uswyJk6Cdot0jiEa09/vgV5CtyFnF1U+CmtFxn X-Received: by 2002:aa7:df96:0:b0:4b1:b71d:cbfe with SMTP id b22-20020aa7df96000000b004b1b71dcbfemr11438305edy.2.1678130305335; Mon, 06 Mar 2023 11:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678130305; cv=none; d=google.com; s=arc-20160816; b=kSRjduY8PrCUGEA0zVNMaiQfgX871yp27mzsI+uDx/x8jJluCJoYIjKbW1WzgXL6Nk yXecJuC7csNHHhTgIWxjPcAOWmdoyc7lhX4L0MoUfeSQqEwfXjgzq50/Je4s6Rzw+Nb/ DtZaUR5gr1NVuUeM3YKHwd6qQ1kwHIY16SOKiojcObMo6BlrjaTvPk27oAyypdalYar3 Ryby23JKJHso5PDQvLx46bQMqhl8KFvnmgC68GglHlZ5LgbfWUD04ZUd8yKkLHqnlKS9 ageD7V9N0NHf9wbUcBj/tiM8/+cXMcvakeG7EHZzCiS/f9HWgizQxqBIB2nzTFPoRHXh f5YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=PmMDDJRtyCas+gEQGUxoOCoXfmRcFScKvilxpcfU4LE=; b=LkOJ4NQsWfHW+SJUkA1fQnX20kTZGhveXYE/EAILMOdKYmomVFRxiXf8QK0lbi0GlW 5heTKVcpm4n2Ntd+2RkWxNXlgas+uFivbPgMN+CqS4NmlpH50sHb1Ru9+CaA0Fwg48SA pdmso5HtjZ7E2BNT+c4Cz39Z5/azuIyVOWLveZHACVpCE9I7+hipNEYo0QLAptjDg59i b6++K7VZ/5Vp32IScBUtEIortpizc2yAGF3dlmcRRMP+V9LpfiZiP9DxdeFBGfB/cfzd rBtrV+UFYFEQtXbGcI6ZSa0/ritS12XPSS8oK1wIzBZ5GSnLF9giPt0NRpccJbCXj6Xd oPwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=myy9sQJ5; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m11-20020aa7d34b000000b004ad79f4686dsi11623597edr.86.2023.03.06.11.18.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=myy9sQJ5; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C7B438515C3 for ; Mon, 6 Mar 2023 19:18:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C7B438515C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678130304; bh=PmMDDJRtyCas+gEQGUxoOCoXfmRcFScKvilxpcfU4LE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=myy9sQJ53LpFJHKX4f7JUbyFmwoCdlJpeiAv8MbWKVWx20Uc0UiOvnafmoxJE5tjP mcKXB1djvQAejKKa/OrdB7TaP85WfW1AxWrePm4EHtrCV54fawhQTROniV0uqpVcdr apf/Jyl7pUoHKt/0XK4o9iMgrc7xQrQc/SQ/8Y/M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id 87A553858D39 for ; Mon, 6 Mar 2023 19:16:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87A553858D39 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-176e43eb199so2435982fac.7 for ; Mon, 06 Mar 2023 11:16:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678130212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PmMDDJRtyCas+gEQGUxoOCoXfmRcFScKvilxpcfU4LE=; b=deU3CeFoKs1G8X9NzuiXRfPTFLEldzxkdEPf2TGgRoU1ULmXdV6NWKo7SoQ1DLITba WAdarx1Ej5h7sqrNoYFp3JbSWFIDkfg6+J2VIn1JBjZzcRSup1cLr4z3+hNS6+RMY4mj v8jfHsNgpr6f52XDkWJ2dfcGwARzUGHtX7ZwU9BDV9L3oFRo/6UmnWtInONWS+panT3R p2RyTOqKnDa8yPIpfxgCoK69KnmFrLCqRyx+d1OjUYJ/zhSyTxeIsC+3+2Gu0h8M4iOa zjTK/HU8wNR+WrPW1tDZzH8s+RfEV3gpITZwb6mZZ2IZN0WpliKqrvRBFvhsV11or6SG Y4ZQ== X-Gm-Message-State: AO0yUKUXkId7IgDLpacmt9sv/UF3azH2ok4DSthTYsFkKN/X31tb+T33 bThujfARmMc7pHbrELlpejw4VFkGOCtkkAt77dr+JQ== X-Received: by 2002:a05:6870:428f:b0:15f:d9a0:a1b3 with SMTP id y15-20020a056870428f00b0015fd9a0a1b3mr7793578oah.1.1678130211173; Mon, 06 Mar 2023 11:16:51 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:8c2f:e58d:3e6:9de5]) by smtp.gmail.com with ESMTPSA id zf29-20020a0568716a9d00b00176598b79d3sm4280668oab.24.2023.03.06.11.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:16:50 -0800 (PST) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell Cc: Adhemerval Zanella Netto Subject: [PATCH v5 1/5] Move libc_freeres_ptrs and libc_subfreeres to hidden/weak functions Date: Mon, 6 Mar 2023 16:16:38 -0300 Message-Id: <20230306191642.347001-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306191642.347001-1-adhemerval.zanella@linaro.org> References: <20230306191642.347001-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto They are both used by __libc_freeres to free all library malloc allocated resources to help tooling like mtrace or valgrind with memory leak tracking. The current scheme uses assembly markers and linker script entries to consolidate the free routine function pointers in the RELRO segment and to be freed buffers in BSS. This patch changes it to use specific free functions for libc_freeres_ptrs buffers and call the function pointer array directly with call_function_static_weak. It allows the removal of both the internal macros and the linker script sections. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell --- Makerules | 7 - crypt/md5-crypt.c | 7 +- crypt/sha256-crypt.c | 7 +- crypt/sha512-crypt.c | 7 +- dlfcn/dlerror.h | 1 - elf/dl-libc.c | 5 +- grp/fgetgrent.c | 5 +- gshadow/fgetsgent.c | 5 +- iconv/gconv_cache.c | 3 +- iconv/gconv_conf.c | 3 +- iconv/gconv_db.c | 6 +- iconv/gconv_dl.c | 5 +- include/libc-symbols.h | 73 -------- include/set-freeres.h | 142 ++++++++++++++++ inet/getnameinfo.c | 5 +- inet/getnetgrent.c | 5 +- inet/rcmd.c | 5 +- inet/rexec.c | 5 +- intl/dcigettext.c | 3 +- intl/finddomain.c | 2 +- intl/loadmsgcat.c | 1 - intl/localealias.c | 15 +- libio/fcloseall.c | 1 + libio/genops.c | 8 +- libio/libioP.h | 1 - locale/loadarchive.c | 2 +- locale/localeinfo.h | 4 +- locale/setlocale.c | 4 +- login/getutent.c | 5 +- login/getutid.c | 6 +- login/getutline.c | 5 +- malloc/set-freeres.c | 156 +++++++++++++++--- malloc/thread-freeres.c | 9 +- misc/efgcvt-template.c | 5 +- misc/efgcvt.c | 1 + misc/fstab.c | 3 +- misc/hsearch.c | 4 - misc/mntent.c | 5 +- misc/qefgcvt.c | 1 + misc/unwind-link.c | 2 +- nptl/nptlfreeres.c | 1 - nscd/nscd_getgr_r.c | 3 +- nscd/nscd_gethst_r.c | 3 +- nscd/nscd_getpw_r.c | 3 +- nscd/nscd_getserv_r.c | 3 +- nscd/nscd_netgroup.c | 3 +- nss/getXXbyYY.c | 7 +- nss/getXXent.c | 7 +- nss/nss_action.c | 2 +- nss/nss_action.h | 3 - nss/nss_database.c | 2 +- nss/nss_database.h | 3 - nss/nss_module.c | 2 +- nss/nss_module.h | 3 - posix/regcomp.c | 3 +- posix/register-atfork.c | 3 +- pwd/fgetpwent.c | 5 +- resolv/gai_misc.c | 6 +- resolv/res-close.c | 2 - resolv/res_hconf.c | 16 +- resolv/resolv-internal.h | 14 ++ resolv/resolv_conf.c | 3 +- resolv/tst-leaks2.c | 2 + rt/aio_misc.c | 6 +- shadow/fgetspent.c | 5 +- stdio-common/reg-modifier.c | 3 +- stdio-common/reg-printf.c | 6 +- stdio-common/reg-type.c | 6 +- stdlib/exit.c | 2 +- stdlib/fmtmsg.c | 3 +- stdlib/setenv.c | 3 +- sunrpc/clnt_perr.c | 4 +- sunrpc/rpc_thread.c | 1 - sunrpc/tst-svc_register.c | 6 +- sysdeps/generic/set-freeres-fp.h | 19 +++ sysdeps/generic/set-freeres-os.h | 19 +++ sysdeps/generic/set-freeres-system.h | 27 +++ .../ldbl-128ibm-compat/ieee128-qefgcvt.c | 1 + .../ldbl-128ibm-compat/set-freeres-fp.h | 22 +++ sysdeps/mach/hurd/bits/errno.h | 1 - sysdeps/posix/getaddrinfo.c | 5 +- sysdeps/posix/ttyname.c | 4 +- sysdeps/unix/sysv/linux/check_pf.c | 3 +- .../unix/sysv/linux/s390/s390-32/getutent.c | 1 + .../unix/sysv/linux/s390/s390-32/getutid.c | 1 + .../unix/sysv/linux/s390/s390-32/getutline.c | 1 + sysdeps/unix/sysv/linux/set-freeres-os.h | 24 +++ sysdeps/unix/sysv/linux/ttyname.c | 8 +- time/tzfile.c | 5 +- time/tzset.c | 3 +- 90 files changed, 584 insertions(+), 243 deletions(-) create mode 100644 include/set-freeres.h create mode 100644 sysdeps/generic/set-freeres-fp.h create mode 100644 sysdeps/generic/set-freeres-os.h create mode 100644 sysdeps/generic/set-freeres-system.h create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h create mode 100644 sysdeps/unix/sysv/linux/set-freeres-os.h diff --git a/Makerules b/Makerules index fae6b626e6..f6071eab50 100644 --- a/Makerules +++ b/Makerules @@ -560,14 +560,7 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules -Wl,--verbose 2>/dev/null | \ sed > $@T \ -e '/^=========/,/^=========/!d;/^=========/d' \ - -e 's/^.*\*(\.dynbss).*$$/& \ - PROVIDE(__start___libc_freeres_ptrs = .); \ - *(__libc_freeres_ptrs) \ - PROVIDE(__stop___libc_freeres_ptrs = .);/'\ -e 's@^.*\*(\.jcr).*$$@& \ - PROVIDE(__start___libc_subfreeres = .);\ - __libc_subfreeres : { *(__libc_subfreeres) }\ - PROVIDE(__stop___libc_subfreeres = .);\ PROVIDE(__start___libc_IO_vtables = .);\ __libc_IO_vtables : { *(__libc_IO_vtables) }\ PROVIDE(__stop___libc_IO_vtables = .);\ diff --git a/crypt/md5-crypt.c b/crypt/md5-crypt.c index 0cc597a7f2..4e4760545a 100644 --- a/crypt/md5-crypt.c +++ b/crypt/md5-crypt.c @@ -299,10 +299,7 @@ __md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen) return buffer; } -#ifndef _LIBC -# define libc_freeres_ptr(decl) decl -#endif -libc_freeres_ptr (static char *buffer); +static char *buffer; char * __md5_crypt (const char *key, const char *salt) @@ -326,11 +323,9 @@ __md5_crypt (const char *key, const char *salt) return __md5_crypt_r (key, salt, buffer, buflen); } -#ifndef _LIBC static void __attribute__ ((__destructor__)) free_mem (void) { free (buffer); } -#endif diff --git a/crypt/sha256-crypt.c b/crypt/sha256-crypt.c index 1ef16af80f..e90eb590bb 100644 --- a/crypt/sha256-crypt.c +++ b/crypt/sha256-crypt.c @@ -386,10 +386,7 @@ __sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen) return buffer; } -#ifndef _LIBC -# define libc_freeres_ptr(decl) decl -#endif -libc_freeres_ptr (static char *buffer); +static char *buffer; /* This entry point is equivalent to the `crypt' function in Unix libcs. */ @@ -418,11 +415,9 @@ __sha256_crypt (const char *key, const char *salt) return __sha256_crypt_r (key, salt, buffer, buflen); } -#ifndef _LIBC static void __attribute__ ((__destructor__)) free_mem (void) { free (buffer); } -#endif diff --git a/crypt/sha512-crypt.c b/crypt/sha512-crypt.c index b592eb0976..d9c0de14d2 100644 --- a/crypt/sha512-crypt.c +++ b/crypt/sha512-crypt.c @@ -408,10 +408,7 @@ __sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen) return buffer; } -#ifndef _LIBC -# define libc_freeres_ptr(decl) decl -#endif -libc_freeres_ptr (static char *buffer); +static char *buffer; /* This entry point is equivalent to the `crypt' function in Unix libcs. */ @@ -440,11 +437,9 @@ __sha512_crypt (const char *key, const char *salt) return __sha512_crypt_r (key, salt, buffer, buflen); } -#ifndef _LIBC static void __attribute__ ((__destructor__)) free_mem (void) { free (buffer); } -#endif diff --git a/dlfcn/dlerror.h b/dlfcn/dlerror.h index 999b9f26ae..c6697728a9 100644 --- a/dlfcn/dlerror.h +++ b/dlfcn/dlerror.h @@ -87,6 +87,5 @@ static struct dl_action_result *const dl_action_result_malloc_failed reporting via dlerror. */ extern __thread struct dl_action_result *__libc_dlerror_result attribute_tls_model_ie; -void __libc_dlerror_result_free (void) attribute_hidden; #endif /* _DLERROR_H */ diff --git a/elf/dl-libc.c b/elf/dl-libc.c index 7e71bfb534..c12e52f330 100644 --- a/elf/dl-libc.c +++ b/elf/dl-libc.c @@ -228,7 +228,7 @@ __libc_dlclose (void *map) } -static bool __libc_freeres_fn_section +static bool free_slotinfo (struct dtv_slotinfo_list **elemp) { size_t cnt; @@ -256,7 +256,8 @@ free_slotinfo (struct dtv_slotinfo_list **elemp) } -libc_freeres_fn (free_mem) +void +__dl_libc_freemem (void) { struct link_map *l; struct r_search_path_elem *d; diff --git a/grp/fgetgrent.c b/grp/fgetgrent.c index d6ee2db656..2e7c7fe5fb 100644 --- a/grp/fgetgrent.c +++ b/grp/fgetgrent.c @@ -20,12 +20,13 @@ #include #include #include +#include /* We need to protect the dynamic buffer handling. */ __libc_lock_define_initialized (static, lock); -libc_freeres_ptr (static char *buffer); +static char *buffer; /* Read one entry from the given stream. */ struct group * @@ -82,3 +83,5 @@ fgetgrent (FILE *stream) return result; } + +weak_alias (buffer, __libc_fgetgrent_freemem_ptr) diff --git a/gshadow/fgetsgent.c b/gshadow/fgetsgent.c index 68e69ef6f2..dc26b24b47 100644 --- a/gshadow/fgetsgent.c +++ b/gshadow/fgetsgent.c @@ -20,6 +20,7 @@ #include #include #include +#include /* A reasonable size for a buffer to start with. */ @@ -28,7 +29,7 @@ /* We need to protect the dynamic buffer handling. */ __libc_lock_define_initialized (static, lock); -libc_freeres_ptr (static char *buffer); +static char *buffer; /* Read one shadow entry from the given stream. */ struct sgrp * @@ -85,3 +86,5 @@ fgetsgent (FILE *stream) return result; } + +weak_alias (buffer, __libc_fgetsgent_freeres_ptr); diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index c13fc5ef96..f2100ca88f 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -449,7 +449,8 @@ __gconv_release_cache (struct __gconv_step *steps, size_t nsteps) /* Free all resources if necessary. */ -libc_freeres_fn (free_mem) +void +__gconv_cache_freemem (void) { if (cache_malloced) free (gconv_cache); diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index a75ac13e3f..c76011d6bc 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -530,7 +530,8 @@ __gconv_load_conf (void) /* Free all resources if necessary. */ -libc_freeres_fn (free_mem) +void +__gconv_conf_freemem (void) { if (__gconv_path_elem != NULL && __gconv_path_elem != &empty_path_elem) free ((void *) __gconv_path_elem); diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c index e9b1c07620..0ee8076287 100644 --- a/iconv/gconv_db.c +++ b/iconv/gconv_db.c @@ -169,7 +169,7 @@ add_derivation (const char *fromset, const char *toset, not all memory will be freed. */ } -static void __libc_freeres_fn_section +static void free_derivation (void *p) { struct known_derivation *deriv = (struct known_derivation *) p; @@ -793,7 +793,6 @@ __gconv_close_transform (struct __gconv_step *steps, size_t nsteps) /* Free the modules mentioned. */ static void -__libc_freeres_fn_section free_modules_db (struct gconv_module *node) { if (node->left != NULL) @@ -812,7 +811,8 @@ free_modules_db (struct gconv_module *node) /* Free all resources if necessary. */ -libc_freeres_fn (free_mem) +void +__gconv_db_freemem (void) { /* First free locale memory. This needs to be done before freeing derivations, as ctype cleanup functions dereference steps arrays which we diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c index 911c2031f0..cb51568e4c 100644 --- a/iconv/gconv_dl.c +++ b/iconv/gconv_dl.c @@ -184,7 +184,7 @@ __gconv_release_shlib (struct __gconv_loaded_object *handle) /* We run this if we debug the memory allocation. */ -static void __libc_freeres_fn_section +static void do_release_all (void *nodep) { struct __gconv_loaded_object *obj = (struct __gconv_loaded_object *) nodep; @@ -196,7 +196,8 @@ do_release_all (void *nodep) free (obj); } -libc_freeres_fn (free_mem) +void +__gconv_dl_freemem (void) { __tdestroy (loaded, do_release_all); loaded = NULL; diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 404169ce78..155781d448 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -237,79 +237,6 @@ requires at runtime the shared libraries from the glibc version used \ for linking") #endif -/* Resource Freeing Hooks: - - Normally a process exits and the OS cleans up any allocated - memory. However, when tooling like mtrace or valgrind is monitoring - the process we need to free all resources that are part of the - process in order to provide the consistency required to track - memory leaks. - - A single public API exists and is __libc_freeres(), and this is used - by applications like valgrind to freee resouces. - - There are 3 cases: - - (a) __libc_freeres - - In this case all you need to do is define the freeing routine: - - foo.c: - libfoo_freeres_fn (foo_freeres) - { - complex_free (mem); - } - - This ensures the function is called at the right point to free - resources. - - (b) __libc_freeres_ptr - - The framework for (a) iterates over the list of pointers-to-free - in (b) and frees them. - - foo.c: - libc_freeres_ptr (static char *foo_buffer); - - Freeing these resources alaways happens last and is equivalent - to registering a function that does 'free (foo_buffer)'. - - (c) Explicit lists of free routines to call or objects to free. - - It is the intended goal to remove (a) and (b) which have some - non-determinism based on link order, and instead use explicit - lists of functions and frees to resolve cleanup ordering issues - and make it easy to debug and maintain. - - As of today the following subsystems use (c): - - Per-thread cleanup: - * malloc/thread-freeres.c - - libdl cleanup: - * dlfcn/dlfreeres.c - - libpthread cleanup: - * nptl/nptlfreeres.c - - So if you need any shutdown routines to run you should add them - directly to the appropriate subsystem's shutdown list. */ - -/* Resource pointers to free in libc.so. */ -#define libc_freeres_ptr(decl) \ - __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \ - decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment))) - -/* Resource freeing functions from libc.so go in this section. */ -#define __libc_freeres_fn_section \ - __attribute__ ((__used__, section ("__libc_freeres_fn"))) - -/* Resource freeing functions for libc.so. */ -#define libc_freeres_fn(name) \ - static void name (void) __attribute_used__ __libc_freeres_fn_section; \ - text_set_element (__libc_subfreeres, name); \ - static void name (void) - /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes alias to ORIGINAL, when the assembler supports such declarations (such as in ELF). diff --git a/include/set-freeres.h b/include/set-freeres.h new file mode 100644 index 0000000000..b7f66519a3 --- /dev/null +++ b/include/set-freeres.h @@ -0,0 +1,142 @@ +/* Macros for internal resource Freeing Hooks. + Copyright (C) 2022 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 + . */ + +#ifndef _SET_FREERES_H +#define _SET_FREERES_H 1 + +#include +#include +#include +#include + +/* Resource Freeing Hooks: + + Normally a process exits and the OS cleans up any allocated + memory. However, when tooling like mtrace or valgrind is monitoring + the process we need to free all resources that are part of the + process in order to provide the consistency required to track + memory leaks. + + A single public API exists and is __libc_freeres, and this is used + by applications like valgrind to freee resouces. + + Each free routines must be explicit listed below. */ + +/* From libc.so. */ +extern void __dl_libc_freemem (void) attribute_hidden; +extern void __hdestroy (void) attribute_hidden; +extern void __gconv_cache_freemem (void) attribute_hidden; +extern void __gconv_conf_freemem (void) attribute_hidden; +extern void __gconv_db_freemem (void) attribute_hidden; +extern void __gconv_dl_freemem (void) attribute_hidden; +extern void __intl_freemem (void) attribute_hidden; +extern void __libio_freemem (void) attribute_hidden; +extern void __libc_fstab_freemem (void) attribute_hidden; +extern void __nscd_gr_map_freemem (void) attribute_hidden; +extern void __nscd_hst_map_freemem (void) attribute_hidden; +extern void __nscd_pw_map_freemem (void) attribute_hidden; +extern void __nscd_serv_map_freemem (void) attribute_hidden; +extern void __nscd_group_map_freemem (void) attribute_hidden; +extern void __libc_regcomp_freemem (void) attribute_hidden; +extern void __libc_atfork_freemem (void) attribute_hidden; +extern void __libc_resolv_conf_freemem (void) attribute_hidden; +extern void __res_thread_freeres (void) attribute_hidden; +extern void __libc_printf_freemem (void) attribute_hidden; +extern void __libc_fmtmsg_freemem (void) attribute_hidden; +extern void __libc_setenv_freemem (void) attribute_hidden; +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31) +extern void __rpc_freemem (void) attribute_hidden; +extern void __rpc_thread_destroy (void) attribute_hidden; +#endif +extern void __libc_getaddrinfo_freemem (void) attribute_hidden; +extern void __libc_tzset_freemem (void) attribute_hidden; +extern void __libc_localealias_freemem (void) attribute_hidden; +extern void __libc_getutent_freemem (void) attribute_hidden; +extern void __libc_getutline_freemem (void) attribute_hidden; +/* From nss/nss_module.c */ +extern void __nss_module_freeres (void) attribute_hidden; +/* From nss/nss_action.c */ +extern void __nss_action_freeres (void) attribute_hidden; +/* From nss/nss_database.c */ +extern void __nss_database_freeres (void) attribute_hidden; +/* From libio/genops.c */ +extern int _IO_cleanup (void) attribute_hidden;; +/* From dlfcn/dlerror.c */ +extern void __libc_dlerror_result_free (void) attribute_hidden; + +/* From either libc.so or libpthread.so */ +extern void __libpthread_freeres (void) attribute_hidden; +/* From either libc.so or libanl.so */ +#if PTHREAD_IN_LIBC +extern void __gai_freemem (void) attribute_hidden; +/* From either libc.so or librt.so */ +extern void __aio_freemem (void) attribute_hidden; +#endif + +/* From libc.so */ +extern char * __libc_fgetgrent_freemem_ptr attribute_hidden; +extern char * __libc_fgetsgent_freeres_ptr attribute_hidden; +extern char * __libc_getnetgrent_freemem_ptr attribute_hidden; +extern char * __libc_rcmd_freemem_ptr attribute_hidden; +extern char * __libc_rexec_freemem_ptr attribute_hidden; +extern void * __libc_mntent_freemem_ptr attribute_hidden; +extern char * __libc_fgetpwent_freemem_ptr attribute_hidden; +extern struct netaddr * __libc_resolv_res_hconf_freemem_ptr attribute_hidden; +extern char * __libc_fgetspent_freemem_ptr attribute_hidden; +extern __time64_t * __libc_tzfile_freemem_ptr attribute_hidden; +extern char * __libc_getnameinfo_freemem_ptr attribute_hidden; +extern struct utmp * __libc_getutent_freemem_ptr attribute_hidden; +extern struct utmp * __libc_getutid_freemem_ptr attribute_hidden; +extern struct utmp * __libc_getutline_freemem_ptr attribute_hidden; +extern printf_arginfo_size_function ** __libc_reg_printf_freemem_ptr + attribute_hidden; +extern printf_va_arg_function ** __libc_reg_type_freemem_ptr + attribute_hidden; +/* From nss/getXXbyYY.c */ +extern char * __libc_getgrgid_freemem_ptr attribute_hidden; +extern char * __libc_getgrnam_freemem_ptr attribute_hidden; +extern char * __libc_getpwnam_freemem_ptr attribute_hidden; +extern char * __libc_getpwuid_freemem_ptr attribute_hidden; +extern char * __libc_getspnam_freemem_ptr attribute_hidden; +extern char * __libc_getaliasbyname_freemem_ptr attribute_hidden; +extern char * __libc_gethostbyaddr_freemem_ptr attribute_hidden; +extern char * __libc_gethostbyname_freemem_ptr attribute_hidden; +extern char * __libc_gethostbyname2_freemem_ptr attribute_hidden; +extern char * __libc_getnetbyaddr_freemem_ptr attribute_hidden; +extern char * __libc_getnetbyname_freemem_ptr attribute_hidden; +extern char * __libc_getprotobynumber_freemem_ptr attribute_hidden; +extern char * __libc_getprotobyname_freemem_ptr attribute_hidden; +extern char * __libc_getrpcbyname_freemem_ptr attribute_hidden; +extern char * __libc_getrpcbynumber_freemem_ptr attribute_hidden; +extern char * __libc_getservbyname_freemem_ptr attribute_hidden; +extern char * __libc_getservbyport_freemem_ptr attribute_hidden; +/* From nss/getXXent.c */ +extern char * __libc_getgrent_freemem_ptr attribute_hidden; +extern char * __libc_getpwent_freemem_ptr attribute_hidden; +extern char * __libc_getspent_freemem_ptr attribute_hidden; +extern char * __libc_getaliasent_freemem_ptr attribute_hidden; +extern char * __libc_gethostent_freemem_ptr attribute_hidden; +extern char * __libc_getnetent_freemem_ptr attribute_hidden; +extern char * __libc_getprotoent_freemem_ptr attribute_hidden; +extern char * __libc_getrpcent_freemem_ptr attribute_hidden; +extern char * __libc_getservent_freemem_ptr attribute_hidden; +/* From misc/efgcvt-template.c */ +extern char * __libc_efgcvt_freemem_ptr attribute_hidden; +extern char * __libc_qefgcvt_freemem_ptr attribute_hidden; + +#endif diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c index 5c07b748bc..40c20b4be6 100644 --- a/inet/getnameinfo.c +++ b/inet/getnameinfo.c @@ -72,12 +72,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #ifndef min # define min(x,y) (((x) > (y)) ? (y) : (x)) #endif /* min */ -libc_freeres_ptr (static char *domain); +static char *domain; /* Former NI_IDN_ALLOW_UNASSIGNED, NI_IDN_USE_STD3_ASCII_RULES flags, now ignored. */ @@ -556,3 +557,5 @@ getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host, return 0; } libc_hidden_def (getnameinfo) + +weak_alias (domain, __libc_getnameinfo_freemem_ptr) diff --git a/inet/getnetgrent.c b/inet/getnetgrent.c index 0b689e0ab0..a7c83740a0 100644 --- a/inet/getnetgrent.c +++ b/inet/getnetgrent.c @@ -19,9 +19,10 @@ #include #include #include +#include /* Static buffer for return value. We allocate it when needed. */ -libc_freeres_ptr (static char *buffer); +static char *buffer; /* All three strings should fit in a block of 1kB size. */ #define BUFSIZE 1024 @@ -47,3 +48,5 @@ getnetgrent (char **hostp, char **userp, char **domainp) return __getnetgrent_r (hostp, userp, domainp, buffer, BUFSIZE); } + +weak_alias (buffer, __libc_getnetgrent_freemem_ptr) diff --git a/inet/rcmd.c b/inet/rcmd.c index 2b95fa11d8..ad8a894907 100644 --- a/inet/rcmd.c +++ b/inet/rcmd.c @@ -80,6 +80,7 @@ #include #include #include +#include int __ivaliduser (FILE *, uint32_t, const char *, const char *); @@ -98,7 +99,7 @@ int iruserok (uint32_t raddr, int superuser, const char *ruser, libc_hidden_proto (iruserok_af) -libc_freeres_ptr(static char *ahostbuf); +static char *ahostbuf; int rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser, @@ -817,3 +818,5 @@ __validuser2_sa (FILE *hostf, struct sockaddr *ra, size_t ralen, return retval; } + +weak_alias (ahostbuf, __libc_rcmd_freemem_ptr) diff --git a/inet/rexec.c b/inet/rexec.c index c647b7ac34..1985fa4418 100644 --- a/inet/rexec.c +++ b/inet/rexec.c @@ -40,9 +40,10 @@ #include #include #include +#include int rexecoptions; -libc_freeres_ptr (static char *ahostbuf); +static char *ahostbuf; int rexec_af (char **ahost, int rport, const char *name, const char *pass, @@ -196,3 +197,5 @@ rexec (char **ahost, int rport, const char *name, const char *pass, { return rexec_af(ahost, rport, name, pass, cmd, fd2p, AF_INET); } + +weak_alias (ahostbuf, __libc_rexec_freemem_ptr) diff --git a/intl/dcigettext.c b/intl/dcigettext.c index 64de9d511a..7886ac9545 100644 --- a/intl/dcigettext.c +++ b/intl/dcigettext.c @@ -1667,7 +1667,8 @@ mempcpy (void *dest, const void *src, size_t n) #ifdef _LIBC /* If we want to free all resources we have to do some work at program's end. */ -libc_freeres_fn (free_mem) +void +__intl_freemem (void) { void *old; diff --git a/intl/finddomain.c b/intl/finddomain.c index 5f2508b2ae..6a8b239a97 100644 --- a/intl/finddomain.c +++ b/intl/finddomain.c @@ -185,7 +185,7 @@ out: #ifdef _LIBC /* This is called from iconv/gconv_db.c's free_mem, as locales must be freed before freeing gconv steps arrays. */ -void __libc_freeres_fn_section +void _nl_finddomain_subfreeres (void) { struct loaded_l10nfile *runp = _nl_loaded_domains; diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c index 992489758c..94a362f923 100644 --- a/intl/loadmsgcat.c +++ b/intl/loadmsgcat.c @@ -1284,7 +1284,6 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, #ifdef _LIBC void -__libc_freeres_fn_section _nl_unload_domain (struct loaded_domain *domain) { size_t i; diff --git a/intl/localealias.c b/intl/localealias.c index 42e4569b0a..ea4f48b594 100644 --- a/intl/localealias.c +++ b/intl/localealias.c @@ -126,14 +126,10 @@ struct alias_map }; -#ifndef _LIBC -# define libc_freeres_ptr(decl) decl -#endif - -libc_freeres_ptr (static char *string_space); +static char *string_space; static size_t string_space_act; static size_t string_space_max; -libc_freeres_ptr (static struct alias_map *map); +static struct alias_map *map; static size_t nmap; static size_t maxmap; @@ -439,3 +435,10 @@ alias_compare (const struct alias_map *map1, const struct alias_map *map2) return c1 - c2; #endif } + +void +__libc_localealias_freemem (void) +{ + free (string_space); + free (map); +} diff --git a/libio/fcloseall.c b/libio/fcloseall.c index e1e06d497b..415da65c76 100644 --- a/libio/fcloseall.c +++ b/libio/fcloseall.c @@ -26,6 +26,7 @@ #include "libioP.h" #include +#include int __fcloseall (void) diff --git a/libio/genops.c b/libio/genops.c index 7c45052aa2..7131312704 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -765,8 +765,8 @@ weak_alias (_IO_flush_all_linebuffered, _flushlbf) actual buffer because this will happen anyway once the program terminated. If we do want to look for memory leaks we have to free the buffers. Whether something is freed is determined by the - function sin the libc_freeres section. Those are called as part of - the atexit routine, just like _IO_cleanup. The problem is we do + function called by __libc_freeres (those are not called as part of + the atexit routine, different from _IO_cleanup). The problem is we do not know whether the freeres code is called first or _IO_cleanup. if the former is the case, we set the DEALLOC_BUFFER variable to true and _IO_unbuffer_all will take care of the rest. If @@ -844,8 +844,8 @@ _IO_unbuffer_all (void) #endif } - -libc_freeres_fn (buffer_free) +void +__libio_freemem (void) { dealloc_buffers = true; diff --git a/libio/libioP.h b/libio/libioP.h index 38507388fd..80941b763f 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -491,7 +491,6 @@ libc_hidden_proto (_IO_wdo_write) extern int _IO_flush_all_lockp (int); extern int _IO_flush_all (void); libc_hidden_proto (_IO_flush_all) -extern int _IO_cleanup (void); extern void _IO_flush_all_linebuffered (void); libc_hidden_proto (_IO_flush_all_linebuffered) extern int _IO_new_fgetpos (FILE *, __fpos_t *); diff --git a/locale/loadarchive.c b/locale/loadarchive.c index 454bbc7eda..5b857d5d24 100644 --- a/locale/loadarchive.c +++ b/locale/loadarchive.c @@ -498,7 +498,7 @@ _nl_load_locale_from_archive (int category, const char **namep) return lia->data[category]; } -void __libc_freeres_fn_section +void _nl_archive_subfreeres (void) { struct locale_in_archive *lia; diff --git a/locale/localeinfo.h b/locale/localeinfo.h index 66cad7a83b..8bbf281427 100644 --- a/locale/localeinfo.h +++ b/locale/localeinfo.h @@ -381,10 +381,10 @@ extern struct __locale_data *_nl_load_locale_from_archive (int category, const char **namep) attribute_hidden; -/* Subroutine of setlocale's __libc_subfreeres hook. */ +/* Subroutine of setlocale's free resource. */ extern void _nl_archive_subfreeres (void) attribute_hidden; -/* Subroutine of gconv-db's __libc_subfreeres hook. */ +/* Subroutine of gconv-db's free resource. */ extern void _nl_locale_subfreeres (void) attribute_hidden; /* Validate the contents of a locale file and set up the in-core diff --git a/locale/setlocale.c b/locale/setlocale.c index dd73fa4248..6a902faa50 100644 --- a/locale/setlocale.c +++ b/locale/setlocale.c @@ -468,7 +468,7 @@ setlocale (int category, const char *locale) } libc_hidden_def (setlocale) -static void __libc_freeres_fn_section +static void free_category (int category, struct __locale_data *here, struct __locale_data *c_data) { @@ -498,7 +498,7 @@ free_category (int category, /* This is called from iconv/gconv_db.c's free_mem, as locales must be freed before freeing gconv steps arrays. */ -void __libc_freeres_fn_section +void _nl_locale_subfreeres (void) { #ifdef NL_CURRENT_INDIRECT diff --git a/login/getutent.c b/login/getutent.c index 7a49984912..ed8b162b8a 100644 --- a/login/getutent.c +++ b/login/getutent.c @@ -17,10 +17,11 @@ #include #include +#include /* Local buffer to store the result. */ -libc_freeres_ptr (static struct utmp *buffer); +static struct utmp *buffer; struct utmp * @@ -42,3 +43,5 @@ __getutent (void) } libc_hidden_def (__getutent) weak_alias (__getutent, getutent) + +weak_alias (buffer, __libc_getutent_freemem_ptr) diff --git a/login/getutid.c b/login/getutid.c index 7ecc93c0b7..658fdc08ca 100644 --- a/login/getutid.c +++ b/login/getutid.c @@ -17,10 +17,10 @@ #include #include - +#include /* Local buffer to store the result. */ -libc_freeres_ptr (static struct utmp *buffer); +static struct utmp *buffer; struct utmp * __getutid (const struct utmp *id) @@ -40,3 +40,5 @@ __getutid (const struct utmp *id) } libc_hidden_def (__getutid) weak_alias (__getutid, getutid) + +weak_alias (buffer, __libc_getutid_freemem_ptr) diff --git a/login/getutline.c b/login/getutline.c index c9dcd227a5..a10c256c42 100644 --- a/login/getutline.c +++ b/login/getutline.c @@ -17,10 +17,11 @@ #include #include +#include /* Local buffer to store the result. */ -libc_freeres_ptr (static struct utmp *buffer); +static struct utmp *buffer; struct utmp * @@ -41,3 +42,5 @@ __getutline (const struct utmp *line) } libc_hidden_def (__getutline) weak_alias (__getutline, getutline) + +weak_alias (buffer, __libc_getutline_freemem_ptr) diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c index 4a5cec5d4a..f452ff838b 100644 --- a/malloc/set-freeres.c +++ b/malloc/set-freeres.c @@ -15,32 +15,62 @@ License along with the GNU C Library; if not, see . */ +#include #include #include -#include #include #include -#include #include +#include +#include + +#ifndef SHARED +# pragma weak __nss_module_freeres +# pragma weak __nss_action_freeres +# pragma weak __nss_database_freeres +# pragma weak __dl_libc_freemem +# pragma weak __hdestroy +# pragma weak __gconv_cache_freemem +# pragma weak __gconv_conf_freemem +# pragma weak __gconv_db_freemem +# pragma weak __gconv_dl_freemem +# pragma weak __intl_freemem +# pragma weak __libio_freemem +# pragma weak __libc_fstab_freemem +# pragma weak __nscd_gr_map_freemem +# pragma weak __nscd_hst_map_freemem +# pragma weak __nscd_pw_map_freemem +# pragma weak __nscd_serv_map_freemem +# pragma weak __nscd_group_map_freemem +# pragma weak __libc_regcomp_freemem +# pragma weak __libc_atfork_freemem +# pragma weak __res_thread_freeres +# pragma weak __libc_resolv_conf_freemem +# pragma weak __libc_printf_freemem +# pragma weak __libc_fmtmsg_freemem +# pragma weak __libc_setenv_freemem +# pragma weak __rpc_freemem +# pragma weak __rpc_thread_destroy +# pragma weak __libc_getaddrinfo_freemem +# pragma weak __libc_tzset_freemem +# pragma weak __libc_localealias_freemem +# pragma weak __gai_freemem +# pragma weak __aio_freemem +# pragma weak __libpthread_freeres +# pragma weak __libc_dlerror_result_free +# pragma weak __check_pf_freemem +#endif -#include "../nss/nsswitch.h" -#include "../libio/libioP.h" - -DEFINE_HOOK (__libc_subfreeres, (void)); - -symbol_set_define (__libc_freeres_ptrs); - -extern void __libpthread_freeres (void) -#if PTHREAD_IN_LIBC && defined SHARED -/* It is possible to call __libpthread_freeres directly in shared - builds with an integrated libpthread. */ - attribute_hidden +#ifdef SHARED +# define call_free_static_weak(__ptr) \ + free (__ptr) #else - __attribute__ ((weak)) +# define call_free_static_weak(__ptr) \ + if (&__ptr != NULL) \ + free (__ptr); #endif - ; -void __libc_freeres_fn_section +void __libc_freeres (void) { /* This function might be called from different places. So better @@ -49,8 +79,6 @@ __libc_freeres (void) if (!atomic_compare_and_exchange_bool_acq (&already_called, 1, 0)) { - void *const *p; - call_function_static_weak (__nss_module_freeres); call_function_static_weak (__nss_action_freeres); call_function_static_weak (__nss_database_freeres); @@ -58,7 +86,43 @@ __libc_freeres (void) _IO_cleanup (); /* We run the resource freeing after IO cleanup. */ - RUN_HOOK (__libc_subfreeres, ()); + call_function_static_weak (__dl_libc_freemem); + call_function_static_weak (__hdestroy); + call_function_static_weak (__gconv_cache_freemem); + call_function_static_weak (__gconv_conf_freemem); + call_function_static_weak (__gconv_db_freemem); + call_function_static_weak (__gconv_dl_freemem); + call_function_static_weak (__intl_freemem); + call_function_static_weak (__libio_freemem); + call_function_static_weak (__libc_fstab_freemem); + call_function_static_weak (__nscd_gr_map_freemem); + call_function_static_weak (__nscd_hst_map_freemem); + call_function_static_weak (__nscd_pw_map_freemem); + call_function_static_weak (__nscd_serv_map_freemem); + call_function_static_weak (__nscd_group_map_freemem); + call_function_static_weak (__libc_regcomp_freemem); + call_function_static_weak (__libc_atfork_freemem); + /* __res_thread_freeres deallocates the per-thread resolv_context); + which in turn drop the reference count of the current global object. + So it need to be before __libc_resolv_conf_freemem. */ + call_function_static_weak (__res_thread_freeres); + call_function_static_weak (__libc_resolv_conf_freemem); + call_function_static_weak (__libc_printf_freemem); + call_function_static_weak (__libc_fmtmsg_freemem); + call_function_static_weak (__libc_setenv_freemem); +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31) + call_function_static_weak (__rpc_freemem); + call_function_static_weak (__rpc_thread_destroy); +#endif + call_function_static_weak (__libc_getaddrinfo_freemem); + call_function_static_weak (__libc_tzset_freemem); + call_function_static_weak (__libc_localealias_freemem); + +#if PTHREAD_IN_LIBC + call_function_static_weak (__gai_freemem); + + call_function_static_weak (__aio_freemem); +#endif call_function_static_weak (__libpthread_freeres); @@ -72,9 +136,55 @@ __libc_freeres (void) GLRO (dl_libc_freeres) (); #endif - for (p = symbol_set_first_element (__libc_freeres_ptrs); - !symbol_set_end_p (__libc_freeres_ptrs, p); ++p) - free (*p); + call_free_static_weak (__libc_fgetgrent_freemem_ptr); + call_free_static_weak (__libc_fgetsgent_freeres_ptr); + call_free_static_weak (__libc_getnetgrent_freemem_ptr); + call_free_static_weak (__libc_rcmd_freemem_ptr); + call_free_static_weak (__libc_rexec_freemem_ptr); + call_free_static_weak (__libc_mntent_freemem_ptr); + call_free_static_weak (__libc_fgetpwent_freemem_ptr); + call_free_static_weak (__libc_resolv_res_hconf_freemem_ptr); + call_free_static_weak (__libc_fgetspent_freemem_ptr); + call_free_static_weak (__libc_tzfile_freemem_ptr); + call_free_static_weak (__libc_getnameinfo_freemem_ptr); + call_free_static_weak (__libc_getutent_freemem_ptr); + call_free_static_weak (__libc_getutid_freemem_ptr); + call_free_static_weak (__libc_getutline_freemem_ptr); + call_free_static_weak (__libc_reg_printf_freemem_ptr); + call_free_static_weak (__libc_reg_type_freemem_ptr); + + call_free_static_weak (__libc_getgrgid_freemem_ptr); + call_free_static_weak (__libc_getgrnam_freemem_ptr); + call_free_static_weak (__libc_getpwnam_freemem_ptr); + call_free_static_weak (__libc_getpwuid_freemem_ptr); + call_free_static_weak (__libc_getspnam_freemem_ptr); + call_free_static_weak (__libc_getaliasbyname_freemem_ptr); + call_free_static_weak (__libc_gethostbyaddr_freemem_ptr); + call_free_static_weak (__libc_gethostbyname_freemem_ptr); + call_free_static_weak (__libc_gethostbyname2_freemem_ptr); + call_free_static_weak (__libc_getnetbyaddr_freemem_ptr); + call_free_static_weak (__libc_getnetbyname_freemem_ptr); + call_free_static_weak (__libc_getprotobynumber_freemem_ptr); + call_free_static_weak (__libc_getprotobyname_freemem_ptr); + call_free_static_weak (__libc_getrpcbyname_freemem_ptr); + call_free_static_weak (__libc_getrpcbynumber_freemem_ptr); + call_free_static_weak (__libc_getservbyname_freemem_ptr); + call_free_static_weak (__libc_getservbyport_freemem_ptr); + + call_free_static_weak (__libc_getgrent_freemem_ptr); + call_free_static_weak (__libc_getpwent_freemem_ptr); + call_free_static_weak (__libc_getspent_freemem_ptr); + call_free_static_weak (__libc_getaliasent_freemem_ptr); + call_free_static_weak (__libc_gethostent_freemem_ptr); + call_free_static_weak (__libc_getnetent_freemem_ptr); + call_free_static_weak (__libc_getprotoent_freemem_ptr); + call_free_static_weak (__libc_getrpcent_freemem_ptr); + call_free_static_weak (__libc_getservent_freemem_ptr); + + call_free_static_weak (__libc_efgcvt_freemem_ptr); + call_free_static_weak (__libc_qefgcvt_freemem_ptr); + + call_freeres_system_funcs; } } libc_hidden_def (__libc_freeres) diff --git a/malloc/thread-freeres.c b/malloc/thread-freeres.c index cbb99f8bb4..416d199afd 100644 --- a/malloc/thread-freeres.c +++ b/malloc/thread-freeres.c @@ -16,18 +16,15 @@ License along with the GNU C Library; if not, see . */ -#include #include #include -#include -#include -#include -#include +#include #include +#include /* Thread shutdown function. Note that this function must be called for threads during shutdown for correctness reasons. Unlike - __libc_subfreeres, skipping calls to it is not a valid optimization. + __libc_freeres, skipping calls to it is not a valid optimization. This is called directly from pthread_create as the thread exits. */ void __libc_thread_freeres (void) diff --git a/misc/efgcvt-template.c b/misc/efgcvt-template.c index 27a00a3ab5..00d0aa1d7e 100644 --- a/misc/efgcvt-template.c +++ b/misc/efgcvt-template.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifndef SPRINTF # define SPRINTF sprintf @@ -38,7 +39,7 @@ static char FCVT_BUFFER[MAXDIG]; static char ECVT_BUFFER[MAXDIG]; -libc_freeres_ptr (static char *FCVT_BUFPTR); +static char *FCVT_BUFPTR; char * __FCVT (FLOAT_TYPE value, int ndigit, int *decpt, int *sign) @@ -73,3 +74,5 @@ __GCVT (FLOAT_TYPE value, int ndigit, char *buf) SPRINTF (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value); return buf; } + +weak_alias (FCVT_BUFPTR, __EFGCVT_FREEMEM_PTR); diff --git a/misc/efgcvt.c b/misc/efgcvt.c index 53673a08fe..f2a33afcdf 100644 --- a/misc/efgcvt.c +++ b/misc/efgcvt.c @@ -24,6 +24,7 @@ #define __GCVT __gcvt #define __ECVT_R __ecvt_r #define __FCVT_R __fcvt_r +#define __EFGCVT_FREEMEM_PTR __libc_efgcvt_freemem_ptr #include #include diff --git a/misc/fstab.c b/misc/fstab.c index 0e04235a2b..ea4afc7d0f 100644 --- a/misc/fstab.c +++ b/misc/fstab.c @@ -177,7 +177,8 @@ fstab_convert (struct fstab_state *state) /* Make sure the memory is freed if the programs ends while in memory-debugging mode and something actually was allocated. */ -libc_freeres_fn (fstab_free) +void +__libc_fstab_freemem (void) { char *buffer; diff --git a/misc/hsearch.c b/misc/hsearch.c index 615f7f08a3..f9a3f9267a 100644 --- a/misc/hsearch.c +++ b/misc/hsearch.c @@ -46,7 +46,3 @@ __hdestroy (void) __hdestroy_r (&htab); } weak_alias (__hdestroy, hdestroy) - -/* Make sure the table is freed if we want to free everything before - exiting. */ -text_set_element (__libc_subfreeres, __hdestroy); diff --git a/misc/mntent.c b/misc/mntent.c index 4a1c5444cf..61dc63f253 100644 --- a/misc/mntent.c +++ b/misc/mntent.c @@ -19,6 +19,7 @@ #include #include #include +#include struct mntent_buffer { @@ -28,7 +29,7 @@ struct mntent_buffer /* We don't want to allocate the static buffer all the time since it is not always used (in fact, rather infrequently). */ -libc_freeres_ptr (static void *mntent_buffer); +static void *mntent_buffer; static void * allocate (void *closure) @@ -56,3 +57,5 @@ getmntent (FILE *stream) return __getmntent_r (stream, &buffer->m, buffer->buffer, sizeof (buffer->buffer)); } + +weak_alias (mntent_buffer, __libc_mntent_freemem_ptr) diff --git a/misc/qefgcvt.c b/misc/qefgcvt.c index 91a3e2014a..a4ea8b801e 100644 --- a/misc/qefgcvt.c +++ b/misc/qefgcvt.c @@ -24,6 +24,7 @@ #define __GCVT __qgcvt #define __ECVT_R __qecvt_r #define __FCVT_R __qfcvt_r +#define __EFGCVT_FREEMEM_PTR __libc_qefgcvt_freemem_ptr #include #include diff --git a/misc/unwind-link.c b/misc/unwind-link.c index 63b655949e..c1e971b305 100644 --- a/misc/unwind-link.c +++ b/misc/unwind-link.c @@ -131,7 +131,7 @@ __libc_unwind_link_after_fork (void) } } -void __libc_freeres_fn_section +void __libc_unwind_link_freeres (void) { if (global_libgcc_handle != NULL) diff --git a/nptl/nptlfreeres.c b/nptl/nptlfreeres.c index 03ee6bd31a..ee9bca8387 100644 --- a/nptl/nptlfreeres.c +++ b/nptl/nptlfreeres.c @@ -16,7 +16,6 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c index f30d99973d..07e894019a 100644 --- a/nscd/nscd_getgr_r.c +++ b/nscd/nscd_getgr_r.c @@ -68,7 +68,8 @@ libc_locked_map_ptr (,__gr_map_handle) attribute_hidden; /* Note that we only free the structure if necessary. The memory mapping is not removed since it is not visible to the malloc handling. */ -libc_freeres_fn (gr_map_free) +void +__nscd_gr_map_freemem (void) { if (__gr_map_handle.mapped != NO_MAPPING) { diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c index ab9c9d311f..c6a6247f73 100644 --- a/nscd/nscd_gethst_r.c +++ b/nscd/nscd_gethst_r.c @@ -81,7 +81,8 @@ libc_locked_map_ptr (, __hst_map_handle) attribute_hidden; /* Note that we only free the structure if necessary. The memory mapping is not removed since it is not visible to the malloc handling. */ -libc_freeres_fn (hst_map_free) +void +__nscd_hst_map_freemem (void) { if (__hst_map_handle.mapped != NO_MAPPING) { diff --git a/nscd/nscd_getpw_r.c b/nscd/nscd_getpw_r.c index 0cae7ad61c..17d9753f8a 100644 --- a/nscd/nscd_getpw_r.c +++ b/nscd/nscd_getpw_r.c @@ -67,7 +67,8 @@ libc_locked_map_ptr (static, map_handle); /* Note that we only free the structure if necessary. The memory mapping is not removed since it is not visible to the malloc handling. */ -libc_freeres_fn (pw_map_free) +void +__nscd_pw_map_freemem (void) { if (map_handle.mapped != NO_MAPPING) { diff --git a/nscd/nscd_getserv_r.c b/nscd/nscd_getserv_r.c index 6969fcb739..1458c6ca22 100644 --- a/nscd/nscd_getserv_r.c +++ b/nscd/nscd_getserv_r.c @@ -62,7 +62,8 @@ libc_locked_map_ptr (, __serv_map_handle) attribute_hidden; /* Note that we only free the structure if necessary. The memory mapping is not removed since it is not visible to the malloc handling. */ -libc_freeres_fn (serv_map_free) +void +__nscd_serv_map_freemem (void) { if (__serv_map_handle.mapped != NO_MAPPING) { diff --git a/nscd/nscd_netgroup.c b/nscd/nscd_netgroup.c index 29cd3a5116..6f4c383ace 100644 --- a/nscd/nscd_netgroup.c +++ b/nscd/nscd_netgroup.c @@ -31,7 +31,8 @@ libc_locked_map_ptr (static, map_handle); /* Note that we only free the structure if necessary. The memory mapping is not removed since it is not visible to the malloc handling. */ -libc_freeres_fn (pw_map_free) +void +__nscd_group_map_freemem (void) { if (map_handle.mapped != NO_MAPPING) { diff --git a/nss/getXXbyYY.c b/nss/getXXbyYY.c index 0c473a4294..efb17f0571 100644 --- a/nss/getXXbyYY.c +++ b/nss/getXXbyYY.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "nsswitch.h" @@ -58,6 +59,9 @@ #define APPEND_R1(name) name##_r #define INTERNAL(name) INTERNAL1 (name) #define INTERNAL1(name) __##name +#define APPEND_FREEMEM_NAME1(name) __libc_##name##_freemem_ptr +#define APPEND_FREEMEM_NAME(name) APPEND_FREEMEM_NAME1(name) +#define FREEMEM_NAME APPEND_FREEMEM_NAME (FUNCTION_NAME) /* Sometimes we need to store error codes in the `h_errno' variable. */ #ifdef NEED_H_ERRNO @@ -86,8 +90,9 @@ extern int INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, __libc_lock_define_initialized (static, lock); /* This points to the static buffer used. */ -libc_freeres_ptr (static char *buffer); +static char *buffer; +weak_alias (buffer, FREEMEM_NAME) LOOKUP_TYPE * FUNCTION_NAME (ADD_PARAMS) diff --git a/nss/getXXent.c b/nss/getXXent.c index 7ac8379fbc..8acb6dc54f 100644 --- a/nss/getXXent.c +++ b/nss/getXXent.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "nsswitch.h" @@ -43,6 +44,9 @@ #define APPEND_R1(name) name##_r #define INTERNAL(name) INTERNAL1 (name) #define INTERNAL1(name) __##name +#define APPEND_FREEMEM_NAME1(name) __libc_##name##_freemem_ptr +#define APPEND_FREEMEM_NAME(name) APPEND_FREEMEM_NAME1(name) +#define FREEMEM_NAME APPEND_FREEMEM_NAME (GETFUNC_NAME) /* Sometimes we need to store error codes in the `h_errno' variable. */ #ifdef NEED_H_ERRNO @@ -62,8 +66,9 @@ extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer, __libc_lock_define_initialized (static, lock); /* This points to the static buffer used. */ -libc_freeres_ptr (static char *buffer); +static char *buffer; +weak_alias (buffer, FREEMEM_NAME) LOOKUP_TYPE * GETFUNC_NAME (void) diff --git a/nss/nss_action.c b/nss/nss_action.c index 8ca72546eb..447c219c5b 100644 --- a/nss/nss_action.c +++ b/nss/nss_action.c @@ -102,7 +102,7 @@ __nss_action_allocate (struct nss_action *actions, size_t count) return result; } -void __libc_freeres_fn_section +void __nss_action_freeres (void) { struct nss_action_list_wrapper *current = nss_actions; diff --git a/nss/nss_action.h b/nss/nss_action.h index edd84b8e8a..7ab2415417 100644 --- a/nss/nss_action.h +++ b/nss/nss_action.h @@ -101,8 +101,5 @@ nss_action_list __nss_action_allocate (struct nss_action *actions, EINVAL means that LINE is syntactically invalid. */ nss_action_list __nss_action_parse (const char *line); -/* Called from __libc_freeres. */ -void __nss_action_freeres (void) attribute_hidden; - #endif /* _NSS_ACTION_H */ diff --git a/nss/nss_database.c b/nss/nss_database.c index 335034605f..2edcab4b9d 100644 --- a/nss/nss_database.c +++ b/nss/nss_database.c @@ -495,7 +495,7 @@ __nss_database_get_noreload (enum nss_database db) return result; } -void __libc_freeres_fn_section +void __nss_database_freeres (void) { free (global_database_state); diff --git a/nss/nss_database.h b/nss/nss_database.h index 2462030511..1a17261f65 100644 --- a/nss/nss_database.h +++ b/nss/nss_database.h @@ -64,9 +64,6 @@ libc_hidden_proto (__nss_database_get) nss_action_list __nss_database_get_noreload (enum nss_database db) attribute_hidden; -/* Called from __libc_freeres. */ -void __nss_database_freeres (void) attribute_hidden; - /* Internal type. Exposed only for fork handling purposes. */ struct nss_database_data { diff --git a/nss/nss_module.c b/nss/nss_module.c index 8815fefc21..487e513def 100644 --- a/nss/nss_module.c +++ b/nss/nss_module.c @@ -416,7 +416,7 @@ __nss_module_disable_loading (void) __libc_lock_unlock (nss_module_list_lock); } -void __libc_freeres_fn_section +void __nss_module_freeres (void) { struct nss_module *current = nss_module_list; diff --git a/nss/nss_module.h b/nss/nss_module.h index eda0ebc5ef..fb30fb8b4c 100644 --- a/nss/nss_module.h +++ b/nss/nss_module.h @@ -100,7 +100,4 @@ void *__nss_module_get_function (struct nss_module *module, const char *name) /* Block attempts to dlopen any module we haven't already opened. */ void __nss_module_disable_loading (void); -/* Called from __libc_freeres. */ -void __nss_module_freeres (void) attribute_hidden; - #endif /* NSS_MODULE_H */ diff --git a/posix/regcomp.c b/posix/regcomp.c index c3231ea824..647b18ba9e 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -710,7 +710,8 @@ re_comp (const char *s) } #ifdef _LIBC -libc_freeres_fn (free_mem) +void +__libc_regcomp_freemem (void) { __regfree (&re_comp_buf); } diff --git a/posix/register-atfork.c b/posix/register-atfork.c index 4d89a457a0..14ebc2587a 100644 --- a/posix/register-atfork.c +++ b/posix/register-atfork.c @@ -217,7 +217,8 @@ __run_postfork_handlers (enum __run_fork_handler_type who, _Bool do_locking, } -libc_freeres_fn (free_mem) +void +__libc_atfork_freemem (void) { lll_lock (atfork_lock, LLL_PRIVATE); diff --git a/pwd/fgetpwent.c b/pwd/fgetpwent.c index f069aa6f0c..b7864d263a 100644 --- a/pwd/fgetpwent.c +++ b/pwd/fgetpwent.c @@ -20,12 +20,13 @@ #include #include #include +#include /* We need to protect the dynamic buffer handling. */ __libc_lock_define_initialized (static, lock); -libc_freeres_ptr (static char *buffer); +static char *buffer; /* Read one entry from the given stream. */ struct passwd * @@ -82,3 +83,5 @@ fgetpwent (FILE *stream) return result; } + +weak_alias (buffer, __libc_fgetpwent_freemem_ptr) diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c index dda9b47f00..9e3b1d29b7 100644 --- a/resolv/gai_misc.c +++ b/resolv/gai_misc.c @@ -434,7 +434,11 @@ handle_requests (void *arg) /* Free allocated resources. */ -libc_freeres_fn (free_res) +#if !PTHREAD_IN_LIBC +__attribute__ ((__destructor__)) static +#endif +void +__gai_freemem (void) { size_t row; diff --git a/resolv/res-close.c b/resolv/res-close.c index 936fd3d1dd..8d546777c7 100644 --- a/resolv/res-close.c +++ b/resolv/res-close.c @@ -140,5 +140,3 @@ __res_thread_freeres (void) /* Make sure we do a full re-initialization the next time. */ _res.options = 0; } -/* Also must be called when the main thread exits. */ -text_set_element (__libc_subfreeres, __res_thread_freeres); diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c index 2c4e12b6cd..89bd20be38 100644 --- a/resolv/res_hconf.c +++ b/resolv/res_hconf.c @@ -42,6 +42,7 @@ #include "res_hconf.h" #include #include +#include #if IS_IN (libc) # define fgets_unlocked __fgets_unlocked @@ -330,19 +331,8 @@ _res_hconf_init (void) #if IS_IN (libc) # if defined SIOCGIFCONF && defined SIOCGIFNETMASK /* List of known interfaces. */ -libc_freeres_ptr ( -static struct netaddr -{ - int addrtype; - union - { - struct - { - uint32_t addr; - uint32_t mask; - } ipv4; - } u; -} *ifaddrs); +static struct netaddr *ifaddrs; +weak_alias (ifaddrs, __libc_resolv_res_hconf_freemem_ptr) # endif /* Reorder addresses returned in a hostent such that the first address diff --git a/resolv/resolv-internal.h b/resolv/resolv-internal.h index 97812ebf6c..c55f3c0366 100644 --- a/resolv/resolv-internal.h +++ b/resolv/resolv-internal.h @@ -34,6 +34,20 @@ loads and stores. */ typedef HEADER __attribute__ ((__aligned__(1))) UHEADER; +/* List of known interfaces. */ +struct netaddr +{ + int addrtype; + union + { + struct + { + uint32_t addr; + uint32_t mask; + } ipv4; + } u; +}; + /* Legacy function. This needs to be removed once all NSS modules have been adjusted. */ static inline bool diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c index 2e561c8959..0ef66d49d3 100644 --- a/resolv/resolv_conf.c +++ b/resolv/resolv_conf.c @@ -654,7 +654,8 @@ __resolv_conf_detach (struct __res_state *resp) } /* Deallocate the global data. */ -libc_freeres_fn (freeres) +void +__libc_resolv_conf_freemem (void) { /* No locking because this function is supposed to be called when the process has turned single-threaded. */ diff --git a/resolv/tst-leaks2.c b/resolv/tst-leaks2.c index 3851ea06ce..50a8054546 100644 --- a/resolv/tst-leaks2.c +++ b/resolv/tst-leaks2.c @@ -23,6 +23,8 @@ #include #include +void __libc_freeres (void); + static int do_test (void) { diff --git a/rt/aio_misc.c b/rt/aio_misc.c index cde3de8b7f..49ec0aa293 100644 --- a/rt/aio_misc.c +++ b/rt/aio_misc.c @@ -694,7 +694,11 @@ handle_fildes_io (void *arg) /* Free allocated resources. */ -libc_freeres_fn (free_res) +#if !PTHREAD_IN_LIBC +__attribute__ ((__destructor__)) static +#endif +void +__aio_freemem (void) { size_t row; diff --git a/shadow/fgetspent.c b/shadow/fgetspent.c index 76a18bf4fb..541947bad6 100644 --- a/shadow/fgetspent.c +++ b/shadow/fgetspent.c @@ -20,6 +20,7 @@ #include #include #include +#include /* A reasonable size for a buffer to start with. */ @@ -28,7 +29,7 @@ /* We need to protect the dynamic buffer handling. */ __libc_lock_define_initialized (static, lock); -libc_freeres_ptr (static char *buffer); +static char *buffer; /* Read one shadow entry from the given stream. */ struct spwd * @@ -85,3 +86,5 @@ fgetspent (FILE *stream) return result; } + +weak_alias (buffer, __libc_fgetspent_freemem_ptr); diff --git a/stdio-common/reg-modifier.c b/stdio-common/reg-modifier.c index b911aea703..a52022d1ba 100644 --- a/stdio-common/reg-modifier.c +++ b/stdio-common/reg-modifier.c @@ -183,7 +183,8 @@ __handle_registered_modifier_wc (const unsigned int **format, } -libc_freeres_fn (free_mem) +void +__libc_printf_freemem (void) { if (__printf_modifier_table != NULL) { diff --git a/stdio-common/reg-printf.c b/stdio-common/reg-printf.c index 3ec81e6956..0d14ac6afa 100644 --- a/stdio-common/reg-printf.c +++ b/stdio-common/reg-printf.c @@ -21,11 +21,11 @@ #include #include #include +#include /* Array of functions indexed by format character. */ -libc_freeres_ptr (printf_arginfo_size_function **__printf_arginfo_table) - attribute_hidden; +printf_arginfo_size_function **__printf_arginfo_table attribute_hidden; printf_function **__printf_function_table attribute_hidden; __libc_lock_define_initialized (static, lock) @@ -79,3 +79,5 @@ __register_printf_function (int spec, printf_function converter, (printf_arginfo_size_function*) arginfo); } weak_alias (__register_printf_function, register_printf_function) + +weak_alias (__printf_arginfo_table, __libc_reg_printf_freemem_ptr) diff --git a/stdio-common/reg-type.c b/stdio-common/reg-type.c index 02edac4da3..980a911ae2 100644 --- a/stdio-common/reg-type.c +++ b/stdio-common/reg-type.c @@ -19,11 +19,11 @@ #include #include #include +#include /* Array of functions indexed by format character. */ -libc_freeres_ptr (printf_va_arg_function **__printf_va_arg_table) - attribute_hidden; +printf_va_arg_function **__printf_va_arg_table attribute_hidden; __libc_lock_define_initialized (static, lock); @@ -59,3 +59,5 @@ __register_printf_type (printf_va_arg_function fct) return result; } weak_alias (__register_printf_type, register_printf_type) + +weak_alias (__printf_va_arg_table, __libc_reg_type_freemem_ptr) diff --git a/stdlib/exit.c b/stdlib/exit.c index 1cd0bdfe94..d6c188b739 100644 --- a/stdlib/exit.c +++ b/stdlib/exit.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "exit.h" /* Initialize the flag that indicates exit function processing diff --git a/stdlib/fmtmsg.c b/stdlib/fmtmsg.c index b631ef3d01..3d9a0edf12 100644 --- a/stdlib/fmtmsg.c +++ b/stdlib/fmtmsg.c @@ -361,7 +361,8 @@ __addseverity (int severity, const char *string) weak_alias (__addseverity, addseverity) -libc_freeres_fn (free_mem) +void +__libc_fmtmsg_freemem (void) { struct severity_info *runp = severity_list; diff --git a/stdlib/setenv.c b/stdlib/setenv.c index 2fa9e41e31..ba5257d3bf 100644 --- a/stdlib/setenv.c +++ b/stdlib/setenv.c @@ -323,7 +323,8 @@ clearenv (void) return 0; } #ifdef _LIBC -libc_freeres_fn (free_mem) +void +__libc_setenv_freemem (void) { /* Remove all traces. */ clearenv (); diff --git a/sunrpc/clnt_perr.c b/sunrpc/clnt_perr.c index 67499fd03f..c3d13722df 100644 --- a/sunrpc/clnt_perr.c +++ b/sunrpc/clnt_perr.c @@ -389,8 +389,8 @@ auth_errmsg (enum auth_stat stat) } -libc_freeres_fn (free_mem) +void +__rpc_freemem (void) { - /* Not libc_freeres_ptr, since buf is a macro. */ free (buf); } diff --git a/sunrpc/rpc_thread.c b/sunrpc/rpc_thread.c index 0abe6dc172..a04b7ec47f 100644 --- a/sunrpc/rpc_thread.c +++ b/sunrpc/rpc_thread.c @@ -37,7 +37,6 @@ __rpc_thread_destroy (void) thread_rpc_vars = NULL; } } -text_set_element (__libc_subfreeres, __rpc_thread_destroy); /* * Initialize RPC multi-threaded operation diff --git a/sunrpc/tst-svc_register.c b/sunrpc/tst-svc_register.c index 542c5c2a89..434a5bedef 100644 --- a/sunrpc/tst-svc_register.c +++ b/sunrpc/tst-svc_register.c @@ -276,9 +276,9 @@ do_test (void) else /* This is arguably a bug: Regular process termination does not unregister the service with rpcbind. The - unset rpcbind call happens from a __libc_subfreeres - callback, and this only happens when running under - memory debuggers such as valgrind. */ + unset rpcbind call happens from a __libc_freeres, + and this only happens when running under memory debuggers + such as valgrind. */ TEST_VERIFY (!state.unset_called); } else diff --git a/sysdeps/generic/set-freeres-fp.h b/sysdeps/generic/set-freeres-fp.h new file mode 100644 index 0000000000..f73ac747ad --- /dev/null +++ b/sysdeps/generic/set-freeres-fp.h @@ -0,0 +1,19 @@ +/* System specific resource deallocation. Generic version. + Copyright (C) 2022 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 + . */ + +#define call_freeres_fp_funcs diff --git a/sysdeps/generic/set-freeres-os.h b/sysdeps/generic/set-freeres-os.h new file mode 100644 index 0000000000..6b17c8307a --- /dev/null +++ b/sysdeps/generic/set-freeres-os.h @@ -0,0 +1,19 @@ +/* System specific resource deallocation. Generic version. + Copyright (C) 2020-2022 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 + . */ + +#define call_freeres_os_funcs diff --git a/sysdeps/generic/set-freeres-system.h b/sysdeps/generic/set-freeres-system.h new file mode 100644 index 0000000000..88701a657f --- /dev/null +++ b/sysdeps/generic/set-freeres-system.h @@ -0,0 +1,27 @@ +/* System specific resource deallocation. Generic version. + Copyright (C) 2022 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 + . */ + +/* Each system may define weak functions to free any resource allocated with + malloc to avoid interfere with mtrace. */ + +#include +#include + +#define call_freeres_system_funcs \ + call_freeres_os_funcs; \ + call_freeres_fp_funcs diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-qefgcvt.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-qefgcvt.c index e56e01ab2d..18a881d4d0 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-qefgcvt.c +++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-qefgcvt.c @@ -42,6 +42,7 @@ typeof (qfcvt_r) ___qfcvtieee128_r; #define __GCVT ___qgcvtieee128 #define __ECVT_R ___qecvtieee128_r #define __FCVT_R ___qfcvtieee128_r +#define __EFGCVT_FREEMEM_PTR __libc_efgcvtieee128_freemem_ptr #include #include diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h b/sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h new file mode 100644 index 0000000000..3f6e17612a --- /dev/null +++ b/sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h @@ -0,0 +1,22 @@ +/* System specific resource deallocation. IBM long double 128 version. + Copyright (C) 2022 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 + . */ + +extern char * __libc_efgcvtieee128_freemem_ptr attribute_hidden; + +#define call_freeres_fp_funcs \ + call_free_static_weak (__libc_efgcvtieee128_freemem_ptr) diff --git a/sysdeps/mach/hurd/bits/errno.h b/sysdeps/mach/hurd/bits/errno.h index 90c8897739..0d935e724a 100644 --- a/sysdeps/mach/hurd/bits/errno.h +++ b/sysdeps/mach/hurd/bits/errno.h @@ -9,7 +9,6 @@ mach/boolean.h mach/i386/boolean.h mach/i386/vm_types.h - mach/i386/stdint.h mach/mig_errors.h device/device_types.h mach/std_types.h diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index fd22dc4fcb..0356b622be 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1761,7 +1761,8 @@ check_gaiconf_mtime (const struct __stat64_t64 *st) #endif -libc_freeres_fn(fini) +void +__libc_getaddrinfo_freemem (void) { if (labels != default_labels) { @@ -2233,7 +2234,7 @@ no_file: /* If we previously read the file but it is gone now, free the old data and use the builtin one. Leave the reload flag alone. */ - fini (); + __libc_getaddrinfo_freemem (); } diff --git a/sysdeps/posix/ttyname.c b/sysdeps/posix/ttyname.c index 2e19aff758..a5805cd662 100644 --- a/sysdeps/posix/ttyname.c +++ b/sysdeps/posix/ttyname.c @@ -24,6 +24,7 @@ #include #include #include +#include char *__ttyname; @@ -31,7 +32,8 @@ static char *getttyname (int fd, dev_t mydev, ino_t myino, int save, int *dostat); -libc_freeres_ptr (static char *getttyname_name); +static char *getttyname_name; +weak_alias (getttyname_name, __ttyname_freemem_ptr) static char * getttyname (int fd, dev_t mydev, ino_t myino, int save, int *dostat) diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c index de207122b0..b157c5126c 100644 --- a/sysdeps/unix/sysv/linux/check_pf.c +++ b/sysdeps/unix/sysv/linux/check_pf.c @@ -362,7 +362,8 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, } /* Free the cache if it has been allocated. */ -libc_freeres_fn (freecache) +void +__check_pf_freemem (void) { if (cache) __free_in6ai (cache->in6ai); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c index d8188f8b5b..562495b122 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c @@ -25,6 +25,7 @@ # define weak_alias(n,a) #endif #include "login/getutent.c" +_weak_alias (buffer, __libc_getutent_freemem_ptr) #if defined SHARED default_symbol_version (__getutent, getutent, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c index cd981c72ba..ccdc25b2d6 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c @@ -25,6 +25,7 @@ # define weak_alias(n,a) #endif #include "login/getutid.c" +_weak_alias (buffer, __libc_getutid_freemem_ptr) #if defined SHARED default_symbol_version (__getutid, getutid, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c index 0b611619f1..16e8f17915 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c @@ -25,6 +25,7 @@ # define weak_alias(n,a) #endif #include "login/getutline.c" +_weak_alias (buffer, __libc_getutline_freemem_ptr) #if defined SHARED default_symbol_version (__getutline, getutline, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/set-freeres-os.h b/sysdeps/unix/sysv/linux/set-freeres-os.h new file mode 100644 index 0000000000..964c9a4bfc --- /dev/null +++ b/sysdeps/unix/sysv/linux/set-freeres-os.h @@ -0,0 +1,24 @@ +/* System specific resource deallocation. Linux version. + Copyright (C) 2022 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 + . */ + +extern void __check_pf_freemem (void) attribute_hidden; +extern char * __ttyname_freemem_ptr attribute_hidden; + +#define call_freeres_os_funcs \ + call_function_static_weak (__check_pf_freemem); \ + call_free_static_weak (__ttyname_freemem_ptr) diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c index f3870f8ec3..406fbb30f2 100644 --- a/sysdeps/unix/sysv/linux/ttyname.c +++ b/sysdeps/unix/sysv/linux/ttyname.c @@ -19,15 +19,11 @@ #include #include #include - +#include #include "ttyname.h" static char *ttyname_buf = NULL; - -libc_freeres_fn (free_mem) -{ - free (ttyname_buf); -} +weak_alias (ttyname_buf, __ttyname_freemem_ptr) /* Return the pathname of the terminal FD is open on, or NULL on errors. The returned storage is good only until the next call to this function. */ diff --git a/time/tzfile.c b/time/tzfile.c index 55508c154b..9e27eba4a7 100644 --- a/time/tzfile.c +++ b/time/tzfile.c @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -50,7 +51,7 @@ struct leap }; static size_t num_transitions; -libc_freeres_ptr (static __time64_t *transitions); +static __time64_t *transitions; static unsigned char *type_idxs; static size_t num_types; static struct ttinfo *types; @@ -780,3 +781,5 @@ __tzfile_compute (__time64_t timer, int use_localtime, } } } + +weak_alias (transitions, __libc_tzfile_freemem_ptr) diff --git a/time/tzset.c b/time/tzset.c index 3df62106d8..8c740a4e4d 100644 --- a/time/tzset.c +++ b/time/tzset.c @@ -610,7 +610,8 @@ __tz_convert (__time64_t timer, int use_localtime, struct tm *tp) } -libc_freeres_fn (free_mem) +void +__libc_tzset_freemem (void) { while (tzstring_list != NULL) { From patchwork Mon Mar 6 19:16:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 659264 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1987899wrb; Mon, 6 Mar 2023 11:17:40 -0800 (PST) X-Google-Smtp-Source: AK7set+s67gVXTBkUDngxxsqX/J88Wmt7T6qIhi8q5hYXLKgMGYbExhokJEf7gxQSQICF+O21Qia X-Received: by 2002:a17:906:d296:b0:8b1:315f:6c10 with SMTP id ay22-20020a170906d29600b008b1315f6c10mr12094433ejb.56.1678130260811; Mon, 06 Mar 2023 11:17:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678130260; cv=none; d=google.com; s=arc-20160816; b=sjtSLeCd/6CNGp/wAJdRJD3It6RdNAxmJUO0wSF5ByUOcut7+8PYu4dV9Yky+3YGP1 4ScOel59/XbGXls/oGherqfOmVBY3lW+euh+LPFERpMocgjJMe4wD8qIJQKSIYCkLdoA JE6eUYsNp9wUtycWgwDkSqbRFVHOOIR0wgaKAsrRWkLJHhPr3z8Lx7nmMVX2anhTQyQF 0923nKphht5GRBjnQzAW4Lz18e1JdJvwcCExyicj3nUSjfrSacuH7oSqKarCmB21WK7l Wn6q4zcKW+OOZd+JfNxrgcTc7b6+GCFjnxE86FGaW5jrzynuIW64oc1kuGApXoSUnMLG VKIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=XcR5WZD4eKeabawv6N9xhRny9nAXaV8W99o7i38GdQs=; b=uahrIOojtx6kSspHD54McMyz7r2/CsmVgaqdO1RINfqpjxLkgyNRAeQS43ANVrOTGL J1BHdrVZap/jHWEPrnNMiOc3BKye4/qiTE71NV7n83dLfT4nnTubs/Mu78ZLQ9OJXm5K pvbW+2FFK3W952veInC7o2TjM6pZ+wVufreXRhAGKmsFA6iYguiJ/WiERB7I6H412EMU jn5IEeP6GiRPBP12FqvBDlQ6nUYlMP44ApBzGgeIAdM9t3Y5OBOZvNaNhm/LNMfZ4llK gVV0hVU/71HB5hfGWscsJ8H+pp6RspDnjut+CQD+shz4tPWKCk2eqUsrGQa6Bc+dnr6r BCYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="L/kZkIPc"; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id re26-20020a170906d8da00b008e48d70f31fsi8435535ejb.662.2023.03.06.11.17.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:17:40 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="L/kZkIPc"; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97C3B3854836 for ; Mon, 6 Mar 2023 19:17:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97C3B3854836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678130259; bh=XcR5WZD4eKeabawv6N9xhRny9nAXaV8W99o7i38GdQs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=L/kZkIPcrr+j1j0cKI5Du98gVbEogugu6PrnAhJfPfvuI4eORRPezxE5uGLMJgZBG noSSK+U8C8WlRST2nKCtnwV50QRDp7mLGZcBhVm5LM9nWO4V/FER0pFfsRxB35tkKI UVnWnn3Byz9BI48llDdAiTd/YVXcqKG6tEs0PklE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by sourceware.org (Postfix) with ESMTPS id 45324385B52D for ; Mon, 6 Mar 2023 19:16:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45324385B52D Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1763e201bb4so12601194fac.1 for ; Mon, 06 Mar 2023 11:16:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678130214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XcR5WZD4eKeabawv6N9xhRny9nAXaV8W99o7i38GdQs=; b=PnW6e10w8TGXXoE2EtKa3pmUBDT5XNPhhuWyN9z4l4LQuWm3mBs3mw7lp09g6JToDs hv2xP0NCe/MrbXyX2chUcEj5Ha97aCXUyTmuiaffcuYoz4N31X8WBmxaIvYPuI5+liDd cr/bbytorJwSn+tpvrNnb8p4Za6rUWsSlQaxVtvZ2Gz8ToTC3y5F8GpLN0OM1Fj9H1FS Jp6uILeAMi0vf2YmpVANj8JSs2Oj5QvSBlAbx/79y2rab579dEg8oVb+LtsEW17j2Y81 OayL3bkVcG4p6lC5QPqopF0k89cH6PgQHt/XzhnLsjbf9LJdespAvOC2AVh6Punr6KHk pPnw== X-Gm-Message-State: AO0yUKVtHxRPiv5yNIHT0v3BN2OFz/i3crHMAQB/2cDGgSxF8hrD386r w81LI60urlWse2II/LtuAMhRACQOKQV9pdvzvxlBhQ== X-Received: by 2002:a05:6870:5703:b0:172:2d00:99f7 with SMTP id k3-20020a056870570300b001722d0099f7mr6888476oap.20.1678130213922; Mon, 06 Mar 2023 11:16:53 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:8c2f:e58d:3e6:9de5]) by smtp.gmail.com with ESMTPSA id zf29-20020a0568716a9d00b00176598b79d3sm4280668oab.24.2023.03.06.11.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:16:53 -0800 (PST) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell Cc: Adhemerval Zanella Netto Subject: [PATCH v5 2/5] libio: Do not autogenerate stdio_lim.h Date: Mon, 6 Mar 2023 16:16:39 -0300 Message-Id: <20230306191642.347001-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306191642.347001-1-adhemerval.zanella@linaro.org> References: <20230306191642.347001-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto Instead define the required fields in system dependend files. Thee only system dependent definition is FILENAME_MAX, which should match POSIX PATH_MAX, and it is obtained from either kernel UAPI or mach headers. Currently set pre-defined value from current kernels. It avoid a circular dependendy when including stdio.h in gen-as-const-headers files. Checked on x86_64-linux-gnu and i686-linux-gnu Reviewed-by: Carlos O'Donell --- Makerules | 40 ------------------- Rules | 3 -- libio/stdio.h | 19 +++++---- .../mach/hurd/bits/stdio_lim.h | 17 ++------ sysdeps/posix/Makefile | 5 --- sysdeps/unix/sysv/linux/bits/stdio_lim.h | 28 +++++++++++++ 6 files changed, 43 insertions(+), 69 deletions(-) rename stdio-common/stdio_lim.h.in => sysdeps/mach/hurd/bits/stdio_lim.h (72%) delete mode 100644 sysdeps/posix/Makefile create mode 100644 sysdeps/unix/sysv/linux/bits/stdio_lim.h diff --git a/Makerules b/Makerules index f6071eab50..57b3f093c4 100644 --- a/Makerules +++ b/Makerules @@ -1351,46 +1351,6 @@ endif endif -# These will have been set by sysdeps/posix/Makefile. -L_tmpnam ?= 1 -TMP_MAX ?= 0 -L_ctermid ?= 1 -L_cuserid ?= 1 - -stdio_lim = $(common-objpfx)bits/stdio_lim.h - -$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @: -$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \ - $(common-objpfx)config.make - $(make-target-directory) - { echo '#include "$(..)posix/bits/posix1_lim.h"'; \ - } | \ - $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \ - $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT) - sed $(sed-remove-objpfx) $(sed-remove-dotdot) \ - $(@:st=dT) > $(@:st=dt) - mv -f $(@:st=dt) $(@:st=d) - fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \ - filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \ - fopen_max=$${fopen_max:-16}; \ - filename_max=$${filename_max:-1024}; \ - sed -e "s/@FOPEN_MAX@/$$fopen_max/" \ - -e "s/@FILENAME_MAX@/$$filename_max/" \ - -e "s/@L_tmpnam@/$(L_tmpnam)/" \ - -e "s/@TMP_MAX@/$(TMP_MAX)/" \ - -e "s/@L_ctermid@/$(L_ctermid)/" \ - -e "s/@L_cuserid@/$(L_cuserid)/" \ - $< > $(@:st=h.new) - $(move-if-change) $(@:st=h.new) $(@:st=h) -# Remove these last so that they can be examined if something went wrong. - rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt) - touch $@ -# Get dependencies. -ifndef no_deps --include $(stdio_lim:h=d) -endif -common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st - FORCE: .PHONY: echo-headers diff --git a/Rules b/Rules index fdff415fdc..5e945d7347 100644 --- a/Rules +++ b/Rules @@ -60,9 +60,6 @@ ifneq "$(findstring env,$(origin common-generated))" "" common-generated := endif -# See below. This must be set before Makerules processes it. -before-compile += $(common-objpfx)bits/stdio_lim.h - include $(..)Makerules .PHONY: subdir_lib diff --git a/libio/stdio.h b/libio/stdio.h index 857f02888d..686c40f28d 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -120,18 +120,23 @@ typedef __fpos64_t fpos64_t; # define P_tmpdir "/tmp" #endif +#define L_tmpnam 20 +#define TMP_MAX 238328 /* Get the values: - L_tmpnam How long an array of chars must be to be passed to `tmpnam'. - TMP_MAX The minimum number of unique filenames generated by tmpnam - (and tempnam when it uses tmpnam's name space), - or tempnam (the two are separate). - L_ctermid How long an array to pass to `ctermid'. - L_cuserid How long an array to pass to `cuserid'. - FOPEN_MAX Minimum number of files that can be open at once. FILENAME_MAX Maximum length of a filename. */ #include +#ifdef __USE_POSIX +# define L_ctermid 9 +# if !defined __USE_XOPEN2K || defined __USE_GNU +# define L_cuserid 9 +# endif +#endif + +#undef FOPEN_MAX +#define FOPEN_MAX 16 + #if __GLIBC_USE (ISOC2X) /* Maximum length of printf output for a NaN. */ diff --git a/stdio-common/stdio_lim.h.in b/sysdeps/mach/hurd/bits/stdio_lim.h similarity index 72% rename from stdio-common/stdio_lim.h.in rename to sysdeps/mach/hurd/bits/stdio_lim.h index bc7aacc35e..f3ef0be96e 100644 --- a/stdio-common/stdio_lim.h.in +++ b/sysdeps/mach/hurd/bits/stdio_lim.h @@ -1,4 +1,5 @@ -/* Copyright (C) 1994-2023 Free Software Foundation, Inc. +/* System specific stdio.h definitions. Hurd version. + 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 @@ -22,18 +23,6 @@ # error "Never include directly; use instead." #endif -#define L_tmpnam @L_tmpnam@ -#define TMP_MAX @TMP_MAX@ -#define FILENAME_MAX @FILENAME_MAX@ - -#ifdef __USE_POSIX -# define L_ctermid @L_ctermid@ -# if !defined __USE_XOPEN2K || defined __USE_GNU -# define L_cuserid @L_cuserid@ -# endif -#endif - -#undef FOPEN_MAX -#define FOPEN_MAX @FOPEN_MAX@ +#define FILENAME_MAX 1024 #endif /* bits/stdio_lim.h */ diff --git a/sysdeps/posix/Makefile b/sysdeps/posix/Makefile deleted file mode 100644 index b58aa6aadb..0000000000 --- a/sysdeps/posix/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# These affect the generated bits/stdio_lim.h file. -L_tmpnam = 20 -TMP_MAX = 238328 -L_ctermid = 9 -L_cuserid = 9 diff --git a/sysdeps/unix/sysv/linux/bits/stdio_lim.h b/sysdeps/unix/sysv/linux/bits/stdio_lim.h new file mode 100644 index 0000000000..4c3f36d7ce --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/stdio_lim.h @@ -0,0 +1,28 @@ +/* System specific stdio.h definitions. Linux version. + 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 + . */ + +#ifndef _BITS_STDIO_LIM_H +#define _BITS_STDIO_LIM_H 1 + +#ifndef _STDIO_H +# error "Never include directly; use instead." +#endif + +#define FILENAME_MAX 4096 + +#endif /* bits/stdio_lim.h */ From patchwork Mon Mar 6 19:16:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 659265 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1987954wrb; Mon, 6 Mar 2023 11:17:49 -0800 (PST) X-Google-Smtp-Source: AK7set99TBS3uCyQJapek5/mxk9GWZTvHUM7+6VpOhKXw/2oPTx4/1/yNWCCXg34javgxX8SxW7V X-Received: by 2002:a17:906:2a55:b0:878:66bc:2280 with SMTP id k21-20020a1709062a5500b0087866bc2280mr11396398eje.12.1678130269249; Mon, 06 Mar 2023 11:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678130269; cv=none; d=google.com; s=arc-20160816; b=gLsx83QLc3Lo2fXRTov3EttZzBfk1C4LYo/6rTuSkKotsaECTxgn7EVgMeHHTr+8mP kapb5S8+cDwcznjqOaASHYg/jntLNa3Bx1/VRwyIK21jXvZsx9mYY5Ere0QEF1/BsKI6 jT6JSei7o2wftx8F+xY5z6M4qCOTZecepAnLrhGKzuJ6b68So+w7wGc4Fz7yY78DjLIj 7Zlqboon1xRcX4/Npo+yCHCJUcnqbfcV5W2a6d/Uzgq6rlR2WGvN8i9Kp4BEEa+e+9XB Wvye7i6rNgNEcnubMyxITM68pWCTvQNdto8CnPDzXDUvZF0rKM16a2WT/nLuZdkN8DDx 38Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=7evTZAu7DFiqXRmzfi30YA7UmBKHp8VCVZEnttrhNBE=; b=n3FYE0Hw6i0UIlJjaX/MrIasUnoaxmnK38iKo5NCsDLNh5dEZjtDffBrY+aR8/1SFh +2wrPoqKS2N3N5FFg17fETQQBmHMYkS7QOIFyXW+q/oim7pgy5AcDJdDvsHw+x+EQWWs uIa9ql1TGWeS/oenje/gsjhc/lawsEUp79ksJ2rfckmtTOgaQMkcn+p+7baPmu5w1z9C bIE8DZ+aLz3MqdMykReMsPkzziXmYC0WNScN/HDnhF/oiCxY/O/jxeFD8HjlFDduA63Z J5NIIDqkz3OJa6oEP25n6gpw5xyw0sI13pSzKzQD2ZL40SdsJmg6j0swl20q9EPgx91F /zTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=lpMXgG+a; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id oy12-20020a170907104c00b008b17a861395si10015861ejb.905.2023.03.06.11.17.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:17:49 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=lpMXgG+a; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C32A03858D39 for ; Mon, 6 Mar 2023 19:17:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C32A03858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678130267; bh=7evTZAu7DFiqXRmzfi30YA7UmBKHp8VCVZEnttrhNBE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=lpMXgG+ao+K0CjPgA7id1gnNFZQtInHta85ranzfWrL0LSZaBTSvBCSiPivCiPsp2 n8XsStXkPJ5lOLJUtl5CfsVKB1+wJAJX0vHlB3MdUmzWwDgGb8dgDFYV6YOFNkxuRM MDLAEO6pWNJxsv8IroXtt1o0SfVqb1G8DwO88Rq8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by sourceware.org (Postfix) with ESMTPS id A2346385B527 for ; Mon, 6 Mar 2023 19:16:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2346385B527 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1767a208b30so10621444fac.2 for ; Mon, 06 Mar 2023 11:16:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678130217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7evTZAu7DFiqXRmzfi30YA7UmBKHp8VCVZEnttrhNBE=; b=rvwWVDD/aAiq1fA0EVjiWc/mX2MfjMOLpXg0htMAWUX0mNPhvb1xCXJQBvAsZ40FgR Fp1SDIaDmXhlXTEo9UUgzvBC2yDWP7R1Ku/DHjpCtjzz+SjqxIzhapcRRsIwGjUUWWiL tLEMX5uZoUPN06jlt3ltR5jWyTHOfsAoCvdFHphKctCU2mb5pchWptwUVLiAT7Xoefwl 92JSo2OgGyLwp6nXK6+upxJuOg9OCWd6jQ6x3oR1QT/cLjlVUIPmlXy/lOlLZl9LBqsR /ZQDojymaqMJV2gsoQLFmcj2ritNzkZRAUmUWMpBh+O4wst/6joEPazaeOJgrbsaa/NQ 5sRg== X-Gm-Message-State: AO0yUKVbnSXVkDJD594Lm02ErNrcauL0zQbOt/tubnYDoJoXsuG6aai4 lCy2+xhECT32HoEO7t1YNJXzG4S71ThfKukx1PmKIg== X-Received: by 2002:a05:6870:649f:b0:176:301b:91a4 with SMTP id cz31-20020a056870649f00b00176301b91a4mr7709624oab.13.1678130216288; Mon, 06 Mar 2023 11:16:56 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:8c2f:e58d:3e6:9de5]) by smtp.gmail.com with ESMTPSA id zf29-20020a0568716a9d00b00176598b79d3sm4280668oab.24.2023.03.06.11.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:16:55 -0800 (PST) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell Cc: Adhemerval Zanella Netto Subject: [PATCH v5 3/5] libio: Remove the usage of __libc_IO_vtables Date: Mon, 6 Mar 2023 16:16:40 -0300 Message-Id: <20230306191642.347001-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306191642.347001-1-adhemerval.zanella@linaro.org> References: <20230306191642.347001-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto Instead of using a special ELF section along with a linker script directive to put the IO vtables within the RELRO section, the libio vtables are all moved to an array marked as data.relro (so linker will place in the RELRO segment without the need of extra directives). To avoid static linking namespace issues and including all vtable referenced objects, all required function pointers are set to weak alias. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Carlos O'Donell --- Makerules | 24 -- elf/Makefile | 16 +- include/libc-symbols.h | 18 +- libio/Makefile | 2 + libio/fileops.c | 81 +---- libio/iofopncook.c | 60 +--- libio/iopopen.c | 25 -- libio/libio-macros.sym | 7 + libio/libioP.h | 136 ++++++-- libio/memstream.c | 32 +- libio/oldfileops.c | 23 -- libio/oldiopopen.c | 23 -- libio/stdio.c | 3 + libio/strfile.h | 2 - libio/strops.c | 24 -- libio/tst-vtables-interposed.c | 5 + libio/vtables.c | 478 ++++++++++++++++++++++++++ libio/wfileops.c | 79 +---- libio/wmemstream.c | 32 +- libio/wstrops.c | 24 -- stdio-common/printf_buffer_as_file.c | 28 +- stdio-common/wprintf_buffer_as_file.c | 28 +- 22 files changed, 637 insertions(+), 513 deletions(-) create mode 100644 libio/libio-macros.sym diff --git a/Makerules b/Makerules index 57b3f093c4..16887cb443 100644 --- a/Makerules +++ b/Makerules @@ -544,34 +544,10 @@ $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \ -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) endef -ifeq (yes,$(use-default-link)) # If the linker is good enough, we can let it use its default linker script. # In the long term the custom linker script will be removed. shlib-lds = shlib-lds-flags = -else -# binutils only position loadable notes into the first page for binaries, -# not for shared objects -# lld --verbose does not dump a linker script. Use -fuse-ld=bfd. -$(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules - $(LINK.o) -shared -Wl,-O1 \ - -nostdlib -nostartfiles -fuse-ld=bfd \ - $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \ - -Wl,--verbose 2>/dev/null | \ - sed > $@T \ - -e '/^=========/,/^=========/!d;/^=========/d' \ - -e 's@^.*\*(\.jcr).*$$@& \ - PROVIDE(__start___libc_IO_vtables = .);\ - __libc_IO_vtables : { *(__libc_IO_vtables) }\ - PROVIDE(__stop___libc_IO_vtables = .);\ - /DISCARD/ : { *(.gnu.glibc-stub.*) }@' - test -s $@T - mv -f $@T $@ -common-generated += shlib.lds - -shlib-lds = $(common-objpfx)shlib.lds -shlib-lds-flags = -T $(shlib-lds) -endif define build-shlib $(build-shlib-helper) -o $@ $(shlib-lds-flags) \ diff --git a/elf/Makefile b/elf/Makefile index 0d19964d42..b7f31cdf1c 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -595,23 +595,9 @@ $(objpfx)tst-relro-ldso.out: tst-relro-symbols.py $(..)/scripts/glibcelf.py \ $(objpfx)tst-relro-libc.out: tst-relro-symbols.py $(..)/scripts/glibcelf.py \ $(common-objpfx)libc.so $(PYTHON) tst-relro-symbols.py $(common-objpfx)libc.so \ - --required=_IO_cookie_jumps \ --required=_IO_file_jumps \ - --required=_IO_file_jumps_maybe_mmap \ - --required=_IO_file_jumps_mmap \ - --required=_IO_mem_jumps \ - --required=_IO_printf_buffer_as_file_jumps \ - --required=_IO_proc_jumps \ - --required=_IO_str_jumps \ --required=_IO_wfile_jumps \ - --required=_IO_wfile_jumps_maybe_mmap \ - --required=_IO_wfile_jumps_mmap \ - --required=_IO_wmem_jumps \ - --required=_IO_wprintf_buffer_as_file_jumps \ - --required=_IO_wstr_jumps \ - --optional=_IO_old_cookie_jumps \ - --optional=_IO_old_file_jumps \ - --optional=_IO_old_proc_jumps \ + --required=__io_vtables \ > $@ 2>&1; $(evaluate-test) ifeq ($(run-built-tests),yes) diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 155781d448..37c91bb3a4 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -243,20 +243,26 @@ for linking") This is only necessary when defining something in assembly, or playing funny alias games where the size should be other than what the compiler thinks it is. */ -#ifdef __ASSEMBLER__ -# define declare_object_symbol_alias(symbol, original, size) \ +#define declare_object_symbol_alias(symbol, original, size) \ declare_object_symbol_alias_1 (symbol, original, size) +#ifdef __ASSEMBLER__ # define declare_object_symbol_alias_1(symbol, original, s_size) \ strong_alias (original, symbol) ASM_LINE_SEP \ .type C_SYMBOL_NAME (symbol), %object ASM_LINE_SEP \ .size C_SYMBOL_NAME (symbol), s_size ASM_LINE_SEP #else /* Not __ASSEMBLER__. */ # ifdef HAVE_ASM_SET_DIRECTIVE -# define declare_symbol_alias_1_alias(symbol, original) \ - ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX #original +# define declare_object_symbol_alias_1(symbol, original, size) \ + asm (".global " __SYMBOL_PREFIX # symbol "\n" \ + ".type " __SYMBOL_PREFIX # symbol ", %object\n" \ + ".set " __SYMBOL_PREFIX #symbol ", " __SYMBOL_PREFIX original "\n" \ + ".size " __SYMBOL_PREFIX #symbol ", " #size "\n"); # else -# define declare_symbol_alias_1_alias(symbol, original) \ - __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX #original +# define declare_object_symbol_alias_1(symbol, original, size) \ + asm (".global " __SYMBOL_PREFIX # symbol "\n" \ + ".type " __SYMBOL_PREFIX # symbol ", %object\n" \ + __SYMBOL_PREFIX #symbol " = " __SYMBOL_PREFIX original "\n" \ + ".size " __SYMBOL_PREFIX #symbol ", " #size "\n"); # endif /* HAVE_ASM_SET_DIRECTIVE */ #endif /* __ASSEMBLER__ */ diff --git a/libio/Makefile b/libio/Makefile index 52892a282e..2877fec484 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -51,6 +51,8 @@ routines := \ \ libc_fatal fmemopen oldfmemopen vtables +gen-as-const-headers += libio-macros.sym + tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-ext2 \ tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf \ diff --git a/libio/fileops.c b/libio/fileops.c index b75d748539..58c9e985e4 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -815,7 +815,7 @@ _IO_new_file_sync (FILE *fp) } libc_hidden_ver (_IO_new_file_sync, _IO_file_sync) -static int +int _IO_file_sync_mmap (FILE *fp) { if (fp->_IO_read_ptr != fp->_IO_read_end) @@ -1109,7 +1109,7 @@ _IO_file_seekoff_mmap (FILE *fp, off64_t offset, int dir, int mode) return offset; } -static off64_t +off64_t _IO_file_seekoff_maybe_mmap (FILE *fp, off64_t offset, int dir, int mode) { @@ -1360,7 +1360,7 @@ _IO_file_xsgetn (FILE *fp, void *data, size_t n) } libc_hidden_def (_IO_file_xsgetn) -static size_t +size_t _IO_file_xsgetn_mmap (FILE *fp, void *data, size_t n) { size_t have; @@ -1405,7 +1405,7 @@ _IO_file_xsgetn_mmap (FILE *fp, void *data, size_t n) return s - (char *) data; } -static size_t +size_t _IO_file_xsgetn_maybe_mmap (FILE *fp, void *data, size_t n) { /* We only get here if this is the first attempt to read something. @@ -1428,76 +1428,3 @@ versioned_symbol (libc, _IO_new_file_seekoff, _IO_file_seekoff, GLIBC_2_1); versioned_symbol (libc, _IO_new_file_underflow, _IO_file_underflow, GLIBC_2_1); versioned_symbol (libc, _IO_new_file_write, _IO_file_write, GLIBC_2_1); versioned_symbol (libc, _IO_new_file_xsputn, _IO_file_xsputn, GLIBC_2_1); - -const struct _IO_jump_t _IO_file_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_file_finish), - JUMP_INIT(overflow, _IO_file_overflow), - JUMP_INIT(underflow, _IO_file_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_file_xsputn), - JUMP_INIT(xsgetn, _IO_file_xsgetn), - JUMP_INIT(seekoff, _IO_new_file_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_new_file_setbuf), - JUMP_INIT(sync, _IO_new_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; -libc_hidden_data_def (_IO_file_jumps) - -const struct _IO_jump_t _IO_file_jumps_mmap libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_file_finish), - JUMP_INIT(overflow, _IO_file_overflow), - JUMP_INIT(underflow, _IO_file_underflow_mmap), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_new_file_xsputn), - JUMP_INIT(xsgetn, _IO_file_xsgetn_mmap), - JUMP_INIT(seekoff, _IO_file_seekoff_mmap), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap), - JUMP_INIT(sync, _IO_file_sync_mmap), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close_mmap), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; - -const struct _IO_jump_t _IO_file_jumps_maybe_mmap libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_file_finish), - JUMP_INIT(overflow, _IO_file_overflow), - JUMP_INIT(underflow, _IO_file_underflow_maybe_mmap), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_new_file_xsputn), - JUMP_INIT(xsgetn, _IO_file_xsgetn_maybe_mmap), - JUMP_INIT(seekoff, _IO_file_seekoff_maybe_mmap), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap), - JUMP_INIT(sync, _IO_new_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; diff --git a/libio/iofopncook.c b/libio/iofopncook.c index d6a06c5acb..5511c07c18 100644 --- a/libio/iofopncook.c +++ b/libio/iofopncook.c @@ -30,7 +30,7 @@ #include #include -static ssize_t +ssize_t _IO_cookie_read (FILE *fp, void *buf, ssize_t size) { struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp; @@ -43,7 +43,7 @@ _IO_cookie_read (FILE *fp, void *buf, ssize_t size) return read_cb (cfile->__cookie, buf, size); } -static ssize_t +ssize_t _IO_cookie_write (FILE *fp, const void *buf, ssize_t size) { struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp; @@ -63,7 +63,7 @@ _IO_cookie_write (FILE *fp, const void *buf, ssize_t size) return n; } -static off64_t +off64_t _IO_cookie_seek (FILE *fp, off64_t offset, int dir) { struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp; @@ -77,7 +77,7 @@ _IO_cookie_seek (FILE *fp, off64_t offset, int dir) ? _IO_pos_BAD : offset); } -static int +int _IO_cookie_close (FILE *fp) { struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp; @@ -91,7 +91,7 @@ _IO_cookie_close (FILE *fp) } -static off64_t +off64_t _IO_cookie_seekoff (FILE *fp, off64_t offset, int dir, int mode) { /* We must force the fileops code to always use seek to determine @@ -100,31 +100,6 @@ _IO_cookie_seekoff (FILE *fp, off64_t offset, int dir, int mode) return _IO_file_seekoff (fp, offset, dir, mode); } - -static const struct _IO_jump_t _IO_cookie_jumps libio_vtable = { - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_file_finish), - JUMP_INIT(overflow, _IO_file_overflow), - JUMP_INIT(underflow, _IO_file_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_file_xsputn), - JUMP_INIT(xsgetn, _IO_default_xsgetn), - JUMP_INIT(seekoff, _IO_cookie_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_file_setbuf), - JUMP_INIT(sync, _IO_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_cookie_read), - JUMP_INIT(write, _IO_cookie_write), - JUMP_INIT(seek, _IO_cookie_seek), - JUMP_INIT(close, _IO_cookie_close), - JUMP_INIT(stat, _IO_default_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue), -}; - - /* Copy the callbacks from SOURCE to *TARGET, with pointer mangling. */ static void @@ -209,7 +184,7 @@ versioned_symbol (libc, _IO_fopencookie, fopencookie, GLIBC_2_2); #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) -static off64_t +off64_t attribute_compat_text_section _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir) { @@ -226,29 +201,6 @@ _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir) return (ret == -1) ? _IO_pos_BAD : ret; } -static const struct _IO_jump_t _IO_old_cookie_jumps libio_vtable = { - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_file_finish), - JUMP_INIT(overflow, _IO_file_overflow), - JUMP_INIT(underflow, _IO_file_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_file_xsputn), - JUMP_INIT(xsgetn, _IO_default_xsgetn), - JUMP_INIT(seekoff, _IO_cookie_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_file_setbuf), - JUMP_INIT(sync, _IO_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_cookie_read), - JUMP_INIT(write, _IO_cookie_write), - JUMP_INIT(seek, _IO_old_cookie_seek), - JUMP_INIT(close, _IO_cookie_close), - JUMP_INIT(stat, _IO_default_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue), -}; - FILE * attribute_compat_text_section _IO_old_fopencookie (void *cookie, const char *mode, diff --git a/libio/iopopen.c b/libio/iopopen.c index d0545ad5ea..a64033e60f 100644 --- a/libio/iopopen.c +++ b/libio/iopopen.c @@ -45,8 +45,6 @@ struct _IO_proc_file }; typedef struct _IO_proc_file _IO_proc_file; -static const struct _IO_jump_t _IO_proc_jumps; - static struct _IO_proc_file *proc_file_chain; #ifdef _IO_MTSAFE_IO @@ -297,29 +295,6 @@ _IO_new_proc_close (FILE *fp) return wstatus; } -static const struct _IO_jump_t _IO_proc_jumps libio_vtable = { - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_new_file_finish), - JUMP_INIT(overflow, _IO_new_file_overflow), - JUMP_INIT(underflow, _IO_new_file_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_new_file_xsputn), - JUMP_INIT(xsgetn, _IO_default_xsgetn), - JUMP_INIT(seekoff, _IO_new_file_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_new_file_setbuf), - JUMP_INIT(sync, _IO_new_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_new_proc_close), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; - strong_alias (_IO_new_popen, __new_popen) versioned_symbol (libc, _IO_new_popen, _IO_popen, GLIBC_2_1); versioned_symbol (libc, __new_popen, popen, GLIBC_2_1); diff --git a/libio/libio-macros.sym b/libio/libio-macros.sym new file mode 100644 index 0000000000..cfb5cf2841 --- /dev/null +++ b/libio/libio-macros.sym @@ -0,0 +1,7 @@ +#include + +-- + +IO_JUMP_T_SIZE sizeof (struct _IO_jump_t) +IO_FILE_JUMPS_OFFSET sizeof (struct _IO_jump_t) * IO_FILE_JUMPS +IO_WFILE_JUMPS_OFFSET sizeof (struct _IO_jump_t) * IO_WFILE_JUMPS diff --git a/libio/libioP.h b/libio/libioP.h index 80941b763f..d777553cb0 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -469,19 +469,68 @@ extern int _IO_default_sync (FILE *) __THROW; extern int _IO_default_showmanyc (FILE *) __THROW; extern void _IO_default_imbue (FILE *, void *) __THROW; -extern const struct _IO_jump_t _IO_file_jumps; -libc_hidden_proto (_IO_file_jumps) -extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden; -extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden; -extern const struct _IO_jump_t _IO_wfile_jumps; -libc_hidden_proto (_IO_wfile_jumps) -extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden; -extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden; -extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden; -extern const struct _IO_jump_t _IO_streambuf_jumps; -extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden; -extern const struct _IO_jump_t _IO_str_jumps attribute_hidden; -extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden; +extern int __printf_buffer_as_file_overflow (FILE *fp, int ch); +extern size_t __printf_buffer_as_file_xsputn (FILE *fp, const void *buf, + size_t len); +extern wint_t __wprintf_buffer_as_file_overflow (FILE *fp, int ch); +extern size_t __wprintf_buffer_as_file_xsputn (FILE *fp, const void *buf, + size_t len); + +enum +{ + IO_STR_JUMPS = 0, + IO_WSTR_JUMPS = 1, + IO_FILE_JUMPS = 2, + IO_FILE_JUMPS_MMAP = 3, + IO_FILE_JUMPS_MAYBE_MMAP = 4, + IO_WFILE_JUMPS = 5, + IO_WFILE_JUMPS_MMAP = 6, + IO_WFILE_JUMPS_MAYBE_MMAP = 7, + IO_COOKIE_JUMPS = 8, + IO_PROC_JUMPS = 9, + IO_MEM_JUMPS = 10, + IO_WMEM_JUMPS = 11, + IO_PRINTF_BUFFER_AS_FILE_JUMPS = 12, + IO_WPRINTF_BUFFER_AS_FILE_JUMPS = 13, +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) + IO_OLD_FILE_JUMPS = 14, + IO_OLD_PROC_JUMPS = 15, + IO_OLD_COOKIED_JUMPS = 16, + IO_VTABLES_NUM = IO_OLD_COOKIED_JUMPS + 1, +#elif SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) + IO_OLD_COOKIED_JUMPS = 14, + IO_VTABLES_NUM = IO_OLD_COOKIED_JUMPS + 1, +#else + IO_VTABLES_NUM = IO_WPRINTF_BUFFER_AS_FILE_JUMPS + 1 +#endif +}; +#define IO_VTABLES_LEN (IO_VTABLES_NUM * sizeof (struct _IO_jump_t)) + +extern const struct _IO_jump_t __io_vtables[] attribute_hidden; +#define _IO_str_jumps (__io_vtables[IO_STR_JUMPS]) +#define _IO_wstr_jumps (__io_vtables[IO_WSTR_JUMPS]) +#define _IO_file_jumps (__io_vtables[IO_FILE_JUMPS]) +#define _IO_file_jumps_mmap (__io_vtables[IO_FILE_JUMPS_MMAP]) +#define _IO_file_jumps_maybe_mmap (__io_vtables[IO_FILE_JUMPS_MAYBE_MMAP]) +#define _IO_wfile_jumps (__io_vtables[IO_WFILE_JUMPS]) +#define _IO_wfile_jumps_mmap (__io_vtables[IO_WFILE_JUMPS_MMAP]) +#define _IO_wfile_jumps_maybe_mmap (__io_vtables[IO_WFILE_JUMPS_MAYBE_MMAP]) +#define _IO_cookie_jumps (__io_vtables[IO_COOKIE_JUMPS]) +#define _IO_proc_jumps (__io_vtables[IO_PROC_JUMPS]) +#define _IO_mem_jumps (__io_vtables[IO_MEM_JUMPS]) +#define _IO_wmem_jumps (__io_vtables[IO_WMEM_JUMPS]) +#define _IO_printf_buffer_as_file_jumps (__io_vtables[IO_PRINTF_BUFFER_AS_FILE_JUMPS]) +#define _IO_wprintf_buffer_as_file_jumps (__io_vtables[IO_WPRINTF_BUFFER_AS_FILE_JUMPS]) +#define _IO_old_file_jumps (__io_vtables[IO_OLD_FILE_JUMPS]) +#define _IO_old_proc_jumps (__io_vtables[IO_OLD_PROC_JUMPS]) +#define _IO_old_cookie_jumps (__io_vtables[IO_OLD_COOKIED_JUMPS]) + +#ifdef SHARED +# define libio_static_fn_required(name) +#else +# define libio_static_fn_required(name) __asm (".globl " #name); +#endif + extern int _IO_do_write (FILE *, const char *, size_t); libc_hidden_proto (_IO_do_write) extern int _IO_new_do_write (FILE *, const char *, size_t); @@ -593,6 +642,14 @@ extern void _IO_new_file_init_internal (struct _IO_FILE_plus *) extern FILE* _IO_new_file_setbuf (FILE *, char *, ssize_t); extern FILE* _IO_file_setbuf_mmap (FILE *, char *, ssize_t); extern int _IO_new_file_sync (FILE *); +extern int _IO_file_sync_mmap (FILE *) attribute_hidden; +extern size_t _IO_file_xsgetn_maybe_mmap (FILE *fp, void *data, size_t n) + attribute_hidden; +extern size_t _IO_file_xsgetn_mmap (FILE *fp, void *data, size_t n) + attribute_hidden; +extern off64_t _IO_file_seekoff_maybe_mmap (FILE *fp, off64_t offset, int dir, + int mode) + attribute_hidden; extern int _IO_new_file_underflow (FILE *); extern int _IO_new_file_overflow (FILE *, int); extern off64_t _IO_new_file_seekoff (FILE *, off64_t, int, int); @@ -625,6 +682,10 @@ extern wint_t _IO_wfile_overflow (FILE *, wint_t); libc_hidden_proto (_IO_wfile_overflow) extern off64_t _IO_wfile_seekoff (FILE *, off64_t, int, int); libc_hidden_proto (_IO_wfile_seekoff) +extern wint_t _IO_wfile_underflow_maybe_mmap (FILE *fp) + attribute_hidden; +extern wint_t _IO_wfile_underflow_mmap (FILE *fp) + attribute_hidden; /* Jumptable functions for proc_files. */ extern FILE* _IO_proc_open (FILE *, const char *, const char *) @@ -643,13 +704,41 @@ extern int _IO_str_overflow (FILE *, int) __THROW; libc_hidden_proto (_IO_str_overflow) extern int _IO_str_pbackfail (FILE *, int) __THROW; libc_hidden_proto (_IO_str_pbackfail) -extern off64_t _IO_str_seekoff (FILE *, off64_t, int, int) __THROW; +extern off64_t _IO_str_seekoff (FILE *, off64_t, int, int) __THROW + ; libc_hidden_proto (_IO_str_seekoff) extern void _IO_str_finish (FILE *, int) __THROW; +extern int _IO_str_chk_overflow (FILE *fp, int c) __THROW + attribute_hidden; + +/* Jumptable functions for fopencookie. */ +extern ssize_t _IO_cookie_read (FILE *fp, void *buf, ssize_t size) + attribute_hidden; +extern ssize_t _IO_cookie_write (FILE *fp, const void *buf, ssize_t size) + attribute_hidden; +extern off64_t _IO_cookie_seek (FILE *fp, off64_t offset, int dir) + attribute_hidden; +extern int _IO_cookie_close (FILE *fp) attribute_hidden; +extern off64_t _IO_cookie_seekoff (FILE *fp, off64_t offset, int dir, int mode) + attribute_hidden; +extern off64_t _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir) + attribute_hidden; + +/* Jumptable functions for obstack. */ +extern int __IO_obstack_overflow (FILE *fp, int c) attribute_hidden; +extern size_t __IO_obstack_xsputn (FILE *fp, const void *data, size_t n) + attribute_hidden; + +/* Jumptable functions for open_{w}memstream. */ +extern int _IO_mem_sync (FILE* fp) __THROW attribute_hidden; +extern void _IO_mem_finish (FILE* fp, int) __THROW attribute_hidden; +extern int _IO_wmem_sync (FILE* fp) __THROW attribute_hidden; +extern void _IO_wmem_finish (FILE* fp, int) __THROW attribute_hidden; /* Other strfile functions */ struct _IO_strfile_; extern ssize_t _IO_str_count (FILE *) __THROW; +extern int _IO_strn_overflow (FILE *fp, int c) __THROW attribute_hidden; /* And the wide character versions. */ extern void _IO_wstr_init_static (FILE *, wchar_t *, size_t, wchar_t *) @@ -662,6 +751,10 @@ extern off64_t _IO_wstr_seekoff (FILE *, off64_t, int, int) extern wint_t _IO_wstr_pbackfail (FILE *, wint_t) __THROW; extern void _IO_wstr_finish (FILE *, int) __THROW; +/* Helper functions. */ +int _IO_helper_overflow (FILE *s, int c); +int _IO_whelper_overflow (FILE *s, int c); + /* Internal versions of v*printf that take an additional flags parameter. */ extern int __vfprintf_internal (FILE *fp, const char *format, va_list ap, @@ -895,14 +988,6 @@ _IO_acquire_lock_fct (FILE **p) } while (0) #endif -/* Collect all vtables in a special section for vtable verification. - These symbols cover the extent of this section. */ -symbol_set_declare (__libc_IO_vtables) - -/* libio vtables need to carry this attribute so that they pass - validation. */ -#define libio_vtable __attribute__ ((section ("__libc_IO_vtables"))) - #ifdef SHARED /* If equal to &_IO_vtable_check (with pointer guard protection), unknown vtable pointers are valid. This function pointer is solely @@ -937,12 +1022,9 @@ void _IO_vtable_check (void) attribute_hidden; static inline const struct _IO_jump_t * IO_validate_vtable (const struct _IO_jump_t *vtable) { - /* Fast path: The vtable pointer is within the __libc_IO_vtables - section. */ - uintptr_t section_length = __stop___libc_IO_vtables - __start___libc_IO_vtables; uintptr_t ptr = (uintptr_t) vtable; - uintptr_t offset = ptr - (uintptr_t) __start___libc_IO_vtables; - if (__glibc_unlikely (offset >= section_length)) + uintptr_t offset = ptr - (uintptr_t) &__io_vtables; + if (__glibc_unlikely (offset >= IO_VTABLES_LEN)) /* The vtable pointer is not in the expected section. Use the slow path, which will terminate the process if necessary. */ _IO_vtable_check (); diff --git a/libio/memstream.c b/libio/memstream.c index ad5726baf8..90b42d1e0e 100644 --- a/libio/memstream.c +++ b/libio/memstream.c @@ -29,34 +29,6 @@ struct _IO_FILE_memstream }; -static int _IO_mem_sync (FILE* fp) __THROW; -static void _IO_mem_finish (FILE* fp, int) __THROW; - - -static const struct _IO_jump_t _IO_mem_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT (finish, _IO_mem_finish), - JUMP_INIT (overflow, _IO_str_overflow), - JUMP_INIT (underflow, _IO_str_underflow), - JUMP_INIT (uflow, _IO_default_uflow), - JUMP_INIT (pbackfail, _IO_str_pbackfail), - JUMP_INIT (xsputn, _IO_default_xsputn), - JUMP_INIT (xsgetn, _IO_default_xsgetn), - JUMP_INIT (seekoff, _IO_str_seekoff), - JUMP_INIT (seekpos, _IO_default_seekpos), - JUMP_INIT (setbuf, _IO_default_setbuf), - JUMP_INIT (sync, _IO_mem_sync), - JUMP_INIT (doallocate, _IO_default_doallocate), - JUMP_INIT (read, _IO_default_read), - JUMP_INIT (write, _IO_default_write), - JUMP_INIT (seek, _IO_default_seek), - JUMP_INIT (close, _IO_default_close), - JUMP_INIT (stat, _IO_default_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; - /* Open a stream that writes into a malloc'd buffer that is expanded as necessary. *BUFLOC and *SIZELOC are updated with the buffer's location and the number of characters written on fflush or fclose. */ @@ -105,7 +77,7 @@ libc_hidden_def (__open_memstream) weak_alias (__open_memstream, open_memstream) -static int +int _IO_mem_sync (FILE *fp) { struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp; @@ -123,7 +95,7 @@ _IO_mem_sync (FILE *fp) } -static void +void _IO_mem_finish (FILE *fp, int dummy) { struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp; diff --git a/libio/oldfileops.c b/libio/oldfileops.c index dd455a8ace..d6abbfdc3c 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -716,29 +716,6 @@ _IO_old_file_xsputn (FILE *f, const void *data, size_t n) return n - to_do; } - -const struct _IO_jump_t _IO_old_file_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_old_file_finish), - JUMP_INIT(overflow, _IO_old_file_overflow), - JUMP_INIT(underflow, _IO_old_file_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_old_file_xsputn), - JUMP_INIT(xsgetn, _IO_default_xsgetn), - JUMP_INIT(seekoff, _IO_old_file_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_old_file_setbuf), - JUMP_INIT(sync, _IO_old_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_old_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close), - JUMP_INIT(stat, _IO_file_stat) -}; - compat_symbol (libc, _IO_old_do_write, _IO_do_write, GLIBC_2_0); compat_symbol (libc, _IO_old_file_attach, _IO_file_attach, GLIBC_2_0); compat_symbol (libc, _IO_old_file_close_it, _IO_file_close_it, GLIBC_2_0); diff --git a/libio/oldiopopen.c b/libio/oldiopopen.c index aa5e379c85..b3eccc1352 100644 --- a/libio/oldiopopen.c +++ b/libio/oldiopopen.c @@ -208,29 +208,6 @@ _IO_old_proc_close (FILE *fp) return wstatus; } -const struct _IO_jump_t _IO_old_proc_jumps libio_vtable = { - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_old_file_finish), - JUMP_INIT(overflow, _IO_old_file_overflow), - JUMP_INIT(underflow, _IO_old_file_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_default_pbackfail), - JUMP_INIT(xsputn, _IO_old_file_xsputn), - JUMP_INIT(xsgetn, _IO_default_xsgetn), - JUMP_INIT(seekoff, _IO_old_file_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_old_file_setbuf), - JUMP_INIT(sync, _IO_old_file_sync), - JUMP_INIT(doallocate, _IO_file_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_old_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_old_proc_close), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; - strong_alias (_IO_old_popen, __old_popen) compat_symbol (libc, _IO_old_popen, _IO_popen, GLIBC_2_0); compat_symbol (libc, __old_popen, popen, GLIBC_2_0); diff --git a/libio/stdio.c b/libio/stdio.c index fd94b76b56..c7c1b85c75 100644 --- a/libio/stdio.c +++ b/libio/stdio.c @@ -33,3 +33,6 @@ FILE *stdin = (FILE *) &_IO_2_1_stdin_; FILE *stdout = (FILE *) &_IO_2_1_stdout_; FILE *stderr = (FILE *) &_IO_2_1_stderr_; + +libio_static_fn_required (_IO_file_open); +libio_static_fn_required (_IO_file_doallocate); diff --git a/libio/strfile.h b/libio/strfile.h index c50b34abd1..f21100f963 100644 --- a/libio/strfile.h +++ b/libio/strfile.h @@ -78,8 +78,6 @@ typedef struct wchar_t overflow_buf[64]; } _IO_wstrnfile; -extern const struct _IO_jump_t _IO_wstrn_jumps attribute_hidden; - /* Initialize an _IO_strfile SF to read from narrow string STRING, and return the corresponding FILE object. It is not necessary to fclose the FILE when it is no longer needed. */ diff --git a/libio/strops.c b/libio/strops.c index b5c850b626..6379a87319 100644 --- a/libio/strops.c +++ b/libio/strops.c @@ -352,27 +352,3 @@ _IO_str_finish (FILE *fp, int dummy) _IO_default_finish (fp, 0); } - -const struct _IO_jump_t _IO_str_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_str_finish), - JUMP_INIT(overflow, _IO_str_overflow), - JUMP_INIT(underflow, _IO_str_underflow), - JUMP_INIT(uflow, _IO_default_uflow), - JUMP_INIT(pbackfail, _IO_str_pbackfail), - JUMP_INIT(xsputn, _IO_default_xsputn), - JUMP_INIT(xsgetn, _IO_default_xsgetn), - JUMP_INIT(seekoff, _IO_str_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_default_setbuf), - JUMP_INIT(sync, _IO_default_sync), - JUMP_INIT(doallocate, _IO_default_doallocate), - JUMP_INIT(read, _IO_default_read), - JUMP_INIT(write, _IO_default_write), - JUMP_INIT(seek, _IO_default_seek), - JUMP_INIT(close, _IO_default_close), - JUMP_INIT(stat, _IO_default_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; diff --git a/libio/tst-vtables-interposed.c b/libio/tst-vtables-interposed.c index 9068e53b88..e656f2b203 100644 --- a/libio/tst-vtables-interposed.c +++ b/libio/tst-vtables-interposed.c @@ -21,7 +21,12 @@ /* Provide an interposed definition of the standard file handles with our own vtable. stdout/stdin/stderr will not work as a result, but a succesful test does not print anything, so this is fine. */ +#include "libioP.h" +#undef _IO_file_jumps #define _IO_file_jumps jumps +#undef _IO_wfile_jumps +extern const struct _IO_jump_t _IO_wfile_jumps; +#define _IO_wfile_jumps _IO_wfile_jumps #include "stdfiles.c" static int diff --git a/libio/vtables.c b/libio/vtables.c index 5d5906a818..3facd40a51 100644 --- a/libio/vtables.c +++ b/libio/vtables.c @@ -21,6 +21,472 @@ #include #include #include +#include + +/* Both _IO_str_* and _IO_new_file functions are pulled into every link (from + stdio initialization). */ +#ifndef SHARED +/* NB: the following directives do add pragma weak for _IO_default _* and + _IO_wdefault_* symbols to potentially avoid link failures, since they + are always used when the __io_vtables is used. */ +# pragma weak _IO_wstr_finish +# pragma weak _IO_wstr_overflow +# pragma weak _IO_wstr_pbackfail +# pragma weak _IO_wstr_seekoff +# pragma weak _IO_wstr_underflow + +# pragma weak _IO_file_close +# pragma weak _IO_file_close_mmap +# pragma weak _IO_file_doallocate +# pragma weak _IO_file_finish +# pragma weak _IO_file_jumps_alias +# pragma weak _IO_file_overflow +# pragma weak _IO_file_read +# pragma weak _IO_file_seek +# pragma weak _IO_file_seekoff_maybe_mmap +# pragma weak _IO_file_seekoff_mmap +# pragma weak _IO_file_setbuf +# pragma weak _IO_file_setbuf_mmap +# pragma weak _IO_file_setbuf_mmap +# pragma weak _IO_file_stat +# pragma weak _IO_file_sync +# pragma weak _IO_file_sync_mmap +# pragma weak _IO_file_underflow +# pragma weak _IO_file_underflow_maybe_mmap +# pragma weak _IO_file_underflow_mmap +# pragma weak _IO_file_xsgetn +# pragma weak _IO_file_xsgetn_maybe_mmap +# pragma weak _IO_file_xsgetn_mmap +# pragma weak _IO_file_xsputn + +# pragma weak _IO_wfile_overflow +# pragma weak _IO_wfile_sync +# pragma weak _IO_wfile_underflow +# pragma weak _IO_wfile_underflow_maybe_mmap +# pragma weak _IO_wfile_underflow_mmap +# pragma weak _IO_wfile_doallocate +# pragma weak _IO_wfile_jumps_alia +# pragma weak _IO_wfile_seekoff +# pragma weak _IO_wfile_xsputn + +# pragma weak _IO_new_proc_close + +# pragma weak _IO_cookie_close +# pragma weak _IO_cookie_read +# pragma weak _IO_cookie_seek +# pragma weak _IO_cookie_seekoff +# pragma weak _IO_cookie_write + +# pragma weak _IO_mem_finish +# pragma weak _IO_mem_sync + +# pragma weak _IO_wmem_finish +# pragma weak _IO_wmem_sync + +# pragma weak __printf_buffer_as_file_overflow +# pragma weak __printf_buffer_as_file_xsputn + +# pragma weak __wprintf_buffer_as_file_overflow +# pragma weak __wprintf_buffer_as_file_xsputn +#endif + +const struct _IO_jump_t __io_vtables[IO_VTABLES_LEN] attribute_relro = +{ + /* _IO_str_jumps */ + [IO_STR_JUMPS] = + { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_str_finish), + JUMP_INIT (overflow, _IO_str_overflow), + JUMP_INIT (underflow, _IO_str_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_str_pbackfail), + JUMP_INIT (xsputn, _IO_default_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_str_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_default_setbuf), + JUMP_INIT (sync, _IO_default_sync), + JUMP_INIT (doallocate, _IO_default_doallocate), + JUMP_INIT (read, _IO_default_read), + JUMP_INIT (write, _IO_default_write), + JUMP_INIT (seek, _IO_default_seek), + JUMP_INIT (close, _IO_default_close), + JUMP_INIT (stat, _IO_default_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_wstr_jumps */ + [IO_WSTR_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_wstr_finish), + JUMP_INIT (overflow, (_IO_overflow_t) _IO_wstr_overflow), + JUMP_INIT (underflow, (_IO_underflow_t) _IO_wstr_underflow), + JUMP_INIT (uflow, (_IO_underflow_t) _IO_wdefault_uflow), + JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail), + JUMP_INIT (xsputn, _IO_wdefault_xsputn), + JUMP_INIT (xsgetn, _IO_wdefault_xsgetn), + JUMP_INIT (seekoff, _IO_wstr_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_default_setbuf), + JUMP_INIT (sync, _IO_default_sync), + JUMP_INIT (doallocate, _IO_wdefault_doallocate), + JUMP_INIT (read, _IO_default_read), + JUMP_INIT (write, _IO_default_write), + JUMP_INIT (seek, _IO_default_seek), + JUMP_INIT (close, _IO_default_close), + JUMP_INIT (stat, _IO_default_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_file_jumps */ + [IO_FILE_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_file_finish), + JUMP_INIT (overflow, _IO_file_overflow), + JUMP_INIT (underflow, _IO_file_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_file_xsputn), + JUMP_INIT (xsgetn, _IO_file_xsgetn), + JUMP_INIT (seekoff, _IO_new_file_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_new_file_setbuf), + JUMP_INIT (sync, _IO_new_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_file_jumps_mmap */ + [IO_FILE_JUMPS_MMAP] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_file_finish), + JUMP_INIT (overflow, _IO_file_overflow), + JUMP_INIT (underflow, _IO_file_underflow_mmap), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_new_file_xsputn), + JUMP_INIT (xsgetn, _IO_file_xsgetn_mmap), + JUMP_INIT (seekoff, _IO_file_seekoff_mmap), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap), + JUMP_INIT (sync, _IO_file_sync_mmap), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close_mmap), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_file_jumps_maybe_mmap */ + [IO_FILE_JUMPS_MAYBE_MMAP] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_file_finish), + JUMP_INIT (overflow, _IO_file_overflow), + JUMP_INIT (underflow, _IO_file_underflow_maybe_mmap), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_new_file_xsputn), + JUMP_INIT (xsgetn, _IO_file_xsgetn_maybe_mmap), + JUMP_INIT (seekoff, _IO_file_seekoff_maybe_mmap), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap), + JUMP_INIT (sync, _IO_new_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_wfile_jumps */ + [IO_WFILE_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_new_file_finish), + JUMP_INIT (overflow, (_IO_overflow_t) _IO_wfile_overflow), + JUMP_INIT (underflow, (_IO_underflow_t) _IO_wfile_underflow), + JUMP_INIT (uflow, (_IO_underflow_t) _IO_wdefault_uflow), + JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail), + JUMP_INIT (xsputn, _IO_wfile_xsputn), + JUMP_INIT (xsgetn, _IO_file_xsgetn), + JUMP_INIT (seekoff, _IO_wfile_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_new_file_setbuf), + JUMP_INIT (sync, (_IO_sync_t) _IO_wfile_sync), + JUMP_INIT (doallocate, _IO_wfile_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_wfile_jumps_mmap */ + [IO_WFILE_JUMPS_MMAP] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_new_file_finish), + JUMP_INIT (overflow, (_IO_overflow_t) _IO_wfile_overflow), + JUMP_INIT (underflow, (_IO_underflow_t) _IO_wfile_underflow_mmap), + JUMP_INIT (uflow, (_IO_underflow_t) _IO_wdefault_uflow), + JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail), + JUMP_INIT (xsputn, _IO_wfile_xsputn), + JUMP_INIT (xsgetn, _IO_file_xsgetn), + JUMP_INIT (seekoff, _IO_wfile_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_file_setbuf_mmap), + JUMP_INIT (sync, (_IO_sync_t) _IO_wfile_sync), + JUMP_INIT (doallocate, _IO_wfile_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close_mmap), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_wfile_jumps_maybe_mmap */ + [IO_WFILE_JUMPS_MAYBE_MMAP] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_new_file_finish), + JUMP_INIT (overflow, (_IO_overflow_t) _IO_wfile_overflow), + JUMP_INIT (underflow, (_IO_underflow_t) _IO_wfile_underflow_maybe_mmap), + JUMP_INIT (uflow, (_IO_underflow_t) _IO_wdefault_uflow), + JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail), + JUMP_INIT (xsputn, _IO_wfile_xsputn), + JUMP_INIT (xsgetn, _IO_file_xsgetn), + JUMP_INIT (seekoff, _IO_wfile_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_file_setbuf_mmap), + JUMP_INIT (sync, (_IO_sync_t) _IO_wfile_sync), + JUMP_INIT (doallocate, _IO_wfile_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_cookie_jumps */ + [IO_COOKIE_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_file_finish), + JUMP_INIT (overflow, _IO_file_overflow), + JUMP_INIT (underflow, _IO_file_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_file_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_cookie_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_file_setbuf), + JUMP_INIT (sync, _IO_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_cookie_read), + JUMP_INIT (write, _IO_cookie_write), + JUMP_INIT (seek, _IO_cookie_seek), + JUMP_INIT (close, _IO_cookie_close), + JUMP_INIT (stat, _IO_default_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue), + }, + /* _IO_proc_jumps */ + [IO_PROC_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_new_file_finish), + JUMP_INIT (overflow, _IO_new_file_overflow), + JUMP_INIT (underflow, _IO_new_file_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_new_file_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_new_file_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_new_file_setbuf), + JUMP_INIT (sync, _IO_new_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_new_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_new_proc_close), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_mem_jumps */ + [IO_MEM_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_mem_finish), + JUMP_INIT (overflow, _IO_str_overflow), + JUMP_INIT (underflow, _IO_str_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_str_pbackfail), + JUMP_INIT (xsputn, _IO_default_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_str_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_default_setbuf), + JUMP_INIT (sync, _IO_mem_sync), + JUMP_INIT (doallocate, _IO_default_doallocate), + JUMP_INIT (read, _IO_default_read), + JUMP_INIT (write, _IO_default_write), + JUMP_INIT (seek, _IO_default_seek), + JUMP_INIT (close, _IO_default_close), + JUMP_INIT (stat, _IO_default_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + /* _IO_wmem_jumps */ + [IO_WMEM_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_wmem_finish), + JUMP_INIT (overflow, (_IO_overflow_t) _IO_wstr_overflow), + JUMP_INIT (underflow, (_IO_underflow_t) _IO_wstr_underflow), + JUMP_INIT (uflow, (_IO_underflow_t) _IO_wdefault_uflow), + JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail), + JUMP_INIT (xsputn, _IO_wdefault_xsputn), + JUMP_INIT (xsgetn, _IO_wdefault_xsgetn), + JUMP_INIT (seekoff, _IO_wstr_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_default_setbuf), + JUMP_INIT (sync, _IO_wmem_sync), + JUMP_INIT (doallocate, _IO_wdefault_doallocate), + JUMP_INIT (read, _IO_default_read), + JUMP_INIT (write, _IO_default_write), + JUMP_INIT (seek, _IO_default_seek), + JUMP_INIT (close, _IO_default_close), + JUMP_INIT (stat, _IO_default_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, + [IO_PRINTF_BUFFER_AS_FILE_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, NULL), + JUMP_INIT (overflow, __printf_buffer_as_file_overflow), + JUMP_INIT (underflow, NULL), + JUMP_INIT (uflow, NULL), + JUMP_INIT (pbackfail, NULL), + JUMP_INIT (xsputn, __printf_buffer_as_file_xsputn), + JUMP_INIT (xsgetn, NULL), + JUMP_INIT (seekoff, NULL), + JUMP_INIT (seekpos, NULL), + JUMP_INIT (setbuf, NULL), + JUMP_INIT (sync, NULL), + JUMP_INIT (doallocate, NULL), + JUMP_INIT (read, NULL), + JUMP_INIT (write, NULL), + JUMP_INIT (seek, NULL), + JUMP_INIT (close, NULL), + JUMP_INIT (stat, NULL), + JUMP_INIT (showmanyc, NULL), + JUMP_INIT (imbue, NULL) + }, + [IO_WPRINTF_BUFFER_AS_FILE_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, NULL), + JUMP_INIT (overflow, (_IO_overflow_t) __wprintf_buffer_as_file_overflow), + JUMP_INIT (underflow, NULL), + JUMP_INIT (uflow, NULL), + JUMP_INIT (pbackfail, NULL), + JUMP_INIT (xsputn, __wprintf_buffer_as_file_xsputn), + JUMP_INIT (xsgetn, NULL), + JUMP_INIT (seekoff, NULL), + JUMP_INIT (seekpos, NULL), + JUMP_INIT (setbuf, NULL), + JUMP_INIT (sync, NULL), + JUMP_INIT (doallocate, NULL), + JUMP_INIT (read, NULL), + JUMP_INIT (write, NULL), + JUMP_INIT (seek, NULL), + JUMP_INIT (close, NULL), + JUMP_INIT (stat, NULL), + JUMP_INIT (showmanyc, NULL), + JUMP_INIT (imbue, NULL) + }, + +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) + /* _IO_old_file_jumps */ + [IO_OLD_FILE_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_old_file_finish), + JUMP_INIT (overflow, _IO_old_file_overflow), + JUMP_INIT (underflow, _IO_old_file_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_old_file_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_old_file_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_old_file_setbuf), + JUMP_INIT (sync, _IO_old_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_old_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_file_close), + JUMP_INIT (stat, _IO_file_stat) + }, + /* _IO_old_proc_jumps */ + [IO_OLD_PROC_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_old_file_finish), + JUMP_INIT (overflow, _IO_old_file_overflow), + JUMP_INIT (underflow, _IO_old_file_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_old_file_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_old_file_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_old_file_setbuf), + JUMP_INIT (sync, _IO_old_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_file_read), + JUMP_INIT (write, _IO_old_file_write), + JUMP_INIT (seek, _IO_file_seek), + JUMP_INIT (close, _IO_old_proc_close), + JUMP_INIT (stat, _IO_file_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) + }, +#endif + +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2) + /* _IO_old_cookie_jumps */ + [IO_OLD_COOKIED_JUMPS] = { + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_file_finish), + JUMP_INIT (overflow, _IO_file_overflow), + JUMP_INIT (underflow, _IO_file_underflow), + JUMP_INIT (uflow, _IO_default_uflow), + JUMP_INIT (pbackfail, _IO_default_pbackfail), + JUMP_INIT (xsputn, _IO_file_xsputn), + JUMP_INIT (xsgetn, _IO_default_xsgetn), + JUMP_INIT (seekoff, _IO_cookie_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_file_setbuf), + JUMP_INIT (sync, _IO_file_sync), + JUMP_INIT (doallocate, _IO_file_doallocate), + JUMP_INIT (read, _IO_cookie_read), + JUMP_INIT (write, _IO_cookie_write), + JUMP_INIT (seek, _IO_old_cookie_seek), + JUMP_INIT (close, _IO_cookie_close), + JUMP_INIT (stat, _IO_default_stat), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue), + }, +#endif +}; #ifdef SHARED @@ -82,3 +548,15 @@ check_stdfiles_vtables (void) IO_set_accept_foreign_vtables (&_IO_vtable_check); } #endif + +#define STR(s) XSTR(s) +#define XSTR(s) #s + +#undef _IO_file_jumps +#define _IO_file_jumps_alias "__io_vtables + " STR(IO_FILE_JUMPS_OFFSET) +declare_object_symbol_alias (_IO_file_jumps, _IO_file_jumps_alias, + IO_JUMP_T_SIZE) +#undef _IO_wfile_jumps +#define _IO_wfile_jumps_alias "__io_vtables + " STR(IO_WFILE_JUMPS_OFFSET) +declare_object_symbol_alias (_IO_wfile_jumps, _IO_wfile_jumps_alias, + IO_JUMP_T_SIZE) diff --git a/libio/wfileops.c b/libio/wfileops.c index cecea21c1c..f16f6db1c3 100644 --- a/libio/wfileops.c +++ b/libio/wfileops.c @@ -328,7 +328,7 @@ _IO_wfile_underflow (FILE *fp) libc_hidden_def (_IO_wfile_underflow) -static wint_t +wint_t _IO_wfile_underflow_mmap (FILE *fp) { struct _IO_codecvt *cd; @@ -389,7 +389,7 @@ _IO_wfile_underflow_mmap (FILE *fp) return WEOF; } -static wint_t +wint_t _IO_wfile_underflow_maybe_mmap (FILE *fp) { /* This is the first read attempt. Doing the underflow will choose mmap @@ -1017,78 +1017,3 @@ _IO_wfile_xsputn (FILE *f, const void *data, size_t n) return n - to_do; } libc_hidden_def (_IO_wfile_xsputn) - - -const struct _IO_jump_t _IO_wfile_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_new_file_finish), - JUMP_INIT(overflow, (_IO_overflow_t) _IO_wfile_overflow), - JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow), - JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow), - JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail), - JUMP_INIT(xsputn, _IO_wfile_xsputn), - JUMP_INIT(xsgetn, _IO_file_xsgetn), - JUMP_INIT(seekoff, _IO_wfile_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_new_file_setbuf), - JUMP_INIT(sync, (_IO_sync_t) _IO_wfile_sync), - JUMP_INIT(doallocate, _IO_wfile_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; -libc_hidden_data_def (_IO_wfile_jumps) - - -const struct _IO_jump_t _IO_wfile_jumps_mmap libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_new_file_finish), - JUMP_INIT(overflow, (_IO_overflow_t) _IO_wfile_overflow), - JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow_mmap), - JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow), - JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail), - JUMP_INIT(xsputn, _IO_wfile_xsputn), - JUMP_INIT(xsgetn, _IO_file_xsgetn), - JUMP_INIT(seekoff, _IO_wfile_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_file_setbuf_mmap), - JUMP_INIT(sync, (_IO_sync_t) _IO_wfile_sync), - JUMP_INIT(doallocate, _IO_wfile_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close_mmap), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; - -const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_new_file_finish), - JUMP_INIT(overflow, (_IO_overflow_t) _IO_wfile_overflow), - JUMP_INIT(underflow, (_IO_underflow_t) _IO_wfile_underflow_maybe_mmap), - JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow), - JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail), - JUMP_INIT(xsputn, _IO_wfile_xsputn), - JUMP_INIT(xsgetn, _IO_file_xsgetn), - JUMP_INIT(seekoff, _IO_wfile_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_file_setbuf_mmap), - JUMP_INIT(sync, (_IO_sync_t) _IO_wfile_sync), - JUMP_INIT(doallocate, _IO_wfile_doallocate), - JUMP_INIT(read, _IO_file_read), - JUMP_INIT(write, _IO_new_file_write), - JUMP_INIT(seek, _IO_file_seek), - JUMP_INIT(close, _IO_file_close), - JUMP_INIT(stat, _IO_file_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; diff --git a/libio/wmemstream.c b/libio/wmemstream.c index 6560d7001f..7b04b15cbc 100644 --- a/libio/wmemstream.c +++ b/libio/wmemstream.c @@ -30,34 +30,6 @@ struct _IO_FILE_wmemstream }; -static int _IO_wmem_sync (FILE* fp) __THROW; -static void _IO_wmem_finish (FILE* fp, int) __THROW; - - -static const struct _IO_jump_t _IO_wmem_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT (finish, _IO_wmem_finish), - JUMP_INIT (overflow, (_IO_overflow_t) _IO_wstr_overflow), - JUMP_INIT (underflow, (_IO_underflow_t) _IO_wstr_underflow), - JUMP_INIT (uflow, (_IO_underflow_t) _IO_wdefault_uflow), - JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail), - JUMP_INIT (xsputn, _IO_wdefault_xsputn), - JUMP_INIT (xsgetn, _IO_wdefault_xsgetn), - JUMP_INIT (seekoff, _IO_wstr_seekoff), - JUMP_INIT (seekpos, _IO_default_seekpos), - JUMP_INIT (setbuf, _IO_default_setbuf), - JUMP_INIT (sync, _IO_wmem_sync), - JUMP_INIT (doallocate, _IO_wdefault_doallocate), - JUMP_INIT (read, _IO_default_read), - JUMP_INIT (write, _IO_default_write), - JUMP_INIT (seek, _IO_default_seek), - JUMP_INIT (close, _IO_default_close), - JUMP_INIT (stat, _IO_default_stat), - JUMP_INIT (showmanyc, _IO_default_showmanyc), - JUMP_INIT (imbue, _IO_default_imbue) -}; - /* Open a stream that writes into a malloc'd buffer that is expanded as necessary. *BUFLOC and *SIZELOC are updated with the buffer's location and the number of characters written on fflush or fclose. */ @@ -105,7 +77,7 @@ open_wmemstream (wchar_t **bufloc, size_t *sizeloc) } -static int +int _IO_wmem_sync (FILE *fp) { struct _IO_FILE_wmemstream *mp = (struct _IO_FILE_wmemstream *) fp; @@ -124,7 +96,7 @@ _IO_wmem_sync (FILE *fp) } -static void +void _IO_wmem_finish (FILE *fp, int dummy) { struct _IO_FILE_wmemstream *mp = (struct _IO_FILE_wmemstream *) fp; diff --git a/libio/wstrops.c b/libio/wstrops.c index 9c9d303968..632fc123a2 100644 --- a/libio/wstrops.c +++ b/libio/wstrops.c @@ -361,27 +361,3 @@ _IO_wstr_finish (FILE *fp, int dummy) _IO_wdefault_finish (fp, 0); } - -const struct _IO_jump_t _IO_wstr_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, _IO_wstr_finish), - JUMP_INIT(overflow, (_IO_overflow_t) _IO_wstr_overflow), - JUMP_INIT(underflow, (_IO_underflow_t) _IO_wstr_underflow), - JUMP_INIT(uflow, (_IO_underflow_t) _IO_wdefault_uflow), - JUMP_INIT(pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail), - JUMP_INIT(xsputn, _IO_wdefault_xsputn), - JUMP_INIT(xsgetn, _IO_wdefault_xsgetn), - JUMP_INIT(seekoff, _IO_wstr_seekoff), - JUMP_INIT(seekpos, _IO_default_seekpos), - JUMP_INIT(setbuf, _IO_default_setbuf), - JUMP_INIT(sync, _IO_default_sync), - JUMP_INIT(doallocate, _IO_wdefault_doallocate), - JUMP_INIT(read, _IO_default_read), - JUMP_INIT(write, _IO_default_write), - JUMP_INIT(seek, _IO_default_seek), - JUMP_INIT(close, _IO_default_close), - JUMP_INIT(stat, _IO_default_stat), - JUMP_INIT(showmanyc, _IO_default_showmanyc), - JUMP_INIT(imbue, _IO_default_imbue) -}; diff --git a/stdio-common/printf_buffer_as_file.c b/stdio-common/printf_buffer_as_file.c index 12b0e13f41..fe23797da2 100644 --- a/stdio-common/printf_buffer_as_file.c +++ b/stdio-common/printf_buffer_as_file.c @@ -48,7 +48,7 @@ __printf_buffer_as_file_switch_to_buffer (struct __printf_buffer_as_file *file) /* Only a small subset of the vtable functions is implemented here, following _IO_obstack_jumps. */ -static int +int __printf_buffer_as_file_overflow (FILE *fp, int ch) { struct __printf_buffer_as_file *file = (struct __printf_buffer_as_file *) fp; @@ -72,7 +72,7 @@ __printf_buffer_as_file_overflow (FILE *fp, int ch) return EOF; } -static size_t +size_t __printf_buffer_as_file_xsputn (FILE *fp, const void *buf, size_t len) { struct __printf_buffer_as_file *file = (struct __printf_buffer_as_file *) fp; @@ -93,30 +93,6 @@ __printf_buffer_as_file_xsputn (FILE *fp, const void *buf, size_t len) return 0; } -static const struct _IO_jump_t _IO_printf_buffer_as_file_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, NULL), - JUMP_INIT(overflow, __printf_buffer_as_file_overflow), - JUMP_INIT(underflow, NULL), - JUMP_INIT(uflow, NULL), - JUMP_INIT(pbackfail, NULL), - JUMP_INIT(xsputn, __printf_buffer_as_file_xsputn), - JUMP_INIT(xsgetn, NULL), - JUMP_INIT(seekoff, NULL), - JUMP_INIT(seekpos, NULL), - JUMP_INIT(setbuf, NULL), - JUMP_INIT(sync, NULL), - JUMP_INIT(doallocate, NULL), - JUMP_INIT(read, NULL), - JUMP_INIT(write, NULL), - JUMP_INIT(seek, NULL), - JUMP_INIT(close, NULL), - JUMP_INIT(stat, NULL), - JUMP_INIT(showmanyc, NULL), - JUMP_INIT(imbue, NULL) -}; - void __printf_buffer_as_file_init (struct __printf_buffer_as_file *file, struct __printf_buffer *next) diff --git a/stdio-common/wprintf_buffer_as_file.c b/stdio-common/wprintf_buffer_as_file.c index b2e5b5ada9..dbdb8cc535 100644 --- a/stdio-common/wprintf_buffer_as_file.c +++ b/stdio-common/wprintf_buffer_as_file.c @@ -48,7 +48,7 @@ __wprintf_buffer_as_file_switch_to_buffer (struct __wprintf_buffer_as_file *file /* Only a small subset of the vtable functions is implemented here, following _IO_obstack_jumps. */ -static wint_t +wint_t __wprintf_buffer_as_file_overflow (FILE *fp, int ch) { struct __wprintf_buffer_as_file *file @@ -75,7 +75,7 @@ __wprintf_buffer_as_file_overflow (FILE *fp, int ch) return WEOF; } -static size_t +size_t __wprintf_buffer_as_file_xsputn (FILE *fp, const void *buf, size_t len) { struct __wprintf_buffer_as_file *file @@ -97,30 +97,6 @@ __wprintf_buffer_as_file_xsputn (FILE *fp, const void *buf, size_t len) return 0; } -static const struct _IO_jump_t _IO_wprintf_buffer_as_file_jumps libio_vtable = -{ - JUMP_INIT_DUMMY, - JUMP_INIT(finish, NULL), - JUMP_INIT(overflow, (_IO_overflow_t) __wprintf_buffer_as_file_overflow), - JUMP_INIT(underflow, NULL), - JUMP_INIT(uflow, NULL), - JUMP_INIT(pbackfail, NULL), - JUMP_INIT(xsputn, __wprintf_buffer_as_file_xsputn), - JUMP_INIT(xsgetn, NULL), - JUMP_INIT(seekoff, NULL), - JUMP_INIT(seekpos, NULL), - JUMP_INIT(setbuf, NULL), - JUMP_INIT(sync, NULL), - JUMP_INIT(doallocate, NULL), - JUMP_INIT(read, NULL), - JUMP_INIT(write, NULL), - JUMP_INIT(seek, NULL), - JUMP_INIT(close, NULL), - JUMP_INIT(stat, NULL), - JUMP_INIT(showmanyc, NULL), - JUMP_INIT(imbue, NULL) -}; - void __wprintf_buffer_as_file_init (struct __wprintf_buffer_as_file *file, struct __wprintf_buffer *next) From patchwork Mon Mar 6 19:16:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 659263 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1987747wrb; Mon, 6 Mar 2023 11:17:16 -0800 (PST) X-Google-Smtp-Source: AK7set+KUtvLlO8bkQy5w/cbsDEF+plBVvopTChICyUehFjx6fqxTvGlMDosDnT4qWqHZgrSo35l X-Received: by 2002:a17:907:6da3:b0:878:50f7:a35a with SMTP id sb35-20020a1709076da300b0087850f7a35amr14811902ejc.72.1678130236089; Mon, 06 Mar 2023 11:17:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678130236; cv=none; d=google.com; s=arc-20160816; b=fnN2ozI0HqQwSgcADLbz+P/Kmuws9n1P05cuBMeYiq+Xk3n6IOq19Wuv8BmA2kqUY3 GABtmImWbitjX5o4MtCqdd68FI6AXNT7auEXeHKQ7F/VGxcG/wZhXpLrzUFVDfFuCh4p 1Jt6RSwnViH9/pX3XYCR37U8J0qvVqUAXshfv0Oitl/ombkaECZ09oUjNxMjzxMdPJK5 dcKwcdyl8CIk3MMgiJ7kmjeFkqNaTifhzIedQWyJN2ALoOHWJ608Xn7CRYPJpAsjEGHZ 7ySQCAiThPtRWl8vc25FEbFsxuNs/XWVE0+9INxAI8bohb28FFajS4yBu8gnM3rJKAMa b1Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=pNTk6GJblZrsnWty2ZMiY35c8st3M3q4QYXgHx2nMao=; b=JlcXwzrUaPkg4jsrfUFtZHtr3/ZgIZ9Mc4F5Gm3Av+ro/SkvFhdt4QNbGYVmcpaLgQ H0jtFIzHadR8LvIVh5NcNzznkh7S6k/0fMbinAGxddm3xjJGTU0sBeAaC/thaSC+yc18 57Y9E5aSbL7sEg+w9SLeOermFWipS1R1AAkjUZ/F/j3njXiT8Mn+DGLl5NqmwXBeM2dW 2LNEzIOMxAP2+z3ck3N84qbpPRdL6LDOHAzedY9yTyft7i81SOCm0jyFYMTkYxuay7SR 8ZIPuX/+TVUqHBn9U+TtDDdYLfzww1yihoFrBL4tRuSuXZaTSQdRkvEA1vdmrBI4WsuS KXwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="A/BmxI7D"; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x14-20020a170906b08e00b008de4a641fe0si830707ejy.938.2023.03.06.11.17.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:17:16 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="A/BmxI7D"; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A73C3850875 for ; Mon, 6 Mar 2023 19:17:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A73C3850875 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678130235; bh=pNTk6GJblZrsnWty2ZMiY35c8st3M3q4QYXgHx2nMao=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=A/BmxI7D0qwYZ5fbJssDH3MAGrOeAz/zo74XzPKb0kpo/2KAJHItXGm+zkyfJwSTp eNr+EqPisyQEPJWMq/g3YxoZgI33YAgHiABabMDtrDckhj2ARZTdDkb3dj10V06t+S uSxjL7BVkSi+dirgrcwuT9nmamBeUolcIgFxWpyQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id DA921385C301 for ; Mon, 6 Mar 2023 19:16:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA921385C301 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-17638494edbso12526849fac.10 for ; Mon, 06 Mar 2023 11:16:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678130219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pNTk6GJblZrsnWty2ZMiY35c8st3M3q4QYXgHx2nMao=; b=BRgdBLHM0fy9fvPD/KU578Xiz9dCuUapjzDsmuxSxZPG8e8vd7LvrazoeTmg1KzXMw SFqK4AOA7+V6CRsP3Ts6WypZIS5hoSRH5BV1H2J7x6S/2B0IJjxh2q89p5VlCgI6uwpZ veI1UeRrlut5WHErjeyETctn6WtDBa4i9iUqCeuFK2MA9NhpXtIkPOHtqBFfUcAC3jnj vCsCR2sNzsO9cUoHj6zWLF0ssNo1UzpyRKxzaVegZzeU/7QrreggwW4C4j7CtddI5sQX SHoxawkUFlDgDXWrDy7M7R9FT5K/rtZIWCsAXG+6zfYbc0xq2AiSMkn7wZmnMgUu8hIx YopA== X-Gm-Message-State: AO0yUKUEhW1P/bZ9BCfzRNBO45rYqxEXlSYYnNShsT8UkKM2CJnNDKVu 84VryDxR0Fd6g69/R2uYAGxiUaAa1ytaU+NiIu998w== X-Received: by 2002:a05:6870:1116:b0:176:21a9:bf95 with SMTP id 22-20020a056870111600b0017621a9bf95mr5441619oaf.46.1678130218723; Mon, 06 Mar 2023 11:16:58 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:8c2f:e58d:3e6:9de5]) by smtp.gmail.com with ESMTPSA id zf29-20020a0568716a9d00b00176598b79d3sm4280668oab.24.2023.03.06.11.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:16:58 -0800 (PST) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell Cc: Adhemerval Zanella Netto Subject: [PATCH v5 4/5] Remove --with-default-link configure option Date: Mon, 6 Mar 2023 16:16:41 -0300 Message-Id: <20230306191642.347001-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306191642.347001-1-adhemerval.zanella@linaro.org> References: <20230306191642.347001-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto Now that there is no need to use a special linker script to hardening internal data structures, remove the --with-default-link configure option and associated definitions. Reviewed-by: Carlos O'Donell --- INSTALL | 6 ------ Makerules | 21 ++++++--------------- config.make.in | 1 - configure | 13 ------------- configure.ac | 7 ------- elf/Makefile | 2 -- iconvdata/extra-module.mk | 2 +- manual/install.texi | 6 ------ 8 files changed, 7 insertions(+), 51 deletions(-) diff --git a/INSTALL b/INSTALL index 970d6627e2..cc1bfe9cbb 100644 --- a/INSTALL +++ b/INSTALL @@ -90,12 +90,6 @@ if 'CFLAGS' is specified it must enable optimization. For example: library will still be usable, but functionality may be lost--for example, you can't build a shared libc with old binutils. -'--with-default-link' - With '--with-default-link', the build system does not use a custom - linker script for linking shared objects. The default is - '--without-default-link', because the custom linker script is - needed for full RELRO protection. - '--with-nonshared-cflags=CFLAGS' Use additional compiler flags CFLAGS to build the parts of the library which are always statically linked into applications and diff --git a/Makerules b/Makerules index 16887cb443..31064470e5 100644 --- a/Makerules +++ b/Makerules @@ -544,13 +544,8 @@ $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \ -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) endef -# If the linker is good enough, we can let it use its default linker script. -# In the long term the custom linker script will be removed. -shlib-lds = -shlib-lds-flags = - define build-shlib -$(build-shlib-helper) -o $@ $(shlib-lds-flags) \ +$(build-shlib-helper) -o $@ \ $(csu-objpfx)abi-note.o $(build-shlib-objlist) endef @@ -569,12 +564,12 @@ endef # binutils only position loadable notes into the first page for binaries, # not for shared objects define build-module -$(build-module-helper) -o $@ $(shlib-lds-flags) \ +$(build-module-helper) -o $@ \ $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args) $(call after-link,$@) endef define build-module-asneeded -$(build-module-helper) -o $@ $(shlib-lds-flags) \ +$(build-module-helper) -o $@ \ $(csu-objpfx)abi-note.o \ -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \ $(link-libc-args) @@ -606,7 +601,6 @@ $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a $(LINK.o) -nostdlib -nostartfiles -r -o $@ \ $(LDFLAGS-c_pic.os) $(whole-archive) $^ -o $@ -ifeq (,$(strip $(shlib-lds-flags))) # Generate a list of -R options to excise .gnu.glibc-stub.* sections. $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os $(OBJDUMP) -h $< | \ @@ -620,7 +614,6 @@ $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \ generated += libc_pic.opts libc_pic.os.clean libc_pic_clean := .clean -endif # Build a possibly-modified version of libc_pic.a for use in building # linkobj/libc.so. @@ -650,16 +643,14 @@ $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty $(common-objpfx)libc.so: $(common-objpfx)libc_pic.os$(libc_pic_clean) \ $(elf-objpfx)sofini.os \ $(elf-objpfx)interp.os \ - $(elf-objpfx)ld.so \ - $(shlib-lds) + $(elf-objpfx)ld.so $(build-shlib) $(call after-link,$@) $(common-objpfx)linkobj/libc.so: $(common-objpfx)linkobj/libc_pic.a \ $(elf-objpfx)sofini.os \ $(elf-objpfx)interp.os \ - $(elf-objpfx)ld.so \ - $(shlib-lds) + $(elf-objpfx)ld.so $(build-shlib) $(call after-link,$@) @@ -720,7 +711,7 @@ endif extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names)) $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \ - $(objpfx)%.os $(shlib-lds) $(link-libs-deps) + $(objpfx)%.os $(link-libs-deps) $(build-module) endif diff --git a/config.make.in b/config.make.in index d7c416cbea..befcc22625 100644 --- a/config.make.in +++ b/config.make.in @@ -69,7 +69,6 @@ have-libaudit = @have_libaudit@ have-libcap = @have_libcap@ have-cc-with-libunwind = @libc_cv_cc_with_libunwind@ bind-now = @bindnow@ -use-default-link = @use_default_link@ have-cxx-thread_local = @libc_cv_cxx_thread_local@ have-loop-to-function = @libc_cv_cc_loop_to_function@ have-textrel_ifunc = @libc_cv_textrel_ifunc@ diff --git a/configure b/configure index efb891456a..c5a831e3cd 100755 --- a/configure +++ b/configure @@ -680,7 +680,6 @@ hardcoded_path_in_tests enable_timezone_tools rtld_early_cflags extra_nonshared_cflags -use_default_link sysheaders ac_ct_CXX CXXFLAGS @@ -756,7 +755,6 @@ with_gd_lib with_binutils with_selinux with_headers -with_default_link with_nonshared_cflags with_rtld_early_cflags with_timeoutfactor @@ -1475,7 +1473,6 @@ Optional Packages: --with-selinux if building with SELinux support --with-headers=PATH location of system headers to use (for example /usr/src/linux/include) [default=compiler default] - --with-default-link do not use explicit linker scripts --with-nonshared-cflags=CFLAGS build nonshared libraries with additional CFLAGS --with-rtld-early-cflags=CFLAGS @@ -3275,16 +3272,6 @@ fi - -# Check whether --with-default-link was given. -if test "${with_default_link+set}" = set; then : - withval=$with_default_link; use_default_link=$withval -else - use_default_link=no -fi - - - # Check whether --with-nonshared-cflags was given. if test "${with_nonshared_cflags+set}" = set; then : withval=$with_nonshared_cflags; extra_nonshared_cflags=$withval diff --git a/configure.ac b/configure.ac index 011844a3d4..88a6a88220 100644 --- a/configure.ac +++ b/configure.ac @@ -147,13 +147,6 @@ AC_ARG_WITH([headers], [sysheaders='']) AC_SUBST(sysheaders) -AC_SUBST(use_default_link) -AC_ARG_WITH([default-link], - AS_HELP_STRING([--with-default-link], - [do not use explicit linker scripts]), - [use_default_link=$withval], - [use_default_link=no]) - dnl Additional build flags injection. AC_ARG_WITH([nonshared-cflags], AS_HELP_STRING([--with-nonshared-cflags=CFLAGS], diff --git a/elf/Makefile b/elf/Makefile index b7f31cdf1c..dcdfd0af87 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1237,8 +1237,6 @@ endif # Command to link into a larger single relocatable object. reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -$(objpfx)sotruss-lib.so: $(shlib-lds) - $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os) $(reloc-link) -o $@ $^ diff --git a/iconvdata/extra-module.mk b/iconvdata/extra-module.mk index ecaf507624..a816659763 100644 --- a/iconvdata/extra-module.mk +++ b/iconvdata/extra-module.mk @@ -4,7 +4,7 @@ extra-modules-left := $(strip $(filter-out $(mod),$(extra-modules-left))) extra-objs := $(extra-objs) $(patsubst %,%.os,$($(mod)-routines)) $(objpfx)$(mod).so: $(addprefix $(objpfx),$(addsuffix .os,$($(mod)-routines)))\ - $(shlib-lds) $(link-libc-deps) + $(link-libc-deps) $(build-module-asneeded) ifneq (,$(extra-modules-left)) diff --git a/manual/install.texi b/manual/install.texi index 260f8a5c82..60fca21aed 100644 --- a/manual/install.texi +++ b/manual/install.texi @@ -117,12 +117,6 @@ problem and suppress these constructs, so that the library will still be usable, but functionality may be lost---for example, you can't build a shared libc with old binutils. -@item --with-default-link -With @code{--with-default-link}, the build system does not use a custom -linker script for linking shared objects. The default is -@code{--without-default-link}, because the custom linker script is -needed for full RELRO protection. - @item --with-nonshared-cflags=@var{cflags} Use additional compiler flags @var{cflags} to build the parts of the library which are always statically linked into applications and From patchwork Mon Mar 6 19:16:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 659266 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1988015wrb; Mon, 6 Mar 2023 11:18:00 -0800 (PST) X-Google-Smtp-Source: AK7set/3hOMy2ppixI/h7xSLRV+BgJ9+e8CQYgFu43AhOkHVHEDf0D36OB85e0PeX0yGuRegFA7r X-Received: by 2002:a17:907:a04:b0:7e0:eed0:8beb with SMTP id bb4-20020a1709070a0400b007e0eed08bebmr15699695ejc.41.1678130280130; Mon, 06 Mar 2023 11:18:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678130280; cv=none; d=google.com; s=arc-20160816; b=uALx8NU9MfB9KjjTUOx8pPLYb5GAyf31c0b8EooF/oHB5ghFE+Ob84k9wuWKLf0auK eODMWATYvAKLiSqOdc53X+xvelVI/2KchjuB5KgUSU0sNwMDOPrXbGv90EJ+ofi/ab/x CV+O4SoFENBy+fCzDXT+mMaz+K1BCrVjVJaA340wjj6dlKY9/pCsta+VLM6AZn2WXWFR OaR0AYtL1X+2PnQ9CrBeJjQi3IOL1soC/tG+XBi4Wb3LOGI2O+5WhU+WVt+Q0ms8r5C0 SBGPrkAorIAVlrw7b9qxnSVEhYT1EjMAxFHfUgk4SckCni2TYUZscrh/yKgd2ab460Hy 89Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=pzqCZUZMikQnIY0pFL2djBn+Mq03FBdGCaYoUtnhP3I=; b=RrlHDFyP7+IxbfG3R9DmCk2D2x6cP2oj2P6VMoZW4UXxY9og9Me1wlKZ5hX6+fdi4Q 7yI4szwUbcvM3/GtWNL76GjbHLRGOARnUWK4RIyAc3bu1FwahAx81sTKIxZa7AgMmCSO Xd+zBiUpMcYlhsdv956KLAjL2vGeKEtfikQL+gu0RiC3GXSM/fRKcLFLmYvdOCnBFakL IcODRfRoAqidvUjM/cLzt326GOkWDczBglNURaGo0Tbit5JJjrCrXCk+0j5hVEMtLbe3 uG2umBkMrZ68LQ2JDdi9i+2/DRSll+SqQ5Dt2tH0UVq+kDD5OKgvMF1T0P4m7GPlpbhc v5DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=JILsCg7h; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Return-Path: Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s13-20020a170906168d00b008f0ba0949e0si5225643ejd.980.2023.03.06.11.17.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:18:00 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=JILsCg7h; spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E70E9384D1A7 for ; Mon, 6 Mar 2023 19:17:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E70E9384D1A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678130278; bh=pzqCZUZMikQnIY0pFL2djBn+Mq03FBdGCaYoUtnhP3I=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=JILsCg7hvxlnskEwpds9lnYeXlVt5enzfwKWm0fotu24A1YMtWo/3ntIjVFxQM5aD Oj2Dd8ITxii5Rfsz7OFF8OKyKN7yM/PxMeUdfPv8qcHc4g7klMAKkCMhWHdxfBK3wK zSz34W3aHoxsSepiWewMny1cQcsWjw/F2mUlHmb0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id 6C6E43851ABA for ; Mon, 6 Mar 2023 19:17:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C6E43851ABA Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-173435e0ec4so12517063fac.12 for ; Mon, 06 Mar 2023 11:17:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678130221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pzqCZUZMikQnIY0pFL2djBn+Mq03FBdGCaYoUtnhP3I=; b=nFW5T62hFjroEH3RsqpfnbjmdrZaDixenehKpyoaxxLx52HJi+iIaKyqQdUlDQEHlT sst7vrzVJHAVVQVuQTt9JdR1HSJW9Ve3buvRu1ha2le0greqvsdUgM+GmhsxgbMc3IE3 RhVb+fJ/MVyj2LlZA037nwpIXLonCgmuZA2JEDzkIKlOJVgPMo2ivKyA7CZ+JtJgGXko hvA+0DVi3HDnpV+F0McrbzzS36eu3p9KfLGaumiesSGaOpKP2XgqZEcueZ8Y838Nop+u KgOGWPrQA0ykj5LFiKYqIJZKSJlwHtDC3HhUfMxxebJgLb9MNgmFpMcxGjyxqJcQogXS f3Hw== X-Gm-Message-State: AO0yUKXWT6NFtaNkBBsj7xYdIXsn5rQYXuJjhCs6Vaz4W9jbB7J74LWc n3LcRiFaqaOQ1fKf0SaAECKAuDG8Cg80FFT0WkUVUA== X-Received: by 2002:a05:6871:889:b0:16e:93ba:e55e with SMTP id r9-20020a056871088900b0016e93bae55emr7503840oaq.8.1678130221078; Mon, 06 Mar 2023 11:17:01 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c3:d849:8c2f:e58d:3e6:9de5]) by smtp.gmail.com with ESMTPSA id zf29-20020a0568716a9d00b00176598b79d3sm4280668oab.24.2023.03.06.11.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 11:17:00 -0800 (PST) To: libc-alpha@sourceware.org, Florian Weimer , Carlos O'Donell Cc: Adhemerval Zanella Netto Subject: [PATCH v5 5/5] Remove set-hooks.h from generic includes Date: Mon, 6 Mar 2023 16:16:42 -0300 Message-Id: <20230306191642.347001-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306191642.347001-1-adhemerval.zanella@linaro.org> References: <20230306191642.347001-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Sender: "Libc-alpha" From: Adhemerval Zanella Netto The hooks mechanism uses symbol sets for running lists of functions, which requires either extra linker directives to provide any hardening (such as RELRO) or additional code (such as pointer obfuscation via mangling with random value). Currently only hurd uses set-hooks.h so we remove it from the generic includes. The generic implementation uses direct function calls which provide hardening and good code generation, observability and debugging without the need for extra linking options or special code handling. Reviewed-by: Carlos O'Donell --- {include => hurd}/set-hooks.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {include => hurd}/set-hooks.h (100%) diff --git a/include/set-hooks.h b/hurd/set-hooks.h similarity index 100% rename from include/set-hooks.h rename to hurd/set-hooks.h