From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8YR+J2WDJGj9jCIAWB0awg (envelope-from ) for ; Wed, 14 May 2025 07:49:57 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wvo5sV6T; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ciSXgp83; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wvo5sV6T; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ciSXgp83; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8B5EF1E10E; Wed, 14 May 2025 07:49:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5D13F1E092 for ; Wed, 14 May 2025 07:49:55 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E93FF38560B0 for ; Wed, 14 May 2025 11:49:54 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id BD56A385C017 for ; Wed, 14 May 2025 11:49:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD56A385C017 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BD56A385C017 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747223364; cv=none; b=jb7/JFS/ILwyFrm0ObnjSybP2EBYg/hncSQfS/m8ymveD5zU/eKqpKgE1g1LgMlJp8ySBb3nMXgYlqLOeceoUqcPPuo0LL8n2aUiGi/sw7w7M4LgWXZPcUlD0TaiJt42E1oh/R9+YBEQQq2JbfAu9yKWtttQObkYBFpgu8/YGUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747223364; c=relaxed/simple; bh=/VDif1zzrDItHG/iSf+VI7yby8DGgWUxUy/AywfQJDI=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=wiMQE35QSyOsxjU7g/nBZIooaSk7BZmfU536lJTSG5SMYGataLqTJ08eKbcQmUE9F7Lr/BPLCyAH8LNrese+oZfRat06o/BQMKvlFwncnY6feSyMUlqF+1MzNuDkKncqO12/0/2mb+xTWTQvuuKOuG/8IETM6+uQq0AMR/Lw6UI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from hawking.nue2.suse.org (unknown [10.168.4.11]) by smtp-out1.suse.de (Postfix) with ESMTP id 9903A21204; Wed, 14 May 2025 11:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747223362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=/l4FWYHLPU7R8j9/ta+2PonQTQfhCfJui6ob48jeX0s=; b=wvo5sV6TPnTFUNX/pFxv2sGsLvss5aT4bB8nJEYdQbfEEw4uQUbpFf1kn36j7IsYxhj8Rk MOgtTRecDoMo3DdYoGml7A0nBDS4RSNdQzEhpqJJNBEoPTmUbkpjqLNmp5OOm7pSGfeo+1 Cu2A842cDOm3rVSbWvMLoV+QldA9QSw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747223362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=/l4FWYHLPU7R8j9/ta+2PonQTQfhCfJui6ob48jeX0s=; b=ciSXgp83R6C29/i5EXlwucDXwAZvBH68fwTiQiBq3q0J4fR4gxlP7e6bOsf4Y49Bw2AYiw u8cnHjb3GjKmMbAg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1747223362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=/l4FWYHLPU7R8j9/ta+2PonQTQfhCfJui6ob48jeX0s=; b=wvo5sV6TPnTFUNX/pFxv2sGsLvss5aT4bB8nJEYdQbfEEw4uQUbpFf1kn36j7IsYxhj8Rk MOgtTRecDoMo3DdYoGml7A0nBDS4RSNdQzEhpqJJNBEoPTmUbkpjqLNmp5OOm7pSGfeo+1 Cu2A842cDOm3rVSbWvMLoV+QldA9QSw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1747223362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=/l4FWYHLPU7R8j9/ta+2PonQTQfhCfJui6ob48jeX0s=; b=ciSXgp83R6C29/i5EXlwucDXwAZvBH68fwTiQiBq3q0J4fR4gxlP7e6bOsf4Y49Bw2AYiw u8cnHjb3GjKmMbAg== Received: by hawking.nue2.suse.org (Postfix, from userid 17005) id 8A27E4A038E; Wed, 14 May 2025 13:49:22 +0200 (CEST) From: Andreas Schwab To: gdb-patches@sourceware.org Subject: [PATCH] libiberty: sync with gcc CC: binutils@sourceware.org Date: Wed, 14 May 2025 13:49:22 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spamd-Result: default: False [-4.20 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; RCPT_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Import the following commits from GCC as of r16-614-g9d039eff453f77: 31dd621796f libiberty: add ldirname function f3d07779fdb libiberty: Append to AC_CHECK_DECLS [PR119218]. 90183362524 libiberty, gcc: Add memrchr to libiberty and use it [PR119283]. 43717ee9064 libiberty: Fix off-by-one when collecting range expression In addition, rename uses of ldirname in ld and gdb to fix conflicts. ld/: * ldlang.c (stat_ldirname): Rename from ldirname, all uses changed. --- gdb/darwin-nat.c | 2 +- gdb/dwarf2/dwz.c | 2 +- gdb/dwarf2/read.c | 6 +-- gdb/python/python.c | 2 +- gdb/symtab.c | 2 +- gdb/utils.c | 2 +- gdb/utils.h | 2 +- gdb/xml-syscall.c | 2 +- gdb/xml-tdesc.c | 2 +- include/libiberty.h | 22 ++++++++++ ld/ldlang.c | 4 +- libiberty/ChangeLog | 41 ++++++++++++++++++ libiberty/Makefile.in | 31 ++++++++++--- libiberty/config.in | 6 +++ libiberty/configure | 17 +++++--- libiberty/configure.ac | 14 ++++-- libiberty/configure.com | 2 +- libiberty/functions.texi | 14 ++++++ libiberty/ldirname.c | 94 ++++++++++++++++++++++++++++++++++++++++ libiberty/makefile.vms | 2 +- libiberty/memrchr.c | 33 ++++++++++++++ libiberty/regex.c | 2 +- 22 files changed, 274 insertions(+), 30 deletions(-) create mode 100644 libiberty/ldirname.c create mode 100644 libiberty/memrchr.c diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 6bc0e4f8e7a..ffbf949fe79 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -1853,7 +1853,7 @@ copy_shell_to_cache (const char *shell, const std::string &new_name) error (_("Could not open shell (%s) for reading: %s"), shell, safe_strerror (errno)); - std::string new_dir = ldirname (new_name.c_str ()); + std::string new_dir = gdb_ldirname (new_name.c_str ()); if (!mkdir_recursive (new_dir.c_str ())) error (_("Could not make cache directory \"%s\": %s"), new_dir.c_str (), safe_strerror (errno)); diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index 59fe8e4886b..1aa0d035d22 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -343,7 +343,7 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile) { gdb::unique_xmalloc_ptr abs = gdb_realpath (per_bfd->filename ()); - filename = ldirname (abs.get ()) + SLASH_STRING + filename; + filename = gdb_ldirname (abs.get ()) + SLASH_STRING + filename; } /* First try the file name given in the section. If that doesn't diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 891e10f6e81..75e13159c64 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -5859,7 +5859,7 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) && res.get_name () != nullptr && IS_ABSOLUTE_PATH (res.get_name ())) { - res.set_comp_dir (ldirname (res.get_name ())); + res.set_comp_dir (gdb_ldirname (res.get_name ())); res.set_name (make_unique_xstrdup (lbasename (res.get_name ()))); } @@ -7434,7 +7434,7 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp, search_path = per_bfd->captured_debug_dir.c_str (); /* Add the path for the executable binary to the list of search paths. */ - std::string objfile_dir = ldirname (per_bfd->filename ()); + std::string objfile_dir = gdb_ldirname (per_bfd->filename ()); search_path_holder.reset (concat (objfile_dir.c_str (), dirname_separator_string, search_path, nullptr)); @@ -7807,7 +7807,7 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile) struct objfile *backlink = objfile->separate_debug_objfile_backlink; const char *backlink_basename = lbasename (backlink->original_name); - dwp_name = ldirname (objfile->original_name) + SLASH_STRING + backlink_basename; + dwp_name = gdb_ldirname (objfile->original_name) + SLASH_STRING + backlink_basename; } else dwp_name = objfile->original_name; diff --git a/gdb/python/python.c b/gdb/python/python.c index 24cb511c3d5..7c3d0d104b5 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2446,7 +2446,7 @@ py_initialize () /foo/lib/pythonX.Y/... This must be done before calling Py_Initialize. */ gdb::unique_xmalloc_ptr progname - (concat (ldirname (python_libdir.c_str ()).c_str (), SLASH_STRING, "bin", + (concat (gdb_ldirname (python_libdir.c_str ()).c_str (), SLASH_STRING, "bin", SLASH_STRING, "python", (char *) NULL)); { diff --git a/gdb/symtab.c b/gdb/symtab.c index 5147aee55d5..5e347386be2 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4499,7 +4499,7 @@ info_sources_filter::matches (const char *fullname) const switch (m_match_type) { case match_on::DIRNAME: - dirname = ldirname (fullname); + dirname = gdb_ldirname (fullname); to_match = dirname.c_str (); break; case match_on::BASENAME: diff --git a/gdb/utils.c b/gdb/utils.c index 7b0c8127583..8d9f0033225 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3333,7 +3333,7 @@ gdb_argv_as_array_view_test () argument. */ std::string -ldirname (const char *filename) +gdb_ldirname (const char *filename) { std::string dirname; const char *base = lbasename (filename); diff --git a/gdb/utils.h b/gdb/utils.h index a8834cf4bc2..b37e8f7d7a1 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -133,7 +133,7 @@ struct set_batch_flag_and_restore_page_info extern int gdb_filename_fnmatch (const char *pattern, const char *string, int flags); -std::string ldirname (const char *filename); +std::string gdb_ldirname (const char *filename); extern int count_path_elements (const char *path); diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c index fe0ea2b75a0..b58fe5d0d2f 100644 --- a/gdb/xml-syscall.c +++ b/gdb/xml-syscall.c @@ -319,7 +319,7 @@ xml_init_syscalls_info (const char *filename) if (!full_file) return NULL; - const std::string dirname = ldirname (filename); + const std::string dirname = gdb_ldirname (filename); auto fetch_another = [&dirname] (const char *name) { return xml_fetch_content_from_file (name, dirname.c_str ()); diff --git a/gdb/xml-tdesc.c b/gdb/xml-tdesc.c index 6c095afa699..2f213dc973d 100644 --- a/gdb/xml-tdesc.c +++ b/gdb/xml-tdesc.c @@ -670,7 +670,7 @@ file_read_description_xml (const char *filename) return NULL; } - const std::string dirname = ldirname (filename); + const std::string dirname = gdb_ldirname (filename); auto fetch_another = [&dirname] (const char *name) { return xml_fetch_content_from_file (name, dirname.c_str ()); diff --git a/include/libiberty.h b/include/libiberty.h index e39f1870cb7..b88eb643aa3 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -133,6 +133,18 @@ extern const char *dos_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIB extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1); +/* A dirname () that is always compiled in. */ + +extern char *ldirname (const char *) ATTRIBUTE_NONNULL(1); + +/* Same, but assumes DOS semantics regardless of host. */ + +extern char *dos_ldirname (const char *) ATTRIBUTE_NONNULL(1); + +/* Same, but assumes Unix semantics regardless of host. */ + +extern char *unix_ldirname (const char *) ATTRIBUTE_NONNULL(1); + /* A well-defined realpath () that is always compiled in. */ extern char *lrealpath (const char *); @@ -199,6 +211,16 @@ extern int fdmatch (int fd1, int fd2); extern int ffs(int); #endif +#if defined (HAVE_DECL_MKSTEMPS) && !HAVE_DECL_MKSTEMPS +extern int mkstemps(char *, int); +#endif + +/* Make memrchr available on systems that do not have it. */ +#if !defined (__GNU_LIBRARY__ ) && !defined (__linux__) && \ + !defined (HAVE_MEMRCHR) +extern void *memrchr(const void *, int, size_t); +#endif + /* Get the working directory. The result is cached, so don't call chdir() between calls to getpwd(). */ diff --git a/ld/ldlang.c b/ld/ldlang.c index e0368171fa9..32e6e7abdf1 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -322,7 +322,7 @@ spec_match (const struct wildcard_spec *spec, const char *name) } static char * -ldirname (const char *name) +stat_ldirname (const char *name) { const char *base = lbasename (name); @@ -1266,7 +1266,7 @@ new_afile (const char *name, /* If name is a relative path, search the directory of the current linker script first. */ if (from_filename && !IS_ABSOLUTE_PATH (name)) - p->extra_search_path = ldirname (from_filename); + p->extra_search_path = stat_ldirname (from_filename); p->flags.real = true; p->flags.search_dirs = true; break; diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 83e9120c444..2ae5626ed2e 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,44 @@ +2025-05-13 Andreas Schwab + + * regex.c (regex_compile): Don't write beyond array bounds when + collecting range expression. + +2025-03-29 Iain Sandoe + + PR cobol/119283 + * Makefile.in: Add memrchr build rules. + * config.in: Regenerate. + * configure: Regenerate. + * configure.ac: Check for memrchr. + * functions.texi: Document memrchr. + * memrchr.c: New file. + +2025-03-25 Iain Sandoe + + PR other/119218 + * config.in: Regenerate. + * configure: Regenerate. + * configure.ac: Append to AC_INCLUDES_DEFAULT + when checking for the 'basename' decl. + +2025-03-18 Jose E. Marchesi + + * ldirname.c: New file. + * Makefile.in (CFILES): Add ldirname.c. + (REQUIRED_OFILES): Add ldirname.$(objext). + (./ldirname.$(objext)): New rule. + * makefile.vms (OBJS): Add ldirname.obj. + * configure.com (FILES): Add ldirname. + +2024-12-11 Matthieu Longo + + * configure: Regenerate. + * configure.ac: Fix autoupdate warnings. + +2024-12-11 Sangamesh Mallayya + + * getopt.c: Remove _NO_PROTO block + 2024-11-19 Evgeny Karpov * simple-object-coff.c: Add aarch64. diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index b11df756b4b..387975daf58 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -136,10 +136,11 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \ hashtab.c hex.c \ index.c insque.c \ lbasename.c \ + ldirname.c \ lrealpath.c \ make-relative-prefix.c \ - make-temp-file.c md5.c memchr.c memcmp.c memcpy.c memmem.c \ - memmove.c mempcpy.c memset.c mkstemps.c \ + make-temp-file.c md5.c memchr.c memrchr.c memcmp.c memcpy.c \ + memmem.c memmove.c mempcpy.c memset.c mkstemps.c \ objalloc.c obstack.c \ partition.c pexecute.c \ pex-common.c pex-djgpp.c pex-msdos.c pex-one.c \ @@ -179,7 +180,7 @@ REQUIRED_OFILES = \ ./fnmatch.$(objext) ./fopen_unlocked.$(objext) \ ./getopt.$(objext) ./getopt1.$(objext) ./getpwd.$(objext) \ ./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \ - ./lbasename.$(objext) ./lrealpath.$(objext) \ + ./lbasename.$(objext) ./ldirname.$(objext) ./lrealpath.$(objext)\ ./make-relative-prefix.$(objext) ./make-temp-file.$(objext) \ ./objalloc.$(objext) \ ./obstack.$(objext) \ @@ -212,8 +213,8 @@ CONFIGURED_OFILES = ./asprintf.$(objext) ./atexit.$(objext) \ ./getcwd.$(objext) ./getpagesize.$(objext) \ ./gettimeofday.$(objext) \ ./index.$(objext) ./insque.$(objext) \ - ./memchr.$(objext) ./memcmp.$(objext) ./memcpy.$(objext) \ - ./memmem.$(objext) ./memmove.$(objext) \ + ./memchr.$(objext) ./memrchr.$(objext) ./memcmp.$(objext) \ + ./memcpy.$(objext) ./memmem.$(objext) ./memmove.$(objext) \ ./mempcpy.$(objext) ./memset.$(objext) ./mkstemps.$(objext) \ ./pex-djgpp.$(objext) ./pex-msdos.$(objext) \ ./pex-unix.$(objext) ./pex-win32.$(objext) \ @@ -966,6 +967,17 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir else true; fi $(COMPILE.c) $(srcdir)/lbasename.c $(OUTPUT_OPTION) +./ldirname.$(objext): $(srcdir)/ldirname.c config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/filenames.h $(INCDIR)/hashtab.h $(INCDIR)/libiberty.h \ + $(INCDIR)/safe-ctype.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/ldirname.c -o pic/$@; \ + else true; fi + if [ x"$(NOASANFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/ldirname.c -o noasan/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/ldirname.c $(OUTPUT_OPTION) + ./lrealpath.$(objext): $(srcdir)/lrealpath.c config.h $(INCDIR)/ansidecl.h \ $(INCDIR)/libiberty.h if [ x"$(PICFLAG)" != x ]; then \ @@ -1014,6 +1026,15 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir else true; fi $(COMPILE.c) $(srcdir)/memchr.c $(OUTPUT_OPTION) +./memrchr.$(objext): $(srcdir)/memrchr.c $(INCDIR)/ansidecl.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/memrchr.c -o pic/$@; \ + else true; fi + if [ x"$(NOASANFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/memrchr.c -o noasan/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/memrchr.c $(OUTPUT_OPTION) + ./memcmp.$(objext): $(srcdir)/memcmp.c $(INCDIR)/ansidecl.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/memcmp.c -o pic/$@; \ diff --git a/libiberty/config.in b/libiberty/config.in index 1b1f2b09a8a..3b8716511f0 100644 --- a/libiberty/config.in +++ b/libiberty/config.in @@ -153,6 +153,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_LIBGEN_H + /* Define to 1 if you have the header file. */ #undef HAVE_LIMITS_H @@ -183,6 +186,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the `memrchr' function. */ +#undef HAVE_MEMRCHR + /* Define to 1 if you have the `memset' function. */ #undef HAVE_MEMSET diff --git a/libiberty/configure b/libiberty/configure index f83b42fb0d5..f0309ff78ad 100755 --- a/libiberty/configure +++ b/libiberty/configure @@ -5745,7 +5745,7 @@ host_makefile_frag=${frag} # It's OK to check for header files. Although the compiler may not be # able to link anything, it had better be able to at least compile # something. -for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h +for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h libgen.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_preproc "$LINENO" "$ac_header" "$as_ac_Header" @@ -6210,6 +6210,7 @@ funcs="$funcs gettimeofday" funcs="$funcs index" funcs="$funcs insque" funcs="$funcs memchr" +funcs="$funcs memrchr" funcs="$funcs memcmp" funcs="$funcs memcpy" funcs="$funcs memmem" @@ -6276,7 +6277,7 @@ if test "x" = "y"; then ffs __fsetlocking \ getcwd getpagesize getrlimit getrusage getsysinfo gettimeofday \ index insque \ - memchr memcmp memcpy memmem memmove memset mkstemps \ + memchr memrchr memcmp memcpy memmem memmove memset mkstemps \ on_exit \ pipe2 posix_spawn posix_spawnp psignal \ pstat_getdynamic pstat_getstatic putenv \ @@ -6691,7 +6692,7 @@ esac for f in atexit basename bcmp bcopy bsearch bzero calloc clock ffs \ getcwd getpagesize getrusage gettimeofday \ - index insque memchr memcmp memcpy memmove memset psignal \ + index insque memchr memrchr memcmp memcpy memmove memset psignal \ putenv random rename rindex sbrk setenv stpcpy strcasecmp \ strchr strdup strerror strncasecmp strrchr strstr strtod \ strtol strtoul sysconf times tmpnam vfprintf vprintf \ @@ -7389,7 +7390,12 @@ fi done as_ac_Symbol=`$as_echo "ac_cv_have_decl_basename(char *)" | $as_tr_sh` -ac_fn_c_check_decl "$LINENO" "basename(char *)" "$as_ac_Symbol" "$ac_includes_default" +ac_fn_c_check_decl "$LINENO" "basename(char *)" "$as_ac_Symbol" " +$ac_includes_default +#ifdef HAVE_LIBGEN_H +# include +#endif +" if eval test \"x\$"$as_ac_Symbol"\" = x"yes"; then : ac_have_decl=1 else @@ -7399,7 +7405,8 @@ fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_BASENAME $ac_have_decl _ACEOF -ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default" + + ac_fn_c_check_decl "$LINENO" "ffs" "ac_cv_have_decl_ffs" "$ac_includes_default" if test "x$ac_cv_have_decl_ffs" = xyes; then : ac_have_decl=1 else diff --git a/libiberty/configure.ac b/libiberty/configure.ac index c27e08e1428..3de5eca0df2 100644 --- a/libiberty/configure.ac +++ b/libiberty/configure.ac @@ -291,7 +291,7 @@ AC_SUBST_FILE(host_makefile_frag) # It's OK to check for header files. Although the compiler may not be # able to link anything, it had better be able to at least compile # something. -AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h) +AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h process.h sys/prctl.h spawn.h libgen.h) AC_HEADER_SYS_WAIT AC_HEADER_TIME @@ -370,6 +370,7 @@ funcs="$funcs gettimeofday" funcs="$funcs index" funcs="$funcs insque" funcs="$funcs memchr" +funcs="$funcs memrchr" funcs="$funcs memcmp" funcs="$funcs memcpy" funcs="$funcs memmem" @@ -436,7 +437,7 @@ if test "x" = "y"; then ffs __fsetlocking \ getcwd getpagesize getrlimit getrusage getsysinfo gettimeofday \ index insque \ - memchr memcmp memcpy memmem memmove memset mkstemps \ + memchr memrchr memcmp memcpy memmem memmove memset mkstemps \ on_exit \ pipe2 posix_spawn posix_spawnp psignal \ pstat_getdynamic pstat_getstatic putenv \ @@ -555,7 +556,7 @@ if test -n "${with_target_subdir}"; then for f in atexit basename bcmp bcopy bsearch bzero calloc clock ffs \ getcwd getpagesize getrusage gettimeofday \ - index insque memchr memcmp memcpy memmove memset psignal \ + index insque memchr memrchr memcmp memcpy memmove memset psignal \ putenv random rename rindex sbrk setenv stpcpy strcasecmp \ strchr strdup strerror strncasecmp strrchr strstr strtod \ strtol strtoul sysconf times tmpnam vfprintf vprintf \ @@ -723,7 +724,12 @@ if test -z "${setobjs}"; then [AC_MSG_RESULT([no])]) AC_CHECK_FUNCS($checkfuncs) - AC_CHECK_DECLS([basename(char *), ffs, asprintf, vasprintf, snprintf, vsnprintf]) + AC_CHECK_DECLS([basename(char *)], [], [], [ +AC_INCLUDES_DEFAULT +#ifdef HAVE_LIBGEN_H +# include +#endif]) + AC_CHECK_DECLS([ffs, asprintf, vasprintf, snprintf, vsnprintf]) AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc]) case "${host}" in *-*-darwin*) ;; # Darwin's sbrk implementation is deprecated. diff --git a/libiberty/configure.com b/libiberty/configure.com index 030182914f7..55aee2f78f9 100644 --- a/libiberty/configure.com +++ b/libiberty/configure.com @@ -17,7 +17,7 @@ $DECK $ FILES="getopt,obstack,xexit,xmalloc,hex,getopt1,cplus-dem,cp-demangle,"+- "cp-demint,asprintf,vasprintf,mkstemps,concat,getruntime,getpagesize,"+- "getpwd,xstrerror,xmemdup,xstrdup,xatexit,choose-temp,fnmatch,objalloc,"+- - "safe-ctype,hashtab,lbasename,argv,lrealpath,make-temp-file,"+- + "safe-ctype,hashtab,lbasename,ldirname,argv,lrealpath,make-temp-file,"+- "stpcpy,unlink-if-ordinary" $ OPT="/noopt/debug/warnings=disable=(missingreturn)" $ CFLAGS=OPT + "/include=([],[-.include])/name=(as_is,shortened)" +- diff --git a/libiberty/functions.texi b/libiberty/functions.texi index b56b02e0686..7c7da1ba296 100644 --- a/libiberty/functions.texi +++ b/libiberty/functions.texi @@ -749,6 +749,20 @@ returned. @end deftypefn +@c memrchr.c:3 +@deftypefn Supplemental void* memrchr (const void *@var{s}, int @var{c}, @ + size_t @var{n}) + +This function searches memory for the character @var{c} in reverse order, +starting at @code{*@var{s}+@var{n}-1} . The search only ends with +the first occurrence of @var{c}, or when the start us reached; in particular, +a null character does not terminate the search. If the character @var{c} is +found within @var{length} characters of @code{*@var{s}}, a pointer +to the character is returned. If @var{c} is not found, then @code{NULL} is +returned. + +@end deftypefn + @c memcmp.c:6 @deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, @ size_t @var{count}) diff --git a/libiberty/ldirname.c b/libiberty/ldirname.c new file mode 100644 index 00000000000..e3cd5c816c1 --- /dev/null +++ b/libiberty/ldirname.c @@ -0,0 +1,94 @@ +/* Libiberty dirname. Like dirname, but is not overridden by the + system C library. + Copyright (C) 2025 Free Software Foundation, Inc. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + +/* + +@deftypefn Replacement {char*} ldirname (const char *@var{name}) + +Given a pointer to a string containing a typical pathname +(@samp{/usr/src/cmd/ls/ls.c} for example), returns a string containing the +passed string up to, but not including, the final directory separator. + +If the given pathname doesn't contain a directory separator then this funtion +returns the empty string; this includes an empty given pathname. @code{NULL} +is returned on memory allocation error. + +@end deftypefn + +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "ansidecl.h" +#include "libiberty.h" +#include "safe-ctype.h" +#include "filenames.h" + +/* For malloc. */ +#ifdef HAVE_STDLIB_H +#include +#endif + +/* For memcpy. */ +# if HAVE_STRING_H +# include +# else +# if HAVE_STRINGS_H +# include +# endif +# endif + +#define LDIRNAME(FPREFIX,DIRSEP) \ + char *FPREFIX##_ldirname (const char *name) \ + { \ + /* Note that lbasename guarantees that the returned */ \ + /* pointer lies within the passed string. */ \ + const char *basename = FPREFIX##_lbasename (name); \ + size_t size = basename - name; \ + char *res = NULL; \ + \ + res = (char*) malloc (size + 1); \ + if (res != NULL) \ + { \ + if (size > 0) \ + { \ + if (IS_DIR_SEPARATOR_1 ((DIRSEP),name[size - 1])) \ + size -= 1; \ + memcpy (res, name, size); \ + } \ + res[size] = '\0'; \ + } \ + \ + return res; \ + } + +LDIRNAME(dos,1) +LDIRNAME(unix,0) + +char * +ldirname (const char *name) +{ +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) + return dos_ldirname (name); +#else + return unix_ldirname (name); +#endif +} diff --git a/libiberty/makefile.vms b/libiberty/makefile.vms index 15a7d0a206b..4cfcc986f66 100644 --- a/libiberty/makefile.vms +++ b/libiberty/makefile.vms @@ -12,7 +12,7 @@ OBJS=getopt.obj,obstack.obj,xexit.obj,xmalloc.obj,hex.obj,\ asprintf.obj vasprintf.obj,mkstemps.obj,filename_cmp.obj,\ concat.obj,getruntime.obj,getpagesize.obj,getpwd.obj,xstrerror.obj,\ xmemdup.obj,xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,\ - objalloc.obj,safe-ctype.obj,hashtab.obj,lbasename.obj,argv.obj,\ + objalloc.obj,safe-ctype.obj,hashtab.obj,lbasename.obj,ldirname.obj,argv.obj,\ lrealpath.obj,make-temp-file.obj,stpcpy.obj,unlink-if-ordinary.obj,\ dwarfnames.obj diff --git a/libiberty/memrchr.c b/libiberty/memrchr.c new file mode 100644 index 00000000000..fe7713ecce5 --- /dev/null +++ b/libiberty/memrchr.c @@ -0,0 +1,33 @@ +/* + +@deftypefn Supplemental void* memrchr (const void *@var{s}, int @var{c}, @ + size_t @var{n}) + +This function searches memory for the character @var{c} in reverse order, +starting at @code{*@var{s}+@var{n}-1} . The search only ends with +the first occurrence of @var{c}, or when the start us reached; in particular, +a null character does not terminate the search. If the character @var{c} is +found within @var{length} characters of @code{*@var{s}}, a pointer +to the character is returned. If @var{c} is not found, then @code{NULL} is +returned. + +@end deftypefn + +*/ + +#include +#include + +void * +memrchr (const void *src_void, int c, size_t length) +{ + if (length == 0) + return NULL; + + const unsigned char *p = (const unsigned char*)src_void; + p += length; + while (*--p != (unsigned char)c) + if (src_void == p) + return NULL; + return (void *)p; +} diff --git a/libiberty/regex.c b/libiberty/regex.c index bc36f43d450..8337deaef5a 100644 --- a/libiberty/regex.c +++ b/libiberty/regex.c @@ -3468,7 +3468,7 @@ PREFIX(regex_compile) (const char *ARG_PREFIX(pattern), PATFETCH (c); if ((c == '.' && *p == ']') || p == pend) break; - if (c1 < sizeof (str)) + if (c1 < sizeof (str) - 1) str[c1++] = c; else /* This is in any case an invalid class name. */ -- 2.49.0 -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."