public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl
@ 2022-12-17 16:51 Yonggang Luo
  2022-12-17 16:51 ` [PATCH v2 01/16] ignore build directory Yonggang Luo
                   ` (15 more replies)
  0 siblings, 16 replies; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:51 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

I split it into small patches for easier to review
Changes v1->v2:
  The reviews are applied

Yonggang Luo (16):
  ignore build directory
  move platform depended include into system.h of libebl
  Use configure to detect HAVE_DECL_MMAP and use it for system doesn't
    provide sys/mman.h
  Fixes usage of basename about prototype differences
  libcpu: Remove the need of NMNES by using enum
  libcpu: Use __asm instead asm that can be recognized by both clang-cl
    and gcc
  libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c
  lib: Implement error properly even when not HAVE_ERR_H
  libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using
    long/unsigned long instead on win32
  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
  Add function sys_get_page_size to replace platform dependent sysconf
    (_SC_PAGESIZE)
  libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of
    it
  lib: Use HAVE_LIBINTL_H to guard #include <libintl.h>

 .gitignore                             |  1 +
 ChangeLog                              |  4 ++
 configure.ac                           |  3 +
 debuginfod/debuginfod-client.c         |  4 +-
 lib/Makefile.am                        |  2 +-
 lib/color.c                            |  5 ++
 lib/crc32_file.c                       |  6 +-
 lib/error.c                            | 16 ++++-
 lib/eu-config.h                        |  7 ++
 libdw/dwarf_whatform.c => lib/system.c | 90 ++++++++++++++------------
 lib/system.h                           |  9 ++-
 libasm/asm_begin.c                     |  7 +-
 libasm/asm_end.c                       |  2 +
 libcpu/Makefile.am                     |  2 +-
 libcpu/i386_disasm.c                   | 16 +----
 libcpu/i386_mne.h                      | 36 +++++++++++
 libcpu/i386_parse.y                    |  9 +--
 libdw/dwarf_begin_elf.c                |  2 +-
 libdw/dwarf_getsrc_file.c              |  2 +-
 libdw/dwarf_whatattr.c                 |  9 ++-
 libdw/dwarf_whatform.c                 |  9 ++-
 libdwelf/dwelf_strtab.c                |  2 +-
 libdwelf/libdwelf.h                    |  5 ++
 libdwfl/dwfl_module_getsrc_file.c      |  2 +-
 libdwfl/dwfl_segment_report_module.c   |  2 +-
 libdwfl/find-debuginfo.c               |  6 +-
 libdwfl/link_map.c                     |  2 +-
 libdwfl/linux-kernel-modules.c         |  2 +-
 libdwfl/linux-proc-maps.c              |  2 +-
 libebl/eblauxvinfo.c                   |  2 -
 libebl/eblcorenote.c                   |  2 -
 libebl/ebldynamictagname.c             |  1 -
 libebl/eblobjnote.c                    |  8 +--
 libebl/eblobjnotetypename.c            |  2 -
 libebl/eblopenbackend.c                |  1 -
 libebl/libebl.h                        |  5 ++
 libebl/libeblP.h                       |  1 +
 libelf/elf32_updatefile.c              |  5 +-
 libelf/elf_begin.c                     | 12 +++-
 libelf/elf_end.c                       |  2 +
 libelf/elf_update.c                    |  5 +-
 libelf/libelf.h                        |  6 ++
 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 +-
 49 files changed, 215 insertions(+), 119 deletions(-)
 copy libdw/dwarf_whatform.c => lib/system.c (66%)
 create mode 100644 libcpu/i386_mne.h

-- 
2.36.1.windows.1


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

* [PATCH v2 01/16] ignore build directory
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
@ 2022-12-17 16:51 ` Yonggang Luo
  2022-12-17 16:51 ` [PATCH v2 02/16] move platform depended include into system.h of libebl Yonggang Luo
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:51 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

This is for in in three building and won't affect IDE
for example
mkdir build && cd build && ../configure && make install

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 .gitignore | 1 +
 ChangeLog  | 4 ++++
 2 files changed, 5 insertions(+)

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
diff --git a/ChangeLog b/ChangeLog
index 52efca04..35a37343 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-12-17  Yonggang Luo <mark@klomp.org>
+
+	* .gitignore: Ignore build directory
+
 2022-11-02  Mark Wielaard  <mark@klomp.org>
 
 	* configure.ac (AC_INIT): Set version to 0.188.
-- 
2.36.1.windows.1


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

* [PATCH v2 02/16] move platform depended include into system.h of libebl
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
  2022-12-17 16:51 ` [PATCH v2 01/16] ignore build directory Yonggang Luo
@ 2022-12-17 16:51 ` Yonggang Luo
  2023-02-23 10:44   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:51 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        | 2 --
 libebl/eblcorenote.c        | 2 --
 libebl/ebldynamictagname.c  | 1 -
 libebl/eblobjnote.c         | 8 ++++----
 libebl/eblobjnotetypename.c | 2 --
 libebl/eblopenbackend.c     | 1 -
 libebl/libeblP.h            | 1 +
 7 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/libebl/eblauxvinfo.c b/libebl/eblauxvinfo.c
index ce1141b8..186b8c07 100644
--- a/libebl/eblauxvinfo.c
+++ b/libebl/eblauxvinfo.c
@@ -31,8 +31,6 @@
 #endif
 
 #include <assert.h>
