[PATCH] libiberty, include: add bsearch_r

2020-01-10 Thread Nick Alcock
libctf wants a bsearch that takes a void * arg pointer to avoid a
nonportable use of __thread.

bsearch_r is required, not optional, at this point because as far as I
can see this obvious-sounding function is not implemented by anyone's
libc.  We can easily move it to AC_LIBOBJ later if it proves necessary
to do so.

include/
* libiberty.h (bsearch_r): New.
libiberty/
* bsearch_r.c: New file.
* Makefile.in (CFILES): Add bsearch_r.c.
(REQUIRED_OFILES): Add bsearch_r.o.
* functions.texi: Regenerate.
---
 include/libiberty.h  |  7 +++
 libiberty/Makefile.in| 12 +-
 libiberty/bsearch_r.c| 93 
 libiberty/functions.texi | 17 
 4 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 libiberty/bsearch_r.c

diff --git a/include/libiberty.h b/include/libiberty.h
index 141cb886a85..0bb5b81d4ac 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -641,6 +641,13 @@ extern int pexecute (const char *, char * const *, const 
char *,
 
 extern int pwait (int, int *, int);
 
+/* Like bsearch, but takes and passes on an argument like qsort_r.  */
+
+extern void *bsearch_r (register const void *, const void *,
+   size_t, register size_t,
+   register int (*)(const void *, const void *, void *),
+   void *);
+
 #if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
 /* Like sprintf but provides a pointer to malloc'd storage, which must
be freed by the caller.  */
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index fe738d0db43..53d522d4090 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -123,7 +123,7 @@ COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. 
-I$(INCDIR) \
 # CONFIGURED_OFILES and funcs in configure.ac.  Also run "make maint-deps"
 # to build the new rules.
 CFILES = alloca.c argv.c asprintf.c atexit.c   \
-   basename.c bcmp.c bcopy.c bsearch.c bzero.c \
+   basename.c bcmp.c bcopy.c bsearch.c bsearch_r.c bzero.c \
calloc.c choose-temp.c clock.c concat.c cp-demangle.c   \
 cp-demint.c cplus-dem.c crc32.c\
d-demangle.c dwarfnames.c dyn-string.c  \
@@ -167,6 +167,7 @@ REQUIRED_OFILES =   
\
./regex.$(objext) ./cplus-dem.$(objext) ./cp-demangle.$(objext) \
./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext) \
./argv.$(objext)\
+   ./bsearch_r.$(objext)   \
./choose-temp.$(objext) ./concat.$(objext)  \
./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext)  \
./dwarfnames.$(objext) ./dyn-string.$(objext)   \
@@ -598,6 +599,15 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
else true; fi
$(COMPILE.c) $(srcdir)/bsearch.c $(OUTPUT_OPTION)
 
+./bsearch_r.$(objext): $(srcdir)/bsearch_r.c config.h $(INCDIR)/ansidecl.h
+   if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/bsearch_r.c -o pic/$@; \
+   else true; fi
+   if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/bsearch_r.c -o 
noasan/$@; \
+   else true; fi
+   $(COMPILE.c) $(srcdir)/bsearch_r.c $(OUTPUT_OPTION)
+
 ./bzero.$(objext): $(srcdir)/bzero.c
if [ x"$(PICFLAG)" != x ]; then \
  $(COMPILE.c) $(PICFLAG) $(srcdir)/bzero.c -o pic/$@; \
diff --git a/libiberty/bsearch_r.c b/libiberty/bsearch_r.c
new file mode 100644
index 000..79ebae9b0be
--- /dev/null
+++ b/libiberty/bsearch_r.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. [rescinded 22 July 1999]
+ * 4. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 

Re: Type representation in CTF and DWARF

2019-10-15 Thread Nick Alcock
On 9 Oct 2019, Indu Bhagat told this:

> Yes, CTF does not support C++ at this time. To cover all of C (including
> GNU C extensions), we need to add representation for things like Vector type,
> non IEEE float etc. (somewhat infrequently occurring constructs)

One note: adding C++ support will not make the representation of CTF for
C any larger, because I plan to do as DWARF does and have a language tag
in the header, and only support one language per CTF dictionary[1].  The
type section format will otherwise be completely distinct between the
two languages, specifically in order that the C side of things not pay
the price for the (necessarily richer) C++ type representation. This is
very much a C++ thing: don't pay for what you don't use :)

So there's no need to worry that adding C++ support will make any C
compactness figures worse. You only need to consider that the C++ CTF
representation may not be able to be as compact as the C representation
-- and even there I hope to come close.

[1! though there is a possibility of having a C++ dictionary cite types
from a C one, allowing some sharing: this is all format v5 stuff,
i.e. two format revs away, and this bit in particular is not yet
designed, but feels possible.)


Re: Type representation in CTF and DWARF

2019-10-17 Thread Nick Alcock
On 11 Oct 2019, Indu Bhagat stated:
> Compile with -g -gdwarf-like-ctf and use dwz -o   (using
> dwz compiled from the master branch) on the generated binaries:
>
> (coreutils-0.22)
>  .debug_info(D1) | .debug_abbrev(D2) | .debug_str(D4) | .ctf 
> (uncompressed) | ratio (.ctf/(D1+D2+0.5*D4))
> ls   30616   |1136   |21098   | 26240 
>   | 0.62
> pwd  10734   |788|10433   | 13929 
>   | 0.83
> groups 10706 |811|10249   | 13378 
>   | 0.80
>
> (emacs-26.3)
>  .debug_info(D1) | .debug_abbrev(D2) | .debug_str(D4) | .ctf 
> (uncompressed) | ratio (.ctf/(D1+D2+0.5*D4))
> emacs-26.3.1 674657  |6402   |   273963   |   273910  
>   | 0.33

A side note here: the sizes given above are uncompressed sizes, but in
the real world CTF is almost always compressed: the threshold for
compression is in theory customizable but at the moment is hardwired at
4KiB-uncompressed in the linker. I usually see compression ratios of
roughly 3 or 4 to 1: e.g. I just tried it with a randomly chosen binary,
/usr/lib/libgtk-3.so.0.2404.3, and got these sizes:

.text: 3317489
DWARF: 8589254
Uncompressed CTF (*no* ELF strtab sharing, so a bit bigger than usual): 713264
.ctf section size: 213839

Note that this is not only in the absence of CTF strtab sharing with the
ELF dynstrtab, but also using a less effective compressor: currently we
use gzip, but I expect to transition to lzma iff available at binutils
build time (which it usually is), perhaps as an option (on by default)
to allow interoperability with binutils that don't have lzma available.
Obviously better compressors will save even more space.

It may help that CTF is designed for good compressibility: we try to
minimize the number of unique symbols if we can do so without impairing
other properties, e.g. by avoiding encoding IDs of objects when we can
instead rely on the consumer to compute them at read time by walking
through the relevant data structures and counting.

A few benchamrks indicate that compression by default also saves time
both at compression and decompression time. 

(Within a week I should be able to repeat this with an ld capable of CTF
deduplication rather than kludging it with a deduplicator meant for a
quite different job. I expect the sizes above to improve. In fact if
they *don't* improve I will take this as strong evidence that my
deduplicator is buggy.)


FWIW, here's my Emacs (26.1.50) sizes, again with no strtab sharing, but
with deduplication: it's bigger than I'd like at around 10% of .text
size, but still much less than 1% of binary size (my goal is 1--2% of
.text, but Emacs is a nice tricky case, like Gtk, with lots of big types
and structures with long member names):

section  size  addr
.interp28   4194872
.note.ABI-tag  32   4194900
.note.gnu.build-id 36   4194932
.gnu.hash 628   4194968
.dynsym 24432   4195600
.dynstr 16934   4220032
.gnu.version 2036   4236966
.gnu.version_r704   4239008
.rela.data.rel.ro  72   4239712
.rela.data168   4239784
.rela.got  48   4239952
.rela,bss 336   424
.rela.plt   23448   4240336
.init  23   4263784
.plt15648   4263808
.text 1912622   4279456
.fini   9   6192080
.rodata165416   6192096
.eh_frame_hdr   36196   6357512
.eh_frame  210976   6393712
.init_array 8   6609328
.fini_array 8   6609336
.data.rel.ro 4569   6609344
.dynamic 1104   6613920
.got   16   6615024
.got.plt 7840   6615040
.data 3276077   6622880
,bss 34153472   9899008
.comment   26 0
.gnu_debuglink 24 0
.comment   26 0
.debug_aranges   1536 0
.debug_info   3912261 0
.debug_abbrev   38821 0
.debug_line408063 0
.debug_str 117631 0
.debug_loc 954538 0
.debug_ranges  149590 0
.ctf   213839 0
.ctf (uncompressed)713264 0

(obviously, manually edited a bit, size -A doesn't produce the last line
on its own!)

(I'm not sure what the hell is going on with the weirdly-named ,bss
section. Probably something to do with unexec().)


Re: Type representation in CTF and DWARF

2019-10-17 Thread Nick Alcock
On 17 Oct 2019, Richard Biener verbalised:

