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. \
+	 debuginfod-rpms/hello2.specfile \
+	 debuginfod-rpms/hello3.specfile \
 	 debuginfod-rpms/rhe

[PATCH 02/25] ignore build directory

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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
-- 
2.36.1.windows.1



[PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl

2022-10-20 Thread Yonggang Luo via Elfutils-devel
I split it into small patches for easier to review

Yonggang Luo (25):
  Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'
  ignore build directory
  libebl: There is no need #include  in eblclosebackend.c and
eblopenbackend.c
  libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and
libdwfl_crc32.c
  use #include  instead platform depended header  in
libdw/memory-access.h
  move platform depended include into system.h of libebl
  move platform depended include into system.h of libasm, libcpu, libdw,
libdwfl and libdwelf
  Use configure to detect HAVE_DECL_MMAP and use it for system doesn't
provide sys/mman.h
  include libgen.h in system.h
  libcpu: Remove the need of NMNES by using enum
  libcpu: Use __asm instead asm that can be recognized by both clang-cl
and gcc
  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
  libdw: typeof -> __typeof that can be recognized by both clang-cl and
gcc
  libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to
match the header
  lib: Implement error properly even when not HAVE_ERR_H
  libeu: Move the implementation of  pwrite_retry, write_retry and
pread_retry from header to source
  libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using
long/unsigned long instead on win32
  lib: Use NOT_HAVE_LIBINTL to guard #include 
  libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of
it
  Add function sys_get_page_size to replace platform dependent sysconf
(_SC_PAGESIZE)
  libasm: stdio_ext.h are not present on win32
  libebl/libdwelf: define ssize_t and pid_t for MSVC within installed
header libdwelf.h and libebl.h
  libasm/debuginfod: fchmod doesn't present on win32
  lib: isatty is not available on windows
  Fixes building with msvc/clang mingw/gcc

 .gitignore|1 +
 .vscode/settings.json |  124 ++
 CMakeLists.txt|  106 +
 README|2 +-
 backends/CMakeLists.txt   |  136 ++
 config-cmake/config.h |   40 +
 config-cmake/win32-gnu/search.h   |3 +
 config-cmake/win32-msvc/dirent.c  |  872 
 config-cmake/win32-msvc/dirent.h  |  339 +++
 config-cmake/win32-msvc/search.h  |   21 +
 config-cmake/win32-msvc/sys/time.h|1 +
 .../win32/ar.h|   32 +-
 config-cmake/win32/argp-ba.c  |   23 +
 config-cmake/win32/argp-eexist.c  |   30 +
 config-cmake/win32/argp-fmtstream.c   |  456 
 config-cmake/win32/argp-fmtstream.h   |  112 +
 config-cmake/win32/argp-help.c| 1861 +
 config-cmake/win32/argp-parse.c   | 1373 
 config-cmake/win32/argp-pv.c  |   22 +
 config-cmake/win32/argp-pvh.c |   25 +
 config-cmake/win32/argp-shims.c   |   27 +
 config-cmake/win32/argp-shims.h   |   20 +
 config-cmake/win32/argp.h |  520 +
 config-cmake/win32/internal.h |  163 ++
 config-cmake/win32/obstack.h  |  535 +
 configure.ac  |1 +
 debuginfod/debuginfod-client.c|4 +-
 lib/CMakeLists.txt|   36 +
 lib/Makefile.am   |2 +-
 lib/color.c   |6 +-
 lib/crc32_file.c  |6 +-
 lib/error.c   |9 +-
 lib/eu-config.h   |   11 +
 lib/system.c  |  516 +
 lib/system.h  |  157 +-
 libasm/CMakeLists.txt |   59 +
 libasm/asm_abort.c|1 -
 libasm/asm_addint8.c  |2 -
 libasm/asm_begin.c|9 +-
 libasm/asm_end.c  |4 +-
 libasm/libasmP.h  |3 +
 libcpu/CMakeLists.txt |   34 +
 libcpu/Makefile.am|2 +-
 libcpu/i386_data.h|2 +-
 libcpu/i386_disasm.c  |3 +-
 libcpu/i386_parse.y   |   13 +-
 libcpu/memory-access.h|3 +-
 libdw/CMakeLists.txt  |  152 ++
 libdw/dwarf_begin_elf.c   |4 +-
 libdw/dwarf_end.c |1 -
 libdw/dwarf_getsrc_file.c |2 +-
 libdw/dwarf_setalt.c  |2 -
 libdw/dwarf_whatattr.c|3 +-
 libdw/dwarf_whatform.c  

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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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,

Signed-off-by: Yonggang Luo 
-#include 
-#include 
 #include 
 #include 
 #include 
+
 #include 
 
 #define AUXV_TYPES   \
diff --git a/libebl/eblcorenote.c b/libebl/eblcorenote.c
index 7fab3974..9573e93e 100644
--- a/libebl/eblcorenote.c
+++ b/libebl/eblcorenote.c
@@ -31,12 +31,11 @@
 #endif
 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
 #include 
+
 #include 
 
 
diff --git a/libebl/ebldynamictagname.c b/libebl/ebldynamictagname.c
index 5d4a3a58..018a2ff7 100644
--- a/libebl/ebldynamictagname.c
+++ b/libebl/ebldynamictagname.c
@@ -33,8 +33,8 @@
 
 #include 
 #include 
+
 #include 
-#include "system.h"
 
 
 const char *
diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c
index 5a7c5c62..83ac4f47 100644
--- a/libebl/eblobjnote.c
+++ b/libebl/eblobjnote.c
@@ -35,13 +35,13 @@
 #include 
 #include 
 #include 
-#include 
 
-#include "common.h"
-#include "libelfP.h"
-#include "libdwP.h"
-#include "memory-access.h"
+#include 
 
+#include "../libelf/common.h"
+#include "../libelf/libelfP.h"
+#include "../libdw/libdwP.h"
+#include "../libdw/memory-access.h"
 
 void
 ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 473a1f2f..c15379d6 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -31,11 +31,10 @@
 # include 
 #endif
 
-#include 
-
 #include 
 #include 
 #include 
+
 #include 
 
 
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index 02f80653..7dc760d8 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -31,15 +31,15 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 
-#include 
 #include 
 
+#include "../libelf/libelfP.h"
+
 Ebl *i386_init (Elf *, GElf_Half, Ebl *);
 Ebl *sh_init (Elf *, GElf_Half, Ebl *);
 Ebl *x86_64_init (Elf *, GElf_Half, Ebl *);
diff --git a/libebl/eblresolvesym.c b/libebl/eblresolvesym.c
index 470f6f06..b859bba3 100644
--- a/libebl/eblresolvesym.c
+++ b/libebl/eblresolvesym.c
@@ -30,9 +30,10 @@
 # include 
 #endif
 
-#include 
 #include 
 
+#include 
+
 bool
 ebl_resolve_sym_value (Ebl *ebl, GElf_Addr *addr)
 {
diff --git a/libebl/libeblP.h b/libebl/libeblP.h
index c408ed97..14cb70f3 100644
--- a/libebl/libeblP.h
+++ b/libebl/libeblP.h
@@ -30,9 +30,11 @@
 #define _LIBEBLP_H 1
 
 #include 
-#include 
 #include 
 
+#include 
+
+#include <../libasm/libasm.h>
 
 /* Backend handle.  */
 struct ebl
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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]

Signed-off-by: Yonggang Luo 
---
 libdwfl/libdwfl_crc32.c | 1 -
 libelf/libelf_crc32.c   | 1 -
 2 files changed, 2 deletions(-)

diff --git a/libdwfl/libdwfl_crc32.c b/libdwfl/libdwfl_crc32.c
index b89d0d36..5bc7a4ad 100644
--- a/libdwfl/libdwfl_crc32.c
+++ b/libdwfl/libdwfl_crc32.c
@@ -30,6 +30,5 @@
 #endif
 
 #define crc32 attribute_hidden __libdwfl_crc32
-#define LIB_SYSTEM_H   1
 #include 
 #include "../lib/crc32.c"
diff --git a/libelf/libelf_crc32.c b/libelf/libelf_crc32.c
index 1426faf1..f1cf4868 100644
--- a/libelf/libelf_crc32.c
+++ b/libelf/libelf_crc32.c
@@ -30,6 +30,5 @@
 #endif
 
 #define crc32 attribute_hidden __libelf_crc32
-#define LIB_SYSTEM_H   1
 #include 
 #include "../lib/crc32.c"
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
These filenames are invalid on win32

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 f680d3e1..4add00d8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -566,7 +566,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



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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(-)

diff --git a/lib/color.c b/lib/color.c
index bd105ec2..8063dc26 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "system.h"
 #include "libeu.h"
 #include "color.h"
diff --git a/libasm/asm_abort.c b/libasm/asm_abort.c
index 12743dc6..696298c4 100644
--- a/libasm/asm_abort.c
+++ b/libasm/asm_abort.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 
 #include 
 #include 
diff --git a/libasm/asm_addint8.c b/libasm/asm_addint8.c
index bb7d40f2..7f823e09 100644
--- a/libasm/asm_addint8.c
+++ b/libasm/asm_addint8.c
@@ -31,8 +31,6 @@
 # include 
 #endif
 
-#include 
-#include 
 #include 
 #include 
 
diff --git a/libasm/asm_begin.c b/libasm/asm_begin.c
index a190202c..9e4dfe43 100644
--- a/libasm/asm_begin.c
+++ b/libasm/asm_begin.c
@@ -37,11 +37,9 @@
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include "libasmP.h"
-#include 
 
 
 static AsmCtx_t *
diff --git a/libasm/asm_end.c b/libasm/asm_end.c
index a26120f2..c06d2366 100644
--- a/libasm/asm_end.c
+++ b/libasm/asm_end.c
@@ -35,12 +35,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include 
 #include 
-#include 
 
 
 static int
diff --git a/libasm/libasmP.h b/libasm/libasmP.h
index 5b5fb776..11f42511 100644
--- a/libasm/libasmP.h
+++ b/libasm/libasmP.h
@@ -32,6 +32,9 @@
 #include 
 
 #include 
+
+#include 
+
 #include "libebl.h"
 
 #include "libdwelf.h"
diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
index 40475b81..599d1654 100644
--- a/libcpu/i386_disasm.c
+++ b/libcpu/i386_disasm.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/libcpu/memory-access.h b/libcpu/memory-access.h
index 3b6ca19b..6e92fc5b 100644
--- a/libcpu/memory-access.h
+++ b/libcpu/memory-access.h
@@ -29,11 +29,10 @@
 #ifndef _MEMORY_ACCESS_H
 #define _MEMORY_ACCESS_H 1
 
-#include 
-#include 
 #include 
 #include 
 
+#include 
 
 /* When loading this file we require the macro MACHINE_ENCODING to be
defined to signal the endianness of the architecture which is
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index a48dada6..8fcef335 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -38,11 +38,9 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-#include 
 
 #include "libelfP.h"
 #include "libdwP.h"
diff --git a/libdw/dwarf_end.c b/libdw/dwarf_end.c
index 77f537a7..8dd075cf 100644
--- a/libdw/dwarf_end.c
+++ b/libdw/dwarf_end.c
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "libdwP.h"
 #include "cfi.h"
diff --git a/libdw/dwarf_setalt.c b/libdw/dwarf_setalt.c
index 9051b8e0..dc9b61cb 100644
--- a/libdw/dwarf_setalt.c
+++ b/libdw/dwarf_setalt.c
@@ -32,8 +32,6 @@
 
 #include "libdwP.h"
 
-#include 
-
 void
 dwarf_setalt (Dwarf *main, Dwarf *alt)
 {
diff --git a/libdw/libdw_find_split_unit.c b/libdw/libdw_find_split_unit.c
index da039e50..a22e7bc9 100644
--- a/libdw/libdw_find_split_unit.c
+++ b/libdw/libdw_find_split_unit.c
@@ -40,7 +40,6 @@
 #include 
 #include 
 #include 
-#include 
 
 void
 try_split_file (Dwarf_CU *cu, const char *dwo_path)
diff --git a/libdwelf/dwelf_elf_begin.c b/libdwelf/dwelf_elf_begin.c
index c3cfe633..17a90fc9 100644
--- a/libdwelf/dwelf_elf_begin.c
+++ b/libdwelf/dwelf_elf_begin.c
@@ -34,8 +34,6 @@
 #include "libdwflP.h"
 #include "libelfP.h"
 
-#include 
-
 NEW_VERSION (dwelf_elf_begin, ELFUTILS_0.177)
 

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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
It's not accessed symbols in dlfcn.h in eblclosebackend.c and eblopenbackend.c

Signed-off-by: Yonggang Luo 
---
 libebl/eblclosebackend.c | 1 -
 libebl/eblopenbackend.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/libebl/eblclosebackend.c b/libebl/eblclosebackend.c
index 501e5c7b..7fa068ec 100644
--- a/libebl/eblclosebackend.c
+++ b/libebl/eblclosebackend.c
@@ -30,7 +30,6 @@
 # include 
 #endif
 
-#include 
 #include 
 
 #include 
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index c6657252..02f80653 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -31,7 +31,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.36.1.windows.1



[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-10-20 Thread Yonggang Luo via Elfutils-devel
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
 
 
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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 -
 7 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 03b67a9d..63aeb748 100644
--- a/configure.ac
+++ b/configure.ac
@@ -428,6 +428,7 @@ AC_CHECK_DECLS([memrchr, rawmemchr],[],[],
[#define _GNU_SOURCE
 #include ])
 AC_CHECK_DECLS([powerof2],[],[],[#include ])
+AC_CHECK_DECLS([mmap],[],[],[#include ])
 AC_CHECK_DECLS([mempcpy],[],[],
[#define _GNU_SOURCE
 #include ])
diff --git a/lib/crc32_file.c b/lib/crc32_file.c
index f7607d0b..66833702 100644
--- a/lib/crc32_file.c
+++ b/lib/crc32_file.c
@@ -32,9 +32,7 @@
 
 #include "libeu.h"
 #include 
-#include 
 #include 
-#include 
 #include "system.h"
 
 int
@@ -45,6 +43,7 @@ crc32_file (int fd, uint32_t *resp)
   off_t off = 0;
   ssize_t count;
 
+#if HAVE_DECL_MMAP
   struct stat st;
   if (fstat (fd, &st) == 0)
 {
@@ -78,6 +77,7 @@ crc32_file (int fd, uint32_t *resp)
  munmap (mapped, mapsize);
}
 }
+#endif
 
   while ((count = TEMP_FAILURE_RETRY (pread (fd, buffer, sizeof buffer,
 off))) > 0)
diff --git a/lib/system.h b/lib/system.h
index bbbe06c4..561d3e03 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -42,7 +42,9 @@
 /* System dependend headers */
 #include 
 #include 
+#if HAVE_DECL_MMAP
 #include 
+#endif
 #include 
 #include 
 
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 46afa1f4..8229fd26 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -96,7 +96,7 @@ sort_sections (Elf_Scn **scns, Elf_ScnList *list)
   qsort (scns, scnp - scns, sizeof (*scns), compare_sections);
 }
 