-#include <byteswap.h>
-#include <endian.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/libebl/eblcorenote.c b/libebl/eblcorenote.c
index 7fab3974..3d4c8a92 100644
--- a/libebl/eblcorenote.c
+++ b/libebl/eblcorenote.c
@@ -31,8 +31,6 @@
 #endif
 
 #include <assert.h>
-#include <byteswap.h>
-#include <endian.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/libebl/ebldynamictagname.c b/libebl/ebldynamictagname.c
index 5d4a3a58..7a430f49 100644
--- a/libebl/ebldynamictagname.c
+++ b/libebl/ebldynamictagname.c
@@ -34,7 +34,6 @@
 #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..0bb56c02 100644
--- a/libebl/eblobjnote.c
+++ b/libebl/eblobjnote.c
@@ -37,10 +37,10 @@
 #include <string.h>
 #include <libeblP.h>
 
-#include "common.h"
-#include "libelfP.h"
-#include "libdwP.h"
-#include "memory-access.h"
+#include "../libelf/common.h"
+#include "../libelf/libelfP.h"
+#include "../libdw/libdwP.h"
+#include "../libdw/memory-access.h"
 
 
 void
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 473a1f2f..2ee1b228 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -31,8 +31,6 @@
 # include <config.h>
 #endif
 
-#include <system.h>
-
 #include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index 02f80653..6e884ea0 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -37,7 +37,6 @@
 #include <string.h>
 #include <stdio.h>
 
-#include <system.h>
 #include <libeblP.h>
 
 Ebl *i386_init (Elf *, GElf_Half, Ebl *);
diff --git a/libebl/libeblP.h b/libebl/libeblP.h
index c408ed97..9dfd60de 100644
--- a/libebl/libeblP.h
+++ b/libebl/libeblP.h
@@ -33,6 +33,7 @@
 #include <libasm.h>
 #include <libebl.h>
 
+#include <system.h>
 
 /* Backend handle.  */
 struct ebl
-- 
2.36.1.windows.1


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

* [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
  2022-12-17 16:51 ` [PATCH v2 01/16] ignore build directory Yonggang Luo
  2022-12-17 16:51 ` [PATCH v2 02/16] move platform depended include into system.h of libebl Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-02-23 10:52   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 04/16] Fixes usage of basename about prototype differences Yonggang Luo
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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 59be27ac..b84623fe 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] 33+ messages in thread

* [PATCH v2 04/16] Fixes usage of basename about prototype differences
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (2 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-02-23 11:00   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum Yonggang Luo
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 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 +-
 9 files changed, 13 insertions(+), 13 deletions(-)

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 19fa6ded..5342648a 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -719,7 +719,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] 33+ messages in thread

* [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (3 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 04/16] Fixes usage of basename about prototype differences Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2022-12-21 17:56   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libcpu/Makefile.am   |  2 +-
 libcpu/i386_disasm.c | 14 +-------------
 libcpu/i386_mne.h    | 36 ++++++++++++++++++++++++++++++++++++
 libcpu/i386_parse.y  |  9 +++------
 4 files changed, 41 insertions(+), 20 deletions(-)
 create mode 100644 libcpu/i386_mne.h

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_disasm.c b/libcpu/i386_disasm.c
index 599d1654..c34f03d6 100644
--- a/libcpu/i386_disasm.c
+++ b/libcpu/i386_disasm.c
@@ -46,10 +46,7 @@
 #define MACHINE_ENCODING LITTLE_ENDIAN
 #include "memory-access.h"
 
-
-#ifndef MNEFILE
-# define MNEFILE "i386.mnemonics"
-#endif
+#include "i386_mne.h"
 
 #define MNESTRFIELD(line) MNESTRFIELD1 (line)
 #define MNESTRFIELD1(line) str##line
@@ -71,15 +68,6 @@ static const union mnestr_t
     }
   };
 
-/* The index can be stored in the instrtab.  */
-enum
-  {
-#define MNE(name) MNE_##name,
-#include MNEFILE
-#undef MNE
-    MNE_INVALID
-  };
-
 static const unsigned short int mneidx[] =
   {
 #define MNE(name) \
diff --git a/libcpu/i386_mne.h b/libcpu/i386_mne.h
new file mode 100644
index 00000000..41dacf61
--- /dev/null
+++ b/libcpu/i386_mne.h
@@ -0,0 +1,36 @@
+/* Compute hash value for given string according to ELF standard.
+   Copyright (C) 1995-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _I386_MNE_H
+#define _I386_MNE_H	1
+
+#ifndef MNEFILE
+# define MNEFILE "i386.mnemonics"
+#endif
+
+/* The index can be stored in the instrtab.  */
+enum
+  {
+#define MNE(name) MNE_##name,
+#include MNEFILE
+#undef MNE
+    MNE_INVALID,
+    MNE_COUNT = MNE_INVALID,
+  };
+
+#endif /* i386_mne.h */
diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
index d2236d59..459684c6 100644
--- a/libcpu/i386_parse.y
+++ b/libcpu/i386_parse.y
@@ -46,6 +46,8 @@
 #include <libeu.h>
 #include <system.h>
 
+#include "i386_mne.h"
+
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
@@ -1107,11 +1109,6 @@ print_op_fct (const void *nodep, VISIT value,
     }
 }
 
-
-#if NMNES < 2
-# error "bogus NMNES value"
-#endif
-
 static void
 instrtable_out (void)
 {
@@ -1123,7 +1120,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] 33+ messages in thread