> On Thu, Oct 17, 2019 at 7:36 PM Nick Alcock  wrote:
>>
>> On 11 Oct 2019, Indu Bhagat stated:
>> > Compile with -g -gdwarf-like-ctf and use dwz -o   
>> > (using
>> > dwz compiled from the master branch) on the generated binaries:
>> >
>> > (coreutils-0.22)
>> >  .debug_info(D1) | .debug_abbrev(D2) | .debug_str(D4) | .ctf 
>> > (uncompressed) | ratio (.ctf/(D1+D2+0.5*D4))
>> > ls   30616   |1136   |21098   | 26240  
>> >  | 0.62
>> > pwd  10734   |788|10433   | 13929  
>> >  | 0.83
>> > groups 10706 |811|10249   | 13378  
>> >  | 0.80
>> >
>> > (emacs-26.3)
>> >  .debug_info(D1) | .debug_abbrev(D2) | .debug_str(D4) | .ctf 
>> > (uncompressed) | ratio (.ctf/(D1+D2+0.5*D4))
>> > emacs-26.3.1 674657  |6402   |   273963   |   273910   
>> >  | 0.33
>
> Btw, for a fair comparison you have to remove all DW_TAG_subroutine
> children as well since CTF doesn't represent scopes or local variables
> at all (nor types only used by locals). It seems CTF only represents
> function entry points.

Good point: I'll have to hack up a DWARF trimmer to do this comparison
properly, I think. (Though CTF does represent global variables,
including file-scope statics.)

In most cases local types etc are a fairly small contributor to the
total volume -- but macros can contribute a lot in some codebases. (The
Linux kernel's READ_ONCE macro is one I've personally been bitten by in
the past, with a new local struct in every use. GCC doesn't deduplicate
any of those so the resulting bloat from tens of thousands of instances
of this identical structure is quite incredible...)


Re: Type representation in CTF and DWARF

2019-10-18 Thread Nick Alcock
On 18 Oct 2019, Pedro Alves stated:

> On 10/18/19 2:21 PM, Richard Biener wrote:
>
 In most cases local types etc are a fairly small contributor to the
 total volume -- but macros can contribute a lot in some codebases.
>>> (The
 Linux kernel's READ_ONCE macro is one I've personally been bitten by
>>> in
 the past, with a new local struct in every use. GCC doesn't
>>> deduplicate
 any of those so the resulting bloat from tens of thousands of
>>> instances
 of this identical structure is quite incredible...)

>>>
>>> Sounds like something that would be beneficial to do with DWARF too.
>> 
>> Otoh those are distinct types according to the C standard and since dwarf is 
>> a source level representation we should preserve this (source locations also 
>> differ). 
>
> Right.  Maybe some partial deduplication would be possible, preserving
> type distinction.  But since CTF doesn't include these, this is moot
> for now.

Yeah, the libctf API and existing CTF users only care if they're
assignment-compatible, which they are. We could preserve more
type-identity information if there was a need to do so, but none has yet
emerged.

-- 
NULL && (void)


Re: [PATCH 14/24] libtool.m4: fix nm BSD flag detection

2023-08-07 Thread Nick Alcock via Gcc-patches
On 7 Aug 2023, Jeff Law uttered the following:

> On 8/7/23 04:32, Arsen Arsenović via Gcc-patches wrote:
>> From: Nick Alcock 
>> Libtool needs to get BSD-format (or MS-format) output out of the system
>> nm, so that it can scan generated object files for symbol names for
>> -export-symbols-regex support.  Some nms need specific flags to turn on
>> BSD-formatted output, so libtool checks for this in its AC_PATH_NM.
>> Unfortunately the code to do this has a pair of interlocking flaws:
[...]
>> zlib/ChangeLog:
>>  * configure: Regenerate.
> OK.  This is probably a prereq for the other NM patch I just ack'd.

It is.

-- 
NULL && (void)


[PATCH] config: check for sighandler_t properly

2021-01-22 Thread Nick Alcock via Gcc-patches
Searching for sighander_t is unlikely to succeed anywhere.

The attempt to #include  is also not working,
and fixing it shows that doing an AC_DEFINE in the body of
an AC_CHECK_TYPE like that is also risky: both fixed.

(The purpose of this check is opaque to me: neither libcody
nor GCC ever includes , and though  is
widely included, it is not directly included by any of the
headers checking this macro...  for now I've fixed things
to conform to the comment, but perhaps we should be checking
the non-deprecated  instead, and #including it
in mapper-client.h?)

Cc: Nathan Sidwell 

gcc/
* configure.ac: Fix sighander_t typo and move AC_DEFINE
out of AC_CHECK_TYPE.
* configure: Regenerated.
---
 gcc/configure| 14 +-
 gcc/configure.ac |  8 +---
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 41641c64395..fa07a1b67b0 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -10435,16 +10435,20 @@ _ACEOF
 
 fi
 
-ac_fn_cxx_check_type "$LINENO" "sighander_t" "ac_cv_type_sighander_t" "signal.h
+ac_fn_cxx_check_type "$LINENO" "sighandler_t" "ac_cv_type_sighandler_t" 
"#include 
 "
-if test "x$ac_cv_type_sighander_t" = xyes; then :
+if test "x$ac_cv_type_sighandler_t" = xyes; then :
+
+fi
+
+
+if test x$ac_cv_type_sighandler_t; then
 
 $as_echo "#define HAVE_SIGHANDLER_T 1" >>confdefs.h
 
 fi
 
 
-
 ac_fn_cxx_check_header_preproc "$LINENO" "sys/mman.h" "ac_cv_header_sys_mman_h"
 if test "x$ac_cv_header_sys_mman_h" = xyes; then :
   gcc_header_sys_mman_h=yes
@@ -19392,7 +19396,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19405 "configure"
+#line 19399 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19498,7 +19502,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19511 "configure"
+#line 19505 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index ff4d3dc078b..66eef665431 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1491,10 +1491,12 @@ fi
 
 AC_CHECK_TYPE(ssize_t, int)
 AC_CHECK_TYPE(caddr_t, char *)