-
+#if HAVE_DECL_MMAP
 static inline void
 fill_mmap (size_t offset, char *last_position, char *scn_start,
char *const shdr_start, char *const shdr_end)
@@ -482,6 +482,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, 
size_t shnum)
 
   return 0;
 }
+#endif
 
 
 /* Size of the buffer we use to generate the blocks of fill bytes.  */
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index fe8c640a..6d31882e 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -645,10 +645,12 @@ static struct Elf *
 read_file (int fildes, int64_t offset, size_t maxsize,
   Elf_Cmd cmd, Elf *parent)
 {
+#if HAVE_DECL_MMAP
   void *map_address = NULL;
   int use_mmap = (cmd == ELF_C_READ_MMAP || cmd == ELF_C_RDWR_MMAP
  || cmd == ELF_C_WRITE_MMAP
  || cmd == ELF_C_READ_MMAP_PRIVATE);
+#endif
 
   if (parent == NULL)
 {
@@ -669,7 +671,7 @@ read_file (int fildes, int64_t offset, size_t maxsize,
   /* The parent is already loaded.  Use it.  */
   assert (maxsize != ~((size_t) 0));
 }
-
+#if HAVE_DECL_MMAP
   if (use_mmap)
 {
   if (parent == NULL)
@@ -713,6 +715,7 @@ read_file (int fildes, int64_t offset, size_t maxsize,
 
   return result;
 }
+#endif
 
   /* Otherwise we have to do it the hard way.  We read as much as necessary
  from the file whenever we need information which is not available.  */
diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 5c451f36..8023b216 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -222,8 +222,10 @@ elf_end (Elf *elf)
   /* The file was read or mapped for this descriptor.  */
   if ((elf->flags & ELF_F_MALLOCED) != 0)
free (elf->map_address);
+#if HAVE_DECL_MMAP
   else if ((elf->flags & ELF_F_MMAPPED) != 0)
munmap (elf->map_address, elf->maximum_size);
+#endif
 }
 
   rwlock_unlock (elf->lock);
diff --git a/libelf/elf_update.c b/libelf/elf_update.c
index 56af3a1c..e81eb6c9 100644
--- a/libelf/elf_update.c
+++ b/libelf/elf_update.c
@@ -64,7 +64,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t 
shnum)
   __libelf_seterrno (ELF_E_WRITE_ERROR);
   return -1;
 }
