Re: [PATCH] elfclassify tool

2019-07-19 Thread Mark
On Fri, 2019-07-19 at 16:43 +0300, Dmitry V. Levin wrote:
> On Fri, Jul 19, 2019 at 02:47:09PM +0200, Mark Wielaard wrote:
> [...]
> > +static bool
> > +is_shared (void)
> > +{
> > +  if (!is_loadable ())
> > +return false;
> > +
> > +  /* The ELF type is very clear: this is an executable.  */
> > +  if (elf_type == ET_EXEC)
> > +return false;
> > +
> > +  /* If the object is marked as PIE, it is definitely an
> > executable,
> > + and not a loadlable shared object.  */
> > +  if (has_pie_flag)
> > +return false;
> > +
> > +  /* Treat a DT_SONAME tag as a strong indicator that this is a
> > shared
> > + object.  */
> > +  if (has_soname)
> > +return true;
> 
> I'm not sure DT_SONAME is a reliable indicator.
> 
> I've seen many cases of DT_SONAME being erroneously applied to 
> non-libraries, e.g. lib.so was used as soname in openjdk executables.

I didn't know. Is this really common?
I did find one java binary on my system that indeed has this problem.
$ eu-readelf -d /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-
0.el7_6.x86_64/jre/bin/policytool

Dynamic segment contains 39 entries:
 Addr: 0x00600d88  Offset: 0x000d88  Link to section: [ 7]
'.dynstr'
  Type  Value
  NEEDEDShared library: [libpthread.so.0]
  NEEDEDShared library: [libz.so.1]
  NEEDEDShared library: [libX11.so.6]
  NEEDEDShared library: [libjli.so]
  NEEDEDShared library: [libdl.so.2]
  NEEDEDShared library: [libc.so.6]
  SONAMELibrary soname: [lib.so]
  RPATH Library rpath:
[$ORIGIN/../lib/amd64/jli:$ORIGIN/../lib/amd64]
[...]

But even so eu-elfclassify still doesn't treat it as a shared library,
because:
$ eu-elfclassify -v --shared policytool; echo $?
info: policytool: ELF kind: ELF_K_ELF (0x3)
info: policytool: ELF type: ET_EXEC (0x2)
info: policytool: PT_LOAD found
info: policytool: allocated PROGBITS section found
info: policytool: program interpreter found
info: policytool: dynamic segment found
info: policytool: soname found
info: policytool: DT_DEBUG found
1

So other characteristics like it being ET_EXEC mark it as an
executable. And I assume if it was PIE (ET_DYN) the PIE DT_FLAGS would
have caught it.

So, I don't think the code is wrong. We might want to tweak the comment
a bit though, to make it less definitive?

Cheers,

Mark


Re: [PATCH] readelf: Handle SHT_RISCV_ATTRIBUTES like SHT_GNU_ATTRIBUTES

2022-08-13 Thread Mark Wielaard
On Wed, 10 Aug 2022 10:52:42 +0200, Andreas Schwab wrote:
> 


Applied, thanks!

[1/1] readelf: Handle SHT_RISCV_ATTRIBUTES like SHT_GNU_ATTRIBUTES
  commit: b713edb9a7f3da8e4dd28ac69a1665ed493ca504

Best regards,
-- 
Mark Wielaard 


Re: cannot skip augment string handling

2022-08-13 Thread Mark Wielaard
Hi Ulrich,

On Tue, Aug 09, 2022 at 08:01:43PM +0200, Ulrich Drepper via Elfutils-devel 
wrote:
> He dwarf_next_cfi function has some clever code which skips over the
> processing of the augmentation string content if the first character is 'z'
> (for sized augmentation).  This would be OK if it wouldn't be for the fact
> that the augment processing loop produces additional information, namely,
> it fills in the fde_augmentation_data_size fields.  That information isn't
> available elsewhere.
> 
> In addition, the loop over the augment string is incorrect because the
> interpretation of the P, L, and R entries depends on 'z' being present.  in
> the absence of 'z', when the loop would be executed in the current version,
> the interpretation of those entries is not the same.
> 
> In the patch below I've removed the shortcut and fixed the handling of the
> P, L, and R entries.  I've also added an additional test checking that the
> entries of the augmentation string don't guide the code to consume more
> data then is indicated in the 'z' data.

Looks good. Thanks for catching this. Please do add a Signed-off-by
line next time. See the CONTRIBUTING file.

I was wondering why this hasn't caused an issue before. But it looks
like internally when we use the result of dwarf_next_cfi in cie.c and
fde.c we always call __libdw_intern_cie or intern_new_cie which
recalculates the fde_augmentation_data_size by reading the
augmentation string and data again.

Thanks,

Mark


Re: buildbot users try branch builders for elfutils

2022-08-15 Thread Mark Wielaard
Hi Martin,

On Mon, Aug 15, 2022 at 09:55:13AM +0200, Martin Liška wrote:
> On 7/28/22 17:26, Mark Wielaard wrote:
> > I setup git users try branches for elfutils. If you have commit
> > access to elfutils.git you can now [...]
> 
> I would like to try this great feature!
> [...]
> But I get:
> 
> git push origin 
> PR29474-fix-debuginfod-concurrency:users/marxin/try-PR29474-fix-debuginfod-concurrency
> [...]
> error: remote unpack failed: unable to create temporary object directory
> To ssh://sourceware.org/git/elfutils.git
>  ! [remote rejected]   PR29474-fix-debuginfod-concurrency -> 
> users/marxin/try-PR29474-fix-debuginfod-concurrency (unpacker error)
> error: failed to push some refs to 'ssh://sourceware.org/git/elfutils.git'
> 
> Can you please take a look what happens?

That unhelpful error message tries to say you are not an elfutils
developer.

Lets fix that. I added you to the elfutils groups. Please remember,
with great power comes great responsibility (aka, please reread the
elfutils CONTRIBUTING file).

You should now also be able to use the users try branches.  So please
try again.

Cheers,

Mark


[PATCH] ar: Correct -N COUNT off-by-one

2022-08-28 Thread Mark Wielaard
When using instance [COUNT], the instance check is wrong.
instance-- == 0 should be --instance == 0.

Add a testcase run-ar-N.sh that uses -N COUNT with extract and delete
operations checking the right instance was extracted and deleted.

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

Reported-by: panxiaohe 
Signed-off-by: Mark Wielaard 
---
 src/ChangeLog |  6 +
 src/ar.c  |  4 +--
 tests/ChangeLog   |  6 +
 tests/Makefile.am |  2 ++
 tests/run-ar-N.sh | 65 +++
 5 files changed, 81 insertions(+), 2 deletions(-)
 create mode 100755 tests/run-ar-N.sh

diff --git a/src/ChangeLog b/src/ChangeLog
index 88db4051..9348c562 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2022-08-28  Mark Wielaard  
+
+   * ar.c (do_oper_extract): Predecrement instance before compare
+   to zero.
+   (do_oper_delete): Likewise.
+
 2022-08-10  Andreas Schwab  
 
* readelf.c (print_attributes): Also handle SHT_RISCV_ATTRIBUTES.
diff --git a/src/ar.c b/src/ar.c
index 9e8df120..04456c18 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -518,7 +518,7 @@ do_oper_extract (int oper, const char *arfname, char 
**argv, int argc,
  ENTRY entry;
  entry.key = arhdr->ar_name;
  ENTRY *res = hsearch (entry, FIND);
- if (res != NULL && (instance < 0 || instance-- == 0)
+ if (res != NULL && (instance < 0 || --instance == 0)
  && !found[(char **) res->data - argv])
found[(char **) res->data - argv] = do_extract = true;
}
@@ -952,7 +952,7 @@ do_oper_delete (const char *arfname, char **argv, int argc,
  ENTRY entry;
  entry.key = arhdr->ar_name;
  ENTRY *res = hsearch (entry, FIND);
- if (res != NULL && (instance < 0 || instance-- == 0)
+ if (res != NULL && (instance < 0 || --instance == 0)
  && !found[(char **) res->data - argv])
found[(char **) res->data - argv] = do_delete = true;
}
diff --git a/tests/ChangeLog b/tests/ChangeLog
index d2952cc9..48bb28d1 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2022-08-26  Mark Wielaard  
+
+   * run-ar-N.sh: New test.
+   * Makefile.am (TESTS): Add run-ar-N.sh.
+   (EXTRA_DIST): Likewise.
+
 2022-08-04  Sergei Trofimovich  
 
* low_high_pc.c (handle_die): Drop redundant 'lx' suffix.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 87988fb9..85514898 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,6 +100,7 @@ test-nlist$(EXEEXT): test-nlist.c
  $(test_nlist_CFLAGS) $(GCOV_FLAGS) -o $@ $< $(test_nlist_LDADD)
 
 TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
+   run-ar-N.sh \
update1 update2 update3 update4 \
run-show-die-info.sh run-get-files.sh run-get-lines.sh \
run-next-files.sh run-next-lines.sh \
@@ -254,6 +255,7 @@ endif
 endif
 
 EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
+run-ar-N.sh \
 run-show-die-info.sh run-get-files.sh run-get-lines.sh \
 run-next-files.sh run-next-lines.sh testfile-only-debug-line.bz2 \
 run-get-pubnames.sh run-get-aranges.sh \
diff --git a/tests/run-ar-N.sh b/tests/run-ar-N.sh
new file mode 100755
index ..de8f62b3
--- /dev/null
+++ b/tests/run-ar-N.sh
@@ -0,0 +1,65 @@
+#! /usr/bin/env bash
+# Copyright (C) 2022 Mark J. Wielaard 
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+tempfiles testfile test.ar
+
+echo create test.ar with 3 testfile
+echo 1 > testfile
+testrun ${abs_top_builddir}/src/ar -vr test.ar testfile
+echo 2 > testfile
+testrun ${abs_top_builddir}/src/ar -vq test.ar testfile
+testrun ${abs_top_builddir}/src/ar -t test.ar
+echo 3 > testfile
+testrun ${abs_top_builddir}/src/ar -vq test.ar testfile
+testrun_compare ${abs_top_builddir}/src/ar -t test.ar << EOF
+testfile
+testfile
+testfile
+EOF
+
+echo list content of testfile 1 2 3
+testrun ${abs_top_builddir}/src/ar -vx -N 1 test.ar testfile
+diff -u testfile - << EOF
+1
+EOF
+testrun ${abs_top_builddir}/src/ar -vx -N 2 test.ar testfile
+diff -u testfile - << EOF
+2
+EOF
+testrun ${abs_top_builddir}/src/ar -vx -N 

[PATCH] libelf: Correctly decode ar_mode as octal string

2022-08-28 Thread Mark Wielaard
ar_mode is encoded as an octal ascii string, not decimal. Add a new
OCT_FIELD macro to decode it.

Signed-off-by: Mark Wielaard 
---

This was found by the run-ar-N.sh testcase on the try builder.

 libelf/ChangeLog   |  5 +
 libelf/elf_begin.c | 25 +++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 35f49516..558d795e 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2022-08-28  Mark Wielaard  
+
+   * elf_begin.c (__libelf_next_arhdr_wrlock): Add OCT_FIELD macro,
+   like INT_FIELD but use strtol with octal base 8. Use for ar_mode.
+
 2022-08-08  Andreas Schwab  
 
* elf.h: Update from glibc.
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 17d9b1f3..71eb3594 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -977,7 +977,8 @@ __libelf_next_arhdr_wrlock (Elf *elf)
  atoll depending on the size of the types.  We are also prepared
  for the case where the whole field in the `struct ar_hdr' is
  filled in which case we cannot simply use atol/l but instead have
- to create a temporary copy.  */
+ to create a temporary copy.  Note that all fields use decimal
+ encoding, except ar_mode which uses octal.  */
 
 #define INT_FIELD(FIELD) \
   do \
@@ -997,10 +998,30 @@ __libelf_next_arhdr_wrlock (Elf *elf)
 }\
   while (0)
 
+#define OCT_FIELD(FIELD) \
+  do \
+{\
+  char buf[sizeof (ar_hdr->FIELD) + 1];  \
+  const char *string = ar_hdr->FIELD;\
+  if (ar_hdr->FIELD[sizeof (ar_hdr->FIELD) - 1] != ' ')  \
+   { \
+ *((char *) mempcpy (buf, ar_hdr->FIELD, sizeof (ar_hdr->FIELD)))  \
+   = '\0';   \
+ string = buf;   \
+   } \
+  if (sizeof (elf_ar_hdr->FIELD) <= sizeof (long int))   \
+   elf_ar_hdr->FIELD \
+ = (__typeof (elf_ar_hdr->FIELD)) strtol (string, NULL, 8);  \
+  else   \
+   elf_ar_hdr->FIELD \
+ = (__typeof (elf_ar_hdr->FIELD)) strtoll (string, NULL, 8); \
+}\
+  while (0)
+
   INT_FIELD (ar_date);
   INT_FIELD (ar_uid);
   INT_FIELD (ar_gid);
-  INT_FIELD (ar_mode);
+  OCT_FIELD (ar_mode);
   INT_FIELD (ar_size);
 
   if (elf_ar_hdr->ar_size < 0)
-- 
2.30.2



Proposing Sourceware as SFC member project

2022-08-30 Thread Mark Wielaard
Hi!

If you have an interest in the long term future of the sourceware
hosting server which this project is using, please consider checking
out this thread on our local overseers@ mailing list.  Everything is
fine, we're just thinking ahead.

https://sourceware.org/pipermail/overseers/2022q3/018802.html

Chris Faylor 
Frank Eigler 
Mark Wielaard 


Re: [patch git] PR28284 - debuginfod x-debuginfod* header processing

2022-09-06 Thread Mark Wielaard
Hi Frank,

On Fri, 2022-09-02 at 20:13 -0400, Frank Ch. Eigler via Elfutils-devel
wrote:
> I had a bit of time to tweak Noah Sanci's PR28284 work, and I believe
> it addresses Mark's last set of comments (from a while ago).  This
> follow-up patch corrects things like case sensitivity, spacing, \r\n
> processing, and tweaks documentation.

I hadn't thought about the \r\n at the end of the HTTP headers. Thanks.
I assume \r\n at the end of HTTP headers required, since you are
expecting in the code now, or could it also be \n on its own?

> The gist of it is to add a new client api function
> debuginfod_get_headers(), documented to return x-debuginfod* headers
> from current or previous fetch requests.

This looks good, but I think c->winning_headers needs to be
freed/cleared at the start of debuginfod_query_server. Otherwise if you
reuse the debuginfod_client and you hit the cache, the user gets the
headers from the last use of debuginfod_client that did fetch something
from a server. Which imho is confusing (the headers won't match the
cached result returned).

>   debuginfod-find prints those
> in -v verbose mode, and debuginfod relays them in federation.

This is the only thing I am not 100% happy about. It means you can only
see the headers using debuginfod-find but no longer with any other
client when DEBUGINFOD_VERBOSE is set. Is this really what we want?

> This stuff is an enabler for rgoldber's subsequent
> signature-passing/checking code, to which I plan to turn my attention
> next.
> 
> Please see users/fche/try-pr28284d for this draft of the code.  I'd
> like to keep it as two separate commits to preserve Noah's id in the
> git history, even though that makes it a bit harder to give a final
> review.

Thanks. I like this version except for those two nitpicks above. What
do you think?

Cheers,

Mark


Re: [patch git] PR28284 - debuginfod x-debuginfod* header processing

2022-09-08 Thread Mark Wielaard
Hi Frank,

On Tue, 2022-09-06 at 12:05 -0400, Frank Ch. Eigler via Elfutils-devel
wrote:
> > This looks good, but I think c->winning_headers needs to be
> > freed/cleared at the start of debuginfod_query_server. Otherwise if you
> > reuse the debuginfod_client and you hit the cache, the user gets the
> > headers from the last use of debuginfod_client that did fetch something
> > from a server. Which imho is confusing (the headers won't match the
> > cached result returned).
> 
> Good point, we don't want an aborted new transfer to retain records
> from a previous run, will fix that.

Not just a new transfer, but also when we hit the cache before doing a
new transfer. Currently when we hit the cache and don't do any transfer
the winning_headers will point to the last http transfer which will
have nothing to do with the returned (cached) result. Just like we
clear client->url early.

Thanks,

Mark


Sourceware accepted as SFC member project

2022-09-08 Thread Mark Wielaard
Hi,

We are very grateful for the public replies and suggestions received
to our proposal, which were all very positive. And we are happy to
report that the SFC's Evaluations Committee has voted to accept
Sourceware as a Conservancy member project. If people are interested
in, or want to help out with, the next steps they are invited to join
the sourceware overseers list.

https://sourceware.org/pipermail/overseers/2022q3/018834.html

Thanks,

Chris Faylor 
Frank Eigler 
Mark Wielaard 


Re: [PATCH v2] tests: do not fail on zero sized DIEs (binutils-2.39 compatible)

2022-10-13 Thread Mark Wielaard
Hi,

On Mon, 2022-08-08 at 01:17 +0200, Mark Wielaard wrote:
> On Sun, Aug 07, 2022 at 07:31:38PM +0100, Sergei Trofimovich via
> Elfutils-devel wrote:
> > binutils started producing 0-sized DIEs on functions interspersed
> > by nested sections (".section ...; .previous). This led to
> > run-low_high_pc.sh failure in form of:
> > 
> > FAIL: run-low_high_pc.sh
> > 
> > 
> > [b] main.c
> > [2d] main
> > 
> > [b] ../sysdeps/i386/start.S
> > [26] _start
> > [40] ../sysdeps/x86/abi-note.c
> > [b52] init.c
> > [b8e] static-reloc.c
> > [2dba] _dl_relocate_static_pie
> > [2dd8] ../sysdeps/i386/crti.S
> > [2def] _init
> > lowpc: 8049000, highpc: 8049000lx
> > ../sysdeps/i386/crti.S: [2def] '_init' highpc <= lowpc
> > FAIL run-low_high_pc.sh (exit status: 255)
> > 
> > To work it around let's allow lowpc == highpc special case.
> > 
> > https://sourceware.org/bugzilla/show_bug.cgi?id=29450
> 
> Thanks for finding this and suggesting a workaround.  But lets first
> try to fix binutils. This seems like a pretty bad bug, lets hope it
> gets fixed soon. So we don't need these kind of workarounds.
> 
> I added a comment to the binutils bug:
> https://sourceware.org/bugzilla/show_bug.cgi?id=29451#c2

Since this binutils bug was fixed I assume this patch isn't needed
anymore.

Thanks,

Mark


Re: [PATCH RFC] backends: Add RISC-V object attribute printing

2022-10-13 Thread Mark Wielaard
Hi Andreas,

On Wed, 2022-08-10 at 11:27 +0200, Andreas Schwab via Elfutils-devel
wrote:
> This does not work yet.  The RISC-V attribute tags use the same
> convention as the GNU attributes: odd numbered tags take a string
> value,
> even numbered ones an integer value, but print_attributes assumes the
> ARM numbering scheme by default for non-GNU attributes.

Yeah, I see this comment in print_attributes:

 /* GNU style tags have either a uleb128 value,
when lowest bit is not set, or a string
when the lowest bit is set.
"compatibility" (32) is special.  It has
both a string and a uleb128 value.  For
non-gnu we assume 6 till 31 only take ints.
XXX see arm backend, do we need a separate
hook?  */

Maybe we need a flag in the backend to tell whether attributes follow
the "gnu_vendor" convention? So that could be checked at:

  bool gnu_vendor = (q - name == sizeof "gnu"
 && !memcmp (name, "gnu", sizeof "gnu"));
  gnu_vendor |= ebl->has_gnu_attributes;

Or something similar?

Cheers,

Mark


Re: [PATCH] tests: Add libeu to tests needing error() API

2022-10-13 Thread Mark Wielaard
Hi,

On Tue, 2022-09-13 at 09:40 -0700, Khem Raj via Elfutils-devel wrote:
> A local error() impelmentation is used when libc does not provide it,
> therefore link in libeu.a which contains this function in tests
> needing
> error() API
> 
> Signed-off-by: Khem Raj 

Thanks. Added a ChangeLog entry and pushed this.

Cheers,

Mark


Re: [PATCH 1/7] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'

2022-10-14 Thread Mark Wielaard
Hi,

On Tue, Sep 20, 2022 at 04:43:01PM +0800, Yonggang Luo via Elfutils-devel wrote:
> These filenames are invalid on win32

This looks ok to me, but I don't really know why these files were
named this way in the first place.

The files themselves are not directly used, they are there to recreate
the hello3*rpm test files.

Frank, would you mind if these are just renamed to normal *.spec?

Thanks,

Mark

> Signed-off-by: Yonggang Luo 
> ---
>  tests/Makefile.am   | 2 +-
>  tests/debuginfod-rpms/{hello2.spec. => hello2.spec} | 0
>  tests/debuginfod-rpms/{hello3.spec. => hello3.spec} | 0
>  3 files changed, 1 insertion(+), 1 deletion(-)
>  rename tests/debuginfod-rpms/{hello2.spec. => hello2.spec} (100%)
>  rename tests/debuginfod-rpms/{hello3.spec. => hello3.spec} (100%)
> 
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 85514898..fc2235f4 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -563,7 +563,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
>debuginfod-rpms/fedora31/hello3-debugsource-1.0-2.x86_64.rpm \
>debuginfod-rpms/fedora31/hello3-two-1.0-2.x86_64.rpm \
>debuginfod-rpms/fedora31/hello3-two-debuginfo-1.0-2.x86_64.rpm \
> -  debuginfod-rpms/hello2.spec. \
> +  debuginfod-rpms/hello2.spec \
>debuginfod-rpms/rhel6/hello2-1.0-2.i686.rpm \
>debuginfod-rpms/rhel6/hello2-1.0-2.src.rpm \
>debuginfod-rpms/rhel6/hello2-debuginfo-1.0-2.i686.rpm \
> diff --git a/tests/debuginfod-rpms/hello2.spec. 
> b/tests/debuginfod-rpms/hello2.spec
> similarity index 100%
> rename from tests/debuginfod-rpms/hello2.spec.
> rename to tests/debuginfod-rpms/hello2.spec
> diff --git a/tests/debuginfod-rpms/hello3.spec. 
> b/tests/debuginfod-rpms/hello3.spec
> similarity index 100%
> rename from tests/debuginfod-rpms/hello3.spec.
> rename to tests/debuginfod-rpms/hello3.spec
> -- 
> 2.36.1.windows.1
> 


Re: [PATCH 2/7] move platform depended include into system.h

2022-10-14 Thread Mark Wielaard
On Tue, Sep 20, 2022 at 04:43:02PM +0800, Yonggang Luo via Elfutils-devel wrote:
> All of these files either #include  directly or #include "libelfP.h"
> And now "libelfP.h also #include , so the platform depended include
> can be moved to system.h safely

I like this in theory since it cleans up some of the includes.
But it doesn't work as is.

libebl/eblobjnotetypename.c only included system.h so now doesn't
compile anymore.  And libintl.h is removed from libelf/elf_error.c
which really is necessary.

Cheers,

Mark


Re: [PATCH] libdwfl: add dwfl_report_offline_memory

2022-10-16 Thread Mark Wielaard
Hi Aleksei,

On Tue, Sep 20, 2022 at 01:36:37PM +, Aleksei Vetrov via Elfutils-devel 
wrote:
> This method allows to read and report ELF from memory instead of opening
> a file. That way arbitrary memory can be worked with, e.g. when coming
> from a stream without the need to persist.
> 
> Another useful application is for fuzzing, because fuzzers might be able
> to track accesses to the memory and change the fuzzer input to cover
> more edge cases through more targeted input. Hence, add a new function
> along with a test case.

This is a very nice patch.  Pushed almost as is.  While reviewing I
added some ChangeLog entries.  I added the NEWS entry.  In libdw.map I
moved dwfl_report_offline_memory under ELFUTILS_0.188.  In the
tests/Makefile.am I added libeu to dwfl_report_offline_memory_LDADD
because the test uses error.

Thanks,

Mark


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

2022-10-16 Thread Mark Wielaard
There is a run-debuginfod-federation-metrics.sh failure that must be
unrelated. It is an odd crash in the shell script wait statement?

But there are also a few failures compiling the new testcase:

In file included from /usr/include/features.h:490,
 from /usr/include/assert.h:35,
 from dwfl-report-offline-memory.c:18:
In function ‘read’,
inlined from ‘main’ at dwfl-report-offline-memory.c:68:23:
/usr/include/bits/unistd.h:38:10: error: ‘__read_alias’ specified size 
18446744073709551615 exceeds maximum object size 9223372036854775807 
[-Werror=stringop-overflow=]
   38 |   return __glibc_fortify (read, __nbytes, sizeof (char),
  |  ^~~
/usr/include/bits/unistd.h: In function ‘main’:
/usr/include/bits/unistd.h:26:16: note: in a call to function ‘__read_alias’ 
declared with attribute ‘access (write_only, 2, 3)’
   26 | extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
  |^~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:2461: dwfl-report-offline-memory.o] Error 1

This seems technically correct since we use the wrong types size_t vs
off_t and ssize_t and don't check the results from lseek, read and
malloc.

Patch to fix that attached.

And there is an error on 32bit systems:
tests/dwfl-report-offline-memory contains non-lfs symbols: lseek open

Fix that by including config.h earlier.

Cheers,

Mark>From 72860bfdca5286399837080d53ba297bf72c56b3 Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Sun, 16 Oct 2022 18:02:46 +0200
Subject: [PATCH] tests: Check lseek, read and malloc results with correct
 types in test.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When compiling dwfl-report-offline-memory.c on some systems (latest
gcc/glibc and --enable-sanitize-undefined) we might get:

In file included from /usr/include/features.h:490,
 from /usr/include/assert.h:35,
 from dwfl-report-offline-memory.c:18:
In function ‘read’,
inlined from ‘main’ at dwfl-report-offline-memory.c:68:23:
/usr/include/bits/unistd.h:38:10: error: ‘__read_alias’ specified size 18446744073709551615
  exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
   38 |   return __glibc_fortify (read, __nbytes, sizeof (char),
  |  ^~~
/usr/include/bits/unistd.h: In function ‘main’:
/usr/include/bits/unistd.h:26:16: note: in a call to function ‘__read_alias’ declared with
  attribute ‘access (write_only, 2, 3)’
   26 | extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
  |^~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:2461: dwfl-report-offline-memory.o] Error 1

Fix by using the correct types and checking all return values.

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog| 5 +
 tests/dwfl-report-offline-memory.c | 8 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 6ac2c1e8..d07a910e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2022-10-16  Mark Wielaard  
+
+	* dwfl-report-offline-memory.c (main): Check lseek, read and malloc
+	results with correct types.
+
 2022-09-13  Aleksei Vetrov  
 
 	* Makefile.am (check_PROGRAMS): Add dwfl-report-offline-memory.
diff --git a/tests/dwfl-report-offline-memory.c b/tests/dwfl-report-offline-memory.c
index 837aca5e..81fa136f 100644
--- a/tests/dwfl-report-offline-memory.c
+++ b/tests/dwfl-report-offline-memory.c
@@ -62,10 +62,14 @@ main (int argc, char **argv)
   int fd = open (fname, O_RDONLY);
   if (fd < 0)
 error (-1, 0, "can't open file %s: %s", fname, strerror (errno));
-  size_t size = lseek (fd, 0, SEEK_END);
+  off_t size = lseek (fd, 0, SEEK_END);
+  if (size < 0)
+error (-1, 0, "can't lseek file %s: %s", fname, strerror (errno));
   lseek (fd, 0, SEEK_SET);
   char *data = malloc (size);
-  size_t bytes_read = read (fd, data, size);
+  if (data == NULL)
+error (-1, 0, "can't malloc: %s", strerror (errno));
+  ssize_t bytes_read = read (fd, data, size);
   assert (bytes_read == size);
   close (fd);
 
-- 
2.30.2

>From 2a4ce08fafcf76d866ae5f6b394389d8d93aa0cb Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Sun, 16 Oct 2022 18:23:06 +0200
Subject: [PATCH] tests: include config.h first.

Otherwise some symbols (lseek, open) might not get the 64bit offset
variants because they don't pick up _FILE_OFFSET_BITS.

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog| 4 
 tests/dwfl-report-offline-memory.c | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index d07a910e..0ea1df3d 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-16  Mark Wielaard  
+
+	* dwfl-report-offline-memory.c: Include confi

Re: [PATCH v2 2/7] move platform depended include into system.h of libelf

2022-10-16 Thread Mark Wielaard
On Sun, Oct 16, 2022 at 12:36:20AM +0800, Yonggang Luo via Elfutils-devel wrote:
> All of these files either #include  directly or #include "libelfP.h"
> And now "libelfP.h also #include , so the platform depended include
> can be moved to system.h safely

Thanks. While reviewing wrote ChangeLog entries. Pushed with those added.

Cheers,

Mark


Re: [PATCH v2 3/7] Move the #include into eu-config.h

2022-10-16 Thread Mark Wielaard
On Sun, Oct 16, 2022 at 12:36:21AM +0800, Yonggang Luo via Elfutils-devel wrote:
> So we do not need include in each file.
> And indeed the macro
> #define _(Str) dgettext ("elfutils", Str)
> access libintl function dgettext, so it's make more sense
> #include  in file eu-config.h

And this works because we include eu-config.h in config.h.  All files
where libintl.h is removed includes config.h, except for libdwP.h and
libeblP.h, but it isn't expected there.

Pushed,

Mark


Re: [PATCH v2 4/7] lib: Use NOT_HAVE_LIBINTL to guard #include

2022-10-16 Thread Mark Wielaard
Hi,

On Sun, Oct 16, 2022 at 12:36:22AM +0800, Yonggang Luo via Elfutils-devel wrote:
> Add NOT_HAVE_LIBINTL macro to disable internationalization,
> sometimes we have don't want access internationalization such as MSVC,
> so the macro NOT_HAVE_LIBINTL can help that.

This needs a configure check.

Cheers,

Mark


Re: [PATCH 5/7] Strip __ prefix from __BYTE_ORDER __LITTLE_ENDIAN and __BIG_ENDIAN

2022-10-16 Thread Mark Wielaard
Hi,

This seems to work and is probably OK.  But do you know when/what the
__ prefix versions are defined and when/what defines the non-prefixed
versions?

Thanks,

Mark

On Tue, Sep 20, 2022 at 04:43:05PM +0800, Yonggang Luo via Elfutils-devel wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  lib/system.h |  4 ++--
>  libcpu/i386_disasm.c |  2 +-
>  libcpu/memory-access.h   | 26 +-
>  libcpu/riscv_disasm.c|  2 +-
>  libdw/memory-access.h|  8 
>  libdwfl/dwfl_segment_report_module.c |  2 +-
>  libelf/common.h  |  2 +-
>  libelf/elf32_checksum.c  |  4 ++--
>  libelf/elf32_xlatetof.c  |  4 ++--
>  libelf/elf_getarsym.c|  6 +++---
>  src/arlib.h  |  2 +-
>  11 files changed, 31 insertions(+), 31 deletions(-)
> 
> diff --git a/lib/system.h b/lib/system.h
> index 48004df1..bbbe06c4 100644
> --- a/lib/system.h
> +++ b/lib/system.h
> @@ -64,12 +64,12 @@ void error(int status, int errnum, const char *format, 
> ...);
>  exit (EXIT_FAILURE); \
>} while (0)
>  
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#if BYTE_ORDER == LITTLE_ENDIAN
>  # define LE32(n) (n)
>  # define LE64(n) (n)
>  # define BE32(n) bswap_32 (n)
>  # define BE64(n) bswap_64 (n)
> -#elif __BYTE_ORDER == __BIG_ENDIAN
> +#elif BYTE_ORDER == BIG_ENDIAN
>  # define BE32(n) (n)
>  # define BE64(n) (n)
>  # define LE32(n) bswap_32 (n)
> diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
> index fd7340cc..40475b81 100644
> --- a/libcpu/i386_disasm.c
> +++ b/libcpu/i386_disasm.c
> @@ -44,7 +44,7 @@
>  
>  #include "../libebl/libeblP.h"
>  
> -#define MACHINE_ENCODING __LITTLE_ENDIAN
> +#define MACHINE_ENCODING LITTLE_ENDIAN
>  #include "memory-access.h"
>  
>  
> diff --git a/libcpu/memory-access.h b/libcpu/memory-access.h
> index 779825fa..3b6ca19b 100644
> --- a/libcpu/memory-access.h
> +++ b/libcpu/memory-access.h
> @@ -41,7 +41,7 @@
>  #ifndef MACHINE_ENCODING
>  # error "MACHINE_ENCODING needs to be defined"
>  #endif
> -#if MACHINE_ENCODING != __BIG_ENDIAN && MACHINE_ENCODING != __LITTLE_ENDIAN
> +#if MACHINE_ENCODING != BIG_ENDIAN && MACHINE_ENCODING != LITTLE_ENDIAN
>  # error "MACHINE_ENCODING must signal either big or little endian"
>  #endif
>  
> @@ -51,31 +51,31 @@
>  #if ALLOW_UNALIGNED
>  
>  # define read_2ubyte_unaligned(Addr) \
> -  (unlikely (MACHINE_ENCODING != __BYTE_ORDER)   
>   \
> +  (unlikely (MACHINE_ENCODING != BYTE_ORDER)   \
> ? bswap_16 (*((const uint16_t *) (Addr)))   \
> : *((const uint16_t *) (Addr)))
>  # define read_2sbyte_unaligned(Addr) \
> -  (unlikely (MACHINE_ENCODING != __BYTE_ORDER)   
>   \
> +  (unlikely (MACHINE_ENCODING != BYTE_ORDER)   \
> ? (int16_t) bswap_16 (*((const int16_t *) (Addr)))
>   \
> : *((const int16_t *) (Addr)))
>  
>  # define read_4ubyte_unaligned_noncvt(Addr) \
> *((const uint32_t *) (Addr))
>  # define read_4ubyte_unaligned(Addr) \
> -  (unlikely (MACHINE_ENCODING != __BYTE_ORDER)   
>   \
> +  (unlikely (MACHINE_ENCODING != BYTE_ORDER)   \
> ? bswap_32 (*((const uint32_t *) (Addr)))   \
> : *((const uint32_t *) (Addr)))
>  # define read_4sbyte_unaligned(Addr) \
> -  (unlikely (MACHINE_ENCODING != __BYTE_ORDER)   
>   \
> +  (unlikely (MACHINE_ENCODING != BYTE_ORDER)   \
> ? (int32_t) bswap_32 (*((const int32_t *) (Addr)))
>   \
> : *((const int32_t *) (Addr)))
>  
>  # define read_8ubyte_unaligned(Addr) \
> -  (unlikely (MACHINE_ENCODING != __BYTE_ORDER)   
>   \
> +  (unlikely (MACHINE_ENCODING != BYTE_ORDER)   \
> ? bswap_64 (*((const uint64_t *) (Addr)))   \
> : *((const uint64_t *) (Addr)))
>  # define read_8sbyte_unaligned(Addr) \
> -  (unlikely (MACHINE_ENCODING != __BYTE_ORDER)   
>   \
> +  (unlikely (MACHINE_ENCODING != BYTE_ORDER)   \
> ? (int64_t) bswap_64 (*((const int64_t *) (Addr)))
>   \
> : *((const int64_t *) (Addr)))
>  
> @@ -96,7 +96,7 @@ static inline uint16_t
>  read_2ubyte

Re: [PATCH 6/7] Fixes building with msvc/clang mingw/gcc

2022-10-16 Thread Mark Wielaard
Hi,

I find this hard to review. I have no experienc with msvc and don't
know when/what _MSC_VER implies or how to verify system_win32.c. I am
also a bit worried that the various ifdefs will be hard to keep
correct.

If we don't have HAVE_DECL_MMAP does the testsuite still work?

Maybe this patch can be split up is separate concerns. But I have to
admit I am a litle afraid this will be hard to keep working.

Cheers,

Mark


Re: [PATCH 7/7] Add CMake build files

2022-10-16 Thread Mark Wielaard
Hi,

I rather not have multiple build systems in the tree. Are the
autotools not available on your system?

Cheers,

Mark


Re: [PATCH 5/7] Strip __ prefix from __BYTE_ORDER __LITTLE_ENDIAN and __BIG_ENDIAN

2022-10-17 Thread Mark Wielaard
Hi,

On Mon, Oct 17, 2022 at 11:40:11AM +0800, 罗勇刚(Yonggang Luo) wrote:
> > This seems to work and is probably OK.  But do you know when/what the
> > __ prefix versions are defined and when/what defines the non-prefixed
> > versions?
> 
> __BYTE_ORDER__ is a predefined macro by gcc/clang,
> 
> BYTE_ORDER is defined in 

Aha, thanks. I added that to the commit message and pushed the change.

Cheers,

Mark


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

2022-10-17 Thread Mark Wielaard
Hi,

On Mon, 2022-10-17 at 09:08 +, builder--- via Elfutils-devel wrote:
> A new failure has been detected on builder elfutils-opensusetw-x86_64 
> while building elfutils.
> 
> Full details are available at:
> https://builder.sourceware.org/buildbot/#builders/88/builds/50
> 
> Build state: failed test (failure)
> Revision: 0e18267a05247b5bda60115270203b4ad3af8e55
> Worker: bb2-1
> Build Reason: (unknown)
> Blamelist: Yonggang Luo 

This is clearly not caused by that last commit.

Sadly run-debuginfod-federation-metrics.sh seem somewhat fragile, but
it isn't immediately clear why. It sometimes seems to crash in a bash
wait? Or does this say, we were waiting, on a process that crashed?

/home/builder/shared/bb2-1/worker/elfutils-opensusetw-
x86_64/build/tests/run-debuginfod-federation-metrics.sh: line 205:
26486 Aborted (core dumped) env LD_LIBRARY_PATH=$ldpath
${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0
-g0 -p $PORT1 L D F > vlog$PORT1 2>&1

The log also says:

Fatal error in GNU libmicrohttpd daemon.c:3831: Failed to remove FD
from epoll set.

Very odd. I don't have any hypothesis for why these are occuring.

Cheers,

Mark


[PATCH] readelf: Handle DW_LLE_GNU_view_pair

2022-10-19 Thread Mark Wielaard
DW_LLE_GNU_view_pair is used by gcc -gvariable-location-views=incompat5.
As described in http://www.fsfla.org/~lxoliva/papers/sfn/dwarf6-sfn-lvu.txt
and proposed for DWARF6 https://dwarfstd.org/ShowIssue.php?issue=170427.1

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog |  4 
 libdw/dwarf.h   |  6 +-
 src/ChangeLog   |  6 ++
 src/readelf.c   | 12 
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index b14b5383..2efcaeb9 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-19  Mark Wielaard  
+
+   * dwarf.h (DW_LLE_GNU_view_pair): New constant.
+
 2022-09-20  Yonggang Luo  
 
* memory-access.h: Use BYTE_ORDER, LITTLE_ENDIAN and BIG_ENDIAN.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index c961bc36..b2e49db2 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -931,7 +931,11 @@ enum
 DW_LLE_GNU_end_of_list_entry = 0x0,
 DW_LLE_GNU_base_address_selection_entry = 0x1,
 DW_LLE_GNU_start_end_entry = 0x2,
-DW_LLE_GNU_start_length_entry = 0x3
+DW_LLE_GNU_start_length_entry = 0x3,
+
+// http://www.fsfla.org/~lxoliva/papers/sfn/dwarf6-sfn-lvu.txt
+// https://dwarfstd.org/ShowIssue.php?issue=170427.1
+DW_LLE_GNU_view_pair = 0x9
   };
 
 /* DWARF5 package file section identifiers.  */
diff --git a/src/ChangeLog b/src/ChangeLog
index 23c971d1..1f369ef6 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2022-10-19  Mark Wielaard  
+
+   * readelf.c (dwarf_loc_list_encoding_string): Handle
+   DW_LLE_GNU_view_pair.
+   (print_debug_loclists_section): Likewise.
+
 2022-09-20  Yonggang Luo  
 
* arlib.h: Use BYTE_ORDER, LITTLE_ENDIAN and BIG_ENDIAN.
diff --git a/src/readelf.c b/src/readelf.c
index a206e60e..7671a31d 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4185,6 +4185,8 @@ dwarf_loc_list_encoding_string (unsigned int kind)
 #define DWARF_ONE_KNOWN_DW_LLE(NAME, CODE) case CODE: return #NAME;
   DWARF_ALL_KNOWN_DW_LLE
 #undef DWARF_ONE_KNOWN_DW_LLE
+/* DW_LLE_GNU_view_pair is special/incompatible with default codes.  */
+case DW_LLE_GNU_view_pair: return "GNU_view_pair";
 default:
   return NULL;
 }
@@ -9744,6 +9746,16 @@ print_debug_loclists_section (Dwfl_Module *dwflmod,
  readp += len;
  break;
 
+   case DW_LLE_GNU_view_pair:
+ if ((uint64_t) (nexthdr - readp) < 1)
+   goto invalid_entry;
+ get_uleb128 (op1, readp, nexthdr);
+ if ((uint64_t) (nexthdr - readp) < 1)
+   goto invalid_entry;
+ get_uleb128 (op2, readp, nexthdr);
+ printf (" %" PRIx64 ", %" PRIx64 "\n", op1, op2);
+ break;
+
default:
  goto invalid_entry;
}
-- 
2.30.2



Re: [PATCH 1/7] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'

2022-10-20 Thread Mark Wielaard
Hi,

On Wed, 2022-10-19 at 15:49 -0400, Frank Ch. Eigler via Elfutils-devel
wrote:
> I really want this to be merged :) ping Frank,
> > as this would stop me clone elfutils on windows
> 
> If it doesn't break "make rpm" (or at least rpm -ts
> elfutils*.tar.bz2),
> it's fine.

make rpm doesn't work because of:

rpmbuild -ts --sign elfutils-0.187.tar.bz2
error: rpmbuild --sign is no longer supported. Use the rpmsign command
instead!
make: *** [Makefile:971: rpm] Error 1

Maybe just remove the --sign?

But then, with the rename, you'll get:

rpmbuild -ts elfutils-0.187.tar.bz2
error: Found more than one spec file in elfutils-0.187.tar.bz2
make: *** [Makefile:971: rpm] Error 1

So maybe we just should rename them to .specfile?
That is what the attached patch does, plus some other cleanups.
- We forgot to include the hello3.specfile
- Remove the --sign from rpmbuild
- escape the % in spec comments

That makes make rpm work out of the box without warnings.
Does it also help the windows git thing?

Cheers,

Mark
From f7bd331326a03108095b7593bb48d7482690501f Mon Sep 17 00:00:00 2001
From: Yonggang Luo 
Date: Tue, 20 Sep 2022 16:43:01 +0800
Subject: [PATCH] Rename 'hello{2,3}.spec.' -> 'hello{2,3}.specfile'

These filenames are invalid on win32.
We don't want to include multiple .spec files for make rpm.
rpmbuild --sign is not supported anymore.
Also include hello3.specfile in EXTRA_DIST.
Escape some macros in the elfutils.spec.in file comments.

Signed-off-by: Yonggang Luo 
Signed-off-by: Mark Wielaard 
---
 ChangeLog   | 4 
 Makefile.am | 2 +-
 config/ChangeLog| 4 
 config/elfutils.spec.in | 6 +++---
 tests/ChangeLog | 9 +
 tests/Makefile.am   | 3 ++-
 tests/debuginfod-rpms/{hello2.spec. => hello2.specfile} | 0
 tests/debuginfod-rpms/{hello3.spec. => hello3.specfile} | 0
 8 files changed, 23 insertions(+), 5 deletions(-)
 rename tests/debuginfod-rpms/{hello2.spec. => hello2.specfile} (100%)
 rename tests/debuginfod-rpms/{hello3.spec. => hello3.specfile} (100%)

diff --git a/ChangeLog b/ChangeLog
index 60624183..2bf99c71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-20  Mark Wielaard  
+
+	* Makefile.am (rpm): Remove --sign.
+
 2022-09-13  Aleksei Vetrov  
 
 	* NEWS (libdwfl): Add dwfl_report_offline_memory.
diff --git a/Makefile.am b/Makefile.am
index 8643312a..e92e05c2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,7 +44,7 @@ distcheck-hook:
 	chmod -R u+w $(distdir)
 
 rpm: dist
-	rpmbuild -ts --sign elfutils-@PACKAGE_VERSION@.tar.bz2
+	rpmbuild -ts elfutils-@PACKAGE_VERSION@.tar.bz2
 
 if GCOV
 
diff --git a/config/ChangeLog b/config/ChangeLog
index 1265f399..4c7164e5 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-20  Mark Wielaard  
+
+	* elfutils.spec.in: Escape % in comments.
+
 2022-08-17  Martin Liska  
 
 	* debuginfod.service: Add new debuginfod.sysconfig
diff --git a/config/elfutils.spec.in b/config/elfutils.spec.in
index 54599159..3282de26 100644
--- a/config/elfutils.spec.in
+++ b/config/elfutils.spec.in
@@ -263,18 +263,18 @@ fi
 %dir %{_includedir}/elfutils
 %{_includedir}/elfutils/elf-knowledge.h
 %{_includedir}/elfutils/known-dwarf.h
-#%{_includedir}/elfutils/libasm.h
+#%%{_includedir}/elfutils/libasm.h
 %{_includedir}/elfutils/libdw.h
 %{_includedir}/elfutils/libdwfl.h
 %{_includedir}/elfutils/libdwelf.h
 %{_includedir}/elfutils/version.h
-#%{_libdir}/libasm.so
+#%%{_libdir}/libasm.so
 %{_libdir}/libdw.so
 %{_libdir}/pkgconfig/libdw.pc
 
 %files devel-static
 %{_libdir}/libdw.a
-#%{_libdir}/libasm.a
+#%%{_libdir}/libasm.a
 
 %files libelf
 %license COPYING-GPLV2 COPYING-LGPLV3
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 0ea1df3d..31f4d0e4 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,12 @@
+2022-09-20  Yonggang Luo  
+
+	* Makefile.am (EXTRA_DIST): Remove debuginfod-rpms/hello2.spec.
+	Add debuginfod-rpms/hello{2,3}.specfile.
+	* tests/debuginfod-rpms/hello2.spec.: Renamed to...
+	* tests/debuginfod-rpms/hello2.specfile: ...this.
+	* tests/debuginfod-rpms/hello3.spec.: Renamed to...
+	* tests/debuginfod-rpms/hello3.specfile: ...this.
+
 2022-10-16  Mark Wielaard  
 
 	* dwfl-report-offline-memory.c: Include config.h first.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f680d3e1..ced4a826 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -566,7 +566,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 	 debuginfod-rpms/fedora31/hello3-debugsource-1.0-2.x86_64.rpm \
 	 debuginfod-rpms/fedora31/hello3-two-1.0-2.x86_64.rpm \
 	 debuginfod-rpms/fedora31/hello3-two-debuginfo-1.0-2.x86_64.rpm \
-	 debuginfod-rpms/hello2.spec. \
+	 debugi

[PATCH] configure.ac: Update AC_PROG_CC and AC_PROG_LEX for autoconf 2.70

2022-10-22 Thread Mark Wielaard
With autoconf 2.70 we must use AC_PROG_CC (which will check for c11
and c99), for earlier versions we'll use AC_PROG_CC_C99. Also use
AC_PROG_LEX([noyywrap]), the extra argument is ignored with earlier
versions, but required for 2.70.

Signed-off-by: Mark Wielaard 
---
 ChangeLog| 5 +
 configure.ac | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 60624183..ee566f53 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-10-22  Mark Wielaard  
+
+   * configure.ac: Use AC_PROG_CC with autoconf 2.70, or AC_PROG_CC_C99
+   for earlier versions. Use AC_PROG_LEX([noyywrap]).
+
 2022-09-13  Aleksei Vetrov  
 
* NEWS (libdwfl): Add dwfl_report_offline_memory.
diff --git a/configure.ac b/configure.ac
index 03b67a9d..1084b469 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,11 +88,11 @@ AS_IF([test "$use_locks" = yes],
 
 AH_TEMPLATE([USE_LOCKS], [Defined if libraries should be thread-safe.])
 
-AC_PROG_CC_C99
+m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_C99])
 AC_PROG_CXX
 AC_PROG_RANLIB
 AC_PROG_YACC
-AM_PROG_LEX
+AC_PROG_LEX([noyywrap])
 # Only available since automake 1.12
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
 AC_CHECK_TOOL([READELF], [readelf])
-- 
2.30.2



Re: [PATCH] debuginfod: Support queries for ELF/DWARF sections

2022-10-26 Thread Mark Wielaard
Hi,

On Mon, 2022-10-24 at 14:38 -0400, Frank Ch. Eigler via Elfutils-devel
wrote:
> - not sure I understand why the code worries about dots in or not in
>   section names.  Why not just pass them verbatim throughout the code
>   base, and not worry about whether or not there's a dot?  Does the
>   ELF standard even require a dot?

I agree that just passing them through as is might be better. The ELF
standard doesn't say much about section names, just:

   Section names with a dot (.) prefix are reserved for the system,
   although applications may use these sections if their existing
   meanings are satisfactory. Applications may use names without the
   prefix to avoid conflicts with system sections.

Is/should the section name be URL-encoded?

I would drop the maybe_debuginfo_section heuristics. There are some
sections like .strtab/.symtab that are probably in the debug file, but
might be in the executable. I would assume that a named section can
normally be found in the debugfile and only use the executable as
fallback.

So see if you can find the .debug file, if you can, then look for the
section by name. If it isn't SHT_NOBITS you found it. If it is
SHT_NOBITS the section should be in the exe. If the section cannot be
found by name (in the .debug file) you can stop searching, it also
won't be in the exe. If you cannot find the .debug file, or the section
was in the .debug file, but had type SHT_NOBITS then search for the exe
file and the named section in there.

Finally, if the section comes from a file in the cache or if we have to
download it in full anyway, then extracting the section into its own
file seems slightly wasteful. It would be great if we could just report
back "here is the full exe/debug file which does contain the requested
section name". But that might make the interface a little ugly.

int
debuginfod_find_section (debuginfod_client *client,
 const unsigned char *build_id,
 int build_id_len,
 const char *section, char **path,
 bool *file_is_elf)

Maybe that is over-designed to avoid a little bit of disk waste?

Cheers,

Mark


Re: [PATCH] debuginfod: Support queries for ELF/DWARF sections

2022-10-26 Thread Mark Wielaard
Hi,

On Mon, 2022-10-24 at 14:38 -0400, Frank Ch. Eigler via Elfutils-devel
wrote:
> - use of write(2) to put files onto disk is not quite right; write(2)
> can
>   be partial, so you need a loop (or a macro wrapping a loop)

Since debuginfod-client.c already includes system.h it can use:

static inline ssize_t
write_retry (int fd, const void *buf, size_t len)

Which takes care of partial and/or interrupted write calls.

Cheers,

Mark


Re: [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'

2022-10-27 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> These filenames are invalid on win32

But using .spec causes make rpm to fail.

Did you try this variant:
https://inbox.sourceware.org/elfutils-devel/3bf19d05c8976411432709fae1cc2bcc2d21d700.ca...@klomp.org/

Thanks,

Mark


Re: [PATCH 02/25] ignore build directory

2022-10-27 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  .gitignore | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 8bcd88d7..ca06 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -21,6 +21,7 @@ Makefile.in
>  /INSTALL
>  /aclocal.m4
>  /autom4te.*
> +/build
>  /config.cache
>  /config.h
>  /config.h.in

Why is this necessary?

Thanks,

Mark


Re: [PATCH 03/25] libebl: There is no need #include in eblclosebackend.c and eblopenbackend.c

2022-10-27 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> It's not accessed symbols in dlfcn.h in eblclosebackend.c and
> eblopenbackend.c

Tweaked the commit message (so it fits on one line), added ChangeLog
entries and pushed.

Thanks,

Mark


Re: [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c

2022-10-27 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> rationale: https://sourceware.org/bugzilla/show_bug.cgi?id=21001
> 
> If we don't remove this macro, when try #include  in
> libdw/memory-access.h
> wont' take effect because "#define LIB_SYSTEM_H   1"
> The compile error:
> ./../libdw/memory-access.h:390:12: error: implicit declaration of
> function ‘bswap_32’ [-Werror=implicit-function-declaration]

Thanks, makes sense.
Added ChangeLog entries and tweaked the commit message a bit to not
exceed 72 chars lines.

Pushed,

Mark


Re: [PATCH 05/25] use #include instead platform depended header in libdw/memory-access.h

2022-10-27 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 

Thanks, added ChangeLog entry and tweaked commit message to have < 72
char lines.

Pushed,

Mark


Re: [PATCH] readelf: Handle DW_LLE_GNU_view_pair

2022-10-27 Thread Mark Wielaard
Hi,

On Thu, 2022-10-20 at 00:02 +0200, Mark Wielaard wrote:
> DW_LLE_GNU_view_pair is used by gcc -gvariable-location-
> views=incompat5.
> As described in 
> http://www.fsfla.org/~lxoliva/papers/sfn/dwarf6-sfn-lvu.txt
> and proposed for DWARF6 
> https://dwarfstd.org/ShowIssue.php?issue=170427.1

Pushed,

Mark


Re: One shot mode for debuginfod server

2022-10-27 Thread Mark Wielaard
Hi Ryan,

On Tue, 2022-08-09 at 17:40 -0400, Ryan Goldberg via Elfutils-devel
wrote:
> Here is a patch for a new one-shot mode for the debuginfod server.
> In this mode the first scanning pass of the server will also output
> the found executables' paths and buildids to the given file
> descriptor. This can (and soon will be used in systemtap)
> as an easy way to scan archive files and quickly/easily extract
> information concerning the executables they contain.

I see how this could be useful, but wouldn't it be easier to have a
database query do this?

Cheers,

Mark


[COMMITTED] config: Add BuildRequires socat for run-debuginfod-response-headers.sh

2022-10-27 Thread Mark Wielaard
Signed-off-by: Mark Wielaard 
---
 config/ChangeLog| 4 
 config/elfutils.spec.in | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/config/ChangeLog b/config/ChangeLog
index 1265f399..9aadd71f 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-27  Mark Wielaard  
+
+   * elfutils.spec.in: Add BuildRequires socat.
+
 2022-08-17  Martin Liska  
 
* debuginfod.service: Add new debuginfod.sysconfig
diff --git a/config/elfutils.spec.in b/config/elfutils.spec.in
index 54599159..333c6239 100644
--- a/config/elfutils.spec.in
+++ b/config/elfutils.spec.in
@@ -40,6 +40,8 @@ BuildRequires: iproute
 BuildRequires: procps
 BuildRequires: bsdtar
 BuildRequires: curl
+# For run-debuginfod-response-headers.sh test case
+BuildRequires: socat
 
 %define _gnu %{nil}
 %define _programprefix eu-
-- 
2.18.4



[COMMITTED] Use grep -E instead of egrep, use grep -F instead of fgrep.

2022-10-27 Thread Mark Wielaard
GNU grep 3.8 gives a deprecation warning when using egrep or fgrep.
Just use grep -E and grep -F.

Signed-off-by: Mark Wielaard 
---
 config/ChangeLog   |  4 
 config/eu.am   |  2 +-
 tests/ChangeLog| 11 +++
 tests/backtrace-subr.sh|  4 ++--
 tests/debuginfod-subr.sh   |  4 ++--
 tests/run-debuginfod-archive-rename.sh |  2 +-
 tests/run-debuginfod-extraction-passive.sh |  4 ++--
 tests/run-debuginfod-response-headers.sh   |  2 +-
 tests/run-debuginfod-webapi-concurrency.sh |  2 +-
 tests/run-strip-test.sh|  2 +-
 10 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/config/ChangeLog b/config/ChangeLog
index 9aadd71f..15fee44f 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-27  Mark Wielaard  
+
+   * eu.am: Use grep -F instead of fgrep.
+
 2022-10-27  Mark Wielaard  
 
* elfutils.spec.in: Add BuildRequires socat.
diff --git a/config/eu.am b/config/eu.am
index 58cd3c4f..c3cefe7e 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -135,7 +135,7 @@ textrel_found = $(textrel_msg); exit 1
 else
 textrel_found = $(textrel_msg)
 endif
-textrel_check = if $(READELF) -d $@ | fgrep -q TEXTREL; then $(textrel_found); 
fi
+textrel_check = if $(READELF) -d $@ | grep -F -q TEXTREL; then 
$(textrel_found); fi
 
 print-%:
@echo $*=$($*)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 0ea1df3d..be90832a 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,14 @@
+2022-10-27  Mark Wielaard  
+
+   * backtrace-subr.sh: Use grep -E instead of egrep, use grep -F
+   instead of fgrep.
+   * debuginfod-subr.sh: Likewise.
+   * run-debuginfod-archive-rename.sh: Likewise.
+   * run-debuginfod-extraction-passive.sh: Likewise.
+   * run-debuginfod-response-headers.sh: Likewise.
+   * run-debuginfod-webapi-concurrency.sh: Likewise.
+   * run-strip-test.sh: Likewise.
+
 2022-10-16  Mark Wielaard  
 
* dwfl-report-offline-memory.c: Include config.h first.
diff --git a/tests/backtrace-subr.sh b/tests/backtrace-subr.sh
index 53c719df..b63e3814 100644
--- a/tests/backtrace-subr.sh
+++ b/tests/backtrace-subr.sh
@@ -59,7 +59,7 @@ check_backtracegen()
 # Ignore it here as it is a bug of OS, not a bug of elfutils.
 check_err()
 {
-  if [ $(egrep -v <$1 'dwfl_thread_getframes: (No DWARF information found|no 
matching address range|address out of range|Invalid register|\(null\))$' \
+  if [ $(grep -E -v <$1 'dwfl_thread_getframes: (No DWARF information found|no 
matching address range|address out of range|Invalid register|\(null\))$' \
  | wc -c) \
-eq 0 ]
   then
@@ -101,7 +101,7 @@ check_native_unsupported()
   # and we can fall back on .debug_frame for the CFI.
   case "`uname -m`" in
 arm* )
-  if egrep 'dwfl_thread_getframes(.*)No DWARF information found' $err; then
+  if grep -E 'dwfl_thread_getframes(.*)No DWARF information found' $err; 
then
echo >&2 $testname: arm needs debuginfo installed for all libraries
exit 77
   fi
diff --git a/tests/debuginfod-subr.sh b/tests/debuginfod-subr.sh
index 0b59b5b8..108dff74 100755
--- a/tests/debuginfod-subr.sh
+++ b/tests/debuginfod-subr.sh
@@ -141,12 +141,12 @@ archive_test() {
 get_ports() {
   while true; do
 PORT1=`expr '(' $RANDOM % 50 ')' + $base`
-ss -atn | fgrep ":$PORT1" || break
+ss -atn | grep -F ":$PORT1" || break
   done
 # Some tests will use two servers, so assign the second var
   while true; do
 PORT2=`expr '(' $RANDOM % 50 ')' + $base + 50`
-ss -atn | fgrep ":$PORT2" || break
+ss -atn | grep -F ":$PORT2" || break
   done
 
 }
diff --git a/tests/run-debuginfod-archive-rename.sh 
b/tests/run-debuginfod-archive-rename.sh
index a1a6cc1e..71f7742a 100755
--- a/tests/run-debuginfod-archive-rename.sh
+++ b/tests/run-debuginfod-archive-rename.sh
@@ -95,7 +95,7 @@ export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
 archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 
/usr/src/debug/hello-1.0/hello.c $SHA
 archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 
/usr/src/debug/hello-1.0/hello.c $SHA
 
-egrep '(libc.error.*rhel7)|(bc1febfd03ca)|(f0aa15b8aba)' vlog$PORT1
+grep -E '(libc.error.*rhel7)|(bc1febfd03ca)|(f0aa15b8aba)' vlog$PORT1
 
 kill $PID1
 wait $PID1
diff --git a/tests/run-debuginfod-extraction-passive.sh 
b/tests/run-debuginfod-extraction-passive.sh
index c2724b58..26618f5c 100755
--- a/tests/run-debuginfod-extraction-passive.sh
+++ b/tests/run-debuginfod-extraction-passive.sh
@@ -56,10 +56,10 @@ wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
 wait_ready $PORT1 'thread_busy{role="scan"}' 0
 
 # No similar metrics for the passive server
-!

Re: [PATCH] configure.ac: Update AC_PROG_CC and AC_PROG_LEX for autoconf 2.70

2022-10-27 Thread Mark Wielaard
On Sat, 2022-10-22 at 21:58 +0200, Mark Wielaard wrote:
> With autoconf 2.70 we must use AC_PROG_CC (which will check for c11
> and c99), for earlier versions we'll use AC_PROG_CC_C99. Also use
> AC_PROG_LEX([noyywrap]), the extra argument is ignored with earlier
> versions, but required for 2.70.

Pushed,

Mark


Re: [PATCH] debuginfod-client: Add DEBUGINFOD_HEADERS_FILE.

2022-10-28 Thread Mark Wielaard
aders need
to be set again.

> diff --git a/debuginfod/debuginfod.h.in b/debuginfod/debuginfod.h.in
> index 40b1ea00..7d8e4972 100644
> --- a/debuginfod/debuginfod.h.in
> +++ b/debuginfod/debuginfod.h.in
> @@ -38,6 +38,7 @@
>  #define DEBUGINFOD_RETRY_LIMIT_ENV_VAR "DEBUGINFOD_RETRY_LIMIT"
>  #define DEBUGINFOD_MAXSIZE_ENV_VAR "DEBUGINFOD_MAXSIZE"
>  #define DEBUGINFOD_MAXTIME_ENV_VAR "DEBUGINFOD_MAXTIME"
> +#define DEBUGINFOD_HEADERS_FILE_ENV_VAR "DEBUGINFOD_HEADERS_FILE"
>  
>  /* The libdebuginfod soname.  */
>  #define DEBUGINFOD_SONAME "@LIBDEBUGINFOD_SONAME@"
> diff --git a/doc/ChangeLog b/doc/ChangeLog
> index b2bb4890..073023b4 100644
> --- a/doc/ChangeLog
> +++ b/doc/ChangeLog
> @@ -1,3 +1,7 @@
> +2022-10-18  Daniel Thornburgh  
> +
> + * debuginfod_find_debuginfo.3: Document DEBUGINFOD_HEADERS_FILE.
> +
>  2022-09-02  Frank Ch. Eigler  
>  
>   * debuginfod_find_debuginfo.3: Tweaked debuginfod_get_headers docs.
> diff --git a/doc/debuginfod-client-config.7 b/doc/debuginfod-client-config.7
> index fecc6038..53d82806 100644
> --- a/doc/debuginfod-client-config.7
> +++ b/doc/debuginfod-client-config.7
> @@ -75,6 +75,13 @@ only small files are downloaded. A value of 0 causes no 
> consideration
>  for size, and the client may attempt to download a file of any size.
>  The default is 0 (infinite size).
>  
> +.TP
> +.B $DEBUGINFOD_HEADERS_FILE
> +This environment variable points to a file that supplies headers to
> +outbound HTTP requests, one per line. The header lines shouldn't end with
> +CRLF, unless that's the system newline convention. Whitespace-only lines
> +are skipped.
> +
>  .SH CACHE
>  
>  Before each query, the debuginfod client library checks for a need to
> diff --git a/doc/debuginfod_find_debuginfo.3 b/doc/debuginfod_find_debuginfo.3
> index aebbec3f..3dd83240 100644
> --- a/doc/debuginfod_find_debuginfo.3
> +++ b/doc/debuginfod_find_debuginfo.3
> @@ -188,12 +188,18 @@ indicates success, but out-of-memory conditions may 
> result in
>  a non-zero \fI-ENOMEM\fP. If the string is in the wrong form
>  \fI-EINVAL\fP will be returned.
>  
> +\fI$DEBUGINFOD_HEADERS_FILE\fP specifies a file to supply headers to
> +outgoing requests. Each non-whitespace line of this file is handled
> +as if
> +.BR \%debuginfod_add_http_header ()
> +were called on the contents.
> +
>  Note that the current debuginfod-client library implementation uses
>  libcurl, but you shouldn't rely on that fact. Don't use this function
>  for replacing any standard headers, except for the User-Agent mentioned
> -below. The only supported usage of this function is for adding an
> -optional header which might or might not be passed through to the
> -server for logging purposes only.
> +below. You can use this function to add authorization information for
> +access control, or to provide optional headers to the server for
> +logging purposes.
>  
>  By default, the library adds a descriptive \fIUser-Agent:\fP
>  header to outgoing requests.  If the client application adds

Thanks for the documentation, which looks good.

I have pushed this with the two extra vfd >= 0 guards mentioned above.

Note that it would be really good to have a testcase for this so it
doesn't accidentally breaks. Since it might be that other developers
won't use this functionality.

Thanks,

Mark


Re: [PATCH 06/25] move platform depended include into system.h of libebl

2022-10-28 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Because all source in libebl #include , so #include
>  in
> libeblP.h is enough, there is multiple memory-access.h file, so use
> relative path to
> include it properly,

I am not a fan of the relative path trick, especially if there it is
clear only one is every needed. You also use it for other files, why?

Cheers,

Mark


Re: [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h

2022-10-28 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  configure.ac  | 1 +
>  lib/crc32_file.c  | 4 ++--
>  lib/system.h  | 2 ++
>  libelf/elf32_updatefile.c | 3 ++-
>  libelf/elf_begin.c| 5 -
>  libelf/elf_end.c  | 2 ++
>  libelf/elf_update.c   | 5 -

Missing commit message and ChangeLog entries.

So this is for a system that doesn't have mmap?
How does the testsuite results look on such a system?

ELF_C_{READ,WRITE,RDWR}_MMAP[_PRIVATE] are elfutils extensions, but
they are used internally in other libraries.

Cheers,

Mark


Re: [PATCH 09/25] include libgen.h in system.h

2022-10-28 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> basename function are accessed multiple place, but used without
> include libgen.h

This is wrong. We use the GNU basename (from string.h with
_GNU_SOURCE), not the POSIX one (from libgen.h).

Cheers,

Mark


Re: [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf

2022-10-28 Thread Mark Wielaard
On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  lib/color.c| 1 -
>  libasm/asm_abort.c | 1 -
>  libasm/asm_addint8.c   | 2 --
>  libasm/asm_begin.c | 2 --
>  libasm/asm_end.c   | 2 --
>  libasm/libasmP.h   | 3 +++
>  libcpu/i386_disasm.c   | 1 -
>  libcpu/memory-access.h | 3 +--
>  libdw/dwarf_begin_elf.c| 2 --
>  libdw/dwarf_end.c  | 1 -
>  libdw/dwarf_setalt.c   | 2 --
>  libdw/libdw_find_split_unit.c  | 1 -
>  libdwelf/dwelf_elf_begin.c | 2 --
>  libdwelf/dwelf_strtab.c| 1 -
>  libdwfl/argp-std.c | 1 -
>  libdwfl/core-file.c| 6 --
>  libdwfl/dwfl_build_id_find_debuginfo.c | 2 --
>  libdwfl/dwfl_build_id_find_elf.c   | 1 -
>  libdwfl/dwfl_end.c | 1 -
>  libdwfl/dwfl_frame.c   | 1 -
>  libdwfl/dwfl_module.c  | 1 -
>  libdwfl/dwfl_module_getdwarf.c | 1 -
>  libdwfl/dwfl_report_elf.c  | 2 --
>  libdwfl/dwfl_segment_report_module.c   | 2 --
>  libdwfl/find-debuginfo.c   | 1 -
>  libdwfl/gzip.c | 2 --
>  libdwfl/image-header.c | 4 
>  libdwfl/link_map.c | 2 --
>  libdwfl/linux-pid-attach.c | 1 -
>  libdwfl/offline.c  | 1 -
>  libdwfl/open.c | 2 --
>  31 files changed, 4 insertions(+), 51 deletions(-)

Tweak the commit message to fit on < 72 chars and added ChangeLog
entries.

Pushed,

Mark


Re: [PATCH][RFC] readelf: partial support of ZSTD compression

2022-10-28 Thread Mark Wielaard
Hi Martin,

On Mon, Oct 24, 2022 at 08:16:09PM +0200, Martin Liška wrote:
> Anyway, I'm sending V2 that works fine --with-zstd and --without-zstd as 
> expected.
> 
> Ready for master?

The decompression part looks good. Few small nitpicks below.

Although I like to also have compression working.  Then we can also
add support to src/elfcompress, which makes for a good testcase. See
tests/run-compress.sh (which has found some subtle memory issues when
run under valgrind).

> From 4aea412783b9b0dcaf0f887947bf2e8ee6c5368b Mon Sep 17 00:00:00 2001
> From: Martin Liska 
> Date: Mon, 24 Oct 2022 11:53:13 +0200
> Subject: [PATCH] readelf: partial support of ZSTD compression
> 
> Support decompression of ZSTD sections and add support
> for it when -SWz is used:
> 
> ...
> [30] .debug_abbrevPROGBITS  1f9d 0168  0 
> C  0   0  1
>  [ELF ZSTD (2) 02fc  1]
> ...

And for this it would be nice to have a tests/run-readelf-z.sh testcase.

> ChangeLog:
> 
>   * configure.ac: Add zstd_LIBS.
> 
> libelf/ChangeLog:
> 
>   * Makefile.am: Use zstd_LIBS.
>   * elf.h (ELFCOMPRESS_ZSTD): Add new value.
>   * elf_compress.c (__libelf_decompress): Dispatch based
>   on the compression algorithm.
>   (__libelf_decompress_zlib): New.
>   (__libelf_decompress_zstd): New.
>   (__libelf_decompress_elf): Pass type of compression to
>   __libelf_decompress.
>   * elf_compress_gnu.c (elf_compress_gnu): Use ELFCOMPRESS_ZLIB
>   as .z* sections can be only compressed with ZLIB.
>   * libelfP.h (__libelf_decompress): Change signature.
> 
> src/ChangeLog:
> 
>   * readelf.c (elf_ch_type_name): Use switch and support ZSTD.

> diff --git a/libelf/elf.h b/libelf/elf.h
> index 02a1b3f5..f0f0ec7d 100644
> --- a/libelf/elf.h
> +++ b/libelf/elf.h

We normally sync elf.h from glibc. I'll do that in a second.

> +#ifdef USE_ZSTD
> +void *
> +internal_function
> +__libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out)
> +{
> +  /* Malloc might return NULL when requestion zero size.  This is highly

requesting

> + unlikely, it would only happen when the compression was forced.
> + But we do need a non-NULL buffer to return and set as result.
> + Just make sure to always allocate at least 1 byte.  */

> +void *
> +internal_function
> +__libelf_decompress (int chtype, void *buf_in, size_t size_in, size_t 
> size_out)
> +{
> +  if (chtype == ELFCOMPRESS_ZLIB)
> +return __libelf_decompress_zlib (buf_in, size_in, size_out);
> +  else
> +{
> +#ifdef USE_ZSTD
> +return __libelf_decompress_zstd (buf_in, size_in, size_out);
> +#else
> +return 0;
> +#endif

return NULL for consistency?

> +}
> +}
> +
>  void *
>  internal_function
>  __libelf_decompress_elf (Elf_Scn *scn, size_t *size_out, size_t *addralign)
> @@ -268,7 +316,7 @@ __libelf_decompress_elf (Elf_Scn *scn, size_t *size_out, 
> size_t *addralign)
>if (gelf_getchdr (scn, &chdr) == NULL)
>  return NULL;
>  
> -  if (chdr.ch_type != ELFCOMPRESS_ZLIB)
> +  if (chdr.ch_type != ELFCOMPRESS_ZLIB && chdr.ch_type != ELFCOMPRESS_ZSTD)
>  {

What about the ifndef USE_ZSTD case? Should this then not recognize
ELFCOMPRESS_ZSTD?

Thanks,

Mark



[COMMITTED] libelf: Sync elf.h from glibc

2022-10-28 Thread Mark Wielaard
Adds ELFCOMPRESS_ZSTD, NT_S390_PV_CPU_DATA and NT_LOONGARCH_*.

Signed-off-by: Mark Wielaard 
---
 libelf/ChangeLog |  4 
 libelf/elf.h | 18 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index aefb31b3..8107c71e 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-28  Mark Wielaard  
+
+   * elf.h: Update from glibc.
+
 2022-10-21  Yonggang Luo  
 
* libelf_crc32.c: Remove LIB_SYSTEM_H define.
diff --git a/libelf/elf.h b/libelf/elf.h
index 02a1b3f5..f51300bc 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -506,6 +506,7 @@ typedef struct
 
 /* Legal values for ch_type (compression algorithm).  */
 #define ELFCOMPRESS_ZLIB   1  /* ZLIB/DEFLATE algorithm.  */
+#define ELFCOMPRESS_ZSTD   2  /* Zstandard algorithm.  */
 #define ELFCOMPRESS_LOOS   0x6000 /* Start of OS-specific.  */
 #define ELFCOMPRESS_HIOS   0x6fff /* End of OS-specific.  */
 #define ELFCOMPRESS_LOPROC 0x7000 /* Start of processor-specific.  */
@@ -808,6 +809,7 @@ typedef struct
 #define NT_S390_GS_BC  0x30c   /* s390 guarded storage
   broadcast control block.  */
 #define NT_S390_RI_CB  0x30d   /* s390 runtime instrumentation.  */
+#define NT_S390_PV_CPU_DATA0x30e   /* s390 protvirt cpu dump data.  */
 #define NT_ARM_VFP 0x400   /* ARM VFP/NEON registers */
 #define NT_ARM_TLS 0x401   /* ARM TLS register */
 #define NT_ARM_HW_BREAK0x402   /* ARM hardware breakpoint 
registers */
@@ -829,6 +831,15 @@ typedef struct
 #define NT_MIPS_DSP0x800   /* MIPS DSP ASE registers.  */
 #define NT_MIPS_FP_MODE0x801   /* MIPS floating-point mode.  */
 #define NT_MIPS_MSA0x802   /* MIPS SIMD registers.  */
+#define NT_LOONGARCH_CPUCFG0xa00   /* LoongArch CPU config registers.  */
+#define NT_LOONGARCH_CSR   0xa01   /* LoongArch control and
+  status registers.  */
+#define NT_LOONGARCH_LSX   0xa02   /* LoongArch Loongson SIMD
+  Extension registers.  */
+#define NT_LOONGARCH_LASX  0xa03   /* LoongArch Loongson Advanced
+  SIMD Extension registers.  */
+#define NT_LOONGARCH_LBT   0xa04   /* LoongArch Loongson Binary
+  Translation registers.  */
 
 /* Legal values for the note segment descriptor types for object files.  */
 
@@ -1054,7 +1065,8 @@ typedef struct
 
 /* Legal values for vd_flags (version information flags).  */
 #define VER_FLG_BASE   0x1 /* Version definition of file itself */
-#define VER_FLG_WEAK   0x2 /* Weak version identifier */
+#define VER_FLG_WEAK   0x2 /* Weak version identifier.  Also
+  used by vna_flags below.  */
 
 /* Versym symbol index values.  */
 #defineVER_NDX_LOCAL   0   /* Symbol is local.  */
@@ -1132,10 +1144,6 @@ typedef struct
 } Elf64_Vernaux;
 
 
-/* Legal values for vna_flags.  */
-#define VER_FLG_WEAK   0x2 /* Weak version identifier */
-
-
 /* Auxiliary vector.  */
 
 /* This vector is normally only used by the program interpreter.  The
-- 
2.30.2



Re: [PATCH v3] debuginfod: Support queries for ELF/DWARF sections

2022-10-29 Thread Mark Wielaard
find [OPTION...] source BUILDID /FILENAME
  or:  debuginfod-find [OPTION...] source PATH /FILENAME
  or:  debuginfod-find [OPTION...] 

> diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
> index 9dc4836b..5e1dec05 100644
> --- a/debuginfod/debuginfod.cxx
> +++ b/debuginfod/debuginfod.cxx

Assuming Frank's review covered the debuginfod server part.

> diff --git a/debuginfod/debuginfod.h.in b/debuginfod/debuginfod.h.in
> index 40b1ea00..134bb1cd 100644
> --- a/debuginfod/debuginfod.h.in
> +++ b/debuginfod/debuginfod.h.in
> @@ -78,6 +78,12 @@ int debuginfod_find_source (debuginfod_client *client,
>  const char *filename,
>  char **path);
>  
> +int debuginfod_find_section (debuginfod_client *client,
> +  const unsigned char *build_id,
> +  int build_id_len,
> +  const char *section,
> +  char **path);
> +
>  typedef int (*debuginfod_progressfn_t)(debuginfod_client *c, long a, long b);
>  void debuginfod_set_progressfn(debuginfod_client *c,
>  debuginfod_progressfn_t fn);

OK.

> diff --git a/debuginfod/libdebuginfod.map b/debuginfod/libdebuginfod.map
> index 93964167..6334373f 100644
> --- a/debuginfod/libdebuginfod.map
> +++ b/debuginfod/libdebuginfod.map
> @@ -20,4 +20,5 @@ ELFUTILS_0.183 {
>  } ELFUTILS_0.179;
>  ELFUTILS_0.188 {
>debuginfod_get_headers;
> +  debuginfod_find_section;
>  } ELFUTILS_0.183;

OK.

> diff --git a/doc/ChangeLog b/doc/ChangeLog
> index b2bb4890..7d49528f 100644
> --- a/doc/ChangeLog
> +++ b/doc/ChangeLog
> @@ -1,3 +1,10 @@
> +2022-10-27  Aaron Merey  
> +
> + * Makefile.am (notrans_dist_man3_MANS): Add debuginfod_find_section.3.
> + * debuginfod_find_section.3: New file.
> + * debuginfod_find_debuginfo.3: Document debuginfod_find_section.
> + * debuginfod.8: Document section webapi.
> +
>  2022-09-02  Frank Ch. Eigler  
>  
>   * debuginfod_find_debuginfo.3: Tweaked debuginfod_get_headers docs.
> diff --git a/doc/Makefile.am b/doc/Makefile.am
> index db2506fd..db5a842e 100644
> --- a/doc/Makefile.am
> +++ b/doc/Makefile.am
> @@ -38,6 +38,7 @@ notrans_dist_man3_MANS += debuginfod_end.3
>  notrans_dist_man3_MANS += debuginfod_find_debuginfo.3
>  notrans_dist_man3_MANS += debuginfod_find_executable.3
>  notrans_dist_man3_MANS += debuginfod_find_source.3
> +notrans_dist_man3_MANS += debuginfod_find_section.3
>  notrans_dist_man3_MANS += debuginfod_get_user_data.3
>  notrans_dist_man3_MANS += debuginfod_get_url.3
>  notrans_dist_man3_MANS += debuginfod_set_progressfn.3

OK.

> diff --git a/doc/debuginfod.8 b/doc/debuginfod.8
> index 7c1dc3dd..e3964e5a 100644
> --- a/doc/debuginfod.8
> +++ b/doc/debuginfod.8
> @@ -363,6 +363,16 @@ Note: the client should %-escape characters in 
> /SOURCE/FILE that are
>  not shown as "unreserved" in section 2.3 of RFC3986. Some characters
>  that will be escaped include "+", "\\", "$", "!", the 'space' character,
>  and ";". RFC3986 includes a more comprehensive list of these characters.
> +
> +.SS /buildid/\fIBUILDID\fP/section\fI/SECTION\fP
> +If the given buildid is known to the server, the server will attempt to
> +extract the contents of an ELF/DWARF section named SECTION from the
> +debuginfo file matching BUILDID.  If the debuginfo file can't be found
> +or the section has type SHT_NOBITS, then the server will attempt to extract
> +the section from the executable matching BUILDID.  If the section is
> +succesfully extracted then this request results in a binary object
> +of the section's contents.

Maybe add something like: this is the raw section content, not an ELF file.

>  .SS /metrics
>  
>  This endpoint returns a Prometheus formatted text/plain dump of a
> diff --git a/doc/debuginfod_find_debuginfo.3 b/doc/debuginfod_find_debuginfo.3
> index aebbec3f..d11e91b3 100644
> --- a/doc/debuginfod_find_debuginfo.3
> +++ b/doc/debuginfod_find_debuginfo.3
> @@ -43,6 +43,12 @@ LOOKUP FUNCTIONS
>  .BI "   int " build_id_len ","
>  .BI "   const char *" filename ","
>  .BI "   char ** " path ");"
> +.BI "int debuginfod_find_section(debuginfod_client *" client ","
> +.BI "   const unsigned char *" build_id ","
> +.BI "   int " build_id_len ","
> +.BI "   const char * " section ","
> +.BI "  

Re: [PATCH] readelf: add binutils-style --syms option

2022-10-29 Thread Mark Wielaard
Hi Arsen,

On Fri, Oct 28, 2022 at 10:44:47PM +0200, Arsen Arsenović via Elfutils-devel 
wrote:
> This helps people with a lot of built up muscle memory :)
> 
> Signed-off-by: Arsen Arsenović 
> ---
> 
> I often use the "medium length" form of --symbols when using readelf, and I've
> been trying to switch to eu-readelf lately (for various reasons); this alias
> comes in handy for this reason.  I also added the matching tests, though I'm
> not sure if they're strictly necessary (but I added them anyway).

Awesome. ChangeLog entries, updated documentation and tests. How can I
not merge this? :) Pushed.

> Some of the .po files need regenerating, I didn't include that here because it
> was a massive diff.

Yeah, we only do that before a release.

Thanks,

Mark


Proposed elfutils 0.188 release in Wednesday

2022-10-31 Thread Mark Wielaard
Hi,

It has been 6 months since 0.187. There have been almost 80 commits
since, various bug fixes and some new features (see NEWS). I would like
to push out a 0.188 this Wednesday (Nov 2). Please go over any open
bugs or patches to see if they should be fixed/committed before the
release or can wait for the next release (lets do 0.189 in 3 months,
end of January, as we normally do, instead of waiting 6 months).

Cheers,

Mark


Re: [PATCH 1/7] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'

2022-10-31 Thread Mark Wielaard
Hi,

On Thu, 2022-10-20 at 18:07 +0200, Mark Wielaard wrote:
> So maybe we just should rename them to .specfile?
> That is what the attached patch does, plus some other cleanups.
> - We forgot to include the hello3.specfile
> - Remove the --sign from rpmbuild
> - escape the % in spec comments
> 
> That makes make rpm work out of the box without warnings.
> Does it also help the windows git thing?

I pushed this. Please let me know if it works for you.

Thanks,

Mark


Re: [PATCH v3] debuginfod: Support queries for ELF/DWARF sections

2022-11-01 Thread Mark Wielaard
Hi Aaron,

On Tue, Nov 01, 2022 at 12:53:41AM -0400, Aaron Merey wrote:
> Thanks again for the detailed review.  I fixed the issues you pointed out.

This version looks really good. Please push, so it is included in the
release tomorrow.

> On Sat, Oct 29, 2022 at 8:29 PM Mark Wielaard  wrote:
> > > @@ -1008,6 +1206,9 @@ debuginfod_query_server (debuginfod_client *c, 
> > >            snprintf(data[i].url, PATH_MAX, "%s/%s/%s/%s", server_url,
> > >                     build_id_bytes, type, escaped_string);
> > >          }
> > > +      else if (section)
> > > +     snprintf(data[i].url, PATH_MAX, "%s/%s/%s/%s", server_url,
> > > +              build_id_bytes, type, section);
> >
> > Does the section part need to be path escaped? Like the filename is
> > with curl_easy_escape? And if it is how does that interact with the 
> > cache file name?
> 
> I assumed that section names would not contain '/'.  However I noticed
> that if we call debuginfod_find_section with a section name containing
> '/', it will return -EINVAL.  This triggers the downloading of debuginfo
> in order to attempt client-side extraction.  This is a waste so I changed
> the client to path-escape the section name for caching purposes just like
> the source query filename.

It is highly unlikely a '/' is in the section name, but good to have
this covered anyway. Nicely extracted that escape function.

> > > +  /* The servers may have lacked support for section queries.  Attempt to
> > > +     download the debuginfo or executable containing the section in order
> > > +     to extract it.  */ 
> >
> > This does somewhat defeat the purpose of just getting the section data
> > of course. So we could also just return EINVAL to the user here, so
> > they have to get the whole debuginfo themselves. But maybe just
> > pretending it worked is fine to keep the code path of the user
> > simpler?
> 
> This keeps the code path simpler for the user and like Frank mentioned
> it enables an intermediate server to extract the section and provide
> it to the client.  This server will also cache the debuginfo/executable,
> possibly speeding up future requests.

Ah, yes, the debuginfod server doesn use the client library too.

Thanks,

Mark


Re: [PATCH] Add support for ARCv2

2022-11-01 Thread Mark Wielaard
Hi Shahab,

On Mon, Oct 31, 2022 at 02:54:33PM +, Shahab Vahedi via Elfutils-devel 
wrote:
> Thank you for response. First and foremost, there is a second iteration of the
> patch [1]. I don't want you, or anybody else, waste time looking into v1. The
> changes from v1 have been mentioned at the end of v2 commit message.

Thanks.

> There is a QEMU target [2]. However, this patch adds a minimal support for 
> ARC.
> I'm not quite sure building and running elfutils natively for ARC would test
> much at this point. That's why I tested with an x86_64 build with ARC target
> support: master + patch -> make check
> 
> Unfortunately, there is no machine in GCC's compile farm. There does exist a
> pre-built compiler [3] and a repo [4] though.

It might be good to add some tests that can be run on a non ARC
architecture just so people can check they didn't break something. See
e.g. tests/run-strip-reloc.sh tests/run-allregs.sh or
tests/run-addrcfi.sh which take small prebuild object files.

> >> ARC target related
> >> macros has been added to libelf/elf.h. However, there a few changes
> >> on existing ARC macros to correct them and be in sync with binutils.
> > 
> > We normally sync with the glibc elf.h, have you submitted these
> > changes to libc-alpha?
> 
> No, but I intend to. In a v2 of the patch [1], I also have added ChangeLog
> entries. It must be easier now to quickly figure out what has changed and
> if it's OK or not.

Thanks. Normally we wait syncing the elf.h file once a patch lands in glibc.

> >> There are no regressions in tests for an x86_64 build.
> >>
> >> ==
> >>elfutils 0.187: tests/test-suite.log
> >> ==
> >>
> >> .. contents:: :depth: 2
> >>
> >> FAIL: run-backtrace-native-core.sh
> >> ==
> >>
> >> backtrace: No modules recognized in core file
> >> backtrace-child-core.8740: no main
> >> rmdir: failed to remove 'test-8732': Directory not empty
> >> FAIL run-backtrace-native-core.sh (exit status: 1)
> >>
> >> FAIL: run-backtrace-native-core-biarch.sh
> >> =
> >>
> >> backtrace: No modules recognized in core file
> >> backtrace-child-biarch-core.8763: no main
> >> rmdir: failed to remove 'test-8755': Directory not empty
> >> FAIL run-backtrace-native-core-biarch.sh (exit status: 1)
> > 
> > These two need abi_cfi hooks to describe the DWARF CFI needed to
> > unwind.
> 
> To be clear, these are the test results on a build without the patch AND
> with the patch. I'm not sure why it happens even without the patch on
> my system. If you want, I can file a bug report with more details.

Aha, sorry, I missed this was on x86_64. That is indeed odd. If you
could file a bug report with your environment where this fails that
would be good.

Thanks,

Mark


Re: PATCH: Bug debuginfod/29472 followup

2022-11-01 Thread Mark Wielaard
Hi Frank,

On Tue, Nov 01, 2022 at 10:23:06AM -0400, Frank Ch. Eigler via Elfutils-devel 
wrote:
> On the users/fche/try-pr29472 branch, I pushed a followup to Ryan's
> PR29472 draft from a bunch of weeks ago.  It's missing some
> ChangeLog's but appears otherwise complete.  It's structured as Ryan's
> original patch plus my followup that changes things around, so as to
> preserve both contributions in the history.  I paste the overall diff
> here.
> 
> There will be some minor merge conflicts between this and amerey's
> section-extraction extensions that are also aiming for this release.
> I'll be glad to deconflict whichever way.

The section extraction extension was just pushed. But the testcase
fails on some systems, which needs investigation.

This is a fairly big patch which introduces even more new
functionality, are you sure you want to target the 0.188 release of
tomorrow?

Are you sure the interface is correct? Is the sqlite "glob" pattern
standardized? Can it be provided if the underlying server database
isn't sqlite?

I haven't read the whole diff yet. There are several refactorings
which would be nice to see a separate patch.

Why does debuginfod-client.c use json-c? Can't the server sent the
json object as a normal char string? Why does the string from the
server need to be interpreted as a json object and then turned into a
string again?

Cheers,

Mark


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

2022-11-02 Thread Mark Wielaard
Hi,

On Wed, 2022-11-02 at 01:15 +, builder--- via Elfutils-devel wrote:
> A new failure has been detected on builder elfutils-fedora-ppc64le
> while building elfutils.
> 
> Full details are available at:
> https://builder.sourceware.org/buildbot/#builders/55/builds/96
> 
> Build state: failed test (failure)
> Revision: f0f155569c6859c5bc529c0279a6b4803aac950f
> Worker: fedora-ppc64le
> Build Reason: (unknown)
> Blamelist: Aaron Merey 
> 
> Steps:
> [...]
> - 7: make check ( failure )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/55/builds/96/steps/7/logs/stdio
> - test-suite.log: 
> https://builder.sourceware.org/buildbot/#builders/55/builds/96/steps/7/logs/test-suite_log

This was not because of any of Aaron's commits (thanks for the
fixups!). This is the run-debuginfod-federation-metrics.sh crash in
libmicrohttpd (version 0.9.75):

libmicrohttpd error: Call to epoll_ctl failed: Bad file descriptor
Fatal error in GNU libmicrohttpd daemon.c:2927: Close socket failed.

Still don't know why that is sometimes triggered. It does seem to be
caused by the latest libmicrohttpd release. But only occasionally.

Cheers,

Mark


[COMMITTED] Prepare for 0.188

2022-11-02 Thread Mark Wielaard
Set version to 0.188
Update elfutils.spec.in
Regenerate po/*.po files

Signed-off-by: Mark Wielaard 
---
 ChangeLog   |5 +
 NEWS|2 +-
 config/ChangeLog|7 +
 config/elfutils.spec.in |   13 +-
 configure.ac|2 +-
 po/ChangeLog|4 +
 po/de.po| 2400 +++---
 po/es.po| 2420 +++---
 po/ja.po| 2412 +++---
 po/pl.po| 2434 ---
 po/uk.po| 2427 +++---
 11 files changed, 6189 insertions(+), 5937 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9179dcea..52efca04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-11-02  Mark Wielaard  
+
+   * configure.ac (AC_INIT): Set version to 0.188.
+   * NEWS: Likewise.
+
 2022-10-31  Aaron Merey  
 
* NEWS: Add debuginfod_find_section.
diff --git a/NEWS b/NEWS
index 9369f809..71534b8c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-Version 0.188 some time after 0.187
+Version 0.188
 
 readelf: Add -D, --use-dynamic option.
 
diff --git a/config/ChangeLog b/config/ChangeLog
index 9c2816b5..c63caa0c 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,10 @@
+2022-10-02  Mark Wielaard  
+
+   * elfutils.spec.in: Update for 0.188.
+   Include %{_mandir}/man8/debuginfod*.8* for new
+   debuginfod-service.8 man page.
+   Remove duplicate %{_sysconfdir}/sysconfig/debuginfod.
+
 2022-10-20  Mark Wielaard  
 
* elfutils.spec.in: Escape % in comments.
diff --git a/config/elfutils.spec.in b/config/elfutils.spec.in
index f491ce0a..c444d1f5 100644
--- a/config/elfutils.spec.in
+++ b/config/elfutils.spec.in
@@ -321,8 +321,7 @@ fi
 %{_bindir}/debuginfod
 %config(noreplace) %{_sysconfdir}/sysconfig/debuginfod
 %{_unitdir}/debuginfod.service
-%{_sysconfdir}/sysconfig/debuginfod
-%{_mandir}/man8/debuginfod.8*
+%{_mandir}/man8/debuginfod*.8*
 %{_mandir}/man7/debuginfod*.7*
 
 %dir %attr(0700,debuginfod,debuginfod) %{_localstatedir}/cache/debuginfod
@@ -342,6 +341,16 @@ exit 0
 %systemd_postun_with_restart debuginfod.service
 
 %changelog
+* Wed Nov  2 2022 Mark Wielaard  0.188-1
+- readelf: Add -D, --use-dynamic option.
+- debuginfod-client: Add $DEBUGINFOD_HEADERS_FILE setting to supply
+  outgoing HTTP headers.
+  Add new function debuginfod_find_section.
+- debuginfod: Add --disable-source-scan option.
+- libdwfl: Add new function dwfl_get_debuginfod_client.
+  Add new function dwfl_frame_reg.
+  Add new function dwfl_report_offline_memory.
+
 * Mon Apr 25 2022 Mark Wielaard  0.187-1
 - debuginfod: Support -C option for connection thread pooling.
 - debuginfod-client: Negative cache file are now zero sized instead
diff --git a/configure.ac b/configure.ac
index 1084b469..59be27ac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@ dnl  GNU General Public License for more details.
 dnl
 dnl  You should have received a copy of the GNU General Public License
 dnl  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-AC_INIT([elfutils],[0.187],[https://sourceware.org/bugzilla],[elfutils],[http://elfutils.org/])
+AC_INIT([elfutils],[0.188],[https://sourceware.org/bugzilla],[elfutils],[http://elfutils.org/])
 
 dnl Workaround for older autoconf < 2.64
 m4_ifndef([AC_PACKAGE_URL],
diff --git a/po/ChangeLog b/po/ChangeLog
index bee350db..8894a9b5 100644
--- a/po/ChangeLog
+++ b/po/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-02  Mark Wielaard  
+
+   * *.po: Update for 0.188.
+
 2022-08-05  Mark Wielaard  
 
* de.po: Set Project-Id-Version: to elfutils.

[...snip new po diff...]


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

2022-11-02 Thread Mark Wielaard
Hi,

On Wed, 2022-11-02 at 13:39 +, builder--- via Elfutils-devel wrote:
> A new failure has been detected on builder elfutils-centos-x86_64
> while building elfutils.
> 
> Full details are available at:
> https://builder.sourceware.org/buildbot/#builders/39/builds/99
> 
> Build state: failed test (failure)
> Revision: e9f3045caa5c4498f371383e5519151942d48b6d
> Worker: centos-x86_64
> Build Reason: (unknown)
> Blamelist: Mark Wielaard 
> 
> Steps:
> [...]
> https://builder.sourceware.org/buildbot/#builders/39/builds/99/steps/6/logs/warnings__2_
> 
> - 7: make check ( failure )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/39/builds/99/steps/7/logs/stdio
> - test-suite.log: 
> https://builder.sourceware.org/buildbot/#builders/39/builds/99/steps/7/logs/test-suite_log

So this is run-backtrace-native-core-biarch.sh which only occasionally
fails. It also fails on on debian-testing. It looks like the pc is off
when the core file is generated, which might be a kernel issue, but I
don't understand why it only happens sometimes. Might be because there
are two threads running?

It seems we have two tests that occasionally fail. Which is not good.
But also not that bad that it should stop the release imho.

Cheers,

Mark


elfutils 0.188 released

2022-11-02 Thread Mark Wielaard
ELFUTILS 0.188 - http://elfutils.org/

A new release of elfutils is available at:
ftp://sourceware.org/pub/elfutils/0.188/
or https://sourceware.org/elfutils/ftp/0.188/

Visit us on the Libera.Chat irc channel #elfutils

* NEWS *

readelf: Add -D, --use-dynamic option.

debuginfod-client: Add $DEBUGINFOD_HEADERS_FILE setting to supply
outgoing
   HTTP headers. Add new function
debuginfod_find_section.

debuginfod: Add --disable-source-scan option.

libdwfl: Add new function dwfl_get_debuginfod_client.
 Add new function dwfl_frame_reg.
 Add new function dwfl_report_offline_memory.

* GIT SHORTLOG *

Aaron Merey (6):
  debuginfod: Use auto-sized connection pool when -C is not given
with arg
  debuginfod-client: Ensure only negative error codes returned.
  debuginfod: Support queries for ELF/DWARF sections
  debuginfod-client: Fix out-of-bounds write
  run-debuginfod-section.sh: Avoid zstd-compressed rpms
  Changelog: Update entries from previous commits.

Aleksei Vetrov (1):
  libdwfl: add dwfl_report_offline_memory

Andreas Schwab (4):
  libelf: Sync elf.h from glibc
  backends: Handle new RISC-V specific definitions
  elflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES
  readelf: Handle SHT_RISCV_ATTRIBUTES like SHT_GNU_ATTRIBUTES

Arsen Arsenović (1):
  readelf: add binutils-style --syms option

Daniel Thornburgh (1):
  debuginfod-client: Add DEBUGINFOD_HEADERS_FILE.

Di Chen (2):
  libdwfl: Add new function dwfl_frame_reg
  readelf: Support --dynamic with --use-dynamic

Frank Ch. Eigler (9):
  PR29117: fix fd leak in debuginfod client for cache-miss files
  debuginfod.8: Tweak wording of fdcache operation & parameters.
  NEWS & ChangeLog: add debuginfod blurbs
  doc/debuginfod.8: tiny obvious typo fix
  PR29474: debuginfod
  config/debuginfod.sysconfig: Clarify & classify the variables
  PR28284: add tweaks on previous debuginfod x-debuginfod* header
forwarding work
  PR28284 cont'd, ->winning_headers reset at start of new query
  debuginfod: report libmicrohttpd version on startup

Josef Cejka (2):
  debuginfod: create indexes to speed up grooming
  debuginfod: optimize regular expressions in groom()

Khem Raj (1):
  tests: Add libeu to tests needing error() API

Mark Wielaard (31):
  configure: Don't use valgrind and sanitize-undefined for make
distcheck
  config: Move the 2>/dev/null inside the sh -c '' quotes for
profile.csh.
  debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
  debuginfod: Use MHD_USE_EPOLL for libmicrohttpd version 0.9.51 or
higher
  elfcompress: Add sanity checks to make sure to not override variable
  debuginfod: Check result of curl_easy_getinfo in
debuginfod_write_callback
  debuginfod: Check all curl_easy_setopt calls
  libdw: Add sanity check to store_implicit_value
  strip: Add more NULL check
  debuginfod: Always request servname from getnameinfo for conninfo.
  debuginfod: Make sure debuginfod_config_cache always returns valid
stat
  debuginfod: Remove debuginfod_init_cache
  debuginfod: update mtime of interval_path as early as possible
  libdwfl: Update docs and nonnull attributes for dwfl_module_addrinfo
  tests: Disable run-debuginfod-federation-metrics.sh for old
libmicrohttpd
  Move dwfl_get_debuginfod_client to ELFUTILS_0.188
  libdwfl: Rewrite reading of ar_size in elf_begin_rand
  readelf: memrchr searches backwards but takes the start buf as
argument
  tests: Add initial scan wait_ready in
run-debuginfod-percent-escape.sh
  po: standardize Project-Id-Version to just elfutils
  lib: Add documentation to explain concurrent htab resizing.
  libelf: Correctly decode ar_mode as octal string
  ar: Correct -N COUNT off-by-one
  tests: Check lseek, read and malloc results with correct types in
test.
  tests: include config.h first.
  readelf: Handle DW_LLE_GNU_view_pair
  config: Add BuildRequires socat for run-debuginfod-response
headers.sh
  Use grep -E instead of egrep, use grep -F instead of fgrep.
  configure.ac: Update AC_PROG_CC and AC_PROG_LEX for autoconf 2.70
  libelf: Sync elf.h from glibc
  Prepare for 0.188

Martin Liska (6):
  Support nullglob in profile.*.in files
  debuginfod: print filename for "cannot open archive" error
  debuginfod: fix http_requests_total{type="debuginfo"} when dwz is
used
  Add new debuginfod.sysconfig value DEBUGINFOD_EXTRA_ARGS
  Add missing changelog entries.
  add debuginfod_get_headers if DUMMY_LIBDEBUGINFOD is used

Michael Trapp (1):
  debuginfod: add --disable-source-scan option

Milian Wolff (1):
  Introduce public dwfl_get_debuginfod_client API

Noah Sanci (5):
  PR29098: debuginfod - set default prefetch cache size to >0
  PR28577: run-debuginfod-fd-prefetch-caches.sh now tests something
run-debuginfod-fd-prefetch-caches.sh now tests the maximum fd
and mb values of prefetch and fd (least recently used) caches.
  Added debuginfod.service.8 manual pa

[COMMITTED] debuginfod: Mark extract_section function static

2022-11-02 Thread Mark Wielaard
The extract_section function in debuginfod-client.c is an internal
function and should not be exported. Mark it as static.

Signed-off-by: Mark Wielaard 
---
 debuginfod/ChangeLog   | 4 
 debuginfod/debuginfod-client.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 50668e61..1efa080f 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,7 @@
+2022-11-02  Mark Wielaard  
+
+   * debuginfod-client.c (extract_section): Mark static.
+
 2022-11-01  Aaron Merey  
 
* debuginfod-client.c (path_escape): Add early return.
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 0c4a00cf..f48e32cc 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -621,7 +621,7 @@ path_escape (const char *src, char *dest)
section name was not found.  -EEXIST indicates that the section was
found but had type SHT_NOBITS.  */
 
-int
+static int
 extract_section (int fd, const char *section, char *fd_path, char **usr_path)
 {
   elf_version (EV_CURRENT);
-- 
2.18.4



[COMMITTED] readelf: Check phdr != NULL or shdr != NULL in handle_dynamic.

2022-11-03 Thread Mark Wielaard
The compiler doesn't know that when use_dynamic_segment is true,
then phdr should/will be non-NULL and otherwise shdr is non-NULL.
Add explicit checks to help the compiler out and in case an error
is made calling the handle_dynamic function.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog |  5 +
 src/readelf.c | 10 +-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index d3399a5c..0c5ab37e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2022-11-03  Mark Wielaard  
+
+   * readelf.c (handle_dynamic): Check phdr != NULL when
+   use_dynamic_segment, otherwise check shdr != NULL.
+
 2022-10-28  Arsen Arsenović  
 
* readelf.c (options): Add Binutils-style --syms alias.
diff --git a/src/readelf.c b/src/readelf.c
index 0e0b05c4..e721a209 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1828,7 +1828,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, 
GElf_Phdr *phdr)
   size_t dyn_ents;
 
   /* Get the data of the section.  */
-  if (use_dynamic_segment)
+  if (use_dynamic_segment && phdr != NULL)
 data = elf_getdata_rawchunk(ebl->elf, phdr->p_offset,
phdr->p_filesz, ELF_T_DYN);
   else
@@ -1840,7 +1840,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, 
GElf_Phdr *phdr)
   /* Get the dynamic section entry number */
   dyn_ents = get_dyn_ents (data);
 
-  if (!use_dynamic_segment)
+  if (!use_dynamic_segment && shdr != NULL)
 {
   /* Get the section header string table index.  */
   if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0))
@@ -1862,7 +1862,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, 
GElf_Phdr *phdr)
  (int) shdr->sh_link,
  elf_strptr (ebl->elf, shstrndx, glink->sh_name));
 }
-  else
+  else if (phdr != NULL)
 {
   printf (ngettext ("\
 \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 "  Offset: %#08" 
PRIx64 "\n",
@@ -1879,7 +1879,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, 
GElf_Phdr *phdr)
   /* if --use-dynamic option is enabled,
  use the string table to get the related library info.  */
   Elf_Data *strtab_data = NULL;
-  if (use_dynamic_segment)
+  if (use_dynamic_segment && phdr != NULL)
 {
   strtab_data = get_dynscn_strtab(ebl->elf, phdr);
   if (strtab_data == NULL)
@@ -1903,7 +1903,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, 
GElf_Phdr *phdr)
  || dyn->d_tag == DT_RPATH
  || dyn->d_tag == DT_RUNPATH)
{
- if (! use_dynamic_segment)
+ if (! use_dynamic_segment && shdr != NULL)
name = elf_strptr (ebl->elf, shdr->sh_link, dyn->d_un.d_val);
  else if (dyn->d_un.d_val < strtab_data->d_size
   && memrchr (strtab_data->d_buf + dyn->d_un.d_val, '\0',
-- 
2.18.4



[COMMITTED] readelf: Check gelf_getdyn doesn't return NULL

2022-11-03 Thread Mark Wielaard
Signed-off-by: Mark Wielaard 
---
 src/ChangeLog | 5 +
 src/readelf.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 0c5ab37e..66428b70 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2022-11-03  Mark Wielaard  
+
+   * readelf.c (get_dynscn_addrs): Check gelf_getdyn doesn't
+   return NULL.
+
 2022-11-03  Mark Wielaard  
 
* readelf.c (handle_dynamic): Check phdr != NULL when
diff --git a/src/readelf.c b/src/readelf.c
index e721a209..3dafb041 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4910,7 +4910,7 @@ get_dynscn_addrs(Elf *elf, GElf_Phdr *phdr, GElf_Addr 
addrs[i_max])
 GElf_Dyn dyn_mem;
 GElf_Dyn *dyn = gelf_getdyn(data, dyn_idx, &dyn_mem);
 /* DT_NULL Marks end of dynamic section.  */
-if (dyn->d_tag == DT_NULL)
+if (dyn == NULL || dyn->d_tag == DT_NULL)
   break;
 
 switch (dyn->d_tag) {
-- 
2.18.4



[COMMITTED] libdw: Don't dereference and assign values we are skipping

2022-11-03 Thread Mark Wielaard
We don't use the FDE address encoding byte, so no reason
to read and store it. Just skip past it.

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog| 5 +
 libdw/dwarf_next_cfi.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 3c595a3d..6cbf192d 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2022-11-03  Mark Wielaard  
+
+   * dwarf_next_cfi.c (dwarf_next_cfi): Don't dereference and assign
+   bytes.
+
 2022-10-21  Yonggang Luo  
 
* dwarf_begin_elf.h: Don't include unistd.h and endian.h.
diff --git a/libdw/dwarf_next_cfi.c b/libdw/dwarf_next_cfi.c
index 23b16885..be08984f 100644
--- a/libdw/dwarf_next_cfi.c
+++ b/libdw/dwarf_next_cfi.c
@@ -226,7 +226,7 @@ dwarf_next_cfi (const unsigned char e_ident[],
  if (sized_augmentation)
{
  /* Skip FDE address encoding byte.  */
- encoding = *bytes++;
+ bytes++;
  continue;
}
  break;
-- 
2.18.4



Re: [COMMITTED] debuginfod_find_section: Always update rc with most recent error code

2022-11-07 Thread Mark Wielaard
Hi Aaron,

On Fri, 2022-11-04 at 17:40 -0400, Aaron Merey via Elfutils-devel
wrote:
> debuginfod_find_section may attempt to download both the debuginfo
> and executable matching the given build-id.  If neither of these
> files can be found, update rc to ensure that we always return an
> accurate error code in this case.

Nicely spotted, otherwise we might have returned -EEXIST.

> diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-
> client.c
> index f48e32cc..99da05ef 100644
> --- a/debuginfod/debuginfod-client.c
> +++ b/debuginfod/debuginfod-client.c
> @@ -1944,7 +1944,8 @@ debuginfod_find_section (debuginfod_client *client,
>  
>if (rc == -EEXIST)
>  {
> -  /* The section should be found in the executable.  */
> +  /* Either the debuginfo couldn't be found or the section should
> +  be in the executable.  */
>fd = debuginfod_find_executable (client, build_id,
>  build_id_len, &tmp_path);
>if (fd > 0)

I know this is in existing code, so this might have missed in a
previous review. But shouldn't this be fd >= 0 ?

That is what is checked in the rest of the code. Except for the
debuginfod_find_section function which uses fd >0 twice.

It is unlikely, but I think fd can be zero if it (stdin) was closed by
the program for some reason. Then I think zero can be reused as new
file descriptor?

Cheers,

Mark


[PATCH] debuginfod: Initialize response_data early in debuginfod-client query

2022-11-15 Thread Mark Wielaard
On error going to out2, the response_data is freed. So initialize the
response_data to NULL immediately after allocation or when going back
to query_in_parallel.

Signed-off-by: Mark Wielaard 
---
 debuginfod/ChangeLog   | 5 +
 debuginfod/debuginfod-client.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 5678002a..2a9ba518 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@
+2022-11-15  Mark Wielaard  
+
+   * debuginfod-client.c (debuginfod_query_server): Initialize
+   response_data early.
+
 2022-11-04  Aaron Merey  
 
* debuginfod-client.c (debuginfod_find_section): Ensure rc
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 99da05ef..c92ef274 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1250,6 +1250,8 @@ debuginfod_query_server (debuginfod_client *c,
   data[i].handle = NULL;
   data[i].fd = -1;
   data[i].errbuf[0] = '\0';
+  data[i].response_data = NULL;
+  data[i].response_data_size = 0;
 }
 
   char *escaped_string = NULL;
@@ -1346,8 +1348,6 @@ debuginfod_query_server (debuginfod_client *c,
  curl_easy_setopt_ck (data[i].handle, CURLOPT_LOW_SPEED_LIMIT,
   100 * 1024L);
}
-  data[i].response_data = NULL;
-  data[i].response_data_size = 0;
   curl_easy_setopt_ck(data[i].handle, CURLOPT_FILETIME, (long) 1);
   curl_easy_setopt_ck(data[i].handle, CURLOPT_FOLLOWLOCATION, (long) 1);
   curl_easy_setopt_ck(data[i].handle, CURLOPT_FAILONERROR, (long) 1);
-- 
2.18.4



elfutils-devel@sourceware.org

2022-11-15 Thread Mark Wielaard
This Friday, 18 November, at 16:00 UTC (11:00am Eastern, 17:00 Central
European Time) the FSF will host a session on their BBB server about
the current sourceware infrastructure and future plans.

https://www.fsf.org/events/sourceware-infrastructure-a-presentation-and-community-q-a
https://inbox.sourceware.org/overseers/6e9cde97-d880-5343-6cfd-16a648cf6...@fsf.org/

We like to discuss how to use the new infrastructure setup this last
year, builder, try/ci/full buildbots, bunsen testsuite analysis,
patchwork patch tracking, handling patches/email with public-inbox,
b4, the sourcehut mirror. And the future of Sourceware as a Software
Freedom Conservancy member project. (*)

This presentation is for everybody who likes to discuss (and wants to
help with) automating the infrastructure to make contributing to our
projects more fun and more productive.

(*) Similar to the BoF we intended to do at the Cauldron this year:
https://gnu.wildebeest.org/~mark/sourceware/presentation.html


Re: [PATCH] debuginfod: Initialize response_data early in debuginfod-client query

2022-11-21 Thread Mark Wielaard
Hi,

On Tue, 2022-11-15 at 17:55 +0100, Mark Wielaard wrote:
> On error going to out2, the response_data is freed. So initialize the
> response_data to NULL immediately after allocation or when going back
> to query_in_parallel.

Frank on irc said this looked fine.

Pushed,

Mark


Re: [PATCH] libebl: Do not require EI_OSABI for IFUNC.

2022-11-24 Thread Mark Wielaard
Hi Martin,

On Thu, 2022-11-24 at 13:23 +0100, Martin Liška wrote:
> Similar fix to:
> https://sourceware.org/bugzilla/show_bug.cgi?id=29718
> 
> Ready for master?

Assuming runtime, glibc/ld.so, accepts this without EI_OSABI set to
ELFOSABI_LINUX, it seems ok to print it as GNU_IFUNC.

> else if (symbol == STT_GNU_IFUNC
>  && ebl != NULL
> -&& (ident = elf_getident (ebl->elf, NULL)) != NULL
> -&& ident[EI_OSABI] == ELFOSABI_LINUX)
> - return "GNU_IFUNC";
> +&& (ident = elf_getident (ebl->elf, NULL)) != NULL)
> + return "GNU_IFUNC"; /* Ignore EI_OSABI
> + as STT_GNU_IFUNC is a reserved name.  */

Note that you technically also don't need the elf_getident call
anymore, except as sanity check that the ELF header can be read
properly.

OK, with and without that change.

Cheers,

Mark


Re: [PATCH] readelf: print warning for -sW

2022-11-25 Thread Mark Wielaard
Hi Marin,

On Fri, 2022-11-25 at 14:29 +0100, Martin Liška wrote:
> The option -s accepts in elfutils (compared to binutils) a positional
> argument that is name of a symbol table section which should be
> printed.
> 
> Thus, print a reasonable warning if -sW is used:
> ./src/readelf -sW a.out
> WARNING: cannot find section: 'W'
> 
> Ready for master?

Looks good. But one nitpick below.

> src/ChangeLog:
> 
>   * readelf.c (print_symtab): Change signature and return true if
>   something is printed.
>   (process_elf_file): Use it and print warning.

Aha, we are processing the symbol sections twice, once for 
SHT_DYNSYM, then for SHT_SYMTAB. And the named section should be one or
the other. Good.

> tests/ChangeLog:
> 
>   * run-readelf-s.sh: Test -sW.

Plus a new testcase. Perfect..

> diff --git a/tests/run-readelf-s.sh b/tests/run-readelf-s.sh
> index ee1c0e82..c150c165 100755
> --- a/tests/run-readelf-s.sh
> +++ b/tests/run-readelf-s.sh
> @@ -395,4 +395,7 @@ Symbol table [27] '.symtab' contains 42 entries:
> 41: 004003a8  0 FUNCGLOBAL DEFAULT   11 _init
>  EOF
>  
> +${abs_top_builddir}/src/readelf --elf-section -sW testfilebaxmin 2>&1 \
> +  | grep "WARNING: cannot find section: 'W'" >/dev/null || exit 2
> +

You need to run a tests with testrun or testrun_compare so they
actually run against the just build libraries (and so they run under
valgrind when configured with --enable-valgrind).

So in this case just add a testrun in front.

-${abs_top_builddir}/src/readelf --elf-section -sW testfilebaxmin 2>&1 \
+testrun ${abs_top_builddir}/src/readelf --elf-section -sW testfilebaxmin 2>&1 \

OK with that change.

Thanks,

Mark


Re: [PATCH] Missing newline for: elfcompress -t zlib-gnu a.out -force

2022-11-28 Thread Mark Wielaard
Hi Martin,

On Mon, 2022-11-28 at 14:03 +0100, Martin Liška wrote:
> Fixes:
> ./src/elfcompress -t zlib-gnu a.out -force
> [28] .zdebug_aranges unchanged, already GNU compressed[29]
> .zdebug_info unchanged, already GNU compressed[30] .zdebug_abbrev
> unchanged, already GNU compressed[31] .zdebug_line unchanged, already
> GNU compressed[32] .zdebug_str unchanged, already GNU compressed[33]
> .zdebug_line_str unchanged, already GNU compressed[34]
> .zdebug_rnglists unchanged, already GNU compressed
> 
> to:
> ./src/elfcompress -t zlib-gnu a.out -force
> [28] .zdebug_aranges unchanged, already GNU compressed
> [29] .zdebug_info unchanged, already GNU compressed
> [30] .zdebug_abbrev unchanged, already GNU compressed
> [31] .zdebug_line unchanged, already GNU compressed
> [32] .zdebug_str unchanged, already GNU compressed
> [33] .zdebug_line_str unchanged, already GNU compressed
> [34] .zdebug_rnglists unchanged, already GNU compressed
> 
> I'm going to push it as obvious, hope it's fine?

Yes, obvious typo. Thanks for fixing it.

Also the buildbot arm32 failure on run-debuginfod-federation-metrics.sh 
was clearly unrelated. Another Fatal error in GNU libmicrohttpd
daemon.c:3239: Failed to remove FD from epoll set. Grmbl.
Undeterministic tests :{

Cheers,

Mark


Re: [PATCH][RFC] readelf: partial support of ZSTD compression

2022-11-28 Thread Mark Wielaard
Hi Martin,

On Mon, Nov 28, 2022 at 02:16:35PM +0100, Martin Liška wrote:
> On 10/29/22 00:21, Mark Wielaard wrote:
> > Although I like to also have compression working.  Then we can also
> > add support to src/elfcompress, which makes for a good testcase. See
> > tests/run-compress.sh (which has found some subtle memory issues when
> > run under valgrind).
> 
> All right, so I'm preparing a full support for ZSTD (both compression and 
> compression)
> and I noticed a refactoring would be handy for compress_section function and 
> callers
> of the function.
> 
> Note right now, there are basically 3 compression types and process_file
> function handles basically all combinations of these (3 x 3 options), while 
> adding ZSTD
> support would make it even more complicated. However, ZSTD will behave very 
> similar to ZLIB
> (not zlib-gnu), except a different algorithm will be used. Plus, in order to 
> distinguish
> ZLIB from ZSTD, we need to read GElf_Chdr.
> 
> So what do you think about the refactoring as the first step?

Looks good. I would just add a sanity check that chdr.ch_type is of a
known compression type (it is only checked to be not NONE atm).

Cheers,

Mark




Re: [PATCH] libdwfl: Read no more than required to parse dynamic sections

2022-11-29 Thread Mark Wielaard
Hi Gavin,

On Mon, 2022-11-28 at 22:26 -0800, ga...@matician.com wrote:
> Since size checking has been moved to
> dwfl_elf_phdr_memory_callback(),
> there is no longer a need for dwfl_segment_report_module() to enforce
> the same. Reading beyond the end of the dynamic section actually causes
> issues when passing the data to elfXX_xlatetom() because it is possible
> that src->d_size is not a multiple of recsize (for ELF_T_DYN, recsize is
> 16 while the minimum required alignment is 8), causing elfXX_xlatetom()
> to return ELF_E_INVALID_DATA.

I don't fully follow this logic.

The code as written doesn't seem to guarantee that
dwfl_segment_report_module will always be called with
dwfl_elf_phdr_memory_callback as memory_callback. Although it probably
will be in practice.

So you are removing this check:

>   && ! read_portion (&read_state, &dyn_data, &dyn_data_size,
>start, segment, dyn_vaddr, dyn_filesz))
>  {
> -  /* dyn_data_size will be zero if we got everything from the initial
> - buffer, otherwise it will be the size of the new buffer that
> - could be read.  */
> -  if (dyn_data_size != 0)
> - dyn_filesz = dyn_data_size;
> -

Reading read_portion it shows dyn_data_size being set to zero if
read_state->buffer_available has everything (dyn_filesz) requested.
Otherwise memory_callback (we assume dwfl_elf_phdr_memory_callback) is
called with *data_size = dyn_filesz. Which will then be set to the
actual buffer size being read.

So dyn_data_size might be bigger than the dynfilesz we are requesting?
Or smaller I assume.

If you are protecting against it becoming bigger, should the check be
changed to:

if (dyn_data_size != 0 && dyn_data_size < dyn_filesz)
  dyn_filesz = dyn_data_size;

?

Thanks,

Mark


Re: [PATCH] libdwfl: Read no more than required to parse dynamic sections

2022-11-30 Thread Mark Wielaard
Hi Gavin,

On Tue, Nov 29, 2022 at 01:48:42PM -0800, Gavin Li wrote:
> I think for the purposes of reading small segments (like PT_DYNAMIC
> and PT_NOTE), we should ignore *buffer_available altogether.

Thanks for walking me through the code. I think you are right and none
of the buffer_available checks are necessary. So I removed them all. I
also adjusted the commit message a bit. Could you look at this patch
and let me know if this works for you?

Cheers,

Mark>From 59f1b49c1a1163ebde891196c1b24e3f4225915b Mon Sep 17 00:00:00 2001
From: Gavin Li 
Date: Wed, 30 Nov 2022 18:26:19 +0100
Subject: [PATCH] libdwfl: Read no more than required in
 dwfl_segment_report_module

Since read_portion and the standard dwfl_elf_phdr_memory_callback
functions make sure to read at least minread bytes there is no need
for dwfl_segment_report_module to check and adjust the data to the
actual buffer size read. Reading beyond the end of the expected data
size (if the buffer read is much larger) actually causes issues when
passing the data to elfXX_xlatetom() because it is possible that
src->d_size is not a multiple of recsize (for ELF_T_DYN, recsize is 16
while the minimum required alignment is 8), causing elfXX_xlatetom()
to return ELF_E_INVALID_DATA.

Signed-off-by: Gavin Li 
Signed-off-by: Mark Wielaard 
---
 libdwfl/ChangeLog|  6 ++
 libdwfl/dwfl_segment_report_module.c | 28 +++-
 2 files changed, 9 insertions(+), 25 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 6dd84a6f..68527327 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2022-11-28  Gavin Li  
+	Mark Wielaard  
+
+	* dwfl_segment_report_module.c (dwfl_segment_report_module): Remove
+	data size check after read_portion memory_callback.
+
 2022-10-21  Yonggang Luo  
 
 	* argp-std.c: Don't include unistd.h.
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 287fc002..6a7b77f0 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -441,18 +441,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 		start + phoff, xlatefrom.d_size))
 goto out;
 
-  /* ph_buffer_size will be zero if we got everything from the initial
- buffer, otherwise it will be the size of the new buffer that
- could be read.  */
-  if (ph_buffer_size != 0)
-{
-  phnum = ph_buffer_size / phentsize;
-  if (phnum == 0)
-	goto out;
-  xlatefrom.d_size = ph_buffer_size;
-}
-
   xlatefrom.d_buf = ph_buffer;
+  xlatefrom.d_size = xlatefrom.d_size;
 
   bool class32 = ei_class == ELFCLASS32;
   size_t phdr_size = class32 ? sizeof (Elf32_Phdr) : sizeof (Elf64_Phdr);
@@ -533,18 +523,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   /* We calculate from the p_offset of the note segment,
because we don't yet know the bias for its p_vaddr.  */
   const GElf_Addr note_vaddr = start + offset;
-  void *data;
-  size_t data_size;
+  void *data = NULL;
+  size_t data_size = 0;
   if (read_portion (&read_state, &data, &data_size,
 start, segment, note_vaddr, filesz))
 continue; /* Next header */
 
-  /* data_size will be zero if we got everything from the initial
- buffer, otherwise it will be the size of the new buffer that
- could be read.  */
-  if (data_size != 0)
-filesz = data_size;
-
 	  if (filesz > SIZE_MAX / sizeof (Elf32_Nhdr))
 		continue;
 
@@ -821,12 +805,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   && ! read_portion (&read_state, &dyn_data, &dyn_data_size,
 			 start, segment, dyn_vaddr, dyn_filesz))
 {
-  /* dyn_data_size will be zero if we got everything from the initial
- buffer, otherwise it will be the size of the new buffer that
- could be read.  */
-  if (dyn_data_size != 0)
-	dyn_filesz = dyn_data_size;
-
   if ((dyn_filesz / dyn_entsize) == 0
 	  || dyn_filesz > (SIZE_MAX / dyn_entsize))
 	goto out;
-- 
2.30.2



Re: [PATCH] Add support for ARCv2

2022-11-30 Thread Mark Wielaard
Hi Shahab,

On Wed, Nov 30, 2022 at 08:15:55AM +, Shahab Vahedi via Elfutils-devel 
wrote:
> The necessary changes are in glibc now [1]. How/When does the sync happen? 
> Should
> I submit a patch, or trigger a request, etc.?

Nice. I just synced elf.h.

Thanks,

Mark
>From 86347d80bec28c762ddc47aee866fcdaf781f25a Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Thu, 1 Dec 2022 00:25:01 +0100
Subject: [PATCH] libelf: Sync elf.h from glibc

Adds various new ARC related declarations.

Signed-off-by: Mark Wielaard 
---
 libelf/ChangeLog |  4 
 libelf/elf.h | 36 +---
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 8107c71e..3ae3afe3 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2022-11-30  Mark Wielaard  
+
+	* elf.h: Update from glibc.
+
 2022-10-28  Mark Wielaard  
 
 	* elf.h: Update from glibc.
diff --git a/libelf/elf.h b/libelf/elf.h
index f51300bc..da41bad3 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -4093,8 +4093,11 @@ enum
 #define R_NDS32_TLS_DESC	119
 
 /* LoongArch ELF Flags */
-#define EF_LARCH_ABI	0x07
-#define EF_LARCH_ABI_LP64D	0x03
+#define EF_LARCH_ABI_MODIFIER_MASK  0x07
+#define EF_LARCH_ABI_SOFT_FLOAT 0x01
+#define EF_LARCH_ABI_SINGLE_FLOAT   0x02
+#define EF_LARCH_ABI_DOUBLE_FLOAT   0x03
+#define EF_LARCH_OBJABI_V1  0x40
 
 /* LoongArch specific dynamic relocations */
 #define R_LARCH_NONE		0
@@ -4156,6 +4159,15 @@ enum
 #define R_LARCH_GNU_VTINHERIT  57
 #define R_LARCH_GNU_VTENTRY  58
 
+/* ARC specific declarations.  */
+
+/* Processor specific flags for the Ehdr e_flags field.  */
+#define EF_ARC_MACH_MSK	0x00ff
+#define EF_ARC_OSABI_MSK0x0f00
+#define EF_ARC_ALL_MSK	(EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK)
+
+/* Processor specific values for the Shdr sh_type field.  */
+#define SHT_ARC_ATTRIBUTES	(SHT_LOPROC + 1) /* ARC attributes section.  */
 
 /* ARCompact/ARCv2 specific relocs.  */
 #define R_ARC_NONE		0x0
@@ -4163,7 +4175,7 @@ enum
 #define R_ARC_16		0x2
 #define R_ARC_24		0x3
 #define R_ARC_32		0x4
-#define R_ARC_B26		0x5
+
 #define R_ARC_B22_PCREL		0x6
 #define R_ARC_H30		0x7
 #define R_ARC_N8		0x8
@@ -4203,16 +4215,23 @@ enum
 #define R_ARC_SECTOFF_ME_2	0x2A
 #define R_ARC_SECTOFF_1		0x2B
 #define R_ARC_SECTOFF_2		0x2C
+#define R_ARC_SDA_12		0x2D
+#define R_ARC_SDA16_ST2		0x30
+#define R_ARC_32_PCREL		0x31
 #define R_ARC_PC32		0x32
 #define R_ARC_GOTPC32		0x33
 #define R_ARC_PLT32		0x34
 #define R_ARC_COPY		0x35
 #define R_ARC_GLOB_DAT		0x36
-#define R_ARC_JUMP_SLOT		0x37
+#define R_ARC_JMP_SLOT		0x37
 #define R_ARC_RELATIVE		0x38
 #define R_ARC_GOTOFF		0x39
 #define R_ARC_GOTPC		0x3A
 #define R_ARC_GOT32		0x3B
+#define R_ARC_S21W_PCREL_PLT	0x3C
+#define R_ARC_S25H_PCREL_PLT	0x3D
+
+#define R_ARC_JLI_SECTOFF	0x3F
 
 #define R_ARC_TLS_DTPMOD	0x42
 #define R_ARC_TLS_DTPOFF	0x43
@@ -4221,9 +4240,12 @@ enum
 #define R_ARC_TLS_GD_LD	0x46
 #define R_ARC_TLS_GD_CALL	0x47
 #define R_ARC_TLS_IE_GOT	0x48
-#define R_ARC_TLS_DTPOFF_S9	0x4a
-#define R_ARC_TLS_LE_S9		0x4a
-#define R_ARC_TLS_LE_32		0x4b
+#define R_ARC_TLS_DTPOFF_S9	0x49
+#define R_ARC_TLS_LE_S9		0x4A
+#define R_ARC_TLS_LE_32		0x4B
+#define R_ARC_S25W_PCREL_PLT	0x4C
+#define R_ARC_S21H_PCREL_PLT	0x4D
+#define R_ARC_NPS_CMEM16	0x4E
 
 /* OpenRISC 1000 specific relocs.  */
 #define R_OR1K_NONE		0
-- 
2.30.2



Re: dwarf_nextcu can't handle abbrev offset correctly ?

2022-12-01 Thread Mark Wielaard
Hi Hengqi,

On Thu, 2022-12-01 at 23:34 +0800, Hengqi Chen via Elfutils-devel
wrote:
> I am using pahole (which relies on libelf) to process an elf file
> ([0]):
> 
> LLVM_OBJCOPY="objcopy" pahole -J --btf_gen_floats --btf_base
> vmlinux adl_pci9111.ko
> 
> This failed with:
> 
> die__process: DW_TAG_compile_unit, DW_TAG_type_unit,
> DW_TAG_partial_unit or DW_TAG_skeleton_unit expected got member
> (0xd)!
> 
> The .ko contains two CU, readelf says that the abbrev offsets are at
> 0 and 0x907,
> but dwarf_nextcu reports that abbrev offsets are both at 0.
> 
> pahole expects to find DW_TAG_compile_unit, but seams that the wrong
> abbrev offset causes the failure.
> 
> 
>   [0]: https://gitlab.com/chenhengqi/loong-debug

I took a quick look at the adl_pci9111.ko there. And the issue is that
elfutils doesn't know how to handle the relocations for LoongArch yet.

Specifically the backend should implement the reloc_simple_type hook.

Cheers,

Mark


Re: [PATCH 10/25] libcpu: Remove the need of NMNES by using enum

2022-12-12 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  libcpu/Makefile.am  |  2 +-
>  libcpu/i386_parse.y | 13 +
>  2 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am
> index 57d0a164..259ed838 100644
> --- a/libcpu/Makefile.am
> +++ b/libcpu/Makefile.am
> @@ -92,7 +92,7 @@ libeu = ../lib/libeu.a
>  i386_lex_CFLAGS = -Wno-unused-label -Wno-unused-function -Wno-sign-
> compare \
> -Wno-implicit-fallthrough
>  i386_parse.o: i386_parse.c i386.mnemonics
> -i386_parse_CFLAGS = -DNMNES="`wc -l < i386.mnemonics`"
> +i386_parse_CFLAGS =
>  i386_lex.o: i386_parse.h
>  i386_gendis_LDADD = $(libeu) -lm $(obstack_LIBS)
>  
> diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
> index d2236d59..5f31484c 100644
> --- a/libcpu/i386_parse.y
> +++ b/libcpu/i386_parse.y
> @@ -1108,9 +1108,14 @@ print_op_fct (const void *nodep, VISIT value,
>  }
>  
>  
> -#if NMNES < 2
> -# error "bogus NMNES value"
> -#endif
> +/* The index can be stored in the instrtab.  */
> +enum
> +  {
> +#define MNE(name) MNE_##name,
> +#include "i386.mnemonics"
> +#undef MNE
> +MNE_COUNT
> +  };

Since almost the same enum is defined in i386_disasm.c, just with
MNE_COUNT = MNE_INVALID, can we define and use them in one place?

>  static void
>  instrtable_out (void)
> @@ -1123,7 +1128,7 @@ instrtable_out (void)
>fprintf (outfile, "#define MNEMONIC_BITS %zu\n",
> best_mnemonic_bits);
>  #else
>fprintf (outfile, "#define MNEMONIC_BITS %ld\n",
> -lrint (ceil (log2 (NMNES;
> +lrint (ceil (log2 (MNE_COUNT;
>  #endif
>fprintf (outfile, "#define SUFFIX_BITS %d\n", nbitsuf);
>for (int i = 0; i < 3; ++i)


Re: [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc

2022-12-12 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  libcpu/i386_disasm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
> index 599d1654..cc75a7b1 100644
> --- a/libcpu/i386_disasm.c
> +++ b/libcpu/i386_disasm.c
> @@ -480,7 +480,7 @@ i386_disasm (Ebl *ebl __attribute__((unused)),
>  
> /* gcc is not clever enough to see the following
> variables
>are not used uninitialized.  */
> -   asm (""
> +   __asm (""
>  : "=mr" (opoff), "=mr" (correct_prefix), "=mr"
> (codep),
>"=mr" (next_curr), "=mr" (len));
>   }

Urgh. Is this really (still) necessary? It is inside an if (0) block.
So it also is never used. Can we just get rid of the whole block?

Thanks,

Mark


Re: [PATCH 12/25] libcpu: Use "#define FCT_mod$64r_m FCT_mod$r_m" is enough and can be recognized by clang-cl on windows in i386_data.h

2022-12-12 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  libcpu/i386_data.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libcpu/i386_data.h b/libcpu/i386_data.h
> index 06356b8a..fe3c4ae1 100644
> --- a/libcpu/i386_data.h
> +++ b/libcpu/i386_data.h
> @@ -1153,7 +1153,7 @@ FCT_mod$64r_m (struct output_data *d)
>return general_mod$r_m (d);
>  }
>  #else
> -static typeof (FCT_mod$r_m) FCT_mod$64r_m __attribute__ ((alias
> ("FCT_mod$r_m")));
> +#define FCT_mod$64r_m FCT_mod$r_m
>  #endif

Thanks, this indeed looks simpler.
Added a ChangeLog entry and pushed as:

commit dab89fba0e84c948fb270e541d1d1313afd2c2c3 (HEAD -> master)
Author: Yonggang Luo 
Date:   Fri Oct 21 02:25:51 2022 +0800

libcpu: Use "#define FCT_mod$64r_m FCT_mod$r_m" in i386_data.h

This is enough and can be recognized by clang-cl on windows

Signed-off-by: Yonggang Luo 

Cheers,

Mark


Re: [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc

2022-12-12 Thread Mark Wielaard
Hi,

We seem to use __typeof everywhere except in memory-access.h. So this
seems like an OK change.

Added a ChangeLog entry and pushed as:

commit 78dd3b32edf55fc8bdc6268163d5d743a84b1075
Author: Yonggang Luo 
Date:   Fri Oct 21 02:25:52 2022 +0800

libdw: Change typeof -> __typeof in memory-access.h

Signed-off-by: Yonggang Luo 

Thanks,

Mark


Re: [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header

2022-12-12 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> -
> +#ifndef __OPTIMIZE__
>  unsigned int
>  dwarf_whatattr (Dwarf_Attribute *attr)
>  {
>return attr == NULL ? 0 : attr->code;
>  }
> +#endif
> diff --git a/libdw/dwarf_whatform.c b/libdw/dwarf_whatform.c
> index dee29a9f..01a33424 100644
> --- a/libdw/dwarf_whatform.c
> +++ b/libdw/dwarf_whatform.c
> @@ -34,9 +34,10 @@
>  #include 
>  #include "libdwP.h"
>  
> -
> +#ifndef __OPTIMIZE__
>  unsigned int
>  dwarf_whatform (Dwarf_Attribute *attr)
>  {
>return attr == NULL ? 0 : attr->form;
>  }
> +#endif

I don't think this is correct. These functions are defined with extern
inline (if __OPTIMIZE__ is defined). Which means they will not generate
an out-of-line version. But these functions are exported from libdw, so
there must be a real implementation.

So we want to generate code for these functions whether or not
__OPTIMIZE__ is defined.

Cheers,

Mark


Re: ☠ Buildbot (GNU Toolchain): elfutils - failed configure (failure) (master)

2022-12-12 Thread Mark Wielaard
Hi,

On Mon, Dec 12, 2022 at 02:01:49PM +, builder--- via Elfutils-devel wrote:
> A new failure has been detected on builder elfutils-debian-ppc64 while 
> building elfutils.
> 
> Full details are available at:
> https://builder.sourceware.org/buildbot/#builders/63/builds/113
> 
> Build state: failed configure (failure)
> Revision: dab89fba0e84c948fb270e541d1d1313afd2c2c3
> Worker: debian-ppc64
> Build Reason: (unknown)
> Blamelist: Yonggang Luo 
> [...] 
> - 4: configure ( failure )
> Logs:
> - stdio: 
> https://builder.sourceware.org/buildbot/#builders/63/builds/113/steps/4/logs/stdio

That looks like a disk space issue:

./config.status: line 1372: printf: write error: No space left on device
config.status: error: in 
`/var/lib/buildbot/workers/wildebeest/elfutils-debian-ppc64/build':
./config.status: line 127: printf: write error: No space left on device

Tom, could you take a look?

Thanks,

Mark


Re: [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H

2022-12-12 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> on win32, there is no err.h
> [...]
> +#else
> +  (void)status;
> +  vfprintf(stderr, format, argp);
> +#endif
>va_end(argp);

That doesn't look like a valid implementation of error, it ignores
errno and doesn't exit when necessary.

Cheers,

Mark


Re: [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source

2022-12-12 Thread Mark Wielaard
Hi,

Why is this necessary?

Thanks,

Mark


Re: [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it

2022-12-12 Thread Mark Wielaard
Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo 
> ---
>  libelf/elf_begin.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
> index 6d31882e..d867cd6f 100644
> --- a/libelf/elf_begin.c
> +++ b/libelf/elf_begin.c
> @@ -1163,12 +1163,14 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
>if (ref != NULL)
>  /* Make sure the descriptor is not suddenly going away.  */
>  rwlock_rdlock (ref->lock);
> +#if defined(F_GETFD)
>else if (unlikely (fcntl (fildes, F_GETFD) == -1 && errno ==
> EBADF))
>  {
>/* We cannot do anything productive without a file
> descriptor.  */
>__libelf_seterrno (ELF_E_INVALID_FILE);
>return NULL;
>  }
> +#endif

If you cannot check validity of fildes using fcntl, then shouldn't you
at least check for fildes >= 0 ?

Cheers,

Mark


Re: [PATCH] Add support for ARCv2

2022-12-13 Thread Mark Wielaard
Hi Shahab,

On Thu, 2022-12-01 at 09:44 +, Shahab Vahedi via Elfutils-devel
wrote:
> On 12/1/22 00:36, Mark Wielaard wrote:
> > Nice. I just synced elf.h.
> 
> Thanks a lot Mark! I will send a new patch sans the elf.h and will
> add possible test(s) that can be related to it.

Let me know if I should wait for that or review the v2 patch ignoring
the elf.h changes.

CHeers,

Mark


Re: [PATCH] libdwfl: Read no more than required to parse dynamic sections

2022-12-13 Thread Mark Wielaard
Hi Gavin,

On Thu, 2022-12-01 at 13:13 -0800, Gavin Li wrote:
> Awesome, thanks for looking over this. I only have one comment:
> there's an extra "xlatefrom.d_size = xlatefrom.d_size;" line that
> should be removed.

Thanks for spotting that. Odd the compiler didn't warn for that. There
is a xlatefrom.d_size = phnum * phentsize; just before this that does
the correct assignment.

Pushed with that line removed.

Cheers,

Mark


Re: [PATCHv2] support ZSTD compression algorithm

2022-12-15 Thread Mark Wielaard
Hi Martin,

On Tue, 2022-11-29 at 13:05 +0100, Martin Liška wrote:
> There's second version of the patch that fully support both
> compression and decompression.
> 
> Changes from the v1:
> - compression support added
> - zstd detection is fixed
> - new tests are added
> - builds fine w/ and w/o the ZSTD library
> 
> What's currently missing and where I need a help:
> 
> 1) When I build ./configure --without-zstd, I don't have
> a reasonable error message (something similar to binutils's readelf:
> readelf: Warning: section '.debug_str' has unsupported compress type:
> 2)
> even though, __libelf_decompress returns NULL and __libelf_seterrno).
> One can see a garbage in the console.
> 
> How to handle that properly?

Is there a particular way you are running eu-readelf? Is it with
generic -w or -a, or decoding a specific section type?

> 2) How should I run my newly added tests conditionally if zstd
> configuration support is enabled?

eu_ZIP will define an AM_CONDITIONAL for ZSTD (note this is different
from the HAVE_ZSTD, which is the am conditional added for having the
zstd program itself). You could use it in tests/Makefile.am as:

  if ZSTD
  TESTS += run-zstd-compress-test.sh
  endif

If you had a separate test... Otherwise add some variable to
TESTS_ENVIRONMENT (and installed_TESTS_ENVIRONMENT) based on the Make
variable that is tested inside the shell script (somewhat like
USE_VALGRIND) maybe.

>   configure.ac   |   8 +-
>   libelf/Makefile.am |   2 +-
>   libelf/elf_compress.c  | 294 ++--
> -
>   libelf/elf_compress_gnu.c  |   5 +-
>   libelf/libelfP.h   |   4 +-
>   src/elfcompress.c  | 144 ++
>   src/readelf.c  |  18 ++-
>   tests/run-compress-test.sh |  24 +++
>   8 files changed, 373 insertions(+), 126 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 59be27ac..07cfa54b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -410,6 +410,11 @@ dnl Test for bzlib and xz/lzma/zstd, gives 
> BZLIB/LZMALIB/ZSTD .am
>   dnl conditional and config.h USE_BZLIB/USE_LZMALIB/USE_ZSTD #define.
>   save_LIBS="$LIBS"
>   LIBS=
> +eu_ZIPLIB(zstd,ZSTD,zstd,ZSTD_decompress,[ZSTD (zst)])
> +AS_IF([test "x$with_zstd" = xyes], [LIBZSTD="libzstd"], [LIBLZSTD=""])
> +AC_SUBST([LIBZSTD])
> +zstd_LIBS="$LIBS"
> +AC_SUBST([zstd_LIBS])
>   eu_ZIPLIB(bzlib,BZLIB,bz2,BZ2_bzdopen,bzip2)
>   # We need this since bzip2 doesn't have a pkgconfig file.
>   BZ2_LIB="$LIBS"
> @@ -417,9 +422,6 @@ AC_SUBST([BZ2_LIB])
>   eu_ZIPLIB(lzma,LZMA,lzma,lzma_auto_decoder,[LZMA (xz)])
>   AS_IF([test "x$with_lzma" = xyes], [LIBLZMA="liblzma"], [LIBLZMA=""])
>   AC_SUBST([LIBLZMA])
> -eu_ZIPLIB(zstd,ZSTD,zstd,ZSTD_decompress,[ZSTD (zst)])
> -AS_IF([test "x$with_zstd" = xyes], [LIBZSTD="libzstd"], [LIBLZSTD=""])
> -AC_SUBST([LIBZSTD])
>   zip_LIBS="$LIBS"
>   LIBS="$save_LIBS"
>   AC_SUBST([zip_LIBS])

Doing AC_SUBST([zstd_LIBS]) seems correct. Why is the test moved
earlier?

You are testing for ZSTD_decompress, is that enough? Asking because I
see you are using ZSTD_compressStream2, which seems to requires libzstd
v1.4.0+.

In general how stable is the libzstd api?

You'll also need to use the AC_SUBST for LIBZSTD in config/libelf.pc.in
now, as used in the libdw.pc.in:

  Requires.private: zlib @LIBZSTD@

> diff --git a/libelf/Makefile.am b/libelf/Makefile.am
> index 560ed45f..24c25cf8 100644
> --- a/libelf/Makefile.am
> +++ b/libelf/Makefile.am
> @@ -106,7 +106,7 @@ libelf_pic_a_SOURCES =
>   am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os)
>   
>   libelf_so_DEPS = ../lib/libeu.a
> -libelf_so_LDLIBS = $(libelf_so_DEPS) -lz
> +libelf_so_LDLIBS = $(libelf_so_DEPS) -lz $(zstd_LIBS)
>   if USE_LOCKS
>   libelf_so_LDLIBS += -lpthread
>   endif

OK.

Haven't read the actual code yet. I'll get back to that later today.

Cheers,

Mark


Re: [PATCHv2] support ZSTD compression algorithm

2022-12-15 Thread Mark Wielaard
this pass since we might need the section
> @@ -754,7 +777,7 @@ process_file (const char *fname)
>   case ZLIB_GNU:
> if (startswith (sname, ".debug"))
>   {
> -   if (schtype == ZLIB)
> +   if (schtype == ZLIB || schtype == ZSTD)
>   {
> /* First decompress to recompress GNU style.
>Don't report even when verbose.  */

OK.

> @@ -818,19 +841,22 @@ process_file (const char *fname)
> break;
>   case ZLIB:
> -   if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
> + case ZSTD:
> +   if (schtype != type)
>   {
> -   if (schtype == ZLIB_GNU)
> +   if (schtype != NONE)
>   {
> -   /* First decompress to recompress zlib style.
> -  Don't report even when verbose.  */
> +   /* Decompress first.  */
> if (compress_section (scn, size, sname, NULL, ndx,
>   schtype, NONE, false) < 0)
>   goto cleanup;
> -   snamebuf[0] = '.';
> -   strcpy (&snamebuf[1], &sname[2]);
> -   newname = snamebuf;
> +   if (schtype == ZLIB_GNU)
> + {
> +   snamebuf[0] = '.';
> +   strcpy (&snamebuf[1], &sname[2]);
> +   newname = snamebuf;
> + }
>   }
> if (skip_compress_section)

OK.

> @@ -838,7 +864,7 @@ process_file (const char *fname)
> if (ndx == shdrstrndx)
>   {
> shstrtab_size = size;
> -   shstrtab_compressed = ZLIB;
> +   shstrtab_compressed = type;
> if (shstrtab_name != NULL
> || shstrtab_newname != NULL)
>   {
> @@ -855,7 +881,7 @@ process_file (const char *fname)
> else
>   {
> symtab_size = size;
> -   symtab_compressed = ZLIB;
> +   symtab_compressed = type;
> symtab_name = xstrdup (sname);
> symtab_newname = (newname == NULL
>   ? NULL : xstrdup (newname));

OK.

> @@ -1378,7 +1404,7 @@ main (int argc, char **argv)
>   N_("Place (de)compressed output into FILE"),
>   0 },
>{ "type", 't', "TYPE", 0,
> - N_("What type of compression to apply. TYPE can be 'none' (decompress), 
> 'zlib' (ELF ZLIB compression, the default, 'zlib-gabi' is an alias) or 
> 'zlib-gnu' (.zdebug GNU style compression, 'gnu' is an alias)"),
> + N_("What type of compression to apply. TYPE can be 'none' (decompress), 
> 'zlib' (ELF ZLIB compression, the default, 'zlib-gabi' is an alias), 
> 'zlib-gnu' (.zdebug GNU style compression, 'gnu' is an alias) or 'zstd'"),
>   0 },
>{ "name", 'n', "SECTION", 0,
>   N_("SECTION name to (de)compress, SECTION is an extended wildcard 
> pattern (defaults to '.?(z)debug*')"),

I would say or 'zstd' (ELF ZSTD compression)" to match the 'zlib; type
description.

> diff --git a/src/readelf.c b/src/readelf.c
> index cc3e0229..451f8400 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -1238,13 +1238,17 @@ get_visibility_type (int value)
>  static const char *
>  elf_ch_type_name (unsigned int code)
>  {
> -  if (code == 0)
> -return "NONE";
> -
> -  if (code == ELFCOMPRESS_ZLIB)
> -return "ZLIB";
> -
> -  return "UNKNOWN";
> +  switch (code)
> +{
> +case 0:
> +  return "NONE";
> +case ELFCOMPRESS_ZLIB:
> +  return "ZLIB";
> +case ELFCOMPRESS_ZSTD:
> +  return "ZSTD";
> +default:
> +  return "UNKNOWN";
> +}
>  }
>  /* Print the section headers.  */

OK.

> diff --git a/tests/run-compress-test.sh b/tests/run-compress-test.sh
> index a6a298f5..3f9c990e 100755
> --- a/tests/run-compress-test.sh
> +++ b/tests/run-compress-test.sh
> @@ -61,6 +61,30 @@ testrun_elfcompress_file()
>  echo "uncompress $elfcompressedfile -> $elfuncompressedfile"
>  testrun ${abs_top_builddir}/src/elfcompress -v -t none -o 
> ${elfuncompressedfile} ${elfcompressedfile}
>  testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} 
> ${elfuncompressedfile}
> +
> +outputfile="${infile}.gabi.zstd"
> +tempfiles "$outputfile"
> +echo "zstd compress $elfcompressedfile -> $outputfile"
> +testrun ${abs_top_builddir}/src/elfcompress -v -t zstd -o ${outputfile} 
> ${elfcompressedfile}
> +testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${outputfile}
> +echo "checking compressed section header" $outputfile
> +testrun ${abs_top_builddir}/src/readelf -Sz ${outputfile} | grep "ELF 
> ZSTD" >/dev/null
> +
> +zstdfile="${infile}.zstd"
> +tempfiles "$zstdfile"
> +echo "zstd compress $uncompressedfile -> $zstdfile"
> +testrun ${abs_top_builddir}/src/elfcompress -v -t zstd -o ${zstdfile} 
> ${elfuncompressedfile}
> +testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${zstdfile}
> +echo "checking compressed section header" $zstdfile
> +testrun ${abs_top_builddir}/src/readelf -Sz ${zstdfile} | grep "ELF 
> ZSTD" >/dev/null
> +
> +zstdgnufile="${infile}.zstd.gnu"
> +tempfiles "$zstdgnufile"
> +echo "zstd re-compress to GNU ZLIB $zstdfile -> $zstdgnufile"
> +testrun ${abs_top_builddir}/src/elfcompress -v -t zlib-gnu -o 
> ${zstdgnufile} ${zstdfile}
> +testrun ${abs_top_builddir}/src/elfcmp ${uncompressedfile} ${zstdgnufile}
> +echo "checking .zdebug section name" $zstdgnufile
> +testrun ${abs_top_builddir}/src/readelf -S ${zstdgnufile} | grep 
> ".zdebug" >/dev/null
>  }
>  testrun_elfcompress()

You might add these to a separate run test file or pass some ZSTD flag
through the test environment to conditionally run these new tests.

Cheers,

Mark


Re: [PATCHv2] support ZSTD compression algorithm

2022-12-19 Thread Mark Wielaard
Hi Martin,

On Mon, 2022-12-19 at 15:19 +0100, Martin Liška wrote:
> On 12/15/22 14:17, Mark Wielaard wrote:
> > Is there a particular way you are running eu-readelf? Is it with
> > generic -w or -a, or decoding a specific section type?
> 
> Hello.
> 
> $ LD_LIBRARY_PATH=./libelf ./src/readelf -w
> ~/Programming/testcases/a.out
> 
> where I get:
> 
> ./src/readelf: cannot get debug context descriptor: No DWARF
> information found
> 
> DWARF section [37] '.debug_info' at offset 0x1ab2:
>   [Offset]
> ./src/readelf: cannot get next unit: no error
> 
> Call frame information section [13] '.eh_frame' at offset 0x4a8:
> ...
>  
>  
>   t��o5��=I�iAp@aS^R/<�^�qi�ַp@

[...]

> So basically a garbage. And I don't know how to bail out properly?

Aha. If you have that a.out somewhere I can take a look. I suspect this
is because we expect all .debug sections to have been decompressed in
libdw/dwarf_begin_elf.c, but that isn't really true, see check_section
in that file which has:

  if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
{
  if (elf_compress (scn, 0, 0) < 0)
{
  /* It would be nice if we could fail with a specific error.
 But we don't know if this was an essential section or not.
 So just continue for now. See also valid_p().  */
  return result;
}
}

We should probably adjust valid_p so it produces a more appropriate
error message and/or add additional checks in readlelf.c.

But lets do that after this patch goes in.

Cheers,

Mark


Re: [PATCHv2] support ZSTD compression algorithm

2022-12-19 Thread Mark Wielaard
Hi Martin,

On Mon, 2022-12-19 at 15:21 +0100, Martin Liška wrote:
> > > +  else
> > > +error (0, 0, "Couldn't get chdr for section %zd", ndx);
> > 
> > Shouldn't this error be fatal?
> 
> What do you use for fatal errors?

Depends a bit on context. It might be that this error isn't fatal, then
zero as first (status) argument is fine, just know that the program
will just continue. And it looked like not all callers were prepared
for this function to return with a bogus return value.

If it is fatal then depending on context you either call error_exit (0,
"Couldn't get chdr for section %zd", ndx); [see system.h, this really
is just error (EXIT_FAILURE, 0, ...)] if the program needs to terminate
right now.

Or you return a special value from the function (assuming all callers
check for an error here). And/Or if the program needs a cleanup you'll
goto cleanup (as is done in process_file).

Cheers,

Mark


Re: [PATCH] Add support for LoongArch

2022-12-19 Thread Mark Wielaard
 Public License as published by the Free
> +   Software Foundation; either version 3 of the License, or (at
> +   your option) any later version
> +
> +   or
> +
> + * the GNU General Public License as published by the Free
> +   Software Foundation; either version 2 of the License, or (at
> +   your option) any later version
> +
> +   or both in parallel, as here.
> +
> +   elfutils is distributed in the hope that it will be useful, but
> +   WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   General Public License for more details.
> +
> +   You should have received copies of the GNU General Public License and
> +   the GNU Lesser General Public License along with this program.  If
> +   not, see <http://www.gnu.org/licenses/>.  */
> +
> +#ifdef HAVE_CONFIG_H
> +# include 
> +#endif
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define BACKEND loongarch_
> +#include "libebl_CPU.h"
> +
> +
> +/* Check for the simple reloc types.  */
> +Elf_Type
> +loongarch_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
> +  int *addsub)
> +{
> +  switch (type)
> +{
> +case R_LARCH_32:
> +  return ELF_T_WORD;
> +case R_LARCH_64:
> +  return ELF_T_XWORD;
> +case R_LARCH_ADD16:
> +  *addsub = 1;
> +  return ELF_T_HALF;
> +case R_LARCH_ADD32:
> +  *addsub = 1;
> +  return ELF_T_WORD;
> +case R_LARCH_ADD64:
> +  *addsub = 1;
> +  return ELF_T_XWORD;
> +case R_LARCH_SUB16:
> +  *addsub = -1;
> +  return ELF_T_HALF;
> +case R_LARCH_SUB32:
> +  *addsub = -1;
> +  return ELF_T_WORD;
> +case R_LARCH_SUB64:
> +  *addsub = -1;
> +  return ELF_T_XWORD;
> +default:
> +  return ELF_T_NUM;
> +}
> +}

Nice, full set of simple relocations.

> diff --git a/libebl/ChangeLog b/libebl/ChangeLog
> index 6f55a5e7..5f9ea552 100644
> --- a/libebl/ChangeLog
> +++ b/libebl/ChangeLog
> @@ -1,3 +1,7 @@
> +2022-12-02  Hengqi Chen  
> +
> + * eblopenbackend.c (machines): Add entries for LoongArch.
> +
>  2022-10-21  Yonggang Luo  
>  
>   * eblclosebackend.c: Remove dlfcn.h include.
> diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
> index 02f80653..b87aef19 100644
> --- a/libebl/eblopenbackend.c
> +++ b/libebl/eblopenbackend.c
> @@ -55,6 +55,7 @@ Ebl *m68k_init (Elf *, GElf_Half, Ebl *);
>  Ebl *bpf_init (Elf *, GElf_Half, Ebl *);
>  Ebl *riscv_init (Elf *, GElf_Half, Ebl *);
>  Ebl *csky_init (Elf *, GElf_Half, Ebl *);
> +Ebl *loongarch_init (Elf *, GElf_Half, Ebl *);
>  
>  /* This table should contain the complete list of architectures as far
> as the ELF specification is concerned.  */
> @@ -150,6 +151,7 @@ static const struct
>{ riscv_init, "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS64, ELFDATA2LSB },
>{ riscv_init, "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS32, ELFDATA2LSB },
>{ csky_init, "elf_csky", "csky", 4, EM_CSKY, ELFCLASS32, ELFDATA2LSB },
> +  { loongarch_init, "elf_loongarch", "loongarch", 9, EM_LOONGARCH, 
> ELFCLASS64, ELFDATA2LSB },
>  };
>  #define nmachines (sizeof (machines) / sizeof (machines[0]))

OK.

> diff --git a/src/ChangeLog b/src/ChangeLog
> index 66428b70..b679f092 100644
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,7 @@
> +2022-12-02  Hengqi Chen  
> +
> + * elflint.c (valid_e_machine): Add EM_LOONGARCH.
> +
>  2022-11-03  Mark Wielaard  
>  
>   * readelf.c (get_dynscn_addrs): Check gelf_getdyn doesn't
> diff --git a/src/elflint.c b/src/elflint.c
> index 565cffdc..b9548862 100644
> --- a/src/elflint.c
> +++ b/src/elflint.c
> @@ -329,7 +329,7 @@ static const int valid_e_machine[] =
>  EM_CRIS, EM_JAVELIN, EM_FIREPATH, EM_ZSP, EM_MMIX, EM_HUANY, EM_PRISM,
>  EM_AVR, EM_FR30, EM_D10V, EM_D30V, EM_V850, EM_M32R, EM_MN10300,
>  EM_MN10200, EM_PJ, EM_OPENRISC, EM_ARC_A5, EM_XTENSA, EM_ALPHA,
> -EM_TILEGX, EM_TILEPRO, EM_AARCH64, EM_BPF, EM_RISCV, EM_CSKY
> +EM_TILEGX, EM_TILEPRO, EM_AARCH64, EM_BPF, EM_RISCV, EM_CSKY, 
> EM_LOONGARCH,
>};
>  #define nvalid_e_machine \
>(sizeof (valid_e_machine) / sizeof (valid_e_machine[0]))

And with this I assume elflint now works for a native binary?

The patch itself looks good. So I pushed it.

But to get a full (native) make check pass on longaarch a few more
backend hooks are probably needed. What is the current result of make
check on a native longaarch build?

Also to make sure it is/can be tested on other arches it might make
sense to add a testcase. See tests/run-strip-reloc.sh how to create a
small loongarch linux kernel module and test that relocation (and
stripping) works.

Cheers,

Mark


Re: [PATCH 02/25] ignore build directory

2022-12-20 Thread Mark Wielaard
On Sat, 2022-12-17 at 05:14 +0800, 罗勇刚(Yonggang Luo) wrote:
> It's a common step to configure and make under build directory, so
> that the
> IDE won't affect by it

I rather not just ignore a random directory name, unless it clearly is
a default for the build system.


Re: [PATCH 06/25] move platform depended include into system.h of libebl

2022-12-20 Thread Mark Wielaard
Hi,

On Sat, 2022-12-17 at 05:19 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 28, 2022 at 7:35 PM Mark Wielaard  wrote:
> > 
> > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > wrote:
> > > Because all source in libebl #include , so #include
> > >  in
> > > libeblP.h is enough, there is multiple memory-access.h file, so
> > > use
> > > relative path to
> > > include it properly,
> > 
> > I am not a fan of the relative path trick, especially if there it
> > is
> > clear only one is every needed. You also use it for other files,
> > why?
> 
> I am respect the original code
> looks at
> https://github.com/sourceware-org/elfutils/blob/master/libdwfl/core-file.c#L31

I see. But I rather fix that than do the same in new files.

The attached patch does that so no relative paths are needed in
#include statements.

Cheers,

Mark
From 426db34b65d660c439b31d25308bc346d6272923 Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
Date: Tue, 20 Dec 2022 14:53:43 +0100
Subject: [PATCH] Do not use relative include paths in library files.

Rely on include dirs being set up correctly. Setup libdw AM_CPPFLAGS
to include libebl directory. In libdwfl note that debuginfod.h is a
generated file in the builddir. Only include it in the one file
debuginfod-client.c that really needs it.

Signed-off-by: Mark Wielaard 
---
 libasm/ChangeLog |  6 ++
 libasm/disasm_begin.c|  2 +-
 libasm/disasm_cb.c   |  2 +-
 libcpu/ChangeLog |  6 ++
 libcpu/bpf_disasm.c  |  4 ++--
 libcpu/i386_disasm.c |  2 +-
 libcpu/riscv_disasm.c|  2 +-
 libdw/ChangeLog  |  7 +++
 libdw/Makefile.am|  2 +-
 libdw/cfi.c  |  2 +-
 libdw/encoded-value.h|  2 +-
 libdw/frame-cache.c  |  2 +-
 libdwelf/ChangeLog   |  4 
 libdwelf/libdwelfP.h |  2 +-
 libdwfl/ChangeLog| 24 
 libdwfl/Makefile.am  |  2 +-
 libdwfl/core-file.c  |  2 +-
 libdwfl/cu.c |  4 ++--
 libdwfl/debuginfod-client.c  |  2 ++
 libdwfl/dwfl_dwarf_line.c|  2 +-
 libdwfl/dwfl_lineinfo.c  |  2 +-
 libdwfl/dwfl_module.c|  2 +-
 libdwfl/dwfl_module_dwarf_cfi.c  |  2 +-
 libdwfl/dwfl_module_eh_cfi.c |  2 +-
 libdwfl/dwfl_module_getdwarf.c   |  4 ++--
 libdwfl/dwfl_module_getsrc.c |  2 +-
 libdwfl/dwfl_module_getsrc_file.c|  2 +-
 libdwfl/dwfl_segment_report_module.c |  2 +-
 libdwfl/elf-from-memory.c|  2 +-
 libdwfl/frame_unwind.c   |  2 +-
 libdwfl/libdwflP.h   |  8 ++--
 libdwfl/lines.c  |  2 +-
 libdwfl/link_map.c   |  2 +-
 libdwfl/linux-core-attach.c  |  2 +-
 libdwfl/open.c   |  2 +-
 35 files changed, 82 insertions(+), 37 deletions(-)

diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index ce0f24f4..a12d14b3 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,3 +1,9 @@
+2022-12-20  Mark Wielaard  
+
+	* disasm_begin.c: Include libeblP.h.
+	* disasm_cb.c: Likewise.
+	* bpf_disasm.c: Likewise and include common.h.
+
 2022-10-21  Yonggang Luo  
 
 	* asm_abort.c: Don't include unistd.h.
diff --git a/libasm/disasm_begin.c b/libasm/disasm_begin.c
index cb10f66e..78db90c7 100644
--- a/libasm/disasm_begin.c
+++ b/libasm/disasm_begin.c
@@ -34,7 +34,7 @@
 #include 
 
 #include "libasmP.h"
-#include "../libebl/libeblP.h"
+#include "libeblP.h"
 
 
 DisasmCtx_t *
diff --git a/libasm/disasm_cb.c b/libasm/disasm_cb.c
index 80f8b25b..9353e2e5 100644
--- a/libasm/disasm_cb.c
+++ b/libasm/disasm_cb.c
@@ -33,7 +33,7 @@
 #include 
 
 #include "libasmP.h"
-#include "../libebl/libeblP.h"
+#include "libeblP.h"
 
 
 struct symtoken
diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index 248b1aba..bd517b94 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,3 +1,9 @@
+2022-12-20  Mark Wielaard  
+
+	* bpf_disasm.c: Include common.h and libeblP.h.
+	* i386_disasm.c: Include libeblP.h.
+	* riscv_disasm.c: Likewise.
+
 2022-10-21  Yonggang Luo  
 
 	* i386_data.h: Define FCT_mod$64r_m as FCT_mod$r_m for i386.
diff --git a/libcpu/bpf_disasm.c b/libcpu/bpf_disasm.c
index 62643c81..dabd8a4e 100644
--- a/libcpu/bpf_disasm.c
+++ b/libcpu/bpf_disasm.c
@@ -37,8 +37,8 @@
 #include 
 #include "bpf.h"
 
-#include "../libelf/common.h"
-#include "../libebl/libeblP.h"
+#include "common.h"
+#include "libeblP.h"
 
 static const char class_string[8][8] = {
   [BPF_LD]= "ld",
diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c

Re: [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h

2022-12-20 Thread Mark Wielaard
Hi,

On Sat, 2022-12-17 at 05:21 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 28, 2022 at 7:41 PM Mark Wielaard  wrote:
> > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > wrote:
> > > Signed-off-by: Yonggang Luo 
> > > ---
> > >  configure.ac  | 1 +
> > >  lib/crc32_file.c  | 4 ++--
> > >  lib/system.h  | 2 ++
> > >  libelf/elf32_updatefile.c | 3 ++-
> > >  libelf/elf_begin.c| 5 -
> > >  libelf/elf_end.c  | 2 ++
> > >  libelf/elf_update.c   | 5 -
> > 
> > Missing commit message and ChangeLog entries.
> > 
> > So this is for a system that doesn't have mmap?
> > How does the testsuite results look on such a system?
> > 
> > ELF_C_{READ,WRITE,RDWR}_MMAP[_PRIVATE] are elfutils extensions, but
> > they are used internally in other libraries.
> 
> I am trying getting elf support for windows/mingw/msvc, the  MMAP support
> is not needed yet
> for (QEMU/mesa)

I have to think what it means for a system that doesn't have mmap since
the mmap extensions are part of the public interface. And various parts
of the libraries depend on knowledge that they can read/write directly
from mmapped parts. Does it really make sense to try to support a
platform without mmap?

Cheers,

Mark


Re: [PATCH 09/25] include libgen.h in system.h

2022-12-20 Thread Mark Wielaard
On Sat, 2022-12-17 at 05:22 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 28, 2022 at 7:45 PM Mark Wielaard  wrote:
> > 
> > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > wrote:
> > > basename function are accessed multiple place, but used without
> > > include libgen.h
> > 
> > This is wrong. We use the GNU basename (from string.h with
> > _GNU_SOURCE), not the POSIX one (from libgen.h).
> 
> Thanks, that informs me, are they the same thing?

No, they are subtly different things.
See https://www.man7.org/linux/man-pages/man3/basename.3.html#NOTES
In particular the GNU basename never manipulates its argument (which is
why the cast is wrong).

Cheers,

Mark


Re: [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header

2022-12-20 Thread Mark Wielaard
On Sat, 2022-12-17 at 05:47 +0800, 罗勇刚(Yonggang Luo) wrote:
> From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00
> 2001
> From: Yonggang Luo 
> Date: Thu, 20 Oct 2022 02:50:03 +0800
> Subject: [PATCH] libdw: Fixes compile of dwarf_whatattr.c and
> dwarf_whatform.c
> 
> If __OPTIMIZE__ is defined, then compile  dwarf_whatattr.c and
> dwarf_whatform.c
> will cause symbol conflict between
> dwarf_whatattr.c and libdw.h,
> dwarf_whatform.c and libdw.h,
> 
> So always undefined __OPTIMIZE__ when compiling these two files

I don't think this is correct either. Some system headers might depend
on __OPTIMIZE__ being defined. Are you using a compiler that doesn't
define __OPTIMIZE__ ?

Cheers,

Mark


Re: [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H

2022-12-20 Thread Mark Wielaard
Hi,

On Sat, 2022-12-17 at 05:50 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Mon, Dec 12, 2022 at 11:37 PM Mark Wielaard 
> wrote:
> > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > wrote:
> > > on win32, there is no err.h
> > > [...]
> > > +#else
> > > +  (void)status;
> > > +  vfprintf(stderr, format, argp);
> > > +#endif
> > >va_end(argp);
> > 
> > That doesn't look like a valid implementation of error, it ignores
> > errno and doesn't exit when necessary.
> 
> Do you mean it should  call `exit(status)` after the  error message
> is
> printed?

Yes, if status != 0. Also errno should be printed (as a string).

Cheers,

Mark


Re: [PATCH v3] Add support for Synopsys ARCv2 processors

2022-12-20 Thread Mark Wielaard
 + * eblopenbackend.c (arc_init): New function declaration.
> + (machines): Add entry for arc.
> +
>  2022-12-02  Hengqi Chen  
>  
>   * eblopenbackend.c (machines): Add entries for LoongArch.
> diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
> index b87aef19..084a1544 100644
> --- a/libebl/eblopenbackend.c
> +++ b/libebl/eblopenbackend.c
> @@ -56,6 +56,7 @@ Ebl *bpf_init (Elf *, GElf_Half, Ebl *);
>  Ebl *riscv_init (Elf *, GElf_Half, Ebl *);
>  Ebl *csky_init (Elf *, GElf_Half, Ebl *);
>  Ebl *loongarch_init (Elf *, GElf_Half, Ebl *);
> +Ebl *arc_init (Elf *, GElf_Half, Ebl *);
>  
>  /* This table should contain the complete list of architectures as
> far
> as the ELF specification is concerned.  */
> @@ -152,6 +153,7 @@ static const struct
>{ riscv_init, "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS32,
> ELFDATA2LSB },
>{ csky_init, "elf_csky", "csky", 4, EM_CSKY, ELFCLASS32,
> ELFDATA2LSB },
>{ loongarch_init, "elf_loongarch", "loongarch", 9, EM_LOONGARCH,
> ELFCLASS64, ELFDATA2LSB },
> +  { arc_init, "elf_arc", "arc", 3, EM_ARCV2, ELFCLASS32, ELFDATA2LSB
> },
>  };
>  #define nmachines (sizeof (machines) / sizeof (machines[0]))

Good. Note that this only matches for ARCV2, but I assume that is
intended.

> diff --git a/tests/ChangeLog b/tests/ChangeLog
> index b656029f..b5136869 100644
> --- a/tests/ChangeLog
> +++ b/tests/ChangeLog
> @@ -1,3 +1,9 @@
> +2022-12-20  Shahab Vahedi  
> +
> + * hello_arc_hs4.ko.bz2: New testfile.
> + * run-strip-reloc.sh: Add ARC HS4 test.
> + * Makefile.am (EXTRA_DIST): Add hello_arc_hs4.ko.bz2.
> +
>  2022-11-01  Aaron Merey  
>  
>   * run-debuginfod-section.sh (RPM_BUILDID): Use buildid from
> non-zstd
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 356b3fbf..c35a7c33 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -285,6 +285,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh
> run-ar.sh \
>run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
>hello_ppc64.ko.bz2 hello_s390.ko.bz2 hello_aarch64.ko.bz2
> \
>hello_m68k.ko.bz2 hello_riscv64.ko.bz2 hello_csky.ko.bz2 \
> +  hello_arc_hs4.ko.bz2 \
>run-unstrip-test.sh run-unstrip-test2.sh \
>testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \
>testfile-info-link.stripped.bz2 run-unstrip-test3.sh \
> diff --git a/tests/hello_arc_hs4.ko.bz2 b/tests/hello_arc_hs4.ko.bz2
> new file mode 100644
> index
> ..56ccb3c494e84450c7aeac5f57f
> 94aef8336f8e0
> GIT binary patch
> literal 15004
> [...]
> literal 0
> HcmV?d1
>
> diff --git a/tests/run-strip-reloc.sh b/tests/run-strip-reloc.sh
> index b7ec1420..033ed278 100755
> --- a/tests/run-strip-reloc.sh
> +++ b/tests/run-strip-reloc.sh
> @@ -18,7 +18,8 @@
>  . $srcdir/test-subr.sh
>  
>  testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko
> \
> - hello_aarch64.ko hello_m68k.ko hello_riscv64.ko hello_csky.ko
> + hello_aarch64.ko hello_m68k.ko hello_riscv64.ko hello_csky.ko \
> + hello_arc_hs4.ko
>  
>  tempfiles readelf.out readelf.out1 readelf.out2
>  tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2
> @@ -120,6 +121,7 @@ runtest hello_aarch64.ko 1
>  runtest hello_m68k.ko 1
>  runtest hello_riscv64.ko 1
>  runtest hello_csky.ko 1
> +runtest hello_arc_hs4.ko 1
>  
>  # self test, shouldn't impact non-ET_REL files at all.
>  runtest ${abs_top_builddir}/src/strip 0

Very nice, that makes it possible to test some of this on non-ARC
setups. (Seems to run fine here)

Let me know if you want this to go in as is or if you want to sent a v4
with the tweaks suggested above.

Cheers.

Mark
> 


Re: [PATCH 06/25] move platform depended include into system.h of libebl

2022-12-20 Thread Mark Wielaard


On Tue, 2022-12-20 at 14:59 +0100, Mark Wielaard wrote:
> The attached patch does that so no relative paths are needed in
> #include statements.

The try-bot looked good:
https://builder.sourceware.org/buildbot/#/changes/16025

So I pushed this:

commit 6ecd16410ce1fe5cb0ac5b7c3342c5cc330e3a04
Author: Mark Wielaard 
Date:   Tue Dec 20 14:53:43 2022 +0100

Do not use relative include paths in library files.

Rely on include dirs being set up correctly. Setup libdw AM_CPPFLAGS
to include libebl directory. In libdwfl note that debuginfod.h is a
generated file in the builddir. Only include it in the one file
debuginfod-client.c that really needs it.

Signed-off-by: Mark Wielaard 


Re: [PATCHv2] strip: keep .ctf section in stripped file

2022-12-20 Thread Mark Wielaard
Hi Guillermo,

On Wed, Jun 01, 2022 at 10:55:27AM -0500, Guillermo E. Martinez via 
Elfutils-devel wrote:
> This is the second version patch to avoid remove the CTF section in
> stripped files. Changes from v1:
> 
>   - Add description in tests/run-strip-remove-keep-ctf.sh
> mentioning how to regenerate test input file (testfile-ctf)
> 
> Please let me know your thoughts.
>
> [...]
> 
> CTF debug format was designed to be present in stripped files, so
> this section should not be removed, so a new --remove-ctf option
> is added to indicate explicitly that .ctf section will be stripped
> out from binary file.

Sorry, I see I never reviewed this v2 variant.  I know we tried to
coordinate with binutils so eu-strip and binutils strip would do the
same thing. And that Jose had an idea for a new section flag to
automatically detect what section should/shouldn't be stripped (into a
separate .debug file). What was the conclusion of that?

Thanks,

Mark


[PATCH] lib: Remove -ffunction-sections for xmalloc

2022-12-20 Thread Mark Wielaard
The build used -ffunction-sections just for one file.

Signed-off-by: Mark Wielaard 
---
 lib/ChangeLog   | 4 
 lib/Makefile.am | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/ChangeLog b/lib/ChangeLog
index 6bb0d4d0..5ab9477e 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,7 @@
+2022-12-20  Mark Wielaard  
+
+   * Makefile.am (xmalloc_CFLAGS): Remove.
+
 2022-09-21  Yonggang Luo  
 
* color.c: Don't include unistd.h.
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 42ddf5ae..b3bb929f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -41,7 +41,3 @@ noinst_HEADERS = fixedsizehash.h libeu.h system.h 
dynamicsizehash.h list.h \
 eu-config.h color.h printversion.h bpf.h \
 atomics.h stdatomic-fbsd.h dynamicsizehash_concurrent.h
 EXTRA_DIST = dynamicsizehash.c dynamicsizehash_concurrent.c
-
-if !GPROF
-xmalloc_CFLAGS = -ffunction-sections
-endif
-- 
2.30.2



  1   2   3   4   5   6   7   8   9   10   >