-AC_CHECK_TYPE(sighander_t,
+AC_CHECK_TYPE(sighandler_t, [], [], [[#include ]])
+
+if test x$ac_cv_type_sighandler_t; then
   AC_DEFINE(HAVE_SIGHANDLER_T, 1,
-[Define if  defines sighandler_t]),
-,signal.h)
+   [Define if  defines sighandler_t])
+fi
 
 GCC_AC_FUNC_MMAP_BLACKLIST
 
-- 
2.30.0.252.gc27e85e57d



Re: [PATCH] config: check for sighandler_t properly

2021-01-25 Thread Nick Alcock via Gcc-patches
On 25 Jan 2021, Nathan Sidwell uttered the following:

> On 1/22/21 12:19 PM, Nick Alcock wrote:
>> Searching for sighander_t is unlikely to succeed anywhere.
>>
>> The attempt to #include  is also not working,
>> and fixing it shows that doing an AC_DEFINE in the body of
>> an AC_CHECK_TYPE like that is also risky: both fixed.
>>
>> (The purpose of this check is opaque to me: neither libcody
>> nor GCC ever includes , and though  is
>> widely included, it is not directly included by any of the
>> headers checking this macro...  for now I've fixed things
>> to conform to the comment, but perhaps we should be checking
>> the non-deprecated  instead, and #including it
>> in mapper-client.h?)
>
> Thanks for noticint this.  I think this is left over from earlier 
> module-mapper predating its move (and changes) to c++tools.  If
> you'd like to remove that entire bit of configure.ac, that'd be great (or I 
> can do so, if you don't have time)

The sig_handler_t does appear to be still used, albeit not much: it's
used by mapper-client.h for the module_client::sigpipe declaration,
which is then used by the module mapper, which does appear to be still
used from elsewhere in module.c.

I'm not sure how redundant that makes it...


[PATCH] ld: depend on libctf

2021-01-26 Thread Nick Alcock via Gcc-patches
Since ld may depend on libctf (if present), and libctf may be relinked
by the installation process, libctf must be installed before ld is,
or the relink may fail if it calls on symbols or symbol versions that do
not exist in any libctf already present on the system.  (If none is
present, the copy in the build tree will be automatically used, but
if one *is* present, it may take precedence and break things.)

(This is a maybe- dependency, so it will work even if libctf is
disabled.)

ChangeLog
2021-01-26  Nick Alcock  

PR 27250
* Makefile.def: Add install-libctf dependency to install-ld.
* Makefile.in: Regenerated.
---
 Makefile.def | 1 +
 Makefile.in  | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

I'm probably going to put this into binutils directly, rather than via
a later cherry-pick, because this one breaks 'make install' and leaves
you with a broken system ld, so fixing it fast is quite important.

diff --git a/Makefile.def b/Makefile.def
index 3e38f61193f..607eac7fe3c 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -463,6 +463,7 @@ dependencies = { module=all-binutils; on=all-intl; };
 dependencies = { module=all-binutils; on=all-gas; };
 dependencies = { module=all-binutils; on=all-libctf; };
 dependencies = { module=all-ld; on=all-libctf; };
+dependencies = { module=install-ld; on=install-libctf; };
 
 // We put install-opcodes before install-binutils because the installed
 // binutils might be on PATH, and they might need the shared opcodes
diff --git a/Makefile.in b/Makefile.in
index 03785200dc7..d8a94c4173d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -565,7 +565,7 @@ STAGEprofile_TFLAGS = $(STAGE2_TFLAGS)
 STAGEtrain_CFLAGS = $(filter-out -fchecking=1,$(STAGE3_CFLAGS))
 STAGEtrain_TFLAGS = $(filter-out -fchecking=1,$(STAGE3_TFLAGS))
 
-STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use 
-fprofile-reproducible=parallel-runs
+STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use
 STAGEfeedback_TFLAGS = $(STAGE4_TFLAGS)
 
 STAGEautoprofile_CFLAGS = $(STAGE2_CFLAGS) -g
@@ -61234,6 +61234,7 @@ all-stagetrain-ld: maybe-all-stagetrain-libctf
 all-stagefeedback-ld: maybe-all-stagefeedback-libctf
 all-stageautoprofile-ld: maybe-all-stageautoprofile-libctf
 all-stageautofeedback-ld: maybe-all-stageautofeedback-libctf
+install-ld: maybe-install-libctf
 install-binutils: maybe-install-opcodes
 install-strip-binutils: maybe-install-strip-opcodes
 install-opcodes: maybe-install-bfd
-- 
2.30.0.252.gc27e85e57d



Re: [PATCH] config: check for sighandler_t properly

2021-01-26 Thread Nick Alcock via Gcc-patches
On 25 Jan 2021, Nathan Sidwell said:
> I think you're right about checking  though, not 

I'll look at it once I've dealt with this unfortunate "installing
binutils leaves the system linker broken" disaster I've caused. :)

-- 
NULL && (void)


Re: [PATCH] ld: depend on libctf

2021-01-26 Thread Nick Alcock via Gcc-patches
On 26 Jan 2021, Andreas Schwab outgrape:

> On Jan 26 2021, Nick Alcock via Gcc-patches wrote:
>
>> diff --git a/Makefile.in b/Makefile.in
>> index 03785200dc7..d8a94c4173d 100644
>> --- a/Makefile.in
>> +++ b/Makefile.in
>> @@ -565,7 +565,7 @@ STAGEprofile_TFLAGS = $(STAGE2_TFLAGS)
>>  STAGEtrain_CFLAGS = $(filter-out -fchecking=1,$(STAGE3_CFLAGS))
>>  STAGEtrain_TFLAGS = $(filter-out -fchecking=1,$(STAGE3_TFLAGS))
>>  
>> -STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use 
>> -fprofile-reproducible=parallel-runs
>> +STAGEfeedback_CFLAGS = $(STAGE4_CFLAGS) -fprofile-use
>
> Where does this come from?

Arggh. I just did an autogen Makefile.def and trusted that only the
necessary stuff would change.  I should have looked more closely.

I'll repost and drop that hunk, even though that means it's not the same
thing that autogen emits.



[PATCH v2] ld: depend on libctf

2021-01-26 Thread Nick Alcock via Gcc-patches
Since ld may depend on libctf (if present), and libctf may be relinked
by the installation process, libctf must be installed before ld is,
or the relink may fail if it calls on symbols or symbol versions that do
not exist in any libctf already present on the system.  (If none is
present, the copy in the build tree will be automatically used, but
if one *is* present, it may take precedence and break things.)

(This is a maybe- dependency, so it will work even if libctf is
disabled.)

ChangeLog
2021-01-26  Nick Alcock  

PR 27250
* Makefile.def: Add install-libctf dependency to install-ld.
* Makefile.in: Regenerated.
---
 Makefile.def | 1 +
 Makefile.in  | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

I'm probably going to put this into binutils directly, rather than via
a later cherry-pick, because this one breaks 'make install' and leaves
you with a broken system ld, so fixing it fast is quite important.

diff --git a/Makefile.def b/Makefile.def
index 3e38f61193f..607eac7fe3c 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -463,6 +463,7 @@ dependencies = { module=all-binutils; on=all-intl; };
 dependencies = { module=all-binutils; on=all-gas; };
 dependencies = { module=all-binutils; on=all-libctf; };
 dependencies = { module=all-ld; on=all-libctf; };
+dependencies = { module=install-ld; on=install-libctf; };
 
 // We put install-opcodes before install-binutils because the installed
 // binutils might be on PATH, and they might need the shared opcodes
diff --git a/Makefile.in b/Makefile.in
index 03785200dc7..d8a94c4173d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -61234,6 +61234,7 @@ all-stagetrain-ld: maybe-all-stagetrain-libctf
 all-stagefeedback-ld: maybe-all-stagefeedback-libctf
 all-stageautoprofile-ld: maybe-all-stageautoprofile-libctf
 all-stageautofeedback-ld: maybe-all-stageautofeedback-libctf
+install-ld: maybe-install-libctf
 install-binutils: maybe-install-opcodes
 install-strip-binutils: maybe-install-strip-opcodes
 install-opcodes: maybe-install-bfd
-- 
2.30.0.252.gc27e85e57d



[PATCH 0/8 RFC] unbreak --with-included-gettext, and other configury stuff

2021-02-08 Thread Nick Alcock via Gcc-patches
Most of this series serves one goal: fixing problems Stephen Casner reported
with a binutils built --with-included-gettext or built on a platform that
doesn't have a gettext in a system libintl or in libc. This has long been broken
in binutils.

Firstly, two commits from last year that allow intl/ to build on systems with
Bison 3 are missing. That's easy to fix, but even with that fixed we have other
problems.  libctf would like to compile programs that use libctf.la in its
testsuite, without having to account for the fact that some of them might
include libintl symbols (i.e. it would like libctf.la to be complete, and
ideally libbfd.la too); but making these libraries complete is stymied by the
problem that you cannot link the built-in libintl symbols into shared libraries
on many platforms because it's not PIC. So we picize it, much as libiberty
already is. This then lets us fix gdbserver, which builds a preloaded shared
object and thus won't build without libintl if gettext isn't in libc.

That fixes the shared library case -- but then there's the problem Stephen
reported, which is that LIBINTL in intl/config.intl contains things like this:

LIBINTL='${top_builddir}/../libintl.a -liconv"

(sometimes without the -liconv part).

Linking with this doesn't work with static libraries on some platforms
(e.g. MacOS X) which build libintl.a *into* libctf.a or whatever other library,
and then fail to find symbols in it at build time because a .a file isn't an .o
file.  The solution here is to rewrite that into

LIBINTL='-L${top_builddir}/.. -lintl -liconv"

which always works, static or shared, library or not.

The way LIBINTL is transformed is a bit gross: rather than trickle changes
through gettext.m4 (which is frankly painful to contemplate: gettext.m4 has so
many other users and is so complicated...) we just modify the sedding that's
already done in the in-tree intl/configure.ac to sed the thing a bit
differently.

Doing this also lets us rip out some system-dependent hardwired gunge around
whether libintl comes from libc or not and replace it with using the results of
the checks intl/configure has already done.

Nothing seems to break: I've built and tested both binutils-gdb and gcc plus the
two libintl patches with --enable-shared and --disable-shared and with and
without --with-included-gettext on systems with gettext in libc, with gettext in
a system libintl and with no gettext anywhere.  Stephen has verified that MacOS 
X
(a system which had explicit system-dependent libintl gunge in
{bfd,opcodes,libctf}/configure.ac, all of which has gone away) gets further into
the build now (before failing in gdb for not-really-related reasons). Cygwin
(the other system with system-dependent gunge) has been able to have most of it
ripped out, and still builds as above.

Is this sort of thing acceptable? Probably for trunk only, unless people think
that the build failures on MacOS X merit backporting of this to the 2.36 release
branch.

(also in this series, some stuff not needing review: Tcl version checks for the
libctf testsuite and some small configury improvements to libctf.)

(All mails sent to binut...@sourceware.org: relevant subset Cc:ed to gdb and gcc
as well.)

Cc: gdb-patc...@sourceware.org
Cc: gcc-patc...@gnu.org

Jakub Jelinek (2): (sync from gcc)
  intl: Allow building both with old bison and bison >= 3 [PR92008]
  intl: Unbreak intl build with bison 3 when no regeneration is needed
[PR92008]

Nick Alcock (6):
  intl: always picify
  intl: turn LIBINTL into -L / -l form
  bfd, opcodes, libctf: support --with-included-gettext
  gdbserver: explicitly include gettext, etc in inprocess agent
  libctf: require a Tcl capable of try/catch to run tests
  libctf: add missing header in BFD ELF check

 bfd/configure |  11 ++--
 bfd/configure.ac  |  11 ++--
 gdbserver/Makefile.in |   2 +-
 intl/Makefile.in  |  16 --
 intl/aclocal.m4   |   1 +
 intl/configure| 113 +-
 intl/configure.ac |  30 ++-
 intl/plural-config.h  |   1 +
 intl/plural-exp.h |   8 ++-
 intl/plural.c |  62 +++
 intl/plural.y |  27 +-
 libctf/Makefile.am|   6 ++-
 libctf/Makefile.in|  91 +++---
 libctf/configure  |  91 +++---
 libctf/configure.ac   |  27 +++---
 opcodes/configure |   8 ++-
 opcodes/configure.ac  |   8 ++-
 17 files changed, 413 insertions(+), 100 deletions(-)
 create mode 100644 intl/plural-config.h

-- 
2.30.0.252.gc27e85e57d



[PATCH 3/8] intl: always picify

2021-02-08 Thread Nick Alcock via Gcc-patches
libintl is included in several shared libraries (at least
libinproctrace.so and libctf.so): unconditionally picify with code
borrowed from libiberty configure.  (It's not performance-critical, so
don't bother making separate PIC and non-PIC libraries like libiberty
does.)

Cc: gcc-patc...@gnu.org

intl/ChangeLog
2021-02-02  Nick Alcock  

* aclocal.m4: include picflag.m4.
* configure.ac (PICFLAG): Add and substitute.
* Makefile.in (PICFLAG): New.
(COMPILE): Use it.
* configure: Regenerate.
---
 intl/Makefile.in  |  3 +-
 intl/aclocal.m4   |  1 +
 intl/configure| 86 +++
 intl/configure.ac |  5 +++
 4 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/intl/Makefile.in b/intl/Makefile.in
index 356c8ab9b65..96df727baea 100644
--- a/intl/Makefile.in
+++ b/intl/Makefile.in
@@ -49,8 +49,9 @@ CFLAGS = @CFLAGS@
 LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
 DEFS = -DHAVE_CONFIG_H
+PICFLAG = @PICFLAG@
 
-COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(DEFS-$@) $(INCLUDES)
+COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PICFLAG) $(DEFS) $(DEFS-$@) 
$(INCLUDES)
 
 HEADERS = \
   gmo.h \
diff --git a/intl/aclocal.m4 b/intl/aclocal.m4
index 473ec622323..0a42b42ea8c 100644
--- a/intl/aclocal.m4
+++ b/intl/aclocal.m4
@@ -26,6 +26,7 @@ m4_include([../config/lib-link.m4])
 m4_include([../config/lib-prefix.m4])
 m4_include([../config/nls.m4])
 m4_include([../config/override.m4])
+m4_include([../config/picflag.m4])
 m4_include([../config/po.m4])
 m4_include([../config/progtest.m4])
 m4_include([../config/stdint_h.m4])
diff --git a/intl/configure b/intl/configure
index d69767b7d21..6498a392570 100755
--- a/intl/configure
+++ b/intl/configure
@@ -624,6 +624,7 @@ ac_subst_vars='LTLIBOBJS
 LIBOBJS
 BISON3_NO
 BISON3_YES
+PICFLAG
 INCINTL
 LIBINTL_DEP
 MAINT
@@ -6793,6 +6794,91 @@ case $USE_INCLUDED_LIBINTL in
 ;;
 esac
 
+# intl is sometimes linked into shared libraries even without --enable-shared
+# (e.g. gdbsupport's inprocess agent): so always PICify, just in case.
+
+
+
+
+case "${host}" in
+# PIC is the default on some targets or must not be used.
+*-*-darwin*)
+   # For darwin, common symbols are not allowed in MH_DYLIB files
+   case "${CFLAGS}" in
+ # If we are using a compiler supporting mdynamic-no-pic
+ # and the option has been tested as safe to add, then cancel
+ # it here, since the code generated is incompatible with shared
+ # libs.
+ *-mdynamic-no-pic*) PICFLAG='-fno-common -mno-dynamic-no-pic' ;;
+ *) PICFLAG=-fno-common ;;
+   esac
+   ;;
+alpha*-dec-osf5*)
+   # PIC is the default.
+   ;;
+hppa*64*-*-hpux*)
+   # PIC is the default for 64-bit PA HP-UX.
+   ;;
+i[34567]86-*-cygwin* | x86_64-*-cygwin*)
+   ;;
+i[34567]86-*-mingw* | x86_64-*-mingw*)
+   ;;
+i[34567]86-*-interix[3-9]*)
+   # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+   # Instead, we relocate shared libraries at runtime.
+   ;;
+i[34567]86-*-nto-qnx*)
+   # QNX uses GNU C++, but need to define -shared option too, otherwise
+   # it will coredump.
+   PICFLAG='-fPIC -shared'
+   ;;
+i[34567]86-pc-msdosdjgpp*)
+   # DJGPP does not support shared libraries at all.
+   ;;
+ia64*-*-hpux*)
+   # On IA64 HP-UX, PIC is the default but the pic flag
+   # sets the default TLS model and affects inlining.
+   PICFLAG=-fPIC
+   ;;
+mips-sgi-irix6*)
+   # PIC is the default.
+   ;;
+rs6000-ibm-aix* | powerpc-ibm-aix*)
+   # All AIX code is PIC.
+   ;;
+
+# Some targets support both -fPIC and -fpic, but prefer the latter.
+# FIXME: Why?
+i[34567]86-*-* | x86_64-*-*)
+   PICFLAG=-fpic
+   ;;
+# FIXME: Override -fPIC default in libgcc only?
+sh-*-linux* | sh[2346lbe]*-*-linux*)
+   PICFLAG=-fpic
+   ;;
+# FIXME: Simplify to sh*-*-netbsd*?
+sh-*-netbsdelf* | shl*-*-netbsdelf* | sh5-*-netbsd* | sh5l*-*-netbsd* | \
+  sh64-*-netbsd* | sh64l*-*-netbsd*)
+   PICFLAG=-fpic
+   ;;
+# Default to -fPIC unless specified otherwise.
+*)
+   PICFLAG=-fPIC
+   ;;
+esac
+
+# If the user explicitly uses -fpic/-fPIC, keep that.
+case "${CFLAGS}" in
+*-fpic*)
+   PICFLAG=-fpic
+   ;;
+*-fPIC*)
+   PICFLAG=-fPIC
+   ;;
+esac
+
+
+
 BISON3_YES='#'
 BISON3_NO=
 if test "$INTLBISON" != :; then