-
+#if HAVE_DECL_MMAP
   /* Try to map the file if this isn't done yet.  */
   if (elf->map_address == NULL && elf->cmd == ELF_C_WRITE_MMAP)
 {
@@ -125,6 +125,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t 
shnum)
size = -1;
 }
   else
+#endif
 {
   /* The file is not mmaped.  */
   if ((class == ELFCLASS32
@@ -145,6 +146,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t 
shnum)
   size = -1;
 }
 
+#if HAVE_DECL_MMAP
   /* POSIX says that ftruncate and write may clear the S_ISUID and S_ISGID
  mode bits.  So make sure we restore them afterwards if they were set.
  This is not atomic if someone else chmod's the file while we operate.  */
@@ -156,6 +158,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t 
shnum)
   __libelf_seterrno (ELF_E_WRITE_ERROR);
   s

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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
basename function are accessed multiple place, but used without include libgen.h

Signed-off-by: Yonggang Luo 
---
 lib/system.h | 1 +
 libdw/dwarf_getsrc_file.c| 2 +-
 libdwfl/dwfl_module_getsrc_file.c| 2 +-
 libdwfl/dwfl_segment_report_module.c | 2 +-
 libdwfl/find-debuginfo.c | 6 +++---
 libdwfl/link_map.c   | 2 +-
 src/addr2line.c  | 4 ++--
 src/nm.c | 4 ++--
 src/stack.c  | 2 +-
 src/strip.c  | 2 +-
 10 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/system.h b/lib/system.h
index 561d3e03..7132cd6d 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -42,6 +42,7 @@
 /* System dependend headers */
 #include 
 #include 
+#include 
 #if HAVE_DECL_MMAP
 #include 
 #endif