* [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (4 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2022-12-21 18:07   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c Yonggang Luo
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

This block of code can not be removed. As it's contains a goto label
enomem that been used elsewhere

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 c34f03d6..44bf7d37 100644
--- a/libcpu/i386_disasm.c
+++ b/libcpu/i386_disasm.c
@@ -468,7 +468,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] 33+ messages in thread

* [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (5 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-02-23 12:25   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

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

The error message is:
dwarf_whatform.c

[build] C:\work\xemu\elfutils\libdw\dwarf_whatform.c(39,1): error: redefinition of 'dwarf_whatform'
[build] dwarf_whatform (Dwarf_Attribute *attr)
[build] ^
[build] C:\work\xemu\elfutils\libdw/libdw.h(1110,1): note: previous definition is here
[build] dwarf_whatform (Dwarf_Attribute *attr)
[build] ^
[build] 1 error generated.

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

diff --git a/libdw/dwarf_whatattr.c b/libdw/dwarf_whatattr.c
index d664b021..01d92307 100644
--- a/libdw/dwarf_whatattr.c
+++ b/libdw/dwarf_whatattr.c
@@ -30,13 +30,12 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#ifndef __OPTIMIZE__
+#define __OPTIMIZE__
+#endif
 #include <dwarf.h>
 #include "libdwP.h"
 
 
 unsigned int
-dwarf_whatattr (Dwarf_Attribute *attr)
-{
-  return attr == NULL ? 0 : attr->code;
-}
+dwarf_whatattr (Dwarf_Attribute *attr);
diff --git a/libdw/dwarf_whatform.c b/libdw/dwarf_whatform.c
index dee29a9f..9b3e41e6 100644
--- a/libdw/dwarf_whatform.c
+++ b/libdw/dwarf_whatform.c
@@ -30,13 +30,12 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#ifndef __OPTIMIZE__
+#define __OPTIMIZE__
+#endif
 #include <dwarf.h>
 #include "libdwP.h"
 
 
 unsigned int
-dwarf_whatform (Dwarf_Attribute *attr)
-{
-  return attr == NULL ? 0 : attr->form;
-}
+dwarf_whatform (Dwarf_Attribute *attr);
\ No newline at end of file
-- 
2.36.1.windows.1


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

* [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (6 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-02-23 12:31   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 09/16] 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)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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  | 16 +++++++++++++++-
 lib/system.h |  4 +---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/error.c b/lib/error.c
index 5186fc15..d4cbf0ff 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,17 @@ void error(int status, int errnum, const char *format, ...) {
       else
         vwarnx (format, argp);
     }
+#else
+  if (errnum)
+    {
+      errno = errnum;
+    }
+  vfprintf(stderr, format, argp);
+  if (status)
+    {
+      _exit(status);
+    }
+#endif
   va_end(argp);
 
   fflush (stderr);
diff --git a/lib/system.h b/lib/system.h
index 561d3e03..7f9f2a91 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -50,11 +50,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] 33+ messages in thread

* [PATCH v2 09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (7 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-03-02 13:24   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 10/16] libasm: stdio_ext.h are not present " Yonggang Luo
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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] 33+ messages in thread

* [PATCH v2 10/16] libasm: stdio_ext.h are not present on win32
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (8 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-02-23 12:35   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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] 33+ messages in thread

* [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (9 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 10/16] libasm: stdio_ext.h are not present " Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-03-02 13:32   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
                   ` (4 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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] 33+ messages in thread

* [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (10 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2022-12-21 18:16   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 13/16] lib: isatty is not available on windows Yonggang Luo
                   ` (3 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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 8873fcc8..7a67a440 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1708,9 +1708,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] 33+ messages in thread

* [PATCH v2 13/16] lib: isatty is not available on windows
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (11 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2022-12-19 12:32   ` 罗勇刚(Yonggang Luo)
  2022-12-17 16:52 ` [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 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] 33+ messages in thread

* [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE)
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (12 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 13/16] lib: isatty is not available on windows Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2023-03-02 16:33   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
  2022-12-17 16:52 ` [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h> Yonggang Luo
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 lib/Makefile.am                |  2 +-
 lib/crc32_file.c               |  2 +-
 lib/system.c                   | 48 ++++++++++++++++++++++++++++++++++
 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 +-
 12 files changed, 61 insertions(+), 10 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/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
new file mode 100644
index 00000000..bd3831f5
--- /dev/null
+++ b/lib/system.c
@@ -0,0 +1,48 @@
+/* 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 <errno.h>
+
+#include "system.h"
+#if defined(_WIN32)
+#include <windows.h>
+#endif
+
+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 7f9f2a91..c84c416c 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -200,6 +200,9 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
   return recvd;
 }
 
+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] 33+ messages in thread

* [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (13 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2022-12-21 22:29   ` Mark Wielaard
  2022-12-17 16:52 ` [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h> Yonggang Luo
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libelf/elf_begin.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 6d31882e..3d324694 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -1163,12 +1163,19 @@ 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;
     }
+#else
+  else if (fildes < 0)
+    {
+      return NULL;
+    }
+#endif
 
   switch (cmd)
     {
-- 
2.36.1.windows.1


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

* [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h>
  2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
                   ` (14 preceding siblings ...)
  2022-12-17 16:52 ` [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
@ 2022-12-17 16:52 ` Yonggang Luo
  2022-12-21 23:07   ` Mark Wielaard
  15 siblings, 1 reply; 33+ messages in thread
From: Yonggang Luo @ 2022-12-17 16:52 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Yonggang Luo

MSVC doesn't have libintl.h, so use macro to guard it.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 configure.ac    | 2 ++
 lib/eu-config.h | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/configure.ac b/configure.ac
index b84623fe..aea12be3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -441,6 +441,8 @@ AC_CHECK_FUNCS([process_vm_readv mremap])
 AS_IF([test "x$ac_cv_func_mremap" = "xno"],
       [AC_MSG_WARN([elf_update needs mremap to support ELF_C_RDWR_MMAP])])
 
+AC_CHECK_HEADERS([libintl.h])
+
 AC_CHECK_HEADERS([error.h])
 AC_CHECK_HEADERS([err.h])
 
diff --git a/lib/eu-config.h b/lib/eu-config.h
index 78a5c4fe..72b7793e 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(HAVE_LIBINTL_H)
 #include <libintl.h>
+#endif
+
 /* gettext helper macros.  */
 #define N_(Str) Str
+#if defined(HAVE_LIBINTL_H)
 #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] 33+ messages in thread

* Re: [PATCH v2 13/16] lib: isatty is not available on windows
  2022-12-17 16:52 ` [PATCH v2 13/16] lib: isatty is not available on windows Yonggang Luo
@ 2022-12-19 12:32   ` 罗勇刚(Yonggang Luo)
  0 siblings, 0 replies; 33+ messages in thread
From: 罗勇刚(Yonggang Luo) @ 2022-12-19 12:32 UTC (permalink / raw)
  To: elfutils-devel

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

It's because lack  STDOUT_FILENO, so this patch can be dropped

On Sun, Dec 18, 2022 at 12:52 AM Yonggang Luo <luoyonggang@gmail.com> wrote:
>
> 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
>


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

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

* Re: [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum
  2022-12-17 16:52 ` [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum Yonggang Luo
@ 2022-12-21 17:56   ` Mark Wielaard
  2023-02-23 11:50     ` Mark Wielaard
  0 siblings, 1 reply; 33+ messages in thread
From: Mark Wielaard @ 2022-12-21 17:56 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  libcpu/Makefile.am   |  2 +-
>  libcpu/i386_disasm.c | 14 +-------------
>  libcpu/i386_mne.h    | 36 ++++++++++++++++++++++++++++++++++++
>  libcpu/i386_parse.y  |  9 +++------
>  4 files changed, 41 insertions(+), 20 deletions(-)
>  create mode 100644 libcpu/i386_mne.h
> 
> 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)

The new i386_mne.h file should be added to noinst_HEADERS (or it won't
be included in a make dist, so make distcheck fails).

> diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
> index 599d1654..c34f03d6 100644
> --- a/libcpu/i386_disasm.c
> +++ b/libcpu/i386_disasm.c
> @@ -46,10 +46,7 @@
>  #define MACHINE_ENCODING LITTLE_ENDIAN
>  #include "memory-access.h"
>  
> -
> -#ifndef MNEFILE
> -# define MNEFILE "i386.mnemonics"
> -#endif
> +#include "i386_mne.h"
>  
>  #define MNESTRFIELD(line) MNESTRFIELD1 (line)
>  #define MNESTRFIELD1(line) str##line
> @@ -71,15 +68,6 @@ static const union mnestr_t
>      }
>    };
>  
> -/* The index can be stored in the instrtab.  */
> -enum
> -  {
> -#define MNE(name) MNE_##name,
> -#include MNEFILE
> -#undef MNE
> -    MNE_INVALID
> -  };
> -
>  static const unsigned short int mneidx[] =
>    {
>  #define MNE(name) \

OK.

> diff --git a/libcpu/i386_mne.h b/libcpu/i386_mne.h
> new file mode 100644
> index 00000000..41dacf61
> --- /dev/null
> +++ b/libcpu/i386_mne.h
> @@ -0,0 +1,36 @@
> +/* Compute hash value for given string according to ELF standard.
> +   Copyright (C) 1995-2015 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it
> and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later
> version.
> +
> +   The GNU C Library 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
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */

That looks like the wrong header.
Just copy the one from i386_disasm.c

> +#ifndef _I386_MNE_H
> +#define _I386_MNE_H	1
> +
> +#ifndef MNEFILE
> +# define MNEFILE "i386.mnemonics"
> +#endif
> +
> +/* The index can be stored in the instrtab.  */
> +enum
> +  {
> +#define MNE(name) MNE_##name,
> +#include MNEFILE
> +#undef MNE
> +    MNE_INVALID,
> +    MNE_COUNT = MNE_INVALID,
> +  };
> +
> +#endif /* i386_mne.h */

OK.

> diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
> index d2236d59..459684c6 100644
> --- a/libcpu/i386_parse.y
> +++ b/libcpu/i386_parse.y
> @@ -46,6 +46,8 @@
>  #include <libeu.h>
>  #include <system.h>
>  
> +#include "i386_mne.h"
> +
>  #define obstack_chunk_alloc xmalloc
>  #define obstack_chunk_free free
>  
> @@ -1107,11 +1109,6 @@ print_op_fct (const void *nodep, VISIT value,
>      }
>  }
>  
> -
> -#if NMNES < 2
> -# error "bogus NMNES value"
> -#endif
> -
>  static void
>  instrtable_out (void)
>  {
> @@ -1123,7 +1120,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)

OK.

Thanks,

Mark

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

* Re: [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc
  2022-12-17 16:52 ` [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
@ 2022-12-21 18:07   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2022-12-21 18:07 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> This block of code can not be removed. As it's contains a goto label
> enomem that been used elsewhere

aha, that certainly explains why gcc gets confused about whether those
variables are used. It is slightly ugly code :{

But added a ChangeLog entry and pushed as attached.

Thanks,

Mark

[-- Attachment #2: Type: text/x-patch, Size: 1393 bytes --]

From 1984819d6ee2dc56583d3f11b9f6e3b2f491f62e Mon Sep 17 00:00:00 2001
From: Yonggang Luo <luoyonggang@gmail.com>
Date: Sun, 18 Dec 2022 00:52:03 +0800
Subject: [PATCH] libcpu: Use __asm instead of asm to mark variables as used

This block of code can not be removed. As it's contains a goto label
enomem that been used elsewhere.

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

diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index bd517b94..6d4b717a 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,3 +1,7 @@
+2022-12-18  Yonggang Luo  <luoyonggang@gmail.com>
+
+	* i386_disasm.c (i386_disasm): Use __asm instead of asm.
+
 2022-12-20  Mark Wielaard  <mark@klomp.org>
 
 	* bpf_disasm.c: Include common.h and libeblP.h.
diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
index c42f8d1c..09946273 100644
--- a/libcpu/i386_disasm.c
+++ b/libcpu/i386_disasm.c
@@ -480,8 +480,8 @@ i386_disasm (Ebl *ebl __attribute__((unused)),
 
 	      /* gcc is not clever enough to see the following variables
 		 are not used uninitialized.  */
-	      asm (""
-		   : "=mr" (opoff), "=mr" (correct_prefix), "=mr" (codep),
+	      __asm (""
+		     : "=mr" (opoff), "=mr" (correct_prefix), "=mr" (codep),
 		     "=mr" (next_curr), "=mr" (len));
 	    }
 
-- 
2.18.4


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

* Re: [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32
  2022-12-17 16:52 ` [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
@ 2022-12-21 18:16   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2022-12-21 18:16 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> index 8873fcc8..7a67a440 100644
> --- a/debuginfod/debuginfod-client.c
> +++ b/debuginfod/debuginfod-client.c
> @@ -1708,9 +1708,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

I don't like the __WIN32 define checks. Is fchmod really not
available?? It seems it is a standard Posix function. Can we have a
configure check for it then?

Thanks,

Mark

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

* Re: [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it
  2022-12-17 16:52 ` [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
@ 2022-12-21 22:29   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2022-12-21 22:29 UTC (permalink / raw)
  To: Yonggang Luo; +Cc: elfutils-devel

Hi,

On Sun, Dec 18, 2022 at 12:52:12AM +0800, Yonggang Luo via Elfutils-devel wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  libelf/elf_begin.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
> index 6d31882e..3d324694 100644
> --- a/libelf/elf_begin.c
> +++ b/libelf/elf_begin.c
> @@ -1163,12 +1163,19 @@ 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;
>      }
> +#else
> +  else if (fildes < 0)
> +    {
> +      return NULL;
> +    }
> +#endif

That new return NULL is missing a __libelf_seterrno.

Cheers,

Mark

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

* Re: [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h>
  2022-12-17 16:52 ` [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h> Yonggang Luo
@ 2022-12-21 23:07   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2022-12-21 23:07 UTC (permalink / raw)
  To: Yonggang Luo; +Cc: elfutils-devel

Hi,

On Sun, Dec 18, 2022 at 12:52:13AM +0800, Yonggang Luo via Elfutils-devel wrote:
> MSVC doesn't have libintl.h, so use macro to guard it.
> 
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  configure.ac    | 2 ++
>  lib/eu-config.h | 7 +++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/configure.ac b/configure.ac
> index b84623fe..aea12be3 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -441,6 +441,8 @@ AC_CHECK_FUNCS([process_vm_readv mremap])
>  AS_IF([test "x$ac_cv_func_mremap" = "xno"],
>        [AC_MSG_WARN([elf_update needs mremap to support ELF_C_RDWR_MMAP])])
>  
> +AC_CHECK_HEADERS([libintl.h])
> +
>  AC_CHECK_HEADERS([error.h])
>  AC_CHECK_HEADERS([err.h])

We already use AM_GNU_GETTEXT. I think that would detect whether there
is gettext/libintl.h support already. Which defines ENABLE_NLS.

> diff --git a/lib/eu-config.h b/lib/eu-config.h
> index 78a5c4fe..72b7793e 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(HAVE_LIBINTL_H)
>  #include <libintl.h>
> +#endif
> +
>  /* gettext helper macros.  */
>  #define N_(Str) Str
> +#if defined(HAVE_LIBINTL_H)
>  #define _(Str) dgettext ("elfutils", Str)
> +#else
> +#define _(Str) N_(Str)
> +#endif

So I think the guard here is should be #if ENABLE_NLS
Also just define _(Str) Str directly instead of going through N_(Str).

Cheers,

Mark

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

* Re: [PATCH v2 02/16] move platform depended include into system.h of libebl
  2022-12-17 16:51 ` [PATCH v2 02/16] move platform depended include into system.h of libebl Yonggang Luo
@ 2023-02-23 10:44   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 10:44 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:51 +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,

See the discussion around v1 of this patch:
https://inbox.sourceware.org/elfutils-devel/19dc6579ce183b63a8956b17611e4a264d745b34.camel@klomp.org/

I have since pushed:

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>

Please adjust your patch accordingly.

Thanks,

Mark

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

* Re: [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h
  2022-12-17 16:52 ` [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
@ 2023-02-23 10:52   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 10:52 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

See also the discussion on v1 of this patch:
https://inbox.sourceware.org/elfutils-devel/f352dba78caee57afc17995f8e36d28ae98afbc0.camel@klomp.org/#r

I think we need to think about what the libelf API looks like without
mmap. In particular I think we need to decide what to do with the
Elf_Cmds:

  ELF_C_READ_MMAP,              /* Read, but mmap the file if possible.  */
  ELF_C_RDWR_MMAP,              /* Read and write, with mmap.  */
  ELF_C_WRITE_MMAP,             /* Write, with mmap.  */
  ELF_C_READ_MMAP_PRIVATE,      /* Read, but memory is writable, results are
                                   not written to the file.  */

Specifically because libdw does reply on some of them.

Thanks,

Mark

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

* Re: [PATCH v2 04/16] Fixes usage of basename about prototype differences
  2022-12-17 16:52 ` [PATCH v2 04/16] Fixes usage of basename about prototype differences Yonggang Luo
@ 2023-02-23 11:00   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 11:00 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> 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;
>  	    }

I think the reason you need these casts is because you are somehow
getting the wrong basename function. We use the GNU one which doesn't
manipulate the given string. See
https://www.man7.org/linux/man-pages/man3/basename.3.html#NOTES

Cheers,

Mark

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

* Re: [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum
  2022-12-21 17:56   ` Mark Wielaard
@ 2023-02-23 11:50     ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 11:50 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

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

Hi,

On Wed, 2022-12-21 at 18:56 +0100, Mark Wielaard wrote:
> On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
> wrote:
> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> > ---
> >  libcpu/Makefile.am   |  2 +-
> >  libcpu/i386_disasm.c | 14 +-------------
> >  libcpu/i386_mne.h    | 36 ++++++++++++++++++++++++++++++++++++
> >  libcpu/i386_parse.y  |  9 +++------
> >  4 files changed, 41 insertions(+), 20 deletions(-)
> >  create mode 100644 libcpu/i386_mne.h
> > 
> > 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)
> 
> The new i386_mne.h file should be added to noinst_HEADERS (or it won't
> be included in a make dist, so make distcheck fails).
> 

I added this. And did a make distcheck to check things work as
intended.

> > diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
> > index 599d1654..c34f03d6 100644
> > --- a/libcpu/i386_disasm.c
> > +++ b/libcpu/i386_disasm.c
> > @@ -46,10 +46,7 @@
> >  #define MACHINE_ENCODING LITTLE_ENDIAN
> >  #include "memory-access.h"
> >  
> > -
> > -#ifndef MNEFILE
> > -# define MNEFILE "i386.mnemonics"
> > -#endif
> > +#include "i386_mne.h"
> >  
> >  #define MNESTRFIELD(line) MNESTRFIELD1 (line)
> >  #define MNESTRFIELD1(line) str##line
> > @@ -71,15 +68,6 @@ static const union mnestr_t
> >      }
> >    };
> >  
> > -/* The index can be stored in the instrtab.  */
> > -enum
> > -  {
> > -#define MNE(name) MNE_##name,
> > -#include MNEFILE
> > -#undef MNE
> > -    MNE_INVALID
> > -  };
> > -
> >  static const unsigned short int mneidx[] =
> >    {
> >  #define MNE(name) \
> 
> OK.
> 
> > diff --git a/libcpu/i386_mne.h b/libcpu/i386_mne.h
> > new file mode 100644
> > index 00000000..41dacf61
> > --- /dev/null
> > +++ b/libcpu/i386_mne.h
> > @@ -0,0 +1,36 @@
> > +/* Compute hash value for given string according to ELF standard.
> > +   Copyright (C) 1995-2015 Free Software Foundation, Inc.
> > +   This file is part of the GNU C Library.
> > +
> > +   The GNU C Library is free software; you can redistribute it
> > and/or
> > +   modify it under the terms of the GNU Lesser General Public
> > +   License as published by the Free Software Foundation; either
> > +   version 2.1 of the License, or (at your option) any later
> > version.
> > +
> > +   The GNU C Library 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
> > +   Lesser General Public License for more details.
> > +
> > +   You should have received a copy of the GNU Lesser General Public
> > +   License along with the GNU C Library; if not, see
> > +   <http://www.gnu.org/licenses/>.  */
> 
> That looks like the wrong header.
> Just copy the one from i386_disasm.c

I fixed the header.

> > +#ifndef _I386_MNE_H
> > +#define _I386_MNE_H	1
> > +
> > +#ifndef MNEFILE
> > +# define MNEFILE "i386.mnemonics"
> > +#endif
> > +
> > +/* The index can be stored in the instrtab.  */
> > +enum
> > +  {
> > +#define MNE(name) MNE_##name,
> > +#include MNEFILE
> > +#undef MNE
> > +    MNE_INVALID,
> > +    MNE_COUNT = MNE_INVALID,
> > +  };
> > +
> > +#endif /* i386_mne.h */
> 
> OK.
> 
> > diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
> > index d2236d59..459684c6 100644
> > --- a/libcpu/i386_parse.y
> > +++ b/libcpu/i386_parse.y
> > @@ -46,6 +46,8 @@
> >  #include <libeu.h>
> >  #include <system.h>
> >  
> > +#include "i386_mne.h"
> > +
> >  #define obstack_chunk_alloc xmalloc
> >  #define obstack_chunk_free free
> >  
> > @@ -1107,11 +1109,6 @@ print_op_fct (const void *nodep, VISIT value,
> >      }
> >  }
> >  
> > -
> > -#if NMNES < 2
> > -# error "bogus NMNES value"
> > -#endif
> > -
> >  static void
> >  instrtable_out (void)
> >  {
> > @@ -1123,7 +1120,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)
> 
> OK.

Pushed with those changes and a ChangeLog entry as attached.

Cheers,

Mark

[-- Attachment #2: 0001-libcpu-Remove-the-need-of-NMNES-by-using-enum.patch --]
[-- Type: text/x-patch, Size: 4994 bytes --]

From 4961f9ae2f11795022166698aa15a15f48ec8c5b Mon Sep 17 00:00:00 2001
From: Yonggang Luo <luoyonggang@gmail.com>
Date: Sun, 18 Dec 2022 00:52:02 +0800
Subject: [PATCH] libcpu: Remove the need of NMNES by using enum

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libcpu/ChangeLog     |  9 +++++++++
 libcpu/Makefile.am   |  3 +--
 libcpu/i386_disasm.c | 14 +-------------
 libcpu/i386_mne.h    | 46 ++++++++++++++++++++++++++++++++++++++++++++
 libcpu/i386_parse.y  |  9 +++------
 5 files changed, 60 insertions(+), 21 deletions(-)
 create mode 100644 libcpu/i386_mne.h

diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index 6d4b717a..d14cd237 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,3 +1,12 @@
+2022-12-18  Yonggang Luo  <luoyonggang@gmail.com>
+
+	* i386_mne.h: New file, extracted from i386_disasm.c.
+	* Makefile.am (noinst_HEADERS): Add i386_mne.h.
+	(i386_parse_CFLAGS): Removed.
+	* i386_disasm.c: Include i386_mne.h.
+	* i386_parse.y: Include i386_mne.h.
+	(instrtable_out): Use MNE_COUNT instead of NMNES.
+
 2022-12-18  Yonggang Luo  <luoyonggang@gmail.com>
 
 	* i386_disasm.c (i386_disasm): Use __asm instead of asm.
diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am
index 57d0a164..4ba1be56 100644
--- a/libcpu/Makefile.am
+++ b/libcpu/Makefile.am
@@ -40,7 +40,7 @@ AM_YFLAGS = -p$(<F:parse.y=)
 
 noinst_LIBRARIES = libcpu.a libcpu_pic.a
 
-noinst_HEADERS = i386_dis.h x86_64_dis.h
+noinst_HEADERS = i386_dis.h i386_mne.h x86_64_dis.h
 
 libcpu_a_SOURCES = i386_disasm.c x86_64_disasm.c bpf_disasm.c riscv_disasm.c
 
@@ -92,7 +92,6 @@ 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_lex.o: i386_parse.h
 i386_gendis_LDADD = $(libeu) -lm $(obstack_LIBS)
 
diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
index 09946273..dec62bfa 100644
--- a/libcpu/i386_disasm.c
+++ b/libcpu/i386_disasm.c
@@ -46,10 +46,7 @@
 #define MACHINE_ENCODING LITTLE_ENDIAN
 #include "memory-access.h"
 
-
-#ifndef MNEFILE
-# define MNEFILE "i386.mnemonics"
-#endif
+#include "i386_mne.h"
 
 #define MNESTRFIELD(line) MNESTRFIELD1 (line)
 #define MNESTRFIELD1(line) str##line
@@ -71,15 +68,6 @@ static const union mnestr_t
     }
   };
 
-/* The index can be stored in the instrtab.  */
-enum
-  {
-#define MNE(name) MNE_##name,
-#include MNEFILE
-#undef MNE
-    MNE_INVALID
-  };
-
 static const unsigned short int mneidx[] =
   {
 #define MNE(name) \
diff --git a/libcpu/i386_mne.h b/libcpu/i386_mne.h
new file mode 100644
index 00000000..d5157515
--- /dev/null
+++ b/libcpu/i386_mne.h
@@ -0,0 +1,46 @@
+/* Disassembler for x86, MNE enums.
+   Copyright (C) 2007, 2008, 2009, 2011 Red Hat, Inc.
+   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/>.  */
+
+#ifndef _I386_MNE_H
+#define _I386_MNE_H	1
+
+#ifndef MNEFILE
+# define MNEFILE "i386.mnemonics"
+#endif
+
+/* The index can be stored in the instrtab.  */
+enum
+  {
+#define MNE(name) MNE_##name,
+#include MNEFILE
+#undef MNE
+    MNE_INVALID,
+    MNE_COUNT = MNE_INVALID,
+  };
+
+#endif /* i386_mne.h */
diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
index d2236d59..459684c6 100644
--- a/libcpu/i386_parse.y
+++ b/libcpu/i386_parse.y
@@ -46,6 +46,8 @@
 #include <libeu.h>
 #include <system.h>
 
+#include "i386_mne.h"
+
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
@@ -1107,11 +1109,6 @@ print_op_fct (const void *nodep, VISIT value,
     }
 }
 
-
-#if NMNES < 2
-# error "bogus NMNES value"
-#endif
-
 static void
 instrtable_out (void)
 {
@@ -1123,7 +1120,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.39.2


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

* Re: [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c
  2022-12-17 16:52 ` [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c Yonggang Luo
@ 2023-02-23 12:25   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 12:25 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> 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. See also the discussion around v1 of
this patch:
https://inbox.sourceware.org/elfutils-devel/0bc05adaf492c5f57b0b45f520be14b78f3fbd53.camel@klomp.org/

Cheers,

Mark

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

* Re: [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H
  2022-12-17 16:52 ` [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
@ 2023-02-23 12:31   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 12:31 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> on win32, there is no err.h

See also the discussion around v1 of this patch, I don't believe this
is a correct implementation of error. In particular it seems to not
print the errno string.
https://inbox.sourceware.org/elfutils-devel/dbcc7e30f35097e8d231e6a0a071a088f98a7d48.camel@klomp.org

Cheers,

Mark

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

* Re: [PATCH v2 10/16] libasm: stdio_ext.h are not present on win32
  2022-12-17 16:52 ` [PATCH v2 10/16] libasm: stdio_ext.h are not present " Yonggang Luo
@ 2023-02-23 12:35   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-02-23 12:35 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> 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
> +

Can we have a configure check instead?

>  #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;

__fsetlocking is used in a lot of other places.

Cheers,

Mark

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

* Re: [PATCH v2 09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32
  2022-12-17 16:52 ` [PATCH v2 09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
@ 2023-03-02 13:24   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-03-02 13:24 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> 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;

uid_t, gid_t and mode_t are all defined by POSIX to be provided through
sys/types.h. Except for defining them as integer types it doesn't
really say how big they are. elf_begin has some macros to handle either
int or long types generically. But ar.c also simply uses uid_t, gid_t
and mode_t. So those should then also be adjusted.

Can't we use some configure check instead?

I am somewhat hesitant to change this because it is in a public header.

Cheers,

Mark

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

* Re: [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h
  2022-12-17 16:52 ` [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
@ 2023-03-02 13:32   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-03-02 13:32 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> 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

Kind of the same comment as for the uid_t, gid_t and mode_t change.
ssize_t and pid_t according to POSIX come from sys/types.h, both signed
and no wider than a long.

libdwelf.h is a public header. libebl.h isn't. But I am not sure these
are the right places to add these typedefs. pid_t and ssize_t are used
all over the place.

Cheers,

Mark 

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

* Re: [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE)
  2022-12-17 16:52 ` [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
@ 2023-03-02 16:33   ` Mark Wielaard
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Wielaard @ 2023-03-02 16:33 UTC (permalink / raw)
  To: Yonggang Luo, elfutils-devel

Hi,

On Sun, 2022-12-18 at 00:52 +0800, Yonggang Luo via Elfutils-devel
wrote:
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  lib/Makefile.am                |  2 +-
>  lib/crc32_file.c               |  2 +-
>  lib/system.c                   | 48 ++++++++++++++++++++++++++++++++++
>  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 +-
>  12 files changed, 61 insertions(+), 10 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/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
> new file mode 100644
> index 00000000..bd3831f5
> --- /dev/null
> +++ b/lib/system.c
> @@ -0,0 +1,48 @@
> +/* 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 <errno.h>
> +
> +#include "system.h"
> +#if defined(_WIN32)
> +#include <windows.h>
> +#endif
> +
> +size_t
> +sys_get_page_size(void)
> +{
> +#ifdef _WIN32
> +  SYSTEM_INFO info;
> +  GetSystemInfo(&info);
> +  return info.dwPageSize;
> +#else
> +  return sysconf (_SC_PAGESIZE);
> +#endif
> +}

I am not against abstracting this, but can we use some configure check
to see how to get the pagesize? I don't really like these #ifdef
_WIN32.

Does your environment provide the getpagesize() function that comes
from SVr4, 4.4BSD, SUSv2 and was part of older POSIX?

Cheers,

Mark

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

end of thread, other threads:[~2023-03-02 16:33 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-17 16:51 [PATCH v2 00/16] Patches for building with mingw/gcc msvc/clang-cl Yonggang Luo
2022-12-17 16:51 ` [PATCH v2 01/16] ignore build directory Yonggang Luo
2022-12-17 16:51 ` [PATCH v2 02/16] move platform depended include into system.h of libebl Yonggang Luo
2023-02-23 10:44   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 03/16] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Yonggang Luo
2023-02-23 10:52   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 04/16] Fixes usage of basename about prototype differences Yonggang Luo
2023-02-23 11:00   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 05/16] libcpu: Remove the need of NMNES by using enum Yonggang Luo
2022-12-21 17:56   ` Mark Wielaard
2023-02-23 11:50     ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 06/16] libcpu: Use __asm instead asm that can be recognized by both clang-cl and gcc Yonggang Luo
2022-12-21 18:07   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 07/16] libdw: Fixes compile of dwarf_whatattr.c and dwarf_whatform.c Yonggang Luo
2023-02-23 12:25   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 08/16] lib: Implement error properly even when not HAVE_ERR_H Yonggang Luo
2023-02-23 12:31   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 09/16] libelf: uid_t, gid_t and mode_t are not comes with msvcrt, so using long/unsigned long instead on win32 Yonggang Luo
2023-03-02 13:24   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 10/16] libasm: stdio_ext.h are not present " Yonggang Luo
2023-02-23 12:35   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 11/16] libebl/libdwelf: define ssize_t and pid_t for MSVC within installed header libdwelf.h and libebl.h Yonggang Luo
2023-03-02 13:32   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 12/16] libasm/debuginfod: fchmod doesn't present on win32 Yonggang Luo
2022-12-21 18:16   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 13/16] lib: isatty is not available on windows Yonggang Luo
2022-12-19 12:32   ` 罗勇刚(Yonggang Luo)
2022-12-17 16:52 ` [PATCH v2 14/16] Add function sys_get_page_size to replace platform dependent sysconf (_SC_PAGESIZE) Yonggang Luo
2023-03-02 16:33   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it Yonggang Luo
2022-12-21 22:29   ` Mark Wielaard
2022-12-17 16:52 ` [PATCH v2 16/16] lib: Use HAVE_LIBINTL_H to guard #include <libintl.h> Yonggang Luo
2022-12-21 23:07   ` Mark Wielaard

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).