Re: [PATCH RFC 03/11] printversion: Fix unused variable

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
On Tue, 2023-02-07 at 21:44 +0100, Mark Wielaard wrote:
> Hi Ilya (CC Frank),
> 
> On Mon, Feb 06, 2023 at 11:25:05PM +0100, Ilya Leoshkevich via
> Elfutils-devel wrote:
> > clang complains:
> > 
> >     debuginfod.cxx:354:1: error: unused variable 'apba__' [-
> > Werror,-Wunused-const-variable]
> >     ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
> >     ^
> >     ../lib/printversion.h:47:21: note: expanded from macro
> > 'ARGP_PROGRAM_BUG_ADDRESS_DEF'
> >   const char *const apba__ __asm ("argp_program_bug_address")
> >     ^
> > 
> > This is as expected: it's used by argp via the
> > "argp_program_bug_address" name, which is not visible on the C
> > level.
> > Add __attribute__ ((used)) to make sure that the compiler emits it.
> 
> Actually I think it found a real issue. Note that the same construct
> is used the C eu tools.  But in debuginfod.cxx it says:
> 
> /* Name and version of program.  */
> /* ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; */ // not this
> simple for C++
> 
> /* Bug report address.  */
> ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
> 
> Note how ARGP_PROGRAM_VERSION_HOOK_DEF is commented out and in main
> it
> has:
> 
>    /* Parse and process arguments.  */
>    int remaining;
>    argp_program_version_hook = print_version; // this works
>    (void) argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &remaining,
> NULL);
> 
> So it sets print_version, but not argp_program_bug_address.
> And indeed debuginfod --help is missing the bug reporting address.
> 
> I don't really know/understand why the printversion.h macro trick
> doesn't work with C++ (symbol mangling?). But we do need at least
> this patch:
> 
> diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
> index 4271acf4..0ec326d5 100644
> --- a/debuginfod/debuginfod.cxx
> +++ b/debuginfod/debuginfod.cxx
> @@ -4172,6 +4165,7 @@ main (int argc, char *argv[])
>    /* Parse and process arguments.  */
>    int remaining;
>    argp_program_version_hook = print_version; // this works
> +  argp_program_bug_address = PACKAGE_BUGREPORT;
>    (void) argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &remaining,
> NULL);
>    if (remaining != argc)
>    error (EXIT_FAILURE, 0,
> 
> Then debuginfod --help will say: Report bugs to
> https://sourceware.org/bugzilla.
> 
> That of course doesn't help with the -Wunused-const-variable warning.
> 
> If we cannot figure out the magic variable naming trick with with C++
> then maybe we can just not include printversion.h and do it "by
> hand"?
> (as attached)
> 
> Cheers,
> 
> Mark

If I build:

const char *const apba__ __asm ("argp_program_bug_address") \
__attribute__ ((used)) = "foobarbaz";

with C and C++, the difference is going to be:

@@ -1,6 +1,5 @@
.file   "1.c"
.text
-   .globl  argp_program_bug_address
.section.rodata.str1.1,"aMS",@progbits,1
 .LC0:
.string "foobarbaz"

This must have to do with C and C++ standards treating const
differently [1]. The solution is to add extern:

--- a/lib/printversion.h
+++ b/lib/printversion.h
@@ -44,6 +44,7 @@ void print_version (FILE *stream, struct argp_state
*state);
   void (*const apvh) (FILE *, struct argp_state *) \
__asm ("argp_program_version_hook")
 #define ARGP_PROGRAM_BUG_ADDRESS_DEF \
+  extern const char *const apba__; \
   const char *const apba__ __asm ("argp_program_bug_address") \
   __attribute__ ((used))

I can include this in v2 if it works for you.

[1]
https://stackoverflow.com/questions/8908071/const-correctness-in-c-vs-c


Re: ☠ Buildbot (Sourceware): elfutils - failed test (failure) (master)

2023-02-08 Thread Frank Ch. Eigler via Elfutils-devel
Hi -

> > A new failure has been detected on builder elfutils-gentoo-sparc while 
> > building elfutils.
> >
> > Full details are available at:
> > https://builder.sourceware.org/buildbot/#builders/225/builds/10
> > - test-suite.log: 
> > https://builder.sourceware.org/buildbot/#builders/225/builds/10/steps/7/logs/test-suite_log
> 
> Failure due to make command timeout. It looks like the only test that didn't
> finish is run-debuginfod-section.sh, which is related to my changes.
> 
> But I'm not seeing how the changes might cause a timeout and unfortunately
> test-suite.log is empty.

Some useful info may be here:

https://builder.sourceware.org/testrun/fc4dda20768ee7e8fd2b3edf9c391cd84db15edd?focus=filelist

- FChE



☺ Buildbot (Sourceware): elfutils - build successful (master)

2023-02-08 Thread builder--- via Elfutils-devel
A restored build has been detected on builder elfutils-gentoo-sparc while 
building elfutils.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/225/builds/11

Build state: build successful
Revision: 53b596ef4018693403395d702045c15762af3da7
Worker: gentoo-sparc
Build Reason: (unknown)
Blamelist: Aaron Merey 

Steps:

- 0: worker_preparation ( success )

- 1: set package name ( success )

- 2: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/2/logs/stdio

- 3: autoreconf ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/3/logs/stdio

- 4: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/4/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/4/logs/config_log

- 5: get version ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/5/logs/stdio
- property changes: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/5/logs/property_changes

- 6: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/6/logs/stdio
- warnings (3): 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/6/logs/warnings__3_

- 7: make check ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/7/logs/stdio
- test-suite.log: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/7/logs/test-suite_log

- 8: prep ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/8/logs/stdio

- 9: build bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/9/logs/stdio

- 10: fetch bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/10/logs/stdio

- 11: unpack bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/11/logs/stdio

- 12: pass .bunsen.source.gitname ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/12/logs/stdio

- 13: pass .bunsen.source.gitdescribe ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/13/logs/stdio

- 14: pass .bunsen.source.gitbranch ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/14/logs/stdio

- 15: pass .bunsen.source.gitrepo ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/15/logs/stdio

- 16: upload to bunsen ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/16/logs/stdio

- 17: clean up ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/17/logs/stdio

- 18: make distclean ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/11/steps/18/logs/stdio



Re: [PATCH RFC 04/11] readelf: Fix set but not used parameter

2023-02-08 Thread Mark Wielaard
Hi Ilya,

On Mon, 2023-02-06 at 23:25 +0100, Ilya Leoshkevich via Elfutils-devel
wrote:
> clang complains:
> 
> readelf.c:12205:72: error: parameter 'desc' set but not used 
> [-Werror,-Wunused-but-set-parameter]
> handle_bit_registers (const Ebl_Register_Location *regloc, const void 
> *desc,
>^
> 
> Apparently handle_bit_registers() is unimplemented, but one line is
> still written for the future. Silence the warning by casting desc to
> void.

Someone else also noticed this and filed a bug report, could you add
the bug URL to the commit message?

https://sourceware.org/bugzilla/show_bug.cgi?id=30084

Also can we just remove this whole function?

It is never really used since as far as I can see we don't have any
backend with a core register sets where a register doesn't have a
number of bits which isn't a multiple of 8 (only ia64 has some 1 bit
registers, but those don't seem part of the core register set).

If we do accidentally try to handle such a register having an abort is
also not very nice. Lets just warn and return/continue. Something like
the attached?

Thanks,

Mark
diff --git a/src/readelf.c b/src/readelf.c
index 51b0e8b9..50bfd1c8 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12201,24 +12201,17 @@ handle_core_items (Elf *core, const void *desc, size_t descsz,
   return colno;
 }
 
-static unsigned int
-handle_bit_registers (const Ebl_Register_Location *regloc, const void *desc,
-		  unsigned int colno)
-{
-  desc += regloc->offset;
-
-  abort ();			/* XXX */
-  return colno;
-}
-
-
 static unsigned int
 handle_core_register (Ebl *ebl, Elf *core, int maxregname,
 		  const Ebl_Register_Location *regloc, const void *desc,
 		  unsigned int colno)
 {
   if (regloc->bits % 8 != 0)
-return handle_bit_registers (regloc, desc, colno);
+{
+  error (0, 0, "Warning: Cannot handle register with %" PRIu8 "bits\n",
+	 regloc->bits);
+  return colno;
+}
 
   desc += regloc->offset;
 


Re: [PATCH RFC 05/11] readelf: Fix set but not used variable

2023-02-08 Thread Mark Wielaard
Hi Ilya,

On Mon, 2023-02-06 at 23:25 +0100, Ilya Leoshkevich via Elfutils-devel
wrote:
> clang complains:
> 
> readelf.c:10250:10: error: variable 'nculist' set but not used 
> [-Werror,-Wunused-but-set-variable]
>   size_t nculist = 0;
>  ^
> 
> Fix by deleting it.

yeah, this is clearly a copy/paste from print_debug_macinfo_section
into print_debug_macro_section where the nculist isn't actually used.

Not much to add, so pushed as is.

Thanks,

Mark

> 
> Signed-off-by: Ilya Leoshkevich 
> ---
>  src/readelf.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/src/readelf.c b/src/readelf.c
> index f09c5c9b..76ca65f5 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -10247,7 +10247,6 @@ print_debug_macro_section (Dwfl_Module *dwflmod 
> __attribute__ ((unused)),
>Dwarf_Off ncu = 0;
>size_t hsize;
>struct mac_culist *culist = NULL;
> -  size_t nculist = 0;
>while (dwarf_nextcu (dbg, offset = ncu, &ncu, &hsize, NULL, NULL, NULL) == 
> 0)
>  {
>Dwarf_Die cudie;
> @@ -10268,7 +10267,6 @@ print_debug_macro_section (Dwfl_Module *dwflmod 
> __attribute__ ((unused)),
>newp->files = NULL;
>newp->next = culist;
>culist = newp;
> -  ++nculist;
>  }
>  
>const unsigned char *readp = (const unsigned char *) data->d_buf;



Re: [PATCH RFC 06/11] Initialize reglocs for VMCOREINFO

2023-02-08 Thread Mark Wielaard
Hi Ilya,

On Mon, 2023-02-06 at 23:25 +0100, Ilya Leoshkevich via Elfutils-devel
wrote:
> MSan complains:
> 
> Uninitialized value was created by an allocation of 'reglocs' in the 
> stack frame
>#0 0x562d35c686f0 in handle_core_note elfutils/src/readelf.c:12674:3
>#const Ebl_Register_Location *reglocs;
> ==1006199==WARNING: MemorySanitizer: use-of-uninitialized-value
>#0 0x562d35c68a2a in handle_core_note elfutils/src/readelf.c:12692:11
>#colno = handle_core_registers (ebl, ebl->elf, desc + regs_offset,
>#   reglocs, nregloc);
> 
> Strictly speaking, this is not a problem, because nregloc == 0, but for
> other note types we initialize it anyway, so do it here as well.

Yeah, this is something valgrind wouldn't complain about since it
doesn't see passing of an undefined value as "use". But I think msan is
technically correct that passing an indeterminate value to a function
provokes undefined behavior. Also it is of course more consistent with
the rest of the code which does initialize reglocs even when nregloc is
zero.

Pushed as is.

Thanks,

Mark


> Signed-off-by: Ilya Leoshkevich 
> ---
>  backends/linux-core-note.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/backends/linux-core-note.c b/backends/linux-core-note.c
> index 9faae4c3..238ec16d 100644
> --- a/backends/linux-core-note.c
> +++ b/backends/linux-core-note.c
> @@ -239,6 +239,7 @@ EBLHOOK(core_note) (const GElf_Nhdr *nhdr, const char 
> *name,
>   return 0;
>*regs_offset = 0;
>*nregloc = 0;
> +  *reglocs = NULL;
>*nitems = 1;
>*items = vmcoreinfo_items;
>return 1;



☠ Buildbot (Sourceware): elfutils - failed test (failure) (master)

2023-02-08 Thread builder--- via Elfutils-devel
A new failure has been detected on builder elfutils-gentoo-sparc while building 
elfutils.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/225/builds/12

Build state: failed test (failure)
Revision: 85c82b18475dfe1cbbc4250cfbec7844d233100b
Worker: gentoo-sparc
Build Reason: (unknown)
Blamelist: Ilya Leoshkevich 

Steps:

- 0: worker_preparation ( success )

- 1: set package name ( success )

- 2: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/2/logs/stdio

- 3: autoreconf ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/3/logs/stdio

- 4: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/4/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/4/logs/config_log

- 5: get version ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/5/logs/stdio
- property changes: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/5/logs/property_changes

- 6: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/6/logs/stdio
- warnings (3): 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/6/logs/warnings__3_

- 7: make check ( failure )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/7/logs/stdio
- test-suite.log: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/7/logs/test-suite_log

- 8: prep ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/8/logs/stdio

- 9: build bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/9/logs/stdio

- 10: fetch bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/10/logs/stdio

- 11: unpack bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/11/logs/stdio

- 12: pass .bunsen.source.gitname ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/12/logs/stdio

- 13: pass .bunsen.source.gitdescribe ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/13/logs/stdio

- 14: pass .bunsen.source.gitbranch ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/14/logs/stdio

- 15: pass .bunsen.source.gitrepo ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/15/logs/stdio

- 16: upload to bunsen ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/16/logs/stdio

- 17: clean up ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/17/logs/stdio

- 18: make distclean ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/18/logs/stdio



☺ Buildbot (Sourceware): elfutils - build successful (master)

2023-02-08 Thread builder--- via Elfutils-devel
A restored build has been detected on builder elfutils-gentoo-sparc while 
building elfutils.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/225/builds/13

Build state: build successful
Revision: 6cb1547e812e9c2eeca698b38d8ab2785b7a7abf
Worker: gentoo-sparc
Build Reason: (unknown)
Blamelist: Ilya Leoshkevich 

Steps:

- 0: worker_preparation ( success )

- 1: set package name ( success )

- 2: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/2/logs/stdio

- 3: autoreconf ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/3/logs/stdio

- 4: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/4/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/4/logs/config_log

- 5: get version ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/5/logs/stdio
- property changes: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/5/logs/property_changes

- 6: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/6/logs/stdio
- warnings (3): 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/6/logs/warnings__3_

- 7: make check ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/7/logs/stdio
- test-suite.log: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/7/logs/test-suite_log

- 8: prep ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/8/logs/stdio

- 9: build bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/9/logs/stdio

- 10: fetch bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/10/logs/stdio

- 11: unpack bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/11/logs/stdio

- 12: pass .bunsen.source.gitname ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/12/logs/stdio

- 13: pass .bunsen.source.gitdescribe ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/13/logs/stdio

- 14: pass .bunsen.source.gitbranch ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/14/logs/stdio

- 15: pass .bunsen.source.gitrepo ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/15/logs/stdio

- 16: upload to bunsen ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/16/logs/stdio

- 17: clean up ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/17/logs/stdio

- 18: make distclean ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/225/builds/13/steps/18/logs/stdio



Re: [PATCH RFC 10/11] configure: Add --disable-demangle

2023-02-08 Thread Mark Wielaard
Hi Ilya,

On Mon, 2023-02-06 at 23:25 +0100, Ilya Leoshkevich via Elfutils-devel
wrote:
> __cxa_demangle is normally implemented in the C++ runtime library,
> instrumenting which for MSan is a hassle. Add a knob for disabling it.
> 
> Signed-off-by: Ilya Leoshkevich 
> ---
>  configure.ac | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 7dc9be63..6a5c38af 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -466,11 +466,17 @@ CFLAGS="$CFLAGS -D_GNU_SOURCE"
>  AC_FUNC_STRERROR_R()
>  CFLAGS="$old_CFLAGS"
>  
> +AC_ARG_ENABLE([demangler],
> +AS_HELP_STRING([--disable-demangle],
> +   [Disable libstdc++ demangle support]))

Typo [--disable-demangler] (missing r).
Also we want to enable demangler support by default if the enable
option isn't given, so you need to add [], [enable_demangler=yes] at
the end.

AC_ARG_ENABLE (feature, help-string, [action-if-given], [action-if-not-
given])

So the action-if-not-given is to enable the feature.

Note that otherwise the summary at the end will have nothing for:

libstdc++ demangle support : 

Should be either yes or no, even when --enable-demangler or --disable-
demangler isn't given.

Cheers,

Mark

> +AS_IF([test "x$enable_demangler" == xyes],
>  AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl
>  AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])])
>  AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes")
>  AS_IF([test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes"],
> -  [enable_demangler=yes],[enable_demangler=no])
> +  [enable_demangler=yes],[enable_demangler=no]),
> +AM_CONDITIONAL(DEMANGLE, false))
>  
>  AC_ARG_ENABLE([textrelcheck],
>  AS_HELP_STRING([--disable-textrelcheck],



Re: [PATCH RFC 07/11] addr2line: Do not test demangling in run-addr2line-i-test.sh

2023-02-08 Thread Mark Wielaard
Hi Ilya,

On Mon, 2023-02-06 at 23:25 +0100, Ilya Leoshkevich via Elfutils-devel
wrote:
> There is run-addr2line-i-demangle-test.sh for that.

Well spotted. Pushed as is.

Thanks,

Mark

> Signed-off-by: Ilya Leoshkevich 
> ---
>  tests/run-addr2line-i-test.sh | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/tests/run-addr2line-i-test.sh b/tests/run-addr2line-i-test.sh
> index 4f63e487..e7b89083 100755
> --- a/tests/run-addr2line-i-test.sh
> +++ b/tests/run-addr2line-i-test.sh
> @@ -254,13 +254,13 @@ EOF
>  
>  testfiles testfile-inlines-lto
>  
> -testrun_compare ${abs_top_builddir}/src/addr2line --pretty -fiC -e 
> testfile-inlines-lto 0x1118 0x1137 <<\EOF
> -foobar(int) at /tmp/x.cpp:4:14
> - (inlined by) foo(int) at /tmp/x.cpp:22:16
> - (inlined by) fu(int) at /tmp/x.cpp:27:13
> -fubar(int) at /tmp/x.cpp:10:14
> - (inlined by) bar(int) at /tmp/x.cpp:16:15
> - (inlined by) fu(int) at /tmp/x.cpp:27:24
> +testrun_compare ${abs_top_builddir}/src/addr2line --pretty -fi -e 
> testfile-inlines-lto 0x1118 0x1137 <<\EOF
> +_Z6foobari at /tmp/x.cpp:4:14
> + (inlined by) _Z3fooi at /tmp/x.cpp:22:16
> + (inlined by) _Z2fui at /tmp/x.cpp:27:13
> +_Z5fubari at /tmp/x.cpp:10:14
> + (inlined by) _Z3bari at /tmp/x.cpp:16:15
> + (inlined by) _Z2fui at /tmp/x.cpp:27:24
>  EOF
>  
>  exit 0



Re: ☠ Buildbot (Sourceware): elfutils - failed test (failure) (master)

2023-02-08 Thread Mark Wielaard
Hi Ilya,

On Wed, 2023-02-08 at 17:57 +, builder--- via Elfutils-devel wrote:
> A new failure has been detected on builder elfutils-gentoo-sparc while 
> building elfutils.
> 
> Full details are available at:
> https://builder.sourceware.org/buildbot/#builders/225/builds/12
> 
> Build state: failed test (failure)
> Revision: 85c82b18475dfe1cbbc4250cfbec7844d233100b
> Worker: gentoo-sparc
> Build Reason: (unknown)
> Blamelist: Ilya Leoshkevich 

This is clearly not caused by your patch. It seems to be specific to
sparc for which we had an issue earlier today, which also seemed a
false positive.

The log has:
terminate called after throwing an instance of 'sqlite_exception'
But we should catch that (a reportable_exception) almost always.

Odd.

Cheers,

Mark

> Steps:
> 
> - 0: worker_preparation ( success )
> 
> - 1: set package name ( success )
> 
> - 2: git checkout ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/2/logs/stdio
> 
> - 3: autoreconf ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/3/logs/stdio
> 
> - 4: configure ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/4/logs/stdio
> - config.log: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/4/logs/config_log
> 
> - 5: get version ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/5/logs/stdio
> - property changes: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/5/logs/property_changes
> 
> - 6: make ( warnings )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/6/logs/stdio
> - warnings (3): 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/6/logs/warnings__3_
> 
> - 7: make check ( failure )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/7/logs/stdio
> - test-suite.log: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/7/logs/test-suite_log
> 
> - 8: prep ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/8/logs/stdio
> 
> - 9: build bunsen.cpio.gz ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/9/logs/stdio
> 
> - 10: fetch bunsen.cpio.gz ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/10/logs/stdio
> 
> - 11: unpack bunsen.cpio.gz ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/11/logs/stdio
> 
> - 12: pass .bunsen.source.gitname ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/12/logs/stdio
> 
> - 13: pass .bunsen.source.gitdescribe ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/13/logs/stdio
> 
> - 14: pass .bunsen.source.gitbranch ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/14/logs/stdio
> 
> - 15: pass .bunsen.source.gitrepo ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/15/logs/stdio
> 
> - 16: upload to bunsen ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/16/logs/stdio
> 
> - 17: clean up ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/17/logs/stdio
> 
> - 18: make distclean ( success )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/225/builds/12/steps/18/logs/stdio
> 



[PATCH v2 2/7] printversion: Fix unused variable

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
clang complains:

debuginfod.cxx:354:1: error: unused variable 'apba__' 
[-Werror,-Wunused-const-variable]
ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
^
../lib/printversion.h:47:21: note: expanded from macro 
'ARGP_PROGRAM_BUG_ADDRESS_DEF'
  const char *const apba__ __asm ("argp_program_bug_address")
^

This is as expected: it's used by argp via the
"argp_program_bug_address" name, which is not visible on the C level.
Add __attribute__ ((used)) to make sure that the compiler emits it.

While at it, fix debuginfod not printing the bug report address.

Signed-off-by: Ilya Leoshkevich 
---
 lib/printversion.h | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/printversion.h b/lib/printversion.h
index a9e059ff..37adff7e 100644
--- a/lib/printversion.h
+++ b/lib/printversion.h
@@ -39,11 +39,14 @@ void print_version (FILE *stream, struct argp_state *state);
argp_program_bug_address, in all programs.  argp.h declares these
variables as non-const (which is correct in general).  But we can
do better, it is not going to change.  So we want to move them into
-   the .rodata section.  Define macros to do the trick.  */
+   the .rodata section.  Define macros to do the trick.  The default
+   linkage for consts in C++ is internal, so declare them extern.  */
 #define ARGP_PROGRAM_VERSION_HOOK_DEF \
   void (*const apvh) (FILE *, struct argp_state *) \
__asm ("argp_program_version_hook")
 #define ARGP_PROGRAM_BUG_ADDRESS_DEF \
-  const char *const apba__ __asm ("argp_program_bug_address")
+  extern const char *const apba__; \
+  const char *const apba__ __asm ("argp_program_bug_address") \
+  __attribute__ ((used))
 
 #endif // PRINTVERSION_H
-- 
2.39.1



[PATCH v2 1/7] libasm: Fix xdefault_pattern initialization

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
clang complains:

asm_newscn.c:48:22: error: field 'pattern' with variable sized type 'struct 
FillPattern' not at the end of a struct or class is a GNU extension 
[-Werror,-Wgnu-variable-sized-type-not-at-end]
  struct FillPattern pattern;
 ^

Fix by using a union instead. Define the second union member to be a
char array 1 byte larger than struct FillPattern. This should be legal
according to 6.7.9:

If an object that has static or thread storage duration is not
initialized explicitly, then ... if it is a union, the first named
member is initialized (recursively) according to these rules, and
any padding is initialized to zero bits.

Signed-off-by: Ilya Leoshkevich 
---
 libasm/asm_newscn.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libasm/asm_newscn.c b/libasm/asm_newscn.c
index d258d969..f28c40f9 100644
--- a/libasm/asm_newscn.c
+++ b/libasm/asm_newscn.c
@@ -41,19 +41,25 @@
 
 
 /* Memory for the default pattern.  The type uses a flexible array
-   which does work well with a static initializer.  So we play some
-   dirty tricks here.  */
-static const struct
+   which does work well with a static initializer.  Work around this by
+   wrapping it in a union, whose second member is a char array 1 byte larger
+   than struct FillPattern.  According to 6.7.9, this does what we need:
+
+If an object that has static or thread storage duration is not
+initialized explicitly, then ... if it is a union, the first named
+member is initialized (recursively) according to these rules, and
+any padding is initialized to zero bits.  */
+
+static const union
 {
   struct FillPattern pattern;
-  char zero;
+  char zeroes[sizeof(struct FillPattern) + 1];
 } xdefault_pattern =
   {
 .pattern =
 {
   .len = 1
 },
-.zero = '\0'
   };
 const struct FillPattern *__libasm_default_pattern = &xdefault_pattern.pattern;
 
-- 
2.39.1



[PATCH v2 3/7] readelf: Fix set but not used parameter

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
clang complains:

readelf.c:12205:72: error: parameter 'desc' set but not used 
[-Werror,-Wunused-but-set-parameter]
handle_bit_registers (const Ebl_Register_Location *regloc, const void *desc,
   ^

Mark Wielaard says:

It is never really used since as far as I can see we don't have any
backend with a core register sets where a register doesn't have a
number of bits which isn't a multiple of 8 (only ia64 has some 1
bit registers, but those don't seem part of the core register set).

If we do accidentally try to handle such a register having an abort
is also not very nice. Lets just warn and return/continue.

https://sourceware.org/bugzilla/show_bug.cgi?id=30084

Co-developed-by: Mark Wielaard 
Signed-off-by: Ilya Leoshkevich 
---
 src/readelf.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/readelf.c b/src/readelf.c
index 0bbd708e..5b3319c2 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12199,24 +12199,17 @@ handle_core_items (Elf *core, const void *desc, 
size_t descsz,
   return colno;
 }
 
-static unsigned int
-handle_bit_registers (const Ebl_Register_Location *regloc, const void *desc,
- unsigned int colno)
-{
-  desc += regloc->offset;
-
-  abort ();/* XXX */
-  return colno;
-}
-
-
 static unsigned int
 handle_core_register (Ebl *ebl, Elf *core, int maxregname,
  const Ebl_Register_Location *regloc, const void *desc,
  unsigned int colno)
 {
   if (regloc->bits % 8 != 0)
-return handle_bit_registers (regloc, desc, colno);
+{
+  error (0, 0, "Warning: Cannot handle register with %" PRIu8 "bits\n",
+regloc->bits);
+  return colno;
+}
 
   desc += regloc->offset;
 
-- 
2.39.1



[PATCH v2 0/7] Add Memory Sanitizer support

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
Hi,

I've made the updates suggested so far and rebased on top of the latest
master. Please take a look.

v1: https://sourceware.org/pipermail/elfutils-devel/2023q1/005831.html
v1 -> v2:
* Drop the unnecessary and the integrated patches.
* Add a comment to the xdefault_pattern patch.
* Add extern to the printversion patch.
* Use the fix from Mark for the handle_bit_registers() issue.
* Fix the --disable-demangle default value.

Best regards,
Ilya

Ilya Leoshkevich (7):
  libasm: Fix xdefault_pattern initialization
  printversion: Fix unused variable
  readelf: Fix set but not used parameter
  x86_64_return_value_location: Support lvalue and rvalue references
  configure: Use -fno-addrsig if possible
  configure: Add --disable-demangler
  configure: Add --enable-sanitize-memory

 backends/x86_64_retval.c  |  2 ++
 configure.ac  | 40 ++-
 debuginfod/Makefile.am|  3 ++-
 lib/printversion.h|  7 +--
 libasm/Makefile.am|  3 ++-
 libasm/asm_newscn.c   | 16 +++-
 libdw/Makefile.am |  3 ++-
 libelf/Makefile.am|  3 ++-
 src/readelf.c | 17 +
 tests/Makefile.am | 10 +-
 tests/run-readelf-self.sh |  5 +
 tests/run-strip-reloc.sh  |  5 +
 tests/run-varlocs-self.sh |  5 +
 13 files changed, 94 insertions(+), 25 deletions(-)

-- 
2.39.1



[PATCH v2 5/7] configure: Use -fno-addrsig if possible

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
By default, clang produces .llvm_addrsig sections [1]. The GNU
toolchain does not know how to handle them yet [2], so just ask clang
not to generate them for the time being.

[1] 
https://llvm.org/docs/Extensions.html#sht-llvm-addrsig-section-address-significance-table
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105625

Signed-off-by: Ilya Leoshkevich 
---
 configure.ac | 8 
 1 file changed, 8 insertions(+)

diff --git a/configure.ac b/configure.ac
index 8fe8baee..7dc9be63 100644
--- a/configure.ac
+++ b/configure.ac
@@ -588,6 +588,14 @@ CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(HAVE_NO_PACKED_NOT_ALIGNED_WARNING,
   [test "x$ac_cv_no_packed_not_aligned" != "xno"])
 
+AC_CACHE_CHECK([whether the compiler accepts -fno-addrsig], ac_cv_fno_addrsig, 
[dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fno-addrsig -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+  ac_cv_fno_addrsig=yes, ac_cv_fno_addrsig=no)
+CFLAGS="$old_CFLAGS"])
+AS_IF([test "x$ac_cv_fno_addrsig" = "xyes"], CFLAGS="$CFLAGS -fno-addrsig")
+
 saved_LIBS="$LIBS"
 AC_SEARCH_LIBS([argp_parse], [argp])
 LIBS="$saved_LIBS"
-- 
2.39.1



[PATCH v2 4/7] x86_64_return_value_location: Support lvalue and rvalue references

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
On the low level, they are the same as pointers.

Signed-off-by: Ilya Leoshkevich 
---
 backends/x86_64_retval.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/backends/x86_64_retval.c b/backends/x86_64_retval.c
index f9114cb1..e668eacc 100644
--- a/backends/x86_64_retval.c
+++ b/backends/x86_64_retval.c
@@ -106,6 +106,8 @@ x86_64_return_value_location (Dwarf_Die *functypedie, const 
Dwarf_Op **locp)
 case DW_TAG_enumeration_type:
 case DW_TAG_pointer_type:
 case DW_TAG_ptr_to_member_type:
+case DW_TAG_reference_type:
+case DW_TAG_rvalue_reference_type:
   {
Dwarf_Attribute attr_mem;
if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
-- 
2.39.1



[PATCH v2 7/7] configure: Add --enable-sanitize-memory

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
Add support for clang Memory Sanitizer [1], which detects the usage of
uninitialized values. While elfutils itself is already checked with
valgrind, checking code that depends on elfutils requires elfutils to
be built with MSan.

MSan is not linked into shared libraries, and is linked into
executables statically. Therefore, unlike the other sanitizers, MSan
needs to be configured fairly early, since we need to drop
-D_FORTIFY_SOURCE [2], -Wl,-z,defs and --no-undefined.

Disable a few tests that run for more than 5 minutes due to test files
being statically linked with MSan.

[1] https://clang.llvm.org/docs/MemorySanitizer.html
[2] https://github.com/google/sanitizers/issues/247

Signed-off-by: Ilya Leoshkevich 
---
 configure.ac  | 24 
 debuginfod/Makefile.am|  3 ++-
 libasm/Makefile.am|  3 ++-
 libdw/Makefile.am |  3 ++-
 libelf/Makefile.am|  3 ++-
 tests/Makefile.am | 10 +-
 tests/run-readelf-self.sh |  5 +
 tests/run-strip-reloc.sh  |  5 +
 tests/run-varlocs-self.sh |  5 +
 9 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 62a4c8a7..0eb309cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,6 +155,29 @@ AC_SUBST([fpie_CFLAGS])
 
 dso_LDFLAGS="-shared"
 
+NO_UNDEFINED=-Wl,--no-undefined
+AC_ARG_ENABLE([sanitize-memory],
+  AS_HELP_STRING([--enable-sanitize-memory],
+ [Use clang memory sanitizer]),
+ [use_msan=$enableval], [use_msan=no])
+if test "$use_msan" = yes; then
+  old_CFLAGS="$CFLAGS"
+  old_CXXFLAGS="$CXXFLAGS"
+  old_LDFLAGS="$LDFLAGS"
+  # -fsanitize=memory is not compatible with -D_FORTIFY_SOURCE, -Wl,-z,defs 
and --no-undefined
+  CFLAGS="$CFLAGS -fsanitize=memory -fsanitize-memory-track-origins 
-D_FORTIFY_SOURCE=0"
+  CXXFLAGS="$CXXFLAGS -fsanitize=memory -fsanitize-memory-track-origins 
-D_FORTIFY_SOURCE=0"
+  LDFLAGS="-shared"
+  AC_LINK_IFELSE([AC_LANG_SOURCE([int main (int argc, char **argv) { return 0; 
}])], use_msan=yes, use_msan=no)
+  AS_IF([test "x$use_msan" == xyes],
+ac_cv_zdefs=no NO_UNDEFINED=,
+AC_MSG_WARN([clang memory sanitizer not available])
+CFLAGS="$old_CFLAGS" CXXFLAGS="$old_CXXFLAGS")
+  LDFLAGS="$old_LDFLAGS"
+fi
+AC_SUBST(NO_UNDEFINED)
+AM_CONDITIONAL(USE_MEMORY_SANITIZER, test "$use_msan" = yes)
+
 ZDEFS_LDFLAGS="-Wl,-z,defs"
 AC_CACHE_CHECK([whether gcc supports $ZDEFS_LDFLAGS], ac_cv_zdefs, [dnl
 save_LDFLAGS="$LDFLAGS"
@@ -887,6 +910,7 @@ AC_MSG_NOTICE([
 run all tests under valgrind   : ${use_valgrind}
 gcc undefined behaviour sanitizer  : ${use_undefined}
 gcc address sanitizer  : ${use_address}
+clang memory sanitizer : ${use_msan}
 use rpath in tests : ${tests_use_rpath}
 test biarch: ${utrace_cv_cc_biarch}
 ])
diff --git a/debuginfod/Makefile.am b/debuginfod/Makefile.am
index f27d6e2e..125be97b 100644
--- a/debuginfod/Makefile.am
+++ b/debuginfod/Makefile.am
@@ -102,7 +102,8 @@ endif
 $(LIBDEBUGINFOD_SONAME): $(srcdir)/libdebuginfod.map $(libdebuginfod_so_LIBS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$(LIBDEBUGINFOD_SONAME) \
-   -Wl,--version-script,$<,--no-undefined \
+   -Wl,--version-script,$< \
+   $(NO_UNDEFINED) \
-Wl,--whole-archive $(libdebuginfod_so_LIBS) 
-Wl,--no-whole-archive \
$(libdebuginfod_so_LDLIBS)
@$(textrel_check)
diff --git a/libasm/Makefile.am b/libasm/Makefile.am
index c2b54811..1e6b63e8 100644
--- a/libasm/Makefile.am
+++ b/libasm/Makefile.am
@@ -64,7 +64,8 @@ libasm_so_LIBS = libasm_pic.a
 libasm.so: $(srcdir)/libasm.map $(libasm_so_LIBS) $(libasm_so_DEPS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$@.$(VERSION) \
-   -Wl,--version-script,$<,--no-undefined \
+   -Wl,--version-script,$< \
+   $(NO_UNDEFINED) \
-Wl,--whole-archive $(libasm_so_LIBS) -Wl,--no-whole-archive \
$(libasm_so_LDLIBS)
@$(textrel_check)
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index 1b6fead4..e548f38c 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -114,7 +114,8 @@ libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) 
$(fts_LIBS) $(obstack_
 libdw.so: $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$@.$(VERSION),--enable-new-dtags \
-   -Wl,--version-script,$<,--no-undefined \
+   -Wl,--version-script,$< \
+   $(NO_UNDEFINED) \
-Wl,--whole-archive $(libdw_so_LIBS) -Wl,--no-whole-archive \
$(libdw_so_LDLIBS)
@$(textrel_check)
diff --git a/libelf/Makefile.am b/libelf/Makefile.am
index 24c25cf8..aabce43e 100644
--- a/libelf/Makefile.

[PATCH v2 6/7] configure: Add --disable-demangler

2023-02-08 Thread Ilya Leoshkevich via Elfutils-devel
__cxa_demangle is normally implemented in the C++ runtime library,
instrumenting which for MSan is a hassle. Add a knob for disbling it.

Signed-off-by: Ilya Leoshkevich 
---
 configure.ac | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 7dc9be63..62a4c8a7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -466,11 +466,17 @@ CFLAGS="$CFLAGS -D_GNU_SOURCE"
 AC_FUNC_STRERROR_R()
 CFLAGS="$old_CFLAGS"
 
+AC_ARG_ENABLE([demangler],
+AS_HELP_STRING([--disable-demangler],
+  [Disable libstdc++ demangle support]),
+  [], [enable_demangler=yes])
+AS_IF([test "x$enable_demangler" == xyes],
 AC_CHECK_LIB([stdc++], [__cxa_demangle], [dnl
 AC_DEFINE([USE_DEMANGLE], [1], [Defined if demangling is enabled])])
 AM_CONDITIONAL(DEMANGLE, test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes")
 AS_IF([test "x$ac_cv_lib_stdcpp___cxa_demangle" = "xyes"],
-  [enable_demangler=yes],[enable_demangler=no])
+  [enable_demangler=yes],[enable_demangler=no]),
+AM_CONDITIONAL(DEMANGLE, false))
 
 AC_ARG_ENABLE([textrelcheck],
 AS_HELP_STRING([--disable-textrelcheck],
-- 
2.39.1