diff --git a/libdw/dwarf_getsrc_file.c b/libdw/dwarf_getsrc_file.c
index 5289c7da..884fea32 100644
--- a/libdw/dwarf_getsrc_file.c
+++ b/libdw/dwarf_getsrc_file.c
@@ -98,7 +98,7 @@ dwarf_getsrc_file (Dwarf *dbg, const char *fname, int lineno, 
int column,
  /* Match the name with the name the user provided.  */
  const char *fname2 = line->files->info[lastfile].name;
  if (is_basename)
-   lastmatch = strcmp (basename (fname2), fname) == 0;
+   lastmatch = strcmp (basename ((char *)fname2), fname) == 0;
  else
lastmatch = strcmp (fname2, fname) == 0;
}
diff --git a/libdwfl/dwfl_module_getsrc_file.c 
b/libdwfl/dwfl_module_getsrc_file.c
index cea2ba41..6daf29d6 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -103,7 +103,7 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
{
  /* Match the name with the name the user provided.  */
  lastfile = file;
- lastmatch = !strcmp (is_basename ? basename (file) : file,
+ lastmatch = !strcmp (is_basename ? basename ((char *)file) : 
file,
   fname);
}
}
diff --git a/libdwfl/dwfl_segment_report_module.c 
b/libdwfl/dwfl_segment_report_module.c
index 287fc002..aa228254 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -736,7 +736,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char 
*name,
  bias += fixup;
  if (module->name[0] != '\0')
{
- name = basename (module->name);
+ name = basename ((char *)module->name);
  name_is_final = true;
}
  break;
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 7f7ab632..a9b7be3d 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -164,7 +164,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char 
*file_name,
 {
   bool cancheck = debuglink_crc != (GElf_Word) 0;
 
-  const char *file_basename = file_name == NULL ? NULL : basename (file_name);
+  const char *file_basename = file_name == NULL ? NULL : basename ((char 
*)file_name);
   char *localname = NULL;
 
   /* We invent a debuglink .debug name if NULL, but then want to try the
@@ -278,7 +278,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char 
*file_name,
  else
{
  subdir = NULL;
- file = basename (debuglink_file);
+ file = basename ((char *)debuglink_file);
}
  try_file_basename = debuglink_null;
  break;
@@ -306,7 +306,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char 
*file_name,
if (mod->dw != NULL && (p[0] == '\0' || p[0] == '/'))
  {
fd = try_open (&main_stat, dir, ".dwz",
-  basename (file), &fname);
+  basename ((char *)file), &fname);
if (fd < 0)
  {
if (errno != ENOENT && errno != ENOTDIR)
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 7ec7eca1..403d4ee5 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -469,7 +469,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
  if (r_debug_info_module == NULL)
{
  // XXX hook for sysroot
- mod = __libdwfl_report_elf (dwfl, basename (name),
+ mod = __libdwfl_report_elf (dwfl, basename ((char 
*)name),
  name, fd, elf, base,
  true, true);
  if (mod != NULL)
diff --git a/src/addr2line.c b/src/addr2line.c
index 7768b266..3abf1d7a 100644
--- a/src/addr2line.c
+++ b/src/addr2line.c
@@ -381,7 +381,7 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr)
  if (file == NUL

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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 libdw/memory-access.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libdw/memory-access.h b/libdw/memory-access.h
index 800b517c..16c8c851 100644
--- a/libdw/memory-access.h
+++ b/libdw/memory-access.h
@@ -29,11 +29,10 @@
 #ifndef _MEMORY_ACCESS_H
 #define _MEMORY_ACCESS_H 1
 
-#include 
-#include 
 #include 
 #include 
 
+#include 
 
 /* Number decoding macros.  See 7.6 Variable Length Data.  */
 
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 libdw/memory-access.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libdw/memory-access.h b/libdw/memory-access.h
index 16c8c851..fca4129a 100644
--- a/libdw/memory-access.h
+++ b/libdw/memory-access.h
@@ -64,7 +64,7 @@ __libdw_max_len_sleb128 (const unsigned char *addr, const 
unsigned char *end)
 #define get_uleb128_step(var, addr, nth) \
   do {   \
 unsigned char __b = *(addr)++;   \
-(var) |= (typeof (var)) (__b & 0x7f) << ((nth) * 7); \
+(var) |= (__typeof (var)) (__b & 0x7f) << ((nth) * 7);   \
 if (likely ((__b & 0x80) == 0))  \
   return (var);  \
   } while (0)
@@ -112,11 +112,11 @@ __libdw_get_uleb128_unchecked (const unsigned char 
**addrp)
 #define get_sleb128_step(var, addr, nth) \
   do {   \
 unsigned char __b = *(addr)++;   \
-(var) |= (typeof (var)) (__b & 0x7f) << ((nth) * 7); \
+(var) |= (__typeof (var)) (__b & 0x7f) << ((nth) * 7);   \
 if (likely ((__b & 0x80) == 0))  \
   {
  \
if ((__b & 0x40) != 0)\
- (var) |= - ((typeof (var)) 1 << (((nth) + 1) * 7)); \
+ (var) |= - ((__typeof (var)) 1 << (((nth) + 1) * 7));   \
return (var); \
   }
  \
   } while (0)
@@ -146,7 +146,7 @@ __libdw_get_sleb128 (const unsigned char **addrp, const 
unsigned char *end)
 {
   /* We only need the low bit of the final byte, and as it is the
 sign bit, we don't need to do anything else here.  */
-  acc |= ((typeof (acc)) b) << 7 * max;
+  acc |= ((__typeof (acc)) b) << 7 * max;
   return acc;
 }
 
@@ -179,7 +179,7 @@ __libdw_get_sleb128_unchecked (const unsigned char **addrp)
 {
   /* We only need the low bit of the final byte, and as it is the
 sign bit, we don't need to do anything else here.  */
-  acc |= ((typeof (acc)) b) << 7 * max;
+  acc |= ((__typeof (acc)) b) << 7 * max;
   return acc;
 }
 
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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
+  };
 
 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)
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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));
}
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 libdw/dwarf_whatattr.c | 3 ++-
 libdw/dwarf_whatform.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libdw/dwarf_whatattr.c b/libdw/dwarf_whatattr.c
index d664b021..59769865 100644
--- a/libdw/dwarf_whatattr.c
+++ b/libdw/dwarf_whatattr.c
@@ -34,9 +34,10 @@
 #include 
 #include "libdwP.h"
 