diff --git a/intl/configure.ac b/intl/configure.ac
index 6363e55e68a..5ec7b0944e2 100644
--- a/intl/configure.ac
+++ b/intl/configure.ac
@@ -47,6 +47,11 @@ case $USE_INCLUDED_LIBINTL in
 ;;
 esac
 
+# intl is sometimes linked into shared libraries even without --enable-shared
+# (e.g. gdbsupport's inprocess agent): so always PICify, just in case.
+GCC_PICFLAG
+AC_SUBST(PICFLAG)
+
 BISON3_YES='#'
 BISON3_NO=
 if test "$INTLBISON" != :; then
-- 
2.30.0.252.gc27e85e57d



[PATCH 4/8] intl: turn LIBINTL into -L / -l form

2021-02-08 Thread Nick Alcock via Gcc-patches
This variable currently refers directly, not to a .la file, but to an .a
file.  This produces wrong results when building into a library on some
platforms: so convert it to the general form "-L${top_builddir}../intl
-lintl ..." ... so that both libtool and non-libtool builds will always
do the right thing for both static and shared links.

Cc: gcc-patc...@gnu.org

intl/ChangeLog
2021-02-04  Nick Alcock  

* configure.ac (LIBINTL): Transform into -L/-lintl form.
* configure: Regenerate.
---
 intl/configure| 3 +--
 intl/configure.ac | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/intl/configure b/intl/configure
index 6498a392570..7ddb624249d 100755
--- a/intl/configure
+++ b/intl/configure
@@ -6787,8 +6787,7 @@ LIBINTL_DEP=
 INCINTL=
 case $USE_INCLUDED_LIBINTL in
   yes)
-LIBINTL=`echo $LIBINTL | sed 's,${top_builddir},&/..,' `
-LTLIBINTL=`echo $LTLIBINTL | sed 's,${top_builddir},&/..,' `
+LIBINTL=`echo $LIBINTL | sed 's,${top_builddir},-L&/..,; 
s,\.\./intl/libintl\.a,../intl -lintl,' `
 LIBINTL_DEP='${top_builddir}/../intl/libintl.a'
 INCINTL='-I${top_builddir}/../intl'
 ;;
diff --git a/intl/configure.ac b/intl/configure.ac
index 5ec7b0944e2..77e2fd2d8c5 100644
--- a/intl/configure.ac
+++ b/intl/configure.ac
@@ -40,8 +40,7 @@ LIBINTL_DEP=
 INCINTL=
 case $USE_INCLUDED_LIBINTL in
   yes)
-LIBINTL=`echo $LIBINTL | sed 's,${top_builddir},&/..,' `
-LTLIBINTL=`echo $LTLIBINTL | sed 's,${top_builddir},&/..,' `
+LIBINTL=`echo $LIBINTL | sed 's,${top_builddir},-L&/..,; 
s,\.\./intl/libintl\.a,../intl -lintl,' `
 LIBINTL_DEP='${top_builddir}/../intl/libintl.a'
 INCINTL='-I${top_builddir}/../intl'
 ;;
-- 
2.30.0.252.gc27e85e57d



Re: [PATCH 2/4 REVIEW] libtool.m4: fix nm BSD flag detection

2021-09-09 Thread Nick Alcock via Gcc-patches
On 21 Jul 2021, Alan Modra uttered the following:
> On Wed, Jul 07, 2021 at 08:03:45PM +0100, Nick Alcock via Gcc-patches wrote:
>> >>>  PR libctf/27482
>> >>>  * libtool.m4 (LT_PATH_NM): Try BSDization flags with a user-provided
>> >
>> > Changes to libtool need to be posted to the libtool project:
>> >
>> >   https://www.gnu.org/software/libtool/
>> 
>> I considered this, but there is *serious* divergence between the
>> libtool.m4 in our tree and upstream. Fixing this divergence looks to be
>> a fairly major project in and of itself :( the last real sync looked
>> like being all the way back in 2008.
>
> Yes, I looked at doing a sync myself a few years ago..
> I'll OK the two libtool changes for binutils.

Finally getting back to this -- sorry for the delay! (July and August
were fairly fraught for me).  I'll bring them up to date (mostly
affecting the sim/ regenerations as far as I can see) then retest.

