public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl
@ 2022-10-20 18:25 Yonggang Luo
  2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
                   ` (23 more replies)
  0 siblings, 24 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

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 <dlfcn.h> in eblclosebackend.c and
    eblopenbackend.c
  libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and
    libdwfl_crc32.c
  use #include <system.h> instead platform depended header <endian.h> 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 <libintl.h>
  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                        |    3 +-
 libdw/libdw_find_split_unit.c                 |    1 -
 libdw/memory-access.h                         |   13 +-
 libdwelf/CMakeLists.txt                       |   36 +
 libdwelf/dwelf_elf_begin.c                    |    2 -
 libdwelf/dwelf_strtab.c                       |    3 +-
 libdwelf/libdwelf.h                           |    5 +
 libdwfl/CMakeLists.txt                        |   92 +
 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_module_getsrc_file.c             |    2 +-
 libdwfl/dwfl_report_elf.c                     |    2 -
 libdwfl/dwfl_segment_report_module.c          |    4 +-
 libdwfl/find-debuginfo.c                      |    7 +-
 libdwfl/gzip.c                                |    2 -
 libdwfl/image-header.c                        |    4 -
 libdwfl/libdwfl_crc32.c                       |    1 -
 libdwfl/link_map.c                            |    4 +-
 libdwfl/linux-kernel-modules.c                |    2 +-
 libdwfl/linux-pid-attach.c                    |    1 -
 libdwfl/linux-proc-maps.c                     |    2 +-
 libdwfl/offline.c                             |    1 -
 libdwfl/open.c                                |    2 -
 libebl/CMakeLists.txt                         |   80 +
 libebl/eblauxvinfo.c                          |    3 +-
 libebl/eblclosebackend.c                      |    1 -
 libebl/eblcorenote.c                          |    3 +-
 libebl/ebldynamictagname.c                    |    2 +-
 libebl/eblobjnote.c                           |   10 +-
 libebl/eblobjnotetypename.c                   |    3 +-
 libebl/eblopenbackend.c                       |    5 +-
 libebl/eblresolvesym.c                        |    3 +-
 libebl/libebl.h                               |    5 +
 libebl/libeblP.h                              |    4 +-
 libelf/CMakeLists.txt                         |  168 ++
 libelf/elf32_updatefile.c                     |    5 +-
 libelf/elf_begin.c                            |    7 +-
 libelf/elf_end.c                              |    2 +
 libelf/elf_update.c                           |    5 +-
 libelf/libelf.h                               |    6 +
 libelf/libelf_crc32.c                         |    1 -
 src/addr2line.c                               |    4 +-
 src/ar.c                                      |    2 +-
 src/nm.c                                      |    4 +-
 src/ranlib.c                                  |    2 +-
 src/stack.c                                   |    2 +-
 src/strings.c                                 |    2 +-
 src/strip.c                                   |    2 +-
 tests/Makefile.am                             |    2 +-
 .../{hello2.spec. => hello2.spec}             |    0
 .../{hello3.spec. => hello3.spec}             |    0
 110 files changed, 8241 insertions(+), 186 deletions(-)
 create mode 100644 .vscode/settings.json
 create mode 100644 CMakeLists.txt
 create mode 100644 backends/CMakeLists.txt
 create mode 100644 config-cmake/config.h
 create mode 100644 config-cmake/win32-gnu/search.h
 create mode 100644 config-cmake/win32-msvc/dirent.c
 create mode 100644 config-cmake/win32-msvc/dirent.h
 create mode 100644 config-cmake/win32-msvc/search.h
 create mode 100644 config-cmake/win32-msvc/sys/time.h
 copy libdw/dwarf_whatattr.c => config-cmake/win32/ar.h (73%)
 create mode 100644 config-cmake/win32/argp-ba.c
 create mode 100644 config-cmake/win32/argp-eexist.c
 create mode 100644 config-cmake/win32/argp-fmtstream.c
 create mode 100644 config-cmake/win32/argp-fmtstream.h
 create mode 100644 config-cmake/win32/argp-help.c
 create mode 100644 config-cmake/win32/argp-parse.c
 create mode 100644 config-cmake/win32/argp-pv.c
 create mode 100644 config-cmake/win32/argp-pvh.c
 create mode 100644 config-cmake/win32/argp-shims.c
 create mode 100644 config-cmake/win32/argp-shims.h
 create mode 100644 config-cmake/win32/argp.h
 create mode 100644 config-cmake/win32/internal.h
 create mode 100644 config-cmake/win32/obstack.h
 create mode 100644 lib/CMakeLists.txt
 create mode 100644 lib/system.c
 create mode 100644 libasm/CMakeLists.txt
 create mode 100644 libcpu/CMakeLists.txt
 create mode 100644 libdw/CMakeLists.txt
 create mode 100644 libdwelf/CMakeLists.txt
 create mode 100644 libdwfl/CMakeLists.txt
 create mode 100644 libebl/CMakeLists.txt
 create mode 100644 libelf/CMakeLists.txt
 rename tests/debuginfod-rpms/{hello2.spec. => hello2.spec} (100%)
 rename tests/debuginfod-rpms/{hello3.spec. => hello3.spec} (100%)

-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-27 13:02   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 02/25] ignore build directory Yonggang Luo
                   ` (22 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

These filenames are invalid on win32

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 02/25] ignore build directory
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
  2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-27 13:03   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c Yonggang Luo
                   ` (21 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 8bcd88d7..ca06dddd 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
  2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
  2022-10-20 18:25 ` [PATCH 02/25] ignore build directory Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-27 13:09   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c Yonggang Luo
                   ` (20 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

It's not accessed symbols in dlfcn.h in eblclosebackend.c and eblopenbackend.c

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <config.h>
 #endif
 
-#include <dlfcn.h>
 #include <stdlib.h>
 
 #include <libeblP.h>
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 <assert.h>
-#include <dlfcn.h>
 #include <libelfP.h>
 #include <dwarf.h>
 #include <stdlib.h>
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (2 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-27 13:20   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h Yonggang Luo
                   ` (19 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

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

If we don't remove this macro, when try #include <system.h> 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 <luoyonggang@gmail.com>
---
 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 <libdwflP.h>
 #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 <libelf.h>
 #include "../lib/crc32.c"
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (3 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-27 13:26   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 06/25] move platform depended include into system.h of libebl Yonggang Luo
                   ` (18 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <byteswap.h>
-#include <endian.h>
 #include <limits.h>
 #include <stdint.h>
 
+#include <system.h>
 
 /* Number decoding macros.  See 7.6 Variable Length Data.  */
 
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 06/25] move platform depended include into system.h of libebl
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (4 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-28 11:35   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf Yonggang Luo
                   ` (17 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Because all source in libebl #include <libeblP.h>, so #include <system.h> 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 <luoyonggang@gmail.com
---
 libebl/eblauxvinfo.c        |  3 +--
 libebl/eblcorenote.c        |  3 +--
 libebl/ebldynamictagname.c  |  2 +-
 libebl/eblobjnote.c         | 10 +++++-----
 libebl/eblobjnotetypename.c |  3 +--
 libebl/eblopenbackend.c     |  4 ++--
 libebl/eblresolvesym.c      |  3 ++-
 libebl/libeblP.h            |  4 +++-
 8 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libebl/eblauxvinfo.c b/libebl/eblauxvinfo.c
index ce1141b8..36554693 100644
--- a/libebl/eblauxvinfo.c
+++ b/libebl/eblauxvinfo.c
@@ -31,11 +31,10 @@
 #endif
 
 #include <assert.h>
-#include <byteswap.h>
-#include <endian.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stddef.h>
+
 #include <libeblP.h>
 
 #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 <assert.h>
-#include <byteswap.h>
-#include <endian.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stddef.h>
 #include <string.h>
+
 #include <libeblP.h>
 
 
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 <inttypes.h>
 #include <stdio.h>
+
 #include <libeblP.h>
-#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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <libeblP.h>
 
-#include "common.h"
-#include "libelfP.h"
-#include "libdwP.h"
-#include "memory-access.h"
+#include <libeblP.h>
 
+#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 <config.h>
 #endif
 
-#include <system.h>
-
 #include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
+
 #include <libeblP.h>
 
 
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 <assert.h>
-#include <libelfP.h>
 #include <dwarf.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 
-#include <system.h>
 #include <libeblP.h>
 
+#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 <config.h>
 #endif
 
-#include <libeblP.h>
 #include <assert.h>
 
+#include <libeblP.h>
+
 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 <gelf.h>
-#include <libasm.h>
 #include <libebl.h>
 
+#include <system.h>
+
+#include <../libasm/libasm.h>
 
 /* Backend handle.  */
 struct ebl
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (5 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 06/25] move platform depended include into system.h of libebl Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-28 12:07   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
                   ` (16 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <argp.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #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 <stdlib.h>
-#include <unistd.h>
 
 #include <libasmP.h>
 #include <libelf.h>
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 <config.h>
 #endif
 
-#include <byteswap.h>
-#include <endian.h>
 #include <inttypes.h>
 #include <string.h>
 
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 <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
 #include <gelf.h>
 #include "libasmP.h"
-#include <system.h>
 
 
 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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/stat.h>
 
 #include <libasmP.h>
 #include <libelf.h>
-#include <system.h>
 
 
 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 <stdio.h>
 
 #include <libasm.h>
+
+#include <system.h>
+
 #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 <assert.h>
 #include <config.h>
 #include <ctype.h>
-#include <endian.h>
 #include <errno.h>
 #include <gelf.h>
 #include <stddef.h>
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 <byteswap.h>
-#include <endian.h>
 #include <limits.h>
 #include <stdint.h>
 
+#include <system.h>
 
 /* 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 <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <endian.h>
 
 #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 <stdlib.h>
 #include <assert.h>
 #include <string.h>
-#include <unistd.h>
 
 #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 <unistd.h>
-
 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 <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
 
 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 <unistd.h>
-
 NEW_VERSION (dwelf_elf_begin, ELFUTILS_0.177)
 Elf *
 dwelf_elf_begin (int fd)
diff --git a/libdwelf/dwelf_strtab.c b/libdwelf/dwelf_strtab.c
index 5ec8c295..c95f9467 100644
--- a/libdwelf/dwelf_strtab.c
+++ b/libdwelf/dwelf_strtab.c
@@ -37,7 +37,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
 #include "libdwelfP.h"
 #include <system.h>
diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index bc013aa0..1605fbfe 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -35,7 +35,6 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <fcntl.h>
-#include <unistd.h>
 
 
 #define OPT_DEBUGINFO	0x100
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index 4418ef33..cd9b4f38 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -33,12 +33,6 @@
 #include "libdwflP.h"
 #include <gelf.h>
 
-#include <unistd.h>
-#include <endian.h>
-#include <byteswap.h>
-#include "system.h"
-
-
 /* On failure return, we update *NEXT to point back at OFFSET.  */
 static inline Elf *
 do_fail (int error, off_t *next, off_t offset)
diff --git a/libdwfl/dwfl_build_id_find_debuginfo.c b/libdwfl/dwfl_build_id_find_debuginfo.c
index 273e5e5f..856f2312 100644
--- a/libdwfl/dwfl_build_id_find_debuginfo.c
+++ b/libdwfl/dwfl_build_id_find_debuginfo.c
@@ -31,8 +31,6 @@
 #endif
 
 #include "libdwflP.h"
-#include <unistd.h>
-
 
 int
 dwfl_build_id_find_debuginfo (Dwfl_Module *mod,
diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
index 7b604d47..35bc8c9e 100644
--- a/libdwfl/dwfl_build_id_find_elf.c
+++ b/libdwfl/dwfl_build_id_find_elf.c
@@ -33,7 +33,6 @@
 #include "libdwflP.h"
 #include <inttypes.h>
 #include <fcntl.h>
-#include <unistd.h>
 #include "system.h"
 
 
diff --git a/libdwfl/dwfl_end.c b/libdwfl/dwfl_end.c
index b1840191..a1812407 100644
--- a/libdwfl/dwfl_end.c
+++ b/libdwfl/dwfl_end.c
@@ -31,7 +31,6 @@
 #endif
 
 #include "libdwflP.h"
-#include <unistd.h>
 
 void
 dwfl_end (Dwfl *dwfl)
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
index 77e0c5cb..5ee71dd4 100644
--- a/libdwfl/dwfl_frame.c
+++ b/libdwfl/dwfl_frame.c
@@ -33,7 +33,6 @@
 #include <system.h>
 
 #include "libdwflP.h"
-#include <unistd.h>
 
 /* Set STATE->pc_set from STATE->regs according to the backend.  Return true on
    success, false on error.  */
diff --git a/libdwfl/dwfl_module.c b/libdwfl/dwfl_module.c
index e7dfdace..4fbff33e 100644
--- a/libdwfl/dwfl_module.c
+++ b/libdwfl/dwfl_module.c
@@ -33,7 +33,6 @@
 #include "libdwflP.h"
 #include "../libdw/cfi.h"
 #include <search.h>
-#include <unistd.h>
 
 static void
 free_cu (struct dwfl_cu *cu)
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 6f076057..498c7cd2 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -34,7 +34,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <string.h>
-#include <unistd.h>
 #include "../libdw/libdwP.h"	/* DWARF_E_* values are here.  */
 #include "../libelf/libelfP.h"
 #include "system.h"
diff --git a/libdwfl/dwfl_report_elf.c b/libdwfl/dwfl_report_elf.c
index a5f0e5e5..581f4079 100644
--- a/libdwfl/dwfl_report_elf.c
+++ b/libdwfl/dwfl_report_elf.c
@@ -32,8 +32,6 @@
 
 #include "libdwflP.h"
 #include <fcntl.h>
-#include <unistd.h>
-
 
 /* We start every ET_REL module at a moderately aligned boundary.
    This keeps the low addresses easy to read compared to a layout
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 28f87f10..287fc002 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -36,8 +36,6 @@
 #include <elf.h>
 #include <gelf.h>
 #include <inttypes.h>
-#include <endian.h>
-#include <unistd.h>
 #include <fcntl.h>
 
 #include <system.h>
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 449df5a1..7f7ab632 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -33,7 +33,6 @@
 #include "libdwflP.h"
 #include <stdio.h>
 #include <fcntl.h>
-#include <unistd.h>
 #include <sys/stat.h>
 #include "system.h"
 
diff --git a/libdwfl/gzip.c b/libdwfl/gzip.c
index ba8ecfba..53013be3 100644
--- a/libdwfl/gzip.c
+++ b/libdwfl/gzip.c
@@ -33,8 +33,6 @@
 #include "libdwflP.h"
 #include "system.h"
 
-#include <unistd.h>
-
 #ifdef LZMA
 # define USE_INFLATE	1
 # include <lzma.h>
diff --git a/libdwfl/image-header.c b/libdwfl/image-header.c
index f906068a..c777cc84 100644
--- a/libdwfl/image-header.c
+++ b/libdwfl/image-header.c
@@ -32,10 +32,6 @@
 #endif
 
 #include "libdwflP.h"
-#include "system.h"
-
-#include <unistd.h>
-#include <endian.h>
 
 #if BYTE_ORDER == LITTLE_ENDIAN
 # define LE16(x)	(x)
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index c0207cd3..7ec7eca1 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -32,8 +32,6 @@
 #include "../libdw/memory-access.h"
 #include "system.h"
 
-#include <byteswap.h>
-#include <endian.h>
 #include <fcntl.h>
 
 /* This element is always provided and always has a constant value.
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index 09cba07b..de867857 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -38,7 +38,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <dirent.h>
-#include <unistd.h>
 
 #ifdef __linux__
 
diff --git a/libdwfl/offline.c b/libdwfl/offline.c
index 499663e3..e090b42b 100644
--- a/libdwfl/offline.c
+++ b/libdwfl/offline.c
@@ -34,7 +34,6 @@
 
 #include "libdwflP.h"
 #include <fcntl.h>
-#include <unistd.h>
 
 /* Since dwfl_report_elf lays out the sections already, this will only be
    called when the section headers of the debuginfo file are being
diff --git a/libdwfl/open.c b/libdwfl/open.c
index da8b59a3..68b755cd 100644
--- a/libdwfl/open.c
+++ b/libdwfl/open.c
@@ -35,8 +35,6 @@
 #undef	_
 #include "libdwflP.h"
 
-#include <unistd.h>
-
 #if !USE_BZLIB
 # define __libdw_bunzip2(...)	DWFL_E_BADELF
 #endif
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (6 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-28 11:41   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 09/25] include libgen.h in system.h Yonggang Luo
                   ` (15 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <string.h>])
 AC_CHECK_DECLS([powerof2],[],[],[#include <sys/param.h>])
+AC_CHECK_DECLS([mmap],[],[],[#include <sys/mman.h>])
 AC_CHECK_DECLS([mempcpy],[],[],
                [#define _GNU_SOURCE
                 #include <string.h>])
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 <errno.h>
-#include <unistd.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
 #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 <byteswap.h>
 #include <endian.h>
+#if HAVE_DECL_MMAP
 #include <sys/mman.h>
+#endif
 #include <sys/param.h>
 #include <unistd.h>
 
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);
       size = -1;
     }
+#endif
 
   if (size != -1 && elf->parent == NULL)
     elf->maximum_size = size;
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 09/25] include libgen.h in system.h
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (7 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-28 11:45   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 10/25] libcpu: Remove the need of NMNES by using enum Yonggang Luo
                   ` (14 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

basename function are accessed multiple place, but used without include libgen.h

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <byteswap.h>
 #include <endian.h>
+#include <libgen.h>
 #if HAVE_DECL_MMAP
 #include <sys/mman.h>
 #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 == NULL)
 		    file = "???";
 		  else if (only_basenames)
-		    file = basename (file);
+		    file = basename ((char *)file);
 		  else if (use_comp_dir && file[0] != '/')
 		    {
 		      const char *const *dirs;
@@ -564,7 +564,7 @@ print_src (const char *src, int lineno, int linecol, Dwarf_Die *cu)
   const char *comp_dir_sep = "";
 
   if (only_basenames)
-    src = basename (src);
+    src = basename ((char *)src);
   else if (use_comp_dir && src[0] != '/')
     {
       Dwarf_Attribute attr;
diff --git a/src/nm.c b/src/nm.c
index b46c1fd7..717ec0f6 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -1417,7 +1417,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr,
 			  int lineno;
 			  (void) dwarf_lineno (line, &lineno);
 			  const char *file = dwarf_linesrc (line, NULL, NULL);
-			  file = (file != NULL) ? basename (file) : "???";
+			  file = (file != NULL) ? basename ((char *)file) : "???";
 			  int n;
 			  n = obstack_printf (&whereob, "%s:%d%c", file,
 					      lineno, '\0');
@@ -1448,7 +1448,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr,
 		{
 		  /* We found the line.  */
 		  int n = obstack_printf (&whereob, "%s:%" PRIu64 "%c",
-					  basename ((*found)->file),
+					  basename ((char *)(*found)->file),
 					  (*found)->lineno,
 					  '\0');
 		  sym_mem[nentries_used].where = obstack_finish (&whereob);
diff --git a/src/stack.c b/src/stack.c
index 534aa93c..82413772 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -152,7 +152,7 @@ module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)),
 
   int width = get_addr_width (mod);
   printf ("0x%0*" PRIx64 "-0x%0*" PRIx64 " %s\n",
-	  width, start, width, end, basename (name));
+	  width, start, width, end, basename ((char *)name));
 
   const unsigned char *id;
   GElf_Addr id_vaddr;
diff --git a/src/strip.c b/src/strip.c
index 2a2cc801..6ac987fd 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1800,7 +1800,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 		      elf_errmsg (-1));
 	}
 
-      char *debug_basename = basename (debug_fname_embed ?: debug_fname);
+      char *debug_basename = basename ((char *)(debug_fname_embed ?: debug_fname));
       off_t crc_offset = strlen (debug_basename) + 1;
       /* Align to 4 byte boundary */
       crc_offset = ((crc_offset - 1) & ~3) + 4;
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 10/25] libcpu: Remove the need of NMNES by using enum
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (8 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 09/25] include libgen.h in system.h Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 12:37   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
                   ` (13 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (9 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 10/25] libcpu: Remove the need of NMNES by using enum Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 12:42   ` Mark Wielaard
  2022-10-20 18:25 ` [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 Yonggang Luo
                   ` (12 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [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 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (10 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 12:58   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc Yonggang Luo
                   ` (11 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (11 preceding siblings ...)
  2022-10-20 18:25 ` [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 Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 13:12   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header Yonggang Luo
                   ` (10 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (12 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 13:31   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
                   ` (9 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <dwarf.h>
 #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 <dwarf.h>
 #include "libdwP.h"
 
-
+#ifndef __OPTIMIZE__
 unsigned int
 dwarf_whatform (Dwarf_Attribute *attr)
 {
   return attr == NULL ? 0 : attr->form;
 }
+#endif
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (13 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 15:37   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source Yonggang Luo
                   ` (8 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

on win32, there is no err.h

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <config.h>
 
-#if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H)
+#if !defined(HAVE_ERROR_H)
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#if defined(HAVE_ERR_H)
 #include <err.h>
+#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 <error.h>
-#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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 16/25] libeu: Move the implementation of  pwrite_retry, write_retry and pread_retry from header to source
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (14 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 15:45   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 17/25] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
                   ` (7 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 00000000..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 <mark@klomp.org>
+   Copyright (C) 2022 Yonggang Luo <luoyonggang@gmail.com>
+   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 <http://www.gnu.org/licenses/>.  */
+
+#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 char *mangled_name, char *output_buffer,
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [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 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (15 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-20 18:25 ` [PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include <libintl.h> Yonggang Luo
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include <libintl.h>
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (16 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 17/25] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-20 18:25 ` [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

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 <luoyonggang@gmail.com>
---
 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 <libintl.h>
+#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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (17 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include <libintl.h> Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-12-12 15:54   ` Mark Wielaard
  2022-10-20 18:25 ` [PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
                   ` (4 subsequent siblings)
  23 siblings, 1 reply; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE)
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (18 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
@ 2022-10-20 18:25 ` Yonggang Luo
  2022-10-20 18:26 ` [PATCH 21/25] libasm: stdio_ext.h are not present on win32 Yonggang Luo
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:25 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <http://www.gnu.org/licenses/>.  */
 
+#include <errno.h>
+
 #include "system.h"
+#if defined(_WIN32)
+#include <windows.h>
+#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/ar.c
+++ b/src/ar.c
@@ -428,7 +428,7 @@ copy_content (Elf *elf, int newfd, off_t off, size_t n)
   assert (off + n <= len);
 
   /* Tell the kernel we will read all the pages sequentially.  */
-  size_t ps = sysconf (_SC_PAGESIZE);
+  size_t ps = sys_get_page_size();
   if (n > 2 * ps)
     posix_madvise (rawfile + (off & ~(ps - 1)), n, POSIX_MADV_SEQUENTIAL);
 
diff --git a/src/ranlib.c b/src/ranlib.c
index 7838d69e..645b40ae 100644
--- a/src/ranlib.c
+++ b/src/ranlib.c
@@ -122,7 +122,7 @@ copy_content (Elf *elf, int newfd, off_t off, size_t n)
   assert (off + n <= len);
 
   /* Tell the kernel we will read all the pages sequentially.  */
-  size_t ps = sysconf (_SC_PAGESIZE);
+  size_t ps = sys_get_page_size();
   if (n > 2 * ps)
     posix_madvise (rawfile + (off & ~(ps - 1)), n, POSIX_MADV_SEQUENTIAL);
 
diff --git a/src/strings.c b/src/strings.c
index 55b047be..3341760d 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -163,7 +163,7 @@ main (int argc, char *argv[])
   elf_version (EV_CURRENT);
 
   /* Determine the page size.  We will likely need it a couple of times.  */
-  ps = sysconf (_SC_PAGESIZE);
+  ps = sys_get_page_size();
 
   struct stat st;
   int result = 0;
-- 
2.36.1.windows.1


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 21/25] libasm: stdio_ext.h are not present on win32
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (19 preceding siblings ...)
  2022-10-20 18:25 ` [PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
@ 2022-10-20 18:26 ` Yonggang Luo
  2022-10-20 18:26 ` [PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:26 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <assert.h>
 #include <errno.h>
 #include <stdio.h>
-#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 
+#if !defined(_WIN32)
+#include <stdio_ext.h>
+#endif
+
 #include <gelf.h>
 #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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (20 preceding siblings ...)
  2022-10-20 18:26 ` [PATCH 21/25] libasm: stdio_ext.h are not present on win32 Yonggang Luo
@ 2022-10-20 18:26 ` Yonggang Luo
  2022-10-20 18:26 ` [PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
  2022-10-20 18:26 ` [PATCH 24/25] lib: isatty is not available on windows Yonggang Luo
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:26 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 <BaseTsd.h>
+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 <BaseTsd.h>
+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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (21 preceding siblings ...)
  2022-10-20 18:26 ` [PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
@ 2022-10-20 18:26 ` Yonggang Luo
  2022-10-20 18:26 ` [PATCH 24/25] lib: isatty is not available on windows Yonggang Luo
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:26 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* [PATCH 24/25] lib: isatty is not available on windows
  2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (22 preceding siblings ...)
  2022-10-20 18:26 ` [PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
@ 2022-10-20 18:26 ` Yonggang Luo
  23 siblings, 0 replies; 61+ messages in thread
From: Yonggang Luo @ 2022-10-20 18:26 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'
  2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
@ 2022-10-27 13:02   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-10-27 13:02 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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.camel@klomp.org/

Thanks,

Mark

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 02/25] ignore build directory
  2022-10-20 18:25 ` [PATCH 02/25] ignore build directory Yonggang Luo
@ 2022-10-27 13:03   ` Mark Wielaard
  2022-12-16 21:14     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-10-27 13:03 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  .gitignore | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.gitignore b/.gitignore
> index 8bcd88d7..ca06dddd 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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c
  2022-10-20 18:25 ` [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c Yonggang Luo
@ 2022-10-27 13:09   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-10-27 13:09 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c
  2022-10-20 18:25 ` [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c Yonggang Luo
@ 2022-10-27 13:20   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-10-27 13:20 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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 <system.h> 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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h
  2022-10-20 18:25 ` [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h Yonggang Luo
@ 2022-10-27 13:26   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-10-27 13:26 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

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

Pushed,

Mark

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 06/25] move platform depended include into system.h of libebl
  2022-10-20 18:25 ` [PATCH 06/25] move platform depended include into system.h of libebl Yonggang Luo
@ 2022-10-28 11:35   ` Mark Wielaard
  2022-12-16 21:19     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-10-28 11:35 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Because all source in libebl #include <libeblP.h>, so #include
> <system.h> 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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h
  2022-10-20 18:25 ` [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
@ 2022-10-28 11:41   ` Mark Wielaard
  2022-12-16 21:21     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-10-28 11:41 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 09/25] include libgen.h in system.h
  2022-10-20 18:25 ` [PATCH 09/25] include libgen.h in system.h Yonggang Luo
@ 2022-10-28 11:45   ` Mark Wielaard
  2022-12-16 21:22     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-10-28 11:45 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf
  2022-10-20 18:25 ` [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf Yonggang Luo
@ 2022-10-28 12:07   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-10-28 12:07 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 10/25] libcpu: Remove the need of NMNES by using enum
  2022-10-20 18:25 ` [PATCH 10/25] libcpu: Remove the need of NMNES by using enum Yonggang Luo
@ 2022-12-12 12:37   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 12:37 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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)

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc
  2022-10-20 18:25 ` [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
@ 2022-12-12 12:42   ` Mark Wielaard
  2022-12-16 21:36     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 12:42 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* 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-10-20 18:25 ` [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 Yonggang Luo
@ 2022-12-12 12:58   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 12:58 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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 <luoyonggang@gmail.com>
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 <luoyonggang@gmail.com>

Cheers,

Mark

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc
  2022-10-20 18:25 ` [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc Yonggang Luo
@ 2022-12-12 13:12   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 13:12 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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 <luoyonggang@gmail.com>
Date:   Fri Oct 21 02:25:52 2022 +0800

    libdw: Change typeof -> __typeof in memory-access.h
    
    Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

Thanks,

Mark

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header
  2022-10-20 18:25 ` [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header Yonggang Luo
@ 2022-12-12 13:31   ` Mark Wielaard
  2022-12-16 21:47     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 13:31 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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 <dwarf.h>
>  #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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H
  2022-10-20 18:25 ` [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
@ 2022-12-12 15:37   ` Mark Wielaard
  2022-12-16 21:50     ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 15:37 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 16/25] libeu: Move the implementation of  pwrite_retry, write_retry and pread_retry from header to source
  2022-10-20 18:25 ` [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source Yonggang Luo
@ 2022-12-12 15:45   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 15:45 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

Why is this necessary?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it
  2022-10-20 18:25 ` [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
@ 2022-12-12 15:54   ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-12 15:54 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 02/25] ignore build directory
  2022-10-27 13:03   ` Mark Wielaard
@ 2022-12-16 21:14     ` 罗勇刚(Yonggang Luo)
  2022-12-20 12:35       ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:14 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 800 bytes --]

It's a common step to configure and make under build directory, so that the
IDE won't affect by it

On Thu, Oct 27, 2022 at 9:03 PM Mark Wielaard <mark@klomp.org> wrote:

> On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> wrote:
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > ---
> >  .gitignore | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/.gitignore b/.gitignore
> > index 8bcd88d7..ca06dddd 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
>


-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 06/25] move platform depended include into system.h of libebl
  2022-10-28 11:35   ` Mark Wielaard
@ 2022-12-16 21:19     ` 罗勇刚(Yonggang Luo)
  2022-12-20 13:59       ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:19 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]

On Fri, Oct 28, 2022 at 7:35 PM Mark Wielaard <mark@klomp.org> wrote:
>
> On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> wrote:
> > Because all source in libebl #include <libeblP.h>, so #include
> > <system.h> 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

> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* 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 11:41   ` Mark Wielaard
@ 2022-12-16 21:21     ` 罗勇刚(Yonggang Luo)
  2022-12-20 14:04       ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:21 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1018 bytes --]

On Fri, Oct 28, 2022 at 7:41 PM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi,
>
> On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> wrote:
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > ---
> >  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)


>
> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 09/25] include libgen.h in system.h
  2022-10-28 11:45   ` Mark Wielaard
@ 2022-12-16 21:22     ` 罗勇刚(Yonggang Luo)
  2022-12-16 21:34       ` 罗勇刚(Yonggang Luo)
  2022-12-20 15:05       ` Mark Wielaard
  0 siblings, 2 replies; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:22 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

On Fri, Oct 28, 2022 at 7:45 PM Mark Wielaard <mark@klomp.org> 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?
obviously mingw lacked of this

>
> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 09/25] include libgen.h in system.h
  2022-12-16 21:22     ` 罗勇刚(Yonggang Luo)
@ 2022-12-16 21:34       ` 罗勇刚(Yonggang Luo)
  2022-12-20 15:05       ` Mark Wielaard
  1 sibling, 0 replies; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:34 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 839 bytes --]

But still I think the force cast to (char *) is needed

On Sat, Dec 17, 2022 at 5:22 AM 罗勇刚(Yonggang Luo) <luoyonggang@gmail.com>
wrote:
>
>
>
> On Fri, Oct 28, 2022 at 7:45 PM Mark Wielaard <mark@klomp.org> 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?
> obviously mingw lacked of this
>
> >
> > Cheers,
> >
> > Mark
>
>
>
> --
>          此致
> 礼
> 罗勇刚
> Yours
>     sincerely,
> Yonggang Luo



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc
  2022-12-12 12:42   ` Mark Wielaard
@ 2022-12-16 21:36     ` 罗勇刚(Yonggang Luo)
  0 siblings, 0 replies; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:36 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

On Mon, Dec 12, 2022 at 8:42 PM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi,
>
> On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> wrote:
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > ---
> >  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?
OK, I'll get rid of it
>
> Thanks,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header
  2022-12-12 13:31   ` Mark Wielaard
@ 2022-12-16 21:47     ` 罗勇刚(Yonggang Luo)
  2022-12-20 15:08       ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:47 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00 2001
From: Yonggang Luo <luoyonggang@gmail.com>
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

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libdw/dwarf_whatattr.c | 4 +++-
 libdw/dwarf_whatform.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libdw/dwarf_whatattr.c b/libdw/dwarf_whatattr.c
index d664b021..c016f293 100644
--- a/libdw/dwarf_whatattr.c
+++ b/libdw/dwarf_whatattr.c
@@ -30,7 +30,9 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#ifdef __OPTIMIZE__
+#undef __OPTIMIZE__
+#endif
 #include <dwarf.h>
 #include "libdwP.h"

diff --git a/libdw/dwarf_whatform.c b/libdw/dwarf_whatform.c
index dee29a9f..f1d3574d 100644
--- a/libdw/dwarf_whatform.c
+++ b/libdw/dwarf_whatform.c
@@ -30,7 +30,9 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#ifdef __OPTIMIZE__
+#undef __OPTIMIZE__
+#endif
 #include <dwarf.h>
 #include "libdwP.h"

-- 
2.39.0.windows.1

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H
  2022-12-12 15:37   ` Mark Wielaard
@ 2022-12-16 21:50     ` 罗勇刚(Yonggang Luo)
  2022-12-20 15:10       ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-16 21:50 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 626 bytes --]

On Mon, Dec 12, 2022 at 11:37 PM Mark Wielaard <mark@klomp.org> wrote:
>
> 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.

Do you mean it should  call `exit(status)` after the  error message is
printed?


>
> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 02/25] ignore build directory
  2022-12-16 21:14     ` 罗勇刚(Yonggang Luo)
@ 2022-12-20 12:35       ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 12:35 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

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.

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 06/25] move platform depended include into system.h of libebl
  2022-12-16 21:19     ` 罗勇刚(Yonggang Luo)
@ 2022-12-20 13:59       ` Mark Wielaard
  2022-12-20 17:44         ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 13:59 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 930 bytes --]

Hi,

On Sat, 2022-12-17 at 05:19 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 28, 2022 at 7:35 PM Mark Wielaard <mark@klomp.org> wrote:
> > 
> > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > wrote:
> > > Because all source in libebl #include <libeblP.h>, so #include
> > > <system.h> 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

[-- Attachment #2: 0001-Do-not-use-relative-include-paths-in-library-files.patch --]
[-- Type: text/x-patch, Size: 15435 bytes --]

From 426db34b65d660c439b31d25308bc346d6272923 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
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 <mark@klomp.org>
---
 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  <mark@klomp.org>
+
+	* disasm_begin.c: Include libeblP.h.
+	* disasm_cb.c: Likewise.
+	* bpf_disasm.c: Likewise and include common.h.
+
 2022-10-21  Yonggang Luo  <luoyonggang@gmail.com>
 
 	* 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 <stdlib.h>
 
 #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 <string.h>
 
 #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  <mark@klomp.org>
+
+	* bpf_disasm.c: Include common.h and libeblP.h.
+	* i386_disasm.c: Include libeblP.h.
+	* riscv_disasm.c: Likewise.
+
 2022-10-21  Yonggang Luo  <luoyonggang@gmail.com>
 
 	* 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 <inttypes.h>
 #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
index 599d1654..c42f8d1c 100644
--- a/libcpu/i386_disasm.c
+++ b/libcpu/i386_disasm.c
@@ -41,7 +41,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "../libebl/libeblP.h"
+#include "libeblP.h"
 
 #define MACHINE_ENCODING LITTLE_ENDIAN
 #include "memory-access.h"
diff --git a/libcpu/riscv_disasm.c b/libcpu/riscv_disasm.c
index 7175c077..823fe9ca 100644
--- a/libcpu/riscv_disasm.c
+++ b/libcpu/riscv_disasm.c
@@ -39,7 +39,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "../libebl/libeblP.h"
+#include "libeblP.h"
 
 #define MACHINE_ENCODING LITTLE_ENDIAN
 #include "memory-access.h"
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 019c6580..4c7af94e 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,10 @@
+2022-12-20  Mark Wielaard  <mark@klomp.org>
+
+	* Makefile.am (AM_CPPFLAGS): Add -I$(srcdir)/../libebl.
+	* cfi.c: Include libebl.h.
+	* encoded-value.h: Likewise.
+	* frame-cache.h: Likewise.
+
 2022-10-21  Yonggang Luo  <luoyonggang@gmail.com>
 
 	* memory-access.h (get_uleb128_step): Use __typeof.
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index 4fda33bd..1b6fead4 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -31,7 +31,7 @@ include $(top_srcdir)/config/eu.am
 if BUILD_STATIC
 AM_CFLAGS += $(fpic_CFLAGS)
 endif
-AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libdwelf -pthread
+AM_CPPFLAGS += -I$(srcdir)/../libebl -I$(srcdir)/../libelf -I$(srcdir)/../libdwelf -pthread
 VERSION = 1
 
 lib_LIBRARIES = libdw.a
diff --git a/libdw/cfi.c b/libdw/cfi.c
index a73fb03f..6d08ca90 100644
--- a/libdw/cfi.c
+++ b/libdw/cfi.c
@@ -31,7 +31,7 @@
 #endif
 
 #include <dwarf.h>
-#include "../libebl/libebl.h"
+#include "libebl.h"
 #include "cfi.h"
 #include "memory-access.h"
 #include "encoded-value.h"
diff --git a/libdw/encoded-value.h b/libdw/encoded-value.h
index f0df4cec..d4e01924 100644
--- a/libdw/encoded-value.h
+++ b/libdw/encoded-value.h
@@ -32,7 +32,7 @@
 #include <dwarf.h>
 #include <stdlib.h>
 #include "libdwP.h"
-#include "../libelf/common.h"
+#include "common.h"
 
 
 /* Returns zero if the value is omitted, the encoding is unknown or
diff --git a/libdw/frame-cache.c b/libdw/frame-cache.c
index 5b6afb5d..683f7f17 100644
--- a/libdw/frame-cache.c
+++ b/libdw/frame-cache.c
@@ -30,7 +30,7 @@
 # include <config.h>
 #endif
 
-#include "../libebl/libebl.h"
+#include "libebl.h"
 #include "cfi.h"
 #include <search.h>
 #include <stdlib.h>
diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index 5d61aa85..1940629f 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,7 @@
+2022-12-20  Mark Wielaard  <mark@klomp.org>
+
+	* libdwelfP.h: Include libdwP.h.
+
 2022-10-21  Yonggang Luo  <luoyonggang@gmail.com>
 
 	* dwelf_elf_begin.c: Don't include unistd.h.
diff --git a/libdwelf/libdwelfP.h b/libdwelf/libdwelfP.h
index d83c759a..faaf1a20 100644
--- a/libdwelf/libdwelfP.h
+++ b/libdwelf/libdwelfP.h
@@ -30,7 +30,7 @@
 #define _LIBDWELFP_H	1
 
 #include <libdwelf.h>
-#include "../libdw/libdwP.h"	/* We need its INTDECLs.  */
+#include "libdwP.h"	/* We need its INTDECLs.  */
 #include <assert.h>
 #include <string.h>
 
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 68527327..1b465e48 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,27 @@
+2022-12-20  Mark Wielaard  <mark@klomp.org>
+
+	* Makefile.am (AM_CPPFLAGS): debuginfod.h is in builddir.
+	* core-file.c: Include libelfP.h.
+	* cu.c: Include libdwP.h and memory-access.h.
+	* debuginfod-client.c: Include debuginfod.h.
+	* dwfl_dwarf_line.c: Include libdwP.h.
+	* dwfl_lineinfo.c: Include libdwP.h.
+	* dwfl_module.c: Include cfi.h.
+	* dwfl_module_dwarf_cfi.c: Include cfi.h.
+	* dwfl_module_eh_cfi.c: Include cfi.h.
+	* dwfl_module_getdwarf.c: Include libdwP.h and libelfP.h.
+	* dwfl_module_getsrc.c: Include libdwP.h.
+	* dwfl_module_getsrc_file.c: Include libdwP.h.
+	* dwfl_segment_report_module.c: Include libelfP.h.
+	* elf-from-memory.c: Include libelfP.h.
+	* frame_unwind.c: Include dwarf.h.
+	* libdwflP.h: Include libdwP.h and libdwelfP.h. Don't include
+	debuginfod.h.
+	* lines.c: Include libdwP.h.
+	* link_map.c: Include memory-access.h.
+	* linux-core-attach.c: Include memory-access.h.
+	* open.c: Include libelfP.h.
+
 2022-11-28  Gavin Li  <gavin@matician.com>
 	    Mark Wielaard  <mark@klomp.org>
 
diff --git a/libdwfl/Makefile.am b/libdwfl/Makefile.am
index 3278358d..6b26cd51 100644
--- a/libdwfl/Makefile.am
+++ b/libdwfl/Makefile.am
@@ -31,7 +31,7 @@
 ##
 include $(top_srcdir)/config/eu.am
 AM_CPPFLAGS += -I$(srcdir) -I$(srcdir)/../libelf -I$(srcdir)/../libebl \
-	   -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf -I$(srcdir)/../debuginfod
+	   -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf -I$(builddir)/../debuginfod
 VERSION = 1
 
 noinst_LIBRARIES = libdwfl.a
diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c
index cd9b4f38..1ddf0f18 100644
--- a/libdwfl/core-file.c
+++ b/libdwfl/core-file.c
@@ -28,7 +28,7 @@
    not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include "../libelf/libelfP.h"	/* For NOTE_ALIGN.  */
+#include "libelfP.h"	/* For NOTE_ALIGN.  */
 #undef	_
 #include "libdwflP.h"
 #include <gelf.h>
diff --git a/libdwfl/cu.c b/libdwfl/cu.c
index 4de66248..b1afb19a 100644
--- a/libdwfl/cu.c
+++ b/libdwfl/cu.c
@@ -31,8 +31,8 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/libdwP.h"
-#include "../libdw/memory-access.h"
+#include "libdwP.h"
+#include "memory-access.h"
 #include <search.h>
 
 
diff --git a/libdwfl/debuginfod-client.c b/libdwfl/debuginfod-client.c
index d581daab..882a5eff 100644
--- a/libdwfl/debuginfod-client.c
+++ b/libdwfl/debuginfod-client.c
@@ -35,6 +35,8 @@
 
 #ifdef ENABLE_LIBDEBUGINFOD
 
+#include "debuginfod.h"
+
 #include <pthread.h>
 #include <dlfcn.h>
 
diff --git a/libdwfl/dwfl_dwarf_line.c b/libdwfl/dwfl_dwarf_line.c
index e22e984c..5084c659 100644
--- a/libdwfl/dwfl_dwarf_line.c
+++ b/libdwfl/dwfl_dwarf_line.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/libdwP.h"
+#include "libdwP.h"
 
 Dwarf_Line *
 dwfl_dwarf_line (Dwfl_Line *line, Dwarf_Addr *bias)
diff --git a/libdwfl/dwfl_lineinfo.c b/libdwfl/dwfl_lineinfo.c
index 96187128..85c4b314 100644
--- a/libdwfl/dwfl_lineinfo.c
+++ b/libdwfl/dwfl_lineinfo.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/libdwP.h"
+#include "libdwP.h"
 
 const char *
 dwfl_lineinfo (Dwfl_Line *line, Dwarf_Addr *addr, int *linep, int *colp,
diff --git a/libdwfl/dwfl_module.c b/libdwfl/dwfl_module.c
index 4fbff33e..221d726d 100644
--- a/libdwfl/dwfl_module.c
+++ b/libdwfl/dwfl_module.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/cfi.h"
+#include "cfi.h"
 #include <search.h>
 
 static void
diff --git a/libdwfl/dwfl_module_dwarf_cfi.c b/libdwfl/dwfl_module_dwarf_cfi.c
index 0e5b4356..05a14f7c 100644
--- a/libdwfl/dwfl_module_dwarf_cfi.c
+++ b/libdwfl/dwfl_module_dwarf_cfi.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/cfi.h"
+#include "cfi.h"
 
 Dwarf_CFI *
 internal_function
diff --git a/libdwfl/dwfl_module_eh_cfi.c b/libdwfl/dwfl_module_eh_cfi.c
index c296e399..aac6657d 100644
--- a/libdwfl/dwfl_module_eh_cfi.c
+++ b/libdwfl/dwfl_module_eh_cfi.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/cfi.h"
+#include "cfi.h"
 
 Dwarf_CFI *
 dwfl_module_eh_cfi (Dwfl_Module *mod, Dwarf_Addr *bias)
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 498c7cd2..9ba499bb 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -34,8 +34,8 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <string.h>
-#include "../libdw/libdwP.h"	/* DWARF_E_* values are here.  */
-#include "../libelf/libelfP.h"
+#include "libdwP.h"	/* DWARF_E_* values are here.  */
+#include "libelfP.h"
 #include "system.h"
 
 static inline Dwfl_Error
diff --git a/libdwfl/dwfl_module_getsrc.c b/libdwfl/dwfl_module_getsrc.c
index fc99b163..73dbf435 100644
--- a/libdwfl/dwfl_module_getsrc.c
+++ b/libdwfl/dwfl_module_getsrc.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/libdwP.h"
+#include "libdwP.h"
 
 Dwfl_Line *
 dwfl_module_getsrc (Dwfl_Module *mod, Dwarf_Addr addr)
diff --git a/libdwfl/dwfl_module_getsrc_file.c b/libdwfl/dwfl_module_getsrc_file.c
index cea2ba41..513af6b8 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/libdwP.h"
+#include "libdwP.h"
 
 
 static inline const char *
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 19fa6ded..41285103 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -28,7 +28,7 @@
    not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include "../libelf/libelfP.h"	/* For NOTE_ALIGN4 and NOTE_ALIGN8.  */
+#include "libelfP.h"	/* For NOTE_ALIGN4 and NOTE_ALIGN8.  */
 #undef	_
 #include "libdwflP.h"
 #include "common.h"
diff --git a/libdwfl/elf-from-memory.c b/libdwfl/elf-from-memory.c
index a0ef0014..f7fb3ab7 100644
--- a/libdwfl/elf-from-memory.c
+++ b/libdwfl/elf-from-memory.c
@@ -27,7 +27,7 @@
    not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include "../libelf/libelfP.h"
+#include "libelfP.h"
 #undef _
 
 #include "libdwflP.h"
diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c
index 8185d84b..1e2f0255 100644
--- a/libdwfl/frame_unwind.c
+++ b/libdwfl/frame_unwind.c
@@ -33,7 +33,7 @@
 #include "cfi.h"
 #include <stdlib.h>
 #include "libdwflP.h"
-#include "../libdw/dwarf.h"
+#include "dwarf.h"
 #include <system.h>
 
 /* Maximum number of DWARF expression stack slots before returning an error.  */
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 011b5de9..cdc528d0 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -38,12 +38,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "../libdw/libdwP.h"	/* We need its INTDECLs.  */
-#include "../libdwelf/libdwelfP.h"
-
-#ifdef ENABLE_LIBDEBUGINFOD
-#include "../debuginfod/debuginfod.h"
-#endif
+#include "libdwP.h"	/* We need its INTDECLs.  */
+#include "libdwelfP.h"
 
 typedef struct Dwfl_Process Dwfl_Process;
 
diff --git a/libdwfl/lines.c b/libdwfl/lines.c
index 128c0c97..a7f3004a 100644
--- a/libdwfl/lines.c
+++ b/libdwfl/lines.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "libdwflP.h"
-#include "../libdw/libdwP.h"
+#include "libdwP.h"
 
 Dwfl_Error
 internal_function
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 7ec7eca1..06d85eb6 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -29,7 +29,7 @@
 
 #include <config.h>
 #include "libdwflP.h"
-#include "../libdw/memory-access.h"
+#include "memory-access.h"
 #include "system.h"
 
 #include <fcntl.h>
diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c
index ee7afa40..d6f9e971 100644
--- a/libdwfl/linux-core-attach.c
+++ b/libdwfl/linux-core-attach.c
@@ -34,7 +34,7 @@
 #include <fcntl.h>
 #include "system.h"
 
-#include "../libdw/memory-access.h"
+#include "memory-access.h"
 
 struct core_arg
 {
diff --git a/libdwfl/open.c b/libdwfl/open.c
index 68b755cd..32bd7ff8 100644
--- a/libdwfl/open.c
+++ b/libdwfl/open.c
@@ -31,7 +31,7 @@
 # include <config.h>
 #endif
 
-#include "../libelf/libelfP.h"
+#include "libelfP.h"
 #undef	_
 #include "libdwflP.h"
 
-- 
2.18.4


^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h
  2022-12-16 21:21     ` 罗勇刚(Yonggang Luo)
@ 2022-12-20 14:04       ` Mark Wielaard
  2022-12-20 16:30         ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 14:04 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

Hi,

On Sat, 2022-12-17 at 05:21 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 28, 2022 at 7:41 PM Mark Wielaard <mark@klomp.org> wrote:
> > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > wrote:
> > > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > > ---
> > >  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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 09/25] include libgen.h in system.h
  2022-12-16 21:22     ` 罗勇刚(Yonggang Luo)
  2022-12-16 21:34       ` 罗勇刚(Yonggang Luo)
@ 2022-12-20 15:05       ` Mark Wielaard
  1 sibling, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 15:05 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

On Sat, 2022-12-17 at 05:22 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 28, 2022 at 7:45 PM Mark Wielaard <mark@klomp.org> 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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header
  2022-12-16 21:47     ` 罗勇刚(Yonggang Luo)
@ 2022-12-20 15:08       ` Mark Wielaard
  2022-12-20 16:31         ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 15:08 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

On Sat, 2022-12-17 at 05:47 +0800, 罗勇刚(Yonggang Luo) wrote:
> From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00
> 2001
> From: Yonggang Luo <luoyonggang@gmail.com>
> 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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H
  2022-12-16 21:50     ` 罗勇刚(Yonggang Luo)
@ 2022-12-20 15:10       ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 15:10 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

Hi,

On Sat, 2022-12-17 at 05:50 +0800, 罗勇刚(Yonggang Luo) wrote:
> On Mon, Dec 12, 2022 at 11:37 PM Mark Wielaard <mark@klomp.org>
> 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

^ permalink raw reply	[flat|nested] 61+ messages in thread

* 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 14:04       ` Mark Wielaard
@ 2022-12-20 16:30         ` 罗勇刚(Yonggang Luo)
  2022-12-21 16:54           ` Mark Wielaard
  0 siblings, 1 reply; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-20 16:30 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1642 bytes --]

On Tue, Dec 20, 2022 at 10:04 PM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi,
>
> On Sat, 2022-12-17 at 05:21 +0800, 罗勇刚(Yonggang Luo) wrote:
> > On Fri, Oct 28, 2022 at 7:41 PM Mark Wielaard <mark@klomp.org> wrote:
> > > On Fri, 2022-10-21 at 02:25 +0800, Yonggang Luo via Elfutils-devel
> > > wrote:
> > > > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > > > ---
> > > >  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?

Windows have mmap, just didn't have the direct posix mman API


>
> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header
  2022-12-20 15:08       ` Mark Wielaard
@ 2022-12-20 16:31         ` 罗勇刚(Yonggang Luo)
  0 siblings, 0 replies; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-20 16:31 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1018 bytes --]

On Tue, Dec 20, 2022 at 11:08 PM Mark Wielaard <mark@klomp.org> wrote:
>
> On Sat, 2022-12-17 at 05:47 +0800, 罗勇刚(Yonggang Luo) wrote:
> > From bdf8a3b45f063d010e7c93b3d3bfc42b801ee9b2 Mon Sep 17 00:00:00
> > 2001
> > From: Yonggang Luo <luoyonggang@gmail.com>
> > 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__ ?

In debug mode, __OPTIMIZE__   won't be defined.


>
> Cheers,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 06/25] move platform depended include into system.h of libebl
  2022-12-20 13:59       ` Mark Wielaard
@ 2022-12-20 17:44         ` Mark Wielaard
  0 siblings, 0 replies; 61+ messages in thread
From: Mark Wielaard @ 2022-12-20 17:44 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel


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 <mark@klomp.org>
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 <mark@klomp.org>

^ permalink raw reply	[flat|nested] 61+ messages in thread

* 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 16:30         ` 罗勇刚(Yonggang Luo)
@ 2022-12-21 16:54           ` Mark Wielaard
  2022-12-22  3:50             ` 罗勇刚(Yonggang Luo)
  0 siblings, 1 reply; 61+ messages in thread
From: Mark Wielaard @ 2022-12-21 16:54 UTC (permalink / raw)
  To: luoyonggang; +Cc: elfutils-devel

Hi,

On Wed, 2022-12-21 at 00:30 +0800, 罗勇刚(Yonggang Luo) via Elfutils-devel 
wrote:
> On Tue, Dec 20, 2022 at 10:04 PM Mark Wielaard <mark@klomp.org>
> wrot
> > 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?
> 
> Windows have mmap, just didn't have the direct posix mman API

So how does the API look like? Is there a posix mmap emulation
available?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 61+ messages in thread

* Re: [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h
  2022-12-21 16:54           ` Mark Wielaard
@ 2022-12-22  3:50             ` 罗勇刚(Yonggang Luo)
  0 siblings, 0 replies; 61+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-22  3:50 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1001 bytes --]

On Thu, Dec 22, 2022 at 12:54 AM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi,
>
> On Wed, 2022-12-21 at 00:30 +0800, 罗勇刚(Yonggang Luo) via Elfutils-devel
> wrote:
> > On Tue, Dec 20, 2022 at 10:04 PM Mark Wielaard <mark@klomp.org>
> > wrot
> > > 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?
> >
> > Windows have mmap, just didn't have the direct posix mman API
>
> So how does the API look like? Is there a posix mmap emulation
> available?

Cygwin did that, other than cygwin, for mingw/msvc, there is
https://github.com/klauspost/mman-win32/blob/master/mman.h

>
> Thanks,
>
> Mark



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo

^ permalink raw reply	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2022-12-22  3:50 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20 18:25 [PATCH 00/25] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
2022-10-20 18:25 ` [PATCH 01/25] Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec' Yonggang Luo
2022-10-27 13:02   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 02/25] ignore build directory Yonggang Luo
2022-10-27 13:03   ` Mark Wielaard
2022-12-16 21:14     ` 罗勇刚(Yonggang Luo)
2022-12-20 12:35       ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 03/25] libebl: There is no need #include <dlfcn.h> in eblclosebackend.c and eblopenbackend.c Yonggang Luo
2022-10-27 13:09   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 04/25] libelf/libdwfl: Remove "#define LIB_SYSTEM_H 1" in libelf_crc32.c and libdwfl_crc32.c Yonggang Luo
2022-10-27 13:20   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 05/25] use #include <system.h> instead platform depended header <endian.h> in libdw/memory-access.h Yonggang Luo
2022-10-27 13:26   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 06/25] move platform depended include into system.h of libebl Yonggang Luo
2022-10-28 11:35   ` Mark Wielaard
2022-12-16 21:19     ` 罗勇刚(Yonggang Luo)
2022-12-20 13:59       ` Mark Wielaard
2022-12-20 17:44         ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 07/25] move platform depended include into system.h of libasm, libcpu, libdw, libdwfl and libdwelf Yonggang Luo
2022-10-28 12:07   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
2022-10-28 11:41   ` Mark Wielaard
2022-12-16 21:21     ` 罗勇刚(Yonggang Luo)
2022-12-20 14:04       ` Mark Wielaard
2022-12-20 16:30         ` 罗勇刚(Yonggang Luo)
2022-12-21 16:54           ` Mark Wielaard
2022-12-22  3:50             ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 09/25] include libgen.h in system.h Yonggang Luo
2022-10-28 11:45   ` Mark Wielaard
2022-12-16 21:22     ` 罗勇刚(Yonggang Luo)
2022-12-16 21:34       ` 罗勇刚(Yonggang Luo)
2022-12-20 15:05       ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 10/25] libcpu: Remove the need of NMNES by using enum Yonggang Luo
2022-12-12 12:37   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 11/25] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-12 12:42   ` Mark Wielaard
2022-12-16 21:36     ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [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 Yonggang Luo
2022-12-12 12:58   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 13/25] libdw: typeof -> __typeof that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-12 13:12   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 14/25] libdw: check __OPTIMIZE__ in dwarf_whatattr.c and dwarf_whatform.c to match the header Yonggang Luo
2022-12-12 13:31   ` Mark Wielaard
2022-12-16 21:47     ` 罗勇刚(Yonggang Luo)
2022-12-20 15:08       ` Mark Wielaard
2022-12-20 16:31         ` 罗勇刚(Yonggang Luo)
2022-10-20 18:25 ` [PATCH 15/25] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
2022-12-12 15:37   ` Mark Wielaard
2022-12-16 21:50     ` 罗勇刚(Yonggang Luo)
2022-12-20 15:10       ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source Yonggang Luo
2022-12-12 15:45   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 17/25] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
2022-10-20 18:25 ` [PATCH 18/25] lib: Use NOT_HAVE_LIBINTL to guard #include <libintl.h> Yonggang Luo
2022-10-20 18:25 ` [PATCH 19/25] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
2022-12-12 15:54   ` Mark Wielaard
2022-10-20 18:25 ` [PATCH 20/25] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
2022-10-20 18:26 ` [PATCH 21/25] libasm: stdio_ext.h are not present on win32 Yonggang Luo
2022-10-20 18:26 ` [PATCH 22/25] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
2022-10-20 18:26 ` [PATCH 23/25] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
2022-10-20 18:26 ` [PATCH 24/25] lib: isatty is not available on windows Yonggang Luo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).