-
+#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
-- 
2.36.1.windows.1



[PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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.

Signed-off-by: Yonggang Luo 
---
 lib/eu-config.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/lib/eu-config.h b/lib/eu-config.h
index 78a5c4fe..5e6c3c72 100644
--- a/lib/eu-config.h
+++ b/lib/eu-config.h
@@ -52,10 +52,17 @@
 # define rwlock_unlock(lock) ((void) (lock))
 #endif /* USE_LOCKS */
 
+#if !defined(NOT_HAVE_LIBINTL)
 #include 
+#endif
+
 /* gettext helper macros.  */
 #define N_(Str) Str
+#if !defined(NOT_HAVE_LIBINTL)
 #define _(Str) dgettext ("elfutils", Str)
+#else
+#define _(Str) N_(Str)
+#endif
 
 /* Compiler-specific definitions.  */
 #define strong_alias(name, aliasname) \
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 lib/Makefile.am |  2 +-
 lib/system.c| 87 +
 lib/system.h| 59 -
 3 files changed, 94 insertions(+), 54 deletions(-)
 create mode 100644 lib/system.c

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 42ddf5ae..7a50085b 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,7 +35,7 @@ noinst_LIBRARIES = libeu.a
 
 libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \
  crc32.c crc32_file.c \
- color.c error.c printversion.c
+ color.c error.c printversion.c system.c
 
 noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
 eu-config.h color.h printversion.h bpf.h \
diff --git a/lib/system.c b/lib/system.c
new file mode 100644
index ..0fd28968
--- /dev/null
+++ b/lib/system.c
@@ -0,0 +1,87 @@
+/* Definitions for system functions.
+   Copyright (C) 2006-2011 Red Hat, Inc.
+   Copyright (C) 2022 Mark J. Wielaard 
+   Copyright (C) 2022 Yonggang Luo 
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+ * the GNU Lesser General 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 .  */
+
+#include "system.h"
+
+ssize_t
+pwrite_retry(int fd, const void *buf, size_t len, off_t off)
+{
+  ssize_t recvd = 0;
+
+  do
+{
+  ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len 
- recvd,
+  off + recvd));
+  if (ret <= 0)
+return ret < 0 ? ret : recvd;
+
+  recvd += ret;
+}
+  while ((size_t) recvd < len);
+
+  return recvd;
+}
+
+ssize_t
+write_retry(int fd, const void *buf, size_t len)
+{
+  ssize_t recvd = 0;
+
+  do
+{
+  ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len 
- recvd));
+  if (ret <= 0)
+return ret < 0 ? ret : recvd;
+
+  recvd += ret;
+}
+  while ((size_t) recvd < len);
+
+  return recvd;
+}
+
+ssize_t
+pread_retry(int fd, void *buf, size_t len, off_t off)
+{
+  ssize_t recvd = 0;
+
+  do
+{
+  ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len 
- recvd,
+  off + recvd));
+  if (ret <= 0)
+return ret < 0 ? ret : recvd;
+
+  recvd += ret;
+}
+  while ((size_t) recvd < len);
+
+  return recvd;
+}
diff --git a/lib/system.h b/lib/system.h
index 264781c2..05b2d8f9 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -145,61 +145,14 @@ startswith (const char *str, const char *prefix)
 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666 */
 #endif
 
-static inline ssize_t __attribute__ ((unused))
-pwrite_retry (int fd, const void *buf, size_t len, off_t off)
-{
-  ssize_t recvd = 0;
-
-  do
-{
-  ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len 
- recvd,
-   off + recvd));
-  if (ret <= 0)
-   return ret < 0 ? ret : recvd;
+ssize_t
+pwrite_retry (int fd, const void *buf, size_t len, off_t off);
 
-  recvd += ret;
-}
-  while ((size_t) recvd < len);
-
-  return recvd;
-}
+ssize_t
+write_retry (int fd, const void *buf, size_t len);
 