I'm happy to backport this stuff as far back as people have reported
problems, insofar as those branches are even open (that would be back to
2.34 for all the PR27967 stuff, some of which I mislabelled in the
changelog as 27482: will fix). Is that OK? (It doesn't look like any of
the release branches are currently frozen.)

I'll repost the lot (including one new patch which is just under libctf/
and has a testcase, so is probably uncontroversial) and wait a bit
before pushing, because it's been so long.

(I've got a forward-port to libtool trunk too: I'll repost that as well,
and chase up for reviews.)

-- 
NULL && (void)


Re: [PATCH 2/4 REVIEW] libtool.m4: fix nm BSD flag detection

2021-07-06 Thread Nick Alcock via Gcc-patches
Ping?

On 25 Jun 2021, Nick Alcock via Binutils said this:

> Libtool needs to get BSD-format (or MS-format) output out of the system
> nm, so that it can scan generated object files for symbol names for
> -export-symbols-regex support.  Some nms need specific flags to turn on
> BSD-formatted output, so libtool checks for this in its AC_PATH_NM.
> Unfortunately the code to do this has a pair of interlocking flaws:
>
>  - it runs the test by doing an nm of /dev/null.  Some platforms
>reasonably refuse to do an nm on a device file, but before now this
>has only been worked around by assuming that the error message has a
>specific textual form emitted by Tru64 nm, and that getting this
>error means this is Tru64 nm and that nm -B would work to produce
>BSD-format output, even though the test never actually got anything
>but an error message out of nm -B.  This is fixable by nm'ing *nm
>itself* (since we necessarily have a path to it).
>
>  - the test is entirely skipped if NM is set in the environment, on the
>grounds that the user has overridden the test: but the user cannot
>reasonably be expected to know that libtool wants not only nm but
>also flags forcing BSD-format output.  Worse yet, one such "user" is
>the top-level Cygnus configure script, which neither tests for
>nor specifies any BSD-format flags.  So platforms needing BSD-format
>flags always fail to set them when run in a Cygnus tree, breaking
>-export-symbols-regex on such platforms.  Libtool also needs to
>augment $LD on some platforms, but this is done unconditionally,
>augmenting whatever the user specified: the nm check should do the
>same.
>
>One wrinkle: if the user has overridden $NM, a path might have been
>provided: so we use the user-specified path if there was one, and
>otherwise do the path search as usual.  (If the nm specified doesn't
>work, this might lead to a few extra pointless path searches -- but
>the test is going to fail anyway, so that's not a problem.)
>
> (Tested with NM unset, and set to nm, /usr/bin/nm, my-nm where my-nm is a
> symlink to /usr/bin/nm on the PATH, and /not-on-the-path/my-nm where
> *that* is a symlink to /usr/bin/nm.)
>
> Cc: gcc-patches@gcc.gnu.org
>
> ChangeLog
> 2021-06-22  Nick Alcock  
>
>   PR libctf/27482
>   * libtool.m4 (LT_PATH_NM): Try BSDization flags with a user-provided
>   NM, if there is one.  Run nm on itself, not on /dev/null, to avoid
>   errors from nms that refuse to work on non-regular files.  Remove
>   other workarounds for this problem.  Strip out blank lines from the
>   nm output.
> ---
>  libtool.m4 | 88 --
>  1 file changed, 45 insertions(+), 43 deletions(-)
>
> diff --git a/libtool.m4 b/libtool.m4
> index b0a56917497..29dce1f8239 100644
> --- a/libtool.m4
> +++ b/libtool.m4
> @@ -3200,53 +3200,55 @@ _LT_DECL([], [file_magic_cmd], [1],
>  
>  # LT_PATH_NM
>  # --
> -# find the pathname to a BSD- or MS-compatible name lister
> +# find the pathname to a BSD- or MS-compatible name lister, and any flags
> +# needed to make it compatible
>  AC_DEFUN([LT_PATH_NM],
>  [AC_REQUIRE([AC_PROG_CC])dnl
>  AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
>  [if test -n "$NM"; then
> -  # Let the user override the test.
> -  lt_cv_path_NM="$NM"
> -else
> -  lt_nm_to_check="${ac_tool_prefix}nm"
> -  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
> -lt_nm_to_check="$lt_nm_to_check nm"
> -  fi
> -  for lt_tmp_nm in $lt_nm_to_check; do
> -lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
> -for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
> -  IFS="$lt_save_ifs"
> -  test -z "$ac_dir" && ac_dir=.
> -  tmp_nm="$ac_dir/$lt_tmp_nm"
> -  if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
> - # Check to see if the nm accepts a BSD-compat flag.
> - # Adding the `sed 1q' prevents false positives on HP-UX, which says:
> - #   nm: unknown option "B" ignored
> - # Tru64's nm complains that /dev/null is an invalid object file
> - case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
> - */dev/null* | *'Invalid file or object type'*)
> -   lt_cv_path_NM="$tmp_nm -B"
> -   break
> -   ;;
> - *)
> -   case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
> -   */dev

Re: [PATCH 2/4 REVIEW] libtool.m4: fix nm BSD flag detection

2021-07-07 Thread Nick Alcock via Gcc-patches
On 7 Jul 2021, Nick Clifton told this:

> Hi Nick,
>
>> Ping?
>
> Oops.

I sent a bunch of pings out at the same time, to a bunch of different
projects. You are the only person to respond, so thank you!

>>> PR libctf/27482
>>> * libtool.m4 (LT_PATH_NM): Try BSDization flags with a user-provided
>
> Changes to libtool need to be posted to the libtool project:
>
>   https://www.gnu.org/software/libtool/

I considered this, but there is *serious* divergence between the
libtool.m4 in our tree and upstream. Fixing this divergence looks to be
a fairly major project in and of itself :( the last real sync looked
like being all the way back in 2008.

> They have mailing lists for bug reports and patch submissions.
>
> Once the patch has been accepted there it can be backported to the gcc and
> gdb/binutils repositories...

AIUI, libtool has no maintainer currently, and the divergence is such
that the patch might need a near-complete rewrite anyway :( (there were
changes to this function upstream in 2012 and 2013, long after our last
sync.)

(However, I'm going to try in any case. I may have found a sucker, er, I
mean coworker willing to take this on.)


[PATCH toplevel] libctf: new testsuite

2021-01-05 Thread Nick Alcock via Gcc-patches
This enables 'make libctf-check', used by a new libctf testsuite in
binutils.

2021-01-05  Nick Alcock  

* Makefile.def (libctf): No longer no_check.  Checking depends on
all-ld.
* Makefile.in: Regenerated.

---

 Makefile.def  |   4 +-
 Makefile.in   |  13 +

This is a stripped-down top-level-only subset of commit 
c59e30ed1727135f8efb79890f2c458f73709757 in binutils-gdb.git.  (Because
it is identical to what has already landed in binutils, it should apply
without trouble in syncs back to there.)

I don't have permission to push this: Alan has offered to do so.

(I hope I'm doing this right...)

diff --git a/Makefile.def b/Makefile.def
index 089e70ae3ed..cc429aa8628 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -131,8 +131,7 @@ host_modules= { module= lto-plugin; bootstrap=true;
extra_make_flags='@extra_linker_plugin_flags@'; };
 host_modules= { module= libcc1; extra_configure_flags=--enable-shared; };
 host_modules= { module= gotools; };
-host_modules= { module= libctf; no_check=true;
-   bootstrap=true; };
+host_modules= { module= libctf; bootstrap=true; };
 
 target_modules = { module= libstdc++-v3;
   bootstrap=true;
@@ -547,6 +546,7 @@ dependencies = { module=configure-libctf; on=all-bfd; };
 dependencies = { module=configure-libctf; on=all-intl; };
 dependencies = { module=configure-libctf; on=all-zlib; };
 dependencies = { module=configure-libctf; on=all-libiconv; };
+dependencies = { module=check-libctf; on=all-ld; };
 
 // The Makefiles in gdb and gdbserver pull in a file that configure
 // generates in the gnulib directory, so distclean gnulib only after
diff --git a/Makefile.in b/Makefile.in
index fe34132f9e5..4fe7321786e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -34761,6 +34761,12 @@ maybe-check-libctf:
 maybe-check-libctf: check-libctf
 
 check-libctf:
+   @: $(MAKE); $(unstage)
+   @r=`${PWD_COMMAND}`; export r; \
+   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+   $(HOST_EXPORTS) $(EXTRA_HOST_EXPORTS) \
+   (cd $(HOST_SUBDIR)/libctf && \
+ $(MAKE) $(FLAGS_TO_PASS)  $(EXTRA_BOOTSTRAP_FLAGS) check)
 
 @endif libctf
 
@@ -52366,6 +52372,13 @@ configure-stage3-libctf: maybe-all-stage3-libiconv
 configure-stage4-libctf: maybe-all-stage4-libiconv
 configure-stageprofile-libctf: maybe-all-stageprofile-libiconv
 configure-stagefeedback-libctf: maybe-all-stagefeedback-libiconv
+check-libctf: maybe-all-ld
+check-stage1-libctf: maybe-all-stage1-ld
+check-stage2-libctf: maybe-all-stage2-ld
+check-stage3-libctf: maybe-all-stage3-ld
+check-stage4-libctf: maybe-all-stage4-ld
+check-stageprofile-libctf: maybe-all-stageprofile-ld
+check-stagefeedback-libctf: maybe-all-stagefeedback-ld
 distclean-gnulib: maybe-distclean-gdb
 distclean-gnulib: maybe-distclean-gdbserver
 all-bison: maybe-all-build-texinfo
-- 
2.29.2.250.g8336e49d6f.dirty



Re: [PATCH toplevel] libctf: new testsuite

2021-01-06 Thread Nick Alcock via Gcc-patches
On 5 Jan 2021, Alan Modra via Binutils told this:

> It doesn't apply due to gcc missing binutils 87279e3cef5b2c5 changes
> too.  I could fix that easily enough but I'm going to ask that you
> post a combined patch to bring the gcc repo up to date with any libctf
> changes.

Oops! That never occurred to me, but of course all the earlier stuff is
probably missing too. Will come up with one once I've properly woken up.

(Sorry, I really should have tried to apply it :( )

-- 
NULL && (void)


[PATCH v2 toplevel] sync libctf toplevel from binutils-gdb

2021-01-06 Thread Nick Alcock via Gcc-patches
This pulls in the toplevel portions of these binutils-gdb commits:

   1ff6de031241c59d0ff bfd, ld: add CTF section linking
   87279e3cef5b2c54f4a libctf: installable libctf as a shared library
   c59e30ed1727135f8ef libctf: new testsuite

* Makefile.def: Sync with binutils-gdb:
(dependencies): all-ld depends on all-libctf.
(host_modules): libctf is no longer no_install.
No longer no_check.  Checking depends on all-ld.
* Makefile.in: Regenerated.
---
 ChangeLog|  8 
 Makefile.def |  5 +++--
 Makefile.in  | 42 --
 3 files changed, 51 insertions(+), 4 deletions(-)

This should be a little better (though I only had three hours sleep last
night so it's quite possible I messed it up again).

I reviewed the diff with GCC and nothing more libctf-related is missing.
This was generated against GCC trunk directly so should definitely apply
this time. Sorry about that.

diff --git a/ChangeLog b/ChangeLog
index bd87d5fc6ee..0a352870cd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-01-06  Nick Alcock  
+
+   * Makefile.def: Sync with binutils-gdb:
+   (dependencies): all-ld depends on all-libctf.
+   (host_modules): libctf is no longer no_install.
+   No longer no_check.  Checking depends on all-ld.
+   * Makefile.in: Regenerated.
+
 2021-01-05  Samuel Thibault  
 
* libtool.m4: Match gnu* along other GNU systems.
diff --git a/Makefile.def b/Makefile.def
index c45be5bff45..3e38f61193f 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -141,8 +141,7 @@ host_modules= { module= lto-plugin; bootstrap=true;
extra_make_flags='@extra_linker_plugin_flags@'; };
 host_modules= { module= libcc1; extra_configure_flags=--enable-shared; };
 host_modules= { module= gotools; };
-host_modules= { module= libctf; no_install=true; no_check=true;
-   bootstrap=true; };
+host_modules= { module= libctf; bootstrap=true; };
 
 target_modules = { module= libstdc++-v3;
   bootstrap=true;
@@ -463,6 +462,7 @@ dependencies = { module=all-binutils; on=all-build-bison; };
 dependencies = { module=all-binutils; on=all-intl; };
 dependencies = { module=all-binutils; on=all-gas; };
 dependencies = { module=all-binutils; on=all-libctf; };
+dependencies = { module=all-ld; on=all-libctf; };
 
 // We put install-opcodes before install-binutils because the installed
 // binutils might be on PATH, and they might need the shared opcodes
@@ -561,6 +561,7 @@ dependencies = { module=configure-libctf; on=all-bfd; };
 dependencies = { module=configure-libctf; on=all-intl; };
 dependencies = { module=configure-libctf; on=all-zlib; };
 dependencies = { module=configure-libctf; on=all-libiconv; };
+dependencies = { module=check-libctf; on=all-ld; };
 
 // Warning, these are not well tested.
 dependencies = { module=all-bison; on=all-intl; };
diff --git a/Makefile.in b/Makefile.in
index 2307c8dd083..247cb9c8711 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -41747,6 +41747,12 @@ maybe-check-libctf:
 maybe-check-libctf: check-libctf
 
 check-libctf:
+   @: $(MAKE); $(unstage)
+   @r=`${PWD_COMMAND}`; export r; \
+   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+   $(HOST_EXPORTS) $(EXTRA_HOST_EXPORTS) \
+   (cd $(HOST_SUBDIR)/libctf && \
+ $(MAKE) $(FLAGS_TO_PASS)  $(EXTRA_BOOTSTRAP_FLAGS) check)
 
 @endif libctf
 
@@ -41755,7 +41761,13 @@ maybe-install-libctf:
 @if libctf
 maybe-install-libctf: install-libctf
 
-install-libctf:
+install-libctf: installdirs
+   @: $(MAKE); $(unstage)
+   @r=`${PWD_COMMAND}`; export r; \
+   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+   $(HOST_EXPORTS) \
+   (cd $(HOST_SUBDIR)/libctf && \
+ $(MAKE) $(FLAGS_TO_PASS)  install)
 
 @endif libctf
 
@@ -41764,7 +41776,13 @@ maybe-install-strip-libctf:
 @if libctf
 maybe-install-strip-libctf: install-strip-libctf
 
-install-strip-libctf:
+install-strip-libctf: installdirs
+   @: $(MAKE); $(unstage)
+   @r=`${PWD_COMMAND}`; export r; \
+   s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
+   $(HOST_EXPORTS) \
+   (cd $(HOST_SUBDIR)/libctf && \
+ $(MAKE) $(FLAGS_TO_PASS)  install-strip)
 
 @endif libctf
 
@@ -61206,6 +61224,16 @@ all-stagetrain-binutils: maybe-all-stagetrain-libctf
 all-stagefeedback-binutils: maybe-all-stagefeedback-libctf
 all-stageautoprofile-binutils: maybe-all-stageautoprofile-libctf
 all-stageautofeedback-binutils: maybe-all-stageautofeedback-libctf
+all-ld: maybe-all-libctf
+all-stage1-ld: maybe-all-stage1-libctf
+all-stage2-ld: maybe-all-stage2-libctf
+all-stage3-ld: maybe-all-stage3-libctf
+all-stage4-ld: maybe-all-stage4-libctf
+all-stageprofile-ld: maybe-all-stageprofile-libctf
+all-stagetrain-ld: maybe-all-stagetrain-libctf
+all-stagefeedback-ld: maybe-all-stagefeedback-libctf
+all-stageautoprofile-ld: maybe-all-stageautoprofile-libctf
+all-stageautofeedback-ld: mayb

[PATCH] libiberty, include: add bsearch_r

2020-06-16 Thread Nick Alcock via Gcc-patches
A resend of something I sent over, sheesh, six months ago.  Jeff Law acked it
but, well, it was six months ago.  I think getting a re-ack might be a good
idea.

(Also... could someone push it for me? I should have push privs, but only on
binutils and I have yet to test them. Starting my pushing career at sourceware
by fubaring gcc is not my idea of a good time.)

8<--->8
libctf wants a bsearch that takes a void * arg pointer to avoid a
nonportable use of __thread.

bsearch_r is required, not optional, at this point because as far as I
can see this obvious-sounding function is not implemented by anyone's
libc.  We can easily move it to AC_LIBOBJ later if it proves necessary
to do so.

include/
* libiberty.h (bsearch_r): New.
libiberty/
* bsearch_r.c: New file.
* Makefile.in (CFILES): Add bsearch_r.c.
(REQUIRED_OFILES): Add bsearch_r.o.
* functions.texi: Regenerate.
---
 include/libiberty.h   |  7 
 libiberty/Makefile.in | 12 +-
 libiberty/bsearch_r.c | 93 +++
 3 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 libiberty/bsearch_r.c

diff --git a/include/libiberty.h b/include/libiberty.h
index 141cb886a8..0bb5b81d4a 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -641,6 +641,13 @@ extern int pexecute (const char *, char * const *, const 
char *,
 
 extern int pwait (int, int *, int);
 
+/* Like bsearch, but takes and passes on an argument like qsort_r.  */
+
+extern void *bsearch_r (register const void *, const void *,
+   size_t, register size_t,
+   register int (*)(const void *, const void *, void *),
+   void *);
+
 #if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
 /* Like sprintf but provides a pointer to malloc'd storage, which must
be freed by the caller.  */
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index d6b302e02f..895f701bcd 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -124,7 +124,7 @@ COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. 
-I$(INCDIR) \
 # CONFIGURED_OFILES and funcs in configure.ac.  Also run "make maint-deps"
 # to build the new rules.
 CFILES = alloca.c argv.c asprintf.c atexit.c   \
-   basename.c bcmp.c bcopy.c bsearch.c bzero.c \
+   basename.c bcmp.c bcopy.c bsearch.c bsearch_r.c bzero.c \
calloc.c choose-temp.c clock.c concat.c cp-demangle.c   \
 cp-demint.c cplus-dem.c crc32.c\
d-demangle.c dwarfnames.c dyn-string.c  \
@@ -168,6 +168,7 @@ REQUIRED_OFILES =   
\
./regex.$(objext) ./cplus-dem.$(objext) ./cp-demangle.$(objext) \
./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext) \
./argv.$(objext)\
+   ./bsearch_r.$(objext)   \
./choose-temp.$(objext) ./concat.$(objext)  \
./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext)  \
./dwarfnames.$(objext) ./dyn-string.$(objext)   \
@@ -601,6 +602,15 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
else true; fi
$(COMPILE.c) $(srcdir)/bsearch.c $(OUTPUT_OPTION)
 
+./bsearch_r.$(objext): $(srcdir)/bsearch_r.c config.h $(INCDIR)/ansidecl.h
+   if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/bsearch_r.c -o pic/$@; \
+   else true; fi
+   if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/bsearch_r.c -o 
noasan/$@; \
+   else true; fi
+   $(COMPILE.c) $(srcdir)/bsearch_r.c $(OUTPUT_OPTION)
+
 ./bzero.$(objext): $(srcdir)/bzero.c
if [ x"$(PICFLAG)" != x ]; then \
  $(COMPILE.c) $(PICFLAG) $(srcdir)/bzero.c -o pic/$@; \
diff --git a/libiberty/bsearch_r.c b/libiberty/bsearch_r.c
new file mode 100644
index 00..79ebae9b0b
--- /dev/null
+++ b/libiberty/bsearch_r.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. [rescinded 22 July 1999]
+ * 4. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote pro

[PATCH] libiberty, include: add bsearch_r

2020-06-23 Thread Nick Alcock via Gcc-patches
libctf wants a bsearch that takes a void * arg pointer to avoid a
nonportable use of __thread.

bsearch_r is required, not optional, at this point because as far as I
can see this obvious-sounding function is not implemented by anyone's
libc.  We can easily move it to AC_LIBOBJ later if it proves necessary
to do so.

include/
* libiberty.h (bsearch_r): New.
libiberty/
* bsearch_r.c: New file.
* Makefile.in (CFILES): Add bsearch_r.c.
(REQUIRED_OFILES): Add bsearch_r.o.
* functions.texi: Regenerate.
---
 include/libiberty.h   |  7 
 libiberty/Makefile.in | 12 +-
 libiberty/bsearch_r.c | 93 +++
 3 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 libiberty/bsearch_r.c

Acked six months ago (!) by Jeff Law here:


Rebased against master (commit efc16503ca10bc0e934e0bace5777500e4dc757a)
and retested building this morning.

Sorry for the delay.

diff --git a/include/libiberty.h b/include/libiberty.h
index 141cb886a85..0bb5b81d4ac 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -641,6 +641,13 @@ extern int pexecute (const char *, char * const *, const 
char *,
 
 extern int pwait (int, int *, int);
 
+/* Like bsearch, but takes and passes on an argument like qsort_r.  */
+
+extern void *bsearch_r (register const void *, const void *,
+   size_t, register size_t,
+   register int (*)(const void *, const void *, void *),
+   void *);
+
 #if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
 /* Like sprintf but provides a pointer to malloc'd storage, which must
be freed by the caller.  */
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index d6b302e02fd..895f701bcd0 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -124,7 +124,7 @@ COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. 
-I$(INCDIR) \
 # CONFIGURED_OFILES and funcs in configure.ac.  Also run "make maint-deps"
 # to build the new rules.
 CFILES = alloca.c argv.c asprintf.c atexit.c   \
-   basename.c bcmp.c bcopy.c bsearch.c bzero.c \
+   basename.c bcmp.c bcopy.c bsearch.c bsearch_r.c bzero.c \
calloc.c choose-temp.c clock.c concat.c cp-demangle.c   \
 cp-demint.c cplus-dem.c crc32.c\
d-demangle.c dwarfnames.c dyn-string.c  \
@@ -168,6 +168,7 @@ REQUIRED_OFILES =   
\
./regex.$(objext) ./cplus-dem.$(objext) ./cp-demangle.$(objext) \
./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext) \
./argv.$(objext)\
+   ./bsearch_r.$(objext)   \
./choose-temp.$(objext) ./concat.$(objext)  \
./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext)  \
./dwarfnames.$(objext) ./dyn-string.$(objext)   \
@@ -601,6 +602,15 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
else true; fi
$(COMPILE.c) $(srcdir)/bsearch.c $(OUTPUT_OPTION)
 
+./bsearch_r.$(objext): $(srcdir)/bsearch_r.c config.h $(INCDIR)/ansidecl.h
+   if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/bsearch_r.c -o pic/$@; \
+   else true; fi
+   if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/bsearch_r.c -o 
noasan/$@; \
+   else true; fi
+   $(COMPILE.c) $(srcdir)/bsearch_r.c $(OUTPUT_OPTION)
+
 ./bzero.$(objext): $(srcdir)/bzero.c
if [ x"$(PICFLAG)" != x ]; then \
  $(COMPILE.c) $(PICFLAG) $(srcdir)/bzero.c -o pic/$@; \
diff --git a/libiberty/bsearch_r.c b/libiberty/bsearch_r.c
new file mode 100644
index 000..79ebae9b0be
--- /dev/null
+++ b/libiberty/bsearch_r.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. [rescinded 22 July 1999]
+ * 4. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR I

[PATCH v2] libiberty, include: add bsearch_r

2020-06-23 Thread Nick Alcock via Gcc-patches
libctf wants a bsearch that takes a void * arg pointer to avoid a
nonportable use of __thread.

bsearch_r is required, not optional, at this point because as far as I
can see this obvious-sounding function is not implemented by anyone's
libc.  We can easily move it to AC_LIBOBJ later if it proves necessary
to do so.

include/
* libiberty.h (bsearch_r): New.
libiberty/
* bsearch_r.c: New file.
* Makefile.in (CFILES): Add bsearch_r.c.
(REQUIRED_OFILES): Add bsearch_r.o.
* functions.texi: Regenerate.
---
 include/libiberty.h  |  7 +++
 libiberty/Makefile.in| 12 +-
 libiberty/bsearch_r.c| 93 
 libiberty/functions.texi | 21 -
 4 files changed, 130 insertions(+), 3 deletions(-)
 create mode 100644 libiberty/bsearch_r.c

v2: actually regenerate functions.texi.

Acked six months ago (!) by Jeff Law here:


Rebased against master (commit efc16503ca10bc0e934e0bace5777500e4dc757a)
and retested building this morning.

Sorry for the delay.

diff --git a/include/libiberty.h b/include/libiberty.h
index 141cb886a85..0bb5b81d4ac 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -641,6 +641,13 @@ extern int pexecute (const char *, char * const *, const 
char *,
 
 extern int pwait (int, int *, int);
 
+/* Like bsearch, but takes and passes on an argument like qsort_r.  */
+
+extern void *bsearch_r (register const void *, const void *,
+   size_t, register size_t,
+   register int (*)(const void *, const void *, void *),
+   void *);
+
 #if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF
 /* Like sprintf but provides a pointer to malloc'd storage, which must
be freed by the caller.  */
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index d6b302e02fd..895f701bcd0 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -124,7 +124,7 @@ COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. 
-I$(INCDIR) \
 # CONFIGURED_OFILES and funcs in configure.ac.  Also run "make maint-deps"
 # to build the new rules.
 CFILES = alloca.c argv.c asprintf.c atexit.c   \
-   basename.c bcmp.c bcopy.c bsearch.c bzero.c \
+   basename.c bcmp.c bcopy.c bsearch.c bsearch_r.c bzero.c \
calloc.c choose-temp.c clock.c concat.c cp-demangle.c   \
 cp-demint.c cplus-dem.c crc32.c\
d-demangle.c dwarfnames.c dyn-string.c  \
@@ -168,6 +168,7 @@ REQUIRED_OFILES =   
\
./regex.$(objext) ./cplus-dem.$(objext) ./cp-demangle.$(objext) \
./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext) \
./argv.$(objext)\
+   ./bsearch_r.$(objext)   \
./choose-temp.$(objext) ./concat.$(objext)  \
./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext)  \
./dwarfnames.$(objext) ./dyn-string.$(objext)   \
@@ -601,6 +602,15 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
else true; fi
$(COMPILE.c) $(srcdir)/bsearch.c $(OUTPUT_OPTION)
 
+./bsearch_r.$(objext): $(srcdir)/bsearch_r.c config.h $(INCDIR)/ansidecl.h
+   if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/bsearch_r.c -o pic/$@; \
+   else true; fi
+   if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/bsearch_r.c -o 
noasan/$@; \
+   else true; fi
+   $(COMPILE.c) $(srcdir)/bsearch_r.c $(OUTPUT_OPTION)
+
 ./bzero.$(objext): $(srcdir)/bzero.c
if [ x"$(PICFLAG)" != x ]; then \
  $(COMPILE.c) $(PICFLAG) $(srcdir)/bzero.c -o pic/$@; \
diff --git a/libiberty/bsearch_r.c b/libiberty/bsearch_r.c
new file mode 100644
index 000..79ebae9b0be
--- /dev/null
+++ b/libiberty/bsearch_r.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. [rescinded 22 July 1999]
+ * 4. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS

Re: RFA: Remove use of register keyword in libiberty.h

2020-06-25 Thread Nick Alcock via Gcc-patches
On 25 Jun 2020, Nick Clifton outgrape:

> Hi Ian, Hi Nick,
>
>   Comping the GOLD linker with Clang has started producing this error
>   message:
>
> In file included from gold/archive.cc:29:
> include/libiberty.h:646:25: error: 'register' storage class
>   specifier is deprecated and incompatible with C++17
>   [-Werror,-Wdeprecated-register]
>
>   So I would like to apply the patch below to fix this.  Is this OK ?

Yes please! This was copied straight from bsearch.c, so you probably
want to change bsearch.c and bsearch_r.c as well (just in case clang
ever finds itself needing to build bsearch_r out of libiberty).


[PATCH 1/4] libtool.m4: augment symcode for Solaris 11

2021-06-25 Thread Nick Alcock via Gcc-patches
This reports common symbols like GNU nm, via a type code of 'C'.

Cc: gcc-patches@gcc.gnu.org

ChangeLog
2021-06-22  Nick Alcock  

PR libctf/27967
* libtool.m4 (lt_cv_sys_global_symbol_pipe): Augment symcode for
Solaris 11.
---
 libtool.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libtool.m4 b/libtool.m4
index 9a13f3b117a..b0a56917497 100644
--- a/libtool.m4
+++ b/libtool.m4
@@ -3395,7 +3395,7 @@ osf*)
   symcode='[[BCDEGQRST]]'
   ;;
 solaris*)
-  symcode='[[BDRT]]'
+  symcode='[[BCDRT]]'
   ;;
 sco3.2v5*)
   symcode='[[DT]]'
-- 
2.32.0.255.gd9b1d14a2a



[PATCH 2/4 REVIEW] libtool.m4: fix nm BSD flag detection

2021-06-25 Thread Nick Alcock via Gcc-patches
Libtool needs to get BSD-format (or MS-format) output out of the system
nm, so that it can scan generated object files for symbol names for
-export-symbols-regex support.  Some nms need specific flags to turn on
BSD-formatted output, so libtool checks for this in its AC_PATH_NM.
Unfortunately the code to do this has a pair of interlocking flaws:

 - it runs the test by doing an nm of /dev/null.  Some platforms
   reasonably refuse to do an nm on a device file, but before now this
   has only been worked around by assuming that the error message has a
   specific textual form emitted by Tru64 nm, and that getting this
   error means this is Tru64 nm and that nm -B would work to produce
   BSD-format output, even though the test never actually got anything
   but an error message out of nm -B.  This is fixable by nm'ing *nm
   itself* (since we necessarily have a path to it).

 - the test is entirely skipped if NM is set in the environment, on the
   grounds that the user has overridden the test: but the user cannot
   reasonably be expected to know that libtool wants not only nm but
   also flags forcing BSD-format output.  Worse yet, one such "user" is
   the top-level Cygnus configure script, which neither tests for
   nor specifies any BSD-format flags.  So platforms needing BSD-format
   flags always fail to set them when run in a Cygnus tree, breaking
   -export-symbols-regex on such platforms.  Libtool also needs to
   augment $LD on some platforms, but this is done unconditionally,
   augmenting whatever the user specified: the nm check should do the
   same.

   One wrinkle: if the user has overridden $NM, a path might have been
   provided: so we use the user-specified path if there was one, and
   otherwise do the path search as usual.  (If the nm specified doesn't
   work, this might lead to a few extra pointless path searches -- but
   the test is going to fail anyway, so that's not a problem.)

(Tested with NM unset, and set to nm, /usr/bin/nm, my-nm where my-nm is a
symlink to /usr/bin/nm on the PATH, and /not-on-the-path/my-nm where
*that* is a symlink to /usr/bin/nm.)

Cc: gcc-patches@gcc.gnu.org

ChangeLog
2021-06-22  Nick Alcock  

PR libctf/27482
* libtool.m4 (LT_PATH_NM): Try BSDization flags with a user-provided
NM, if there is one.  Run nm on itself, not on /dev/null, to avoid
errors from nms that refuse to work on non-regular files.  Remove
other workarounds for this problem.  Strip out blank lines from the
nm output.
---
 libtool.m4 | 88 --
 1 file changed, 45 insertions(+), 43 deletions(-)

diff --git a/libtool.m4 b/libtool.m4
index b0a56917497..29dce1f8239 100644
--- a/libtool.m4
+++ b/libtool.m4
@@ -3200,53 +3200,55 @@ _LT_DECL([], [file_magic_cmd], [1],
 
 # LT_PATH_NM
 # --
-# find the pathname to a BSD- or MS-compatible name lister
+# find the pathname to a BSD- or MS-compatible name lister, and any flags
+# needed to make it compatible
 AC_DEFUN([LT_PATH_NM],
 [AC_REQUIRE([AC_PROG_CC])dnl
 AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
 [if test -n "$NM"; then
-  # Let the user override the test.
-  lt_cv_path_NM="$NM"
-else
-  lt_nm_to_check="${ac_tool_prefix}nm"
-  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
-lt_nm_to_check="$lt_nm_to_check nm"
-  fi
-  for lt_tmp_nm in $lt_nm_to_check; do
-lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
-  IFS="$lt_save_ifs"
-  test -z "$ac_dir" && ac_dir=.
-  tmp_nm="$ac_dir/$lt_tmp_nm"
-  if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
-   # Check to see if the nm accepts a BSD-compat flag.
-   # Adding the `sed 1q' prevents false positives on HP-UX, which says:
-   #   nm: unknown option "B" ignored
-   # Tru64's nm complains that /dev/null is an invalid object file
-   case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
-   */dev/null* | *'Invalid file or object type'*)
- lt_cv_path_NM="$tmp_nm -B"
- break
- ;;
-   *)
- case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
- */dev/null*)
-   lt_cv_path_NM="$tmp_nm -p"
-   break
-   ;;
- *)
-   lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
-   continue # so that we can try to find one that supports BSD flags
-   ;;
- esac
- ;;
-   esac
-  fi
-done
-IFS="$lt_save_ifs"
-  done
-  : ${lt_cv_path_NM=no}
-fi])
+   # Let the user override the nm to test.
+   lt_nm_to_check="$NM&q

[PATCH 0/4 REVIEW] libtool and libctf fixes for Solaris 11

2021-06-25 Thread Nick Alcock via Gcc-patches
There are three intertwined bugs here, two in libtool.m4, one in libctf.
The underlying "problem" is that libctf tries to version its symbols: if
it can't use a GNU version script it tries to hide unnecessary symbols
using Libtool's --export-symbols-regex flag... and that flag has kinda
rusted.

Firstly, it relies on running nm and knowing what the symbol type codes
it emits (in BSD mode) mean: Solaris 11 has gained 'C' for common
symbols, like GNU nm, but libtool.m4 was never updated to know about
that, so the test failed.

Secondly, it relies on knowing how to switch nm into BSD mode, which it
does by nm'ing a bunch of candidate nms with various flags: but it nms
/dev/null and has not-very-good handling of nms that emit errors if you
do that.

Thirdly, libtool's nm option scanning is entirely suppressed if NM is
set in the environment, on the grounds that the user must have set it --
but libtool already augments other things set in the environment with
extra flags if needed, and the user can hardly be expected to know that
Libtool needs 'nm -p' on Solaris, not just nm. Worse yet, Cygnus
configure sets NM unconditionally, stopping the test dead.  Fixed by
checking flags even if the user overrides nm, but checking the specific
nm they requested.

The first two patches in this series need review because, well, libtool
upstream is dead enough that I don't know if I can even submit it there,
but it should probably go to GCC and binutils-gdb. I have tested it on
Solaris 11.3, Solaris 11.4, FreeBSD, (x86-64 and SPARC) Linux, and
Cygwin, which should be enough coverage, I hope.  libtool upstream has
diverged in this area and the patch would need redoing in any case
(though the conflicts look quite minor, I don't have time right now and
doing that wouldn't help fix any of the reporter's problems in any case).

(The latter two patches, sent to binutils@ alone, enable symbol
versioning on Solaris 11.4, which provides a --version-script flag
almost but not quite compatible with GNU ld's, and regenerate most
relevant configure scripts, skipping only sim/ because it's in a ferment
of change right now.)

Cc: gcc-patches@gcc.gnu.org

Nick Alcock (4):
  libtool.m4: augment symcode for Solaris 11
  libtool.m4: fix nm BSD flag detection
  libctf: try several possibilities for linker versioning flags
  configure: regenerate in all projects that use libtool.m4

 bfd/configure   |  91 -
 binutils/configure  |  91 -
 gas/configure   |  91 -
 gprof/configure |  91 -
 ld/configure|  91 -
 libctf/Makefile.am  |   5 +-
 libctf/Makefile.in  |   6 +-
 libctf/configure| 157 ++--
 libctf/configure.ac |  46 -
 libctf/libctf.ver   |  10 ++-
 libtool.m4  |  90 -
 opcodes/configure   |  91 -
 zlib/configure  |  91 -
 13 files changed, 531 insertions(+), 420 deletions(-)

-- 
2.32.0.255.gd9b1d14a2a