-static inline ssize_t __attribute__ ((unused))
-write_retry (int fd, const void *buf, size_t len)
-{
-  ssize_t recvd = 0;
-
-  do
-{
-  ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len 
- recvd));
-  if (ret <= 0)
-   return ret < 0 ? ret : recvd;
-
-  recvd += ret;
-}
-  while ((size_t) recvd < len);
-
-  return recvd;
-}
-
-static inline ssize_t __attribute__ ((unused))
-pread_retry (int fd, void *buf, size_t len, off_t off)
-{
-  ssize_t recvd = 0;
-
-  do
-{
-  ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len 
- recvd,
-  off + recvd));
-  if (ret <= 0)
-   return ret < 0 ? ret : recvd;
-
-  recvd += ret;
-}
-  while ((size_t) recvd < len);
-
-  return recvd;
-}
+ssize_t
+pread_retry (int fd, void *buf, size_t len, off_t off);
 
 /* The demangler from libstdc++.  */
 extern char *__cxa_demangle (const

[PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 libdwelf/libdwelf.h | 5 +
 libebl/libebl.h | 5 +
 2 files changed, 10 insertions(+)

diff --git a/libdwelf/libdwelf.h b/libdwelf/libdwelf.h
index 263ca60e..167ac0dc 100644
--- a/libdwelf/libdwelf.h
+++ b/libdwelf/libdwelf.h
@@ -31,6 +31,11 @@
 
 #include "libdw.h"
 
+#ifdef _MSC_VER
+#include 
+typedef SSIZE_T ssize_t;
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/libebl/libebl.h b/libebl/libebl.h
index 731001d3..c568f623 100644
--- a/libebl/libebl.h
+++ b/libebl/libebl.h
@@ -44,6 +44,11 @@
 
 #include "elf-knowledge.h"
 
+#ifdef _MSC_VER
+#include 
+typedef SSIZE_T ssize_t;
+typedef int pid_t;
+#endif
 
 /* Opaque type for the handle.  libasm.h defined the same thing.  */
 #ifndef _LIBASM_H
-- 
2.36.1.windows.1



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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
on win32, there is no err.h

Signed-off-by: Yonggang Luo 
---
 lib/error.c  | 9 -
 lib/system.h | 4 +---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/error.c b/lib/error.c
index 5186fc15..7924735e 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -28,12 +28,14 @@
 
 #include 
 
-#if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H)
+#if !defined(HAVE_ERROR_H)
 #include 
 #include 
 #include 
 #include 
+#if defined(HAVE_ERR_H)
 #include 
+#endif
 
 unsigned int error_message_count = 0;
 
@@ -44,6 +46,7 @@ void error(int status, int errnum, const char *format, ...) {
   fflush (stdout);
 
   va_start(argp, format);
+#if defined(HAVE_ERR_H)
   if (status)
 {
   if (errnum)
@@ -64,6 +67,10 @@ void error(int status, int errnum, const char *format, ...) {
   else
 vwarnx (format, argp);
 }
+#else
+  (void)status;
+  vfprintf(stderr, format, argp);
+#endif
   va_end(argp);
 
   fflush (stderr);
diff --git a/lib/system.h b/lib/system.h
index 7132cd6d..264781c2 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -51,11 +51,9 @@
 
 #if defined(HAVE_ERROR_H)
 #include 
-#elif defined(HAVE_ERR_H)
+#else
 extern int error_message_count;
 void error(int status, int errnum, const char *format, ...);
-#else
-#error "err.h or error.h must be available"
 #endif
 
 /* error (EXIT_FAILURE, ...) should be noreturn but on some systems it
-- 
2.36.1.windows.1



[PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE)

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 lib/crc32_file.c   |  2 +-
 lib/system.c   | 17 +
 lib/system.h   |  3 +++
 libdw/dwarf_begin_elf.c|  2 +-
 libdwelf/dwelf_strtab.c|  2 +-
 libdwfl/linux-kernel-modules.c |  2 +-
 libdwfl/linux-proc-maps.c  |  2 +-
 libelf/elf32_updatefile.c  |  2 +-
 src/ar.c   |  2 +-
 src/ranlib.c   |  2 +-
 src/strings.c  |  2 +-
 11 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/lib/crc32_file.c b/lib/crc32_file.c
index 66833702..45e1cc52 100644
--- a/lib/crc32_file.c
+++ b/lib/crc32_file.c
@@ -52,7 +52,7 @@ crc32_file (int fd, uint32_t *resp)
   void *mapped = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
   if (mapped == MAP_FAILED && errno == ENOMEM)
{
- const size_t pagesize = sysconf (_SC_PAGESIZE);
+ const size_t pagesize = sys_get_page_size();
  mapsize = ((mapsize / 2) + pagesize - 1) & -pagesize;
  while (mapsize >= pagesize
 && (mapped = mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE,
diff --git a/lib/system.c b/lib/system.c
index 0fd28968..9ce1b62e 100644
--- a/lib/system.c
+++ b/lib/system.c
@@ -28,7 +28,12 @@
the GNU Lesser General Public License along with this program.  If
not, see .  */
 
+#include 
+
 #include "system.h"
+#if defined(_WIN32)
+#include 
+#endif
 
 ssize_t
 pwrite_retry(int fd, const void *buf, size_t len, off_t off)
@@ -85,3 +90,15 @@ pread_retry(int fd, void *buf, size_t len, off_t off)
 
   return recvd;
 }
+
+size_t
+sys_get_page_size(void)
+{
+#ifdef _WIN32
+  SYSTEM_INFO info;
+  GetSystemInfo(&info);
+  return info.dwPageSize;
+#else
+  return sysconf (_SC_PAGESIZE);
+#endif
+}
diff --git a/lib/system.h b/lib/system.h
index 05b2d8f9..675ed221 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -154,6 +154,9 @@ write_retry (int fd, const void *buf, size_t len);
 ssize_t
 pread_retry (int fd, void *buf, size_t len, off_t off);
 
+size_t
+sys_get_page_size(void);
+
 /* The demangler from libstdc++.  */
 extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,
 size_t *length, int *status);
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 8fcef335..0f13e2f5 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -502,7 +502,7 @@ dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp)
 
 
   /* Default memory allocation size.  */
-  size_t mem_default_size = sysconf (_SC_PAGESIZE) - 4 * sizeof (void *);
+  size_t mem_default_size = sys_get_page_size() - 4 * sizeof (void *);
   assert (sizeof (struct Dwarf) < mem_default_size);
 
   /* Allocate the data structure.  */
diff --git a/libdwelf/dwelf_strtab.c b/libdwelf/dwelf_strtab.c
index c95f9467..293b2d93 100644
--- a/libdwelf/dwelf_strtab.c
+++ b/libdwelf/dwelf_strtab.c
@@ -86,7 +86,7 @@ dwelf_strtab_init (bool nullstr)
 {
   if (ps == 0)
 {
-  ps = sysconf (_SC_PAGESIZE);
+  ps = sys_get_page_size();
   assert (sizeof (struct memoryblock) < ps - MALLOC_OVERHEAD);
 }
 
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 58c0c417..65a58616 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -550,7 +550,7 @@ intuit_kernel_bounds (Dwarf_Addr *start, Dwarf_Addr *end, 
Dwarf_Addr *notes)
*notes = *end;
}
 
-  Dwarf_Addr round_kernel = sysconf (_SC_PAGESIZE);
+  Dwarf_Addr round_kernel = sys_get_page_size();
   *start &= -(Dwarf_Addr) round_kernel;
   *end += round_kernel - 1;
   *end &= -(Dwarf_Addr) round_kernel;
diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c
index 719cba68..40b8050b 100644
--- a/libdwfl/linux-proc-maps.c
+++ b/libdwfl/linux-proc-maps.c
@@ -422,7 +422,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ 
((unused)),
   if (fd < 0)
goto detach;
 
-  *elfp = elf_from_remote_memory (base, sysconf (_SC_PAGESIZE), NULL,
+  *elfp = elf_from_remote_memory (base, sys_get_page_size(), NULL,
  &read_proc_memory, &fd);
 
   close (fd);
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 8229fd26..af4518b8 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -474,7 +474,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, 
size_t shnum)
 
   /* Make sure the content hits the disk.  */
   char *msync_start = ((char *) elf->map_address
-  + (elf->start_offset & ~(sysconf (_SC_PAGESIZE) - 1)));
+  + (elf->start_offset & ~(sys_get_page_size() - 1)));
   char *msync_end = ((char *) elf->map_address
 + elf->start_offset + ehdr->e_shoff
 + ehdr->e_shentsize * shnum);
diff --git a/src/ar.c b/src/ar.c
index 3bcb18fe..d01f8482 100644
--- a/src/

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

2022-10-20 Thread Yonggang Luo via Elfutils-devel
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
 
   switch (cmd)
 {
-- 
2.36.1.windows.1



[PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 debuginfod/debuginfod-client.c | 4 +++-
 libasm/asm_end.c   | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 2a14d9d9..4b7f837b 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1405,9 +1405,11 @@ debuginfod_query_server (debuginfod_client *c,
   tvs[0].tv_usec = tvs[1].tv_usec = 0;
   (void) futimes (fd, tvs);  /* best effort */
 
+#if !defined(_WIN32)
   /* PR27571: make cache files casually unwriteable; dirs are already 0700 */
   (void) fchmod(fd, 0400);
-
+#endif
+
   /* rename tmp->real */
   rc = rename (target_cache_tmppath, target_cache_path);
   if (rc < 0)
diff --git a/libasm/asm_end.c b/libasm/asm_end.c
index c06d2366..54540bc1 100644
--- a/libasm/asm_end.c
+++ b/libasm/asm_end.c
@@ -512,12 +512,14 @@ asm_end (AsmCtx_t *ctx)
   if (result != 0)
 return result;
 
+#if !defined(_WIN32)
   /* Make the new file globally readable and user/group-writable.  */
   if (fchmod (ctx->fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) != 0)
 {
   __libasm_seterrno (ASM_E_CANNOT_CHMOD);
   return -1;
 }
+#endif
 
   /* Rename output file.  */
   if (rename (ctx->tmp_fname, ctx->fname) != 0)
-- 
2.36.1.windows.1



[PATCH 17/25] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 libelf/libelf.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libelf/libelf.h b/libelf/libelf.h
index a139e733..2fa3838b 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -195,9 +195,15 @@ typedef struct
 {
   char *ar_name;   /* Name of archive member.  */
   time_t ar_date;  /* File date.  */
+#if defined(_WIN32)
+  long ar_uid;
+  long ar_gid;
+  unsigned long ar_mode;
+#else
   uid_t ar_uid;/* User ID.  */
   gid_t ar_gid;/* Group ID.  */
   mode_t ar_mode;  /* File mode.  */
+#endif
   int64_t ar_size; /* File size.  */
   char *ar_rawname;/* Original name of archive member.  */
 } Elf_Arhdr;
-- 
2.36.1.windows.1



[PATCH 21/25] libasm: stdio_ext.h are not present on win32

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 libasm/asm_begin.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libasm/asm_begin.c b/libasm/asm_begin.c
index 9e4dfe43..9b6d974e 100644
--- a/libasm/asm_begin.c
+++ b/libasm/asm_begin.c
@@ -34,10 +34,13 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
+#if !defined(_WIN32)
+#include 
+#endif
+
 #include 
 #include "libasmP.h"
 
@@ -56,8 +59,10 @@ prepare_text_output (AsmCtx_t *result)
  free (result);
  result = NULL;
}
+#if !defined(_WIN32)
   else
__fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
+#endif
 }
 
   return result;
-- 
2.36.1.windows.1



[PATCH 24/25] lib: isatty is not available on windows

2022-10-20 Thread Yonggang Luo via Elfutils-devel
Signed-off-by: Yonggang Luo 
---
 lib/color.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/lib/color.c b/lib/color.c
index 8063dc26..963a2ec2 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -117,9 +117,14 @@ parse_opt (int key, char *arg,
if (strcmp (arg, values[i].str) == 0)
  {
color_mode = values[i].mode;
+#ifdef _WIN32
+   if (color_mode == color_auto)
+   color_mode = color_never;
+#else
if (color_mode == color_auto)
  color_mode
= isatty (STDOUT_FILENO) ? color_always : color_never;
+#endif
break;
  }
  if (i == nvalues)
-- 
2.36.1.windows.1



[Bug debuginfod/28204] extend webapi / verification with forthcoming signed-contents archives

2022-10-20 Thread mark at klomp dot org via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28204

--- Comment #8 from Mark Wielaard  ---
Note that we'll need rpm-devel ima-evm-utils-devel openssl-devel rpm-sign to
test this (should go into elfutils.spec BuildRequires).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug debuginfod/28204] extend webapi / verification with forthcoming signed-contents archives

2022-10-20 Thread mark at klomp dot org via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=28204

--- Comment #9 from Mark Wielaard  ---
To make this slightly easier to review I applied the patch and rebased it to
current master. Pushed here:
https://code.wildebeest.org/git/user/mjw/elfutils/commit/?h=ima

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

2022-10-20 Thread Aaron Merey via Elfutils-devel
v1 can be found here:
https://sourceware.org/pipermail/elfutils-devel/2022q3/005402.html

v2 simplifies debuginfod_find_section by automatically checking both
debuginfo and executables to extract the target section from. Previously
this function included a parameter for specifying whether the section should
come from a debuginfo or executable file.  For sections that are normally
stored in debuginfo or for sections that might differ between debuginfo and
executable (ex. .shstrtab, .gnu.build.attributes), debuginfo files are
searched before executables.

Artifacttype "debuginfo-section" and "executable-section" from v1 have
been replaced with artifacttype "section".  An example URL for a
section query is: /buildid/0123456789abcdef/section/.gdb_index
Section files in the client cache are named "section" followed by
the section name. Ex: "section.gdb_index".

debuginfod_query_server now attempts to extract the desired section
from a debuginfo or executable in the client cache before querying
any servers.

If debuginfod servers are built without _find_section support, they will
respond to a section query with response code 503.  If the client recieves
this code in response to a section query, it will attempt to query servers
for the full debuginfo or the executable (possibly both) in order to extract
the section on the client side.  For sections that are normally stored in
debuginfo or for sections that might differ between debuginfo and executable,
debuginfo files are downloaded/searched before executables.
---
 ChangeLog   |   4 +
 NEWS|   2 +
 debuginfod/ChangeLog|  22 ++
 debuginfod/Makefile.am  |   2 +-
 debuginfod/debuginfod-client.c  | 273 +++-
 debuginfod/debuginfod-find.c|  21 +-
 debuginfod/debuginfod.cxx   | 433 +++-
 debuginfod/debuginfod.h.in  |   6 +
 debuginfod/libdebuginfod.map|   1 +
 doc/ChangeLog   |   6 +
 doc/Makefile.am |   1 +
 doc/debuginfod_find_debuginfo.3 |  26 +-
 doc/debuginfod_find_section.3   |   1 +
 tests/ChangeLog |   5 +
 tests/Makefile.am   |   4 +-
 tests/run-debuginfod-section.sh | 141 +++
 16 files changed, 865 insertions(+), 83 deletions(-)
 create mode 100644 doc/debuginfod_find_section.3
 create mode 100755 tests/run-debuginfod-section.sh

diff --git a/ChangeLog b/ChangeLog
index 60624183..29b2108e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-10-20  Aaron Merey  
+
+   * NEWS: Add debuginfod_find_section.
+
 2022-09-13  Aleksei Vetrov  
 
* NEWS (libdwfl): Add dwfl_report_offline_memory.
diff --git a/NEWS b/NEWS
index 6ebd172c..3e290ff7 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ readelf: Add -D, --use-dynamic option.
 
 debuginfod: Add --disable-source-scan option.
 
+debuginfod-client: Add new function debuginfod_find_section.
+
 libdwfl: Add new function dwfl_get_debuginfod_client.
  Add new function dwfl_frame_reg.
  Add new function dwfl_report_offline_memory.
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 59d50df1..aacf655b 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,25 @@
+2022-10-20  Aaron Merey  
+
+   * Makefile.am (libdebuginfod_so_LDLIBS): Add libelf.
+   * debuginfod-client.c (debuginfod_find_section): New function.
+   (extract_section): New function.
+   (maybe_debuginfo_section): New function.
+   (cache_find_section): New function.
+   (debuginfod_query_server): Add support for section queries.
+   * debuginfod-find.c (main): Add support for section queries.
+   * debuginfod.cxx (extract_section): New function.
+   (handle_buildid_f_match): Add section parameter.  When non-empty,
+   try to create response from section contents.
+   (handle_buildid_r_match): Add section parameter.  When non-empty,
+   try to create response from section contents.
+   (handle_buildid_match): Add section parameter. Pass to
+   handle_buildid_{f,r}_match.
+   (handle_buildid): Handle section name when artifacttype is set to
+   "section".  Query upstream servers via debuginfod_find_section
+   when necessary.
+   (debuginfod.h.in): Add declaration for debuginfod_find_section.
+   (libdebuginfod.map): Add debuginfod_find_section.
+
 2022-10-17  Frank Ch. Eigler  
 
* debuginfod.cxx (main): Report libmicrohttpd version.
diff --git a/debuginfod/Makefile.am b/debuginfod/Makefile.am
index 435cb8a6..f27d6e2e 100644
--- a/debuginfod/Makefile.am
+++ b/debuginfod/Makefile.am
@@ -97,7 +97,7 @@ libdebuginfod_so_LIBS = libdebuginfod_pic.a
 if DUMMY_LIBDEBUGINFOD
 libdebuginfod_so_LDLIBS =
 else
-libdebuginfod_so_LDLIBS = -lpthread $(libcurl_LIBS) $(fts_LIBS)
+libdebuginfod_so_LDLIBS = -lpthread $(libcurl_LIBS) $(fts_LIBS) $(libelf)
 endif
 $(LIBDEBUGINFOD_SONAME): $(srcdir)/libdebuginfod.map $(libdebuginfod_so_LIBS)
 

[Bug libdw/29711] New: In libdw.h struct Dwarf, struct Dwarf_Abbrev is defined using typedef and not using #include is not the way to comply with the specification?

2022-10-20 Thread zhuorong.lin at outlook dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=29711

Bug ID: 29711
   Summary: In libdw.h struct Dwarf, struct Dwarf_Abbrev is
defined using typedef and not using #include
 is not the way to comply with the
specification?
   Product: elfutils
   Version: unspecified
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: libdw
  Assignee: unassigned at sourceware dot org
  Reporter: zhuorong.lin at outlook dot com
CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

Is directly typedef an undefined struct not in compliance with the
specification.

libdw.h
```
typedef struct Dwarf_Abbrev Dwarf_Abbrev;

/* Returned to show the last DIE has be returned.  */
#define DWARF_END_ABBREV ((Dwarf_Abbrev *) -1l)

/* Source code line information for CU.  */
typedef struct Dwarf_Lines_s Dwarf_Lines;

/* One source code line information.  */
typedef struct Dwarf_Line_s Dwarf_Line;

/* Source file information.  */
typedef struct Dwarf_Files_s Dwarf_Files;

/* One address range record.  */
typedef struct Dwarf_Arange_s Dwarf_Arange;

/* Address ranges of a file.  */
typedef struct Dwarf_Aranges_s Dwarf_Aranges;
```

libdwP.h
```

/* Abbreviation representation.  */
struct Dwarf_Abbrev
{
  Dwarf_Off offset;   /* Offset to start of abbrev into .debug_abbrev.  */
  unsigned char *attrp;   /* Pointer to start of attribute name/form pairs. */
  bool has_children : 1;  /* Whether or not the DIE has children. */
  unsigned int code : 31; /* The (unique) abbrev code.  */
  unsigned int tag;   /* The tag of the DIE. */
} attribute_packed;

#include "dwarf_abbrev_hash.h"


/* Files in line information records.  */
struct Dwarf_Files_s
  {
unsigned int ndirs;
unsigned int nfiles;
struct Dwarf_Fileinfo_s
{
  char *name;
  Dwarf_Word mtime;
  Dwarf_Word length;
} info[0];
/* nfiles of those, followed by char *[ndirs].  */
  };
typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo;


/* Representation of a row in the line table.  */

struct Dwarf_Line_s
{
  Dwarf_Files *files;

  Dwarf_Addr addr;
  unsigned int file;
  int line;
  unsigned short int column;
  unsigned int is_stmt:1;
  unsigned int basic_block:1;
  unsigned int end_sequence:1;
  unsigned int prologue_end:1;
  unsigned int epilogue_begin:1;
  /* The remaining bit fields are not flags, but hold values presumed to be
 small.  All the flags and other bit fields should add up to 48 bits
 to give the whole struct a nice round size.  */
  unsigned int op_index:8;
  unsigned int isa:8;
  unsigned int discriminator:24;
};

struct Dwarf_Lines_s
{
  size_t nlines;
  struct Dwarf_Line_s info[0];
};
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug libdw/29711] In libdw.h struct Dwarf, struct Dwarf_Abbrev is defined using typedef and not using #include is not the way to comply with the specification?

2022-10-20 Thread fche at redhat dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=29711

Frank Ch. Eigler  changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2022-10-21
 Ever confirmed|0   |1
 CC||fche at redhat dot com

--- Comment #1 from Frank Ch. Eigler  ---
No specification requires elfutils to provide an other than forward declaration
of these types.  Keeping the definitions private is fine, given that opaque
pointers are used in the various libdw* api calls to clients.

-- 
You are receiving this mail because:
You are on the CC list for the bug.