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

2022-10-15 Thread Yonggang Luo via Elfutils-devel
All of these files either #include  directly or #include "libelfP.h"
And now "libelfP.h also #include , so the platform depended include
can be moved to system.h safely

Signed-off-by: Yonggang Luo 
---
 lib/system.h  | 11 +++
 libelf/common.h   |  3 ---
 libelf/elf32_checksum.c   |  1 -
 libelf/elf32_getphdr.c|  2 --
 libelf/elf32_getshdr.c|  2 --
 libelf/elf32_updatefile.c |  3 ---
 libelf/elf32_updatenull.c |  2 --
 libelf/elf32_xlatetof.c   |  1 -
 libelf/elf32_xlatetom.c   |  1 -
 libelf/elf_begin.c|  3 ---
 libelf/elf_cntl.c |  2 --
 libelf/elf_compress.c |  2 --
 libelf/elf_end.c  |  1 -
 libelf/elf_getarsym.c |  4 
 libelf/elf_getdata.c  |  2 --
 libelf/elf_getdata_rawchunk.c |  2 --
 libelf/elf_getshdrstrndx.c|  2 --
 libelf/elf_readall.c  |  2 --
 libelf/elf_update.c   |  2 --
 libelf/gelf_xlate.c   |  1 -
 libelf/libelfP.h  |  1 +
 libelf/nlist.c|  1 -
 22 files changed, 8 insertions(+), 43 deletions(-)

diff --git a/lib/system.h b/lib/system.h
index d3f42c91..48004df1 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -35,14 +35,17 @@
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
 
+/* System dependend headers */
+#include 
+#include 
+#include 
+#include 
+#include 
+
 #if defined(HAVE_ERROR_H)
 #include 
 #elif defined(HAVE_ERR_H)
diff --git a/libelf/common.h b/libelf/common.h
index 3718b3fd..4561854f 100644
--- a/libelf/common.h
+++ b/libelf/common.h
@@ -30,9 +30,6 @@
 #ifndef _COMMON_H
 #define _COMMON_H   1
 
-#include 
-#include 
-#include 
 #include 
 #include 
 
diff --git a/libelf/elf32_checksum.c b/libelf/elf32_checksum.c
index c5f27bbe..521668a7 100644
--- a/libelf/elf32_checksum.c
+++ b/libelf/elf32_checksum.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/libelf/elf32_getphdr.c b/libelf/elf32_getphdr.c
index 99b4ac09..4bfca24b 100644
--- a/libelf/elf32_getphdr.c
+++ b/libelf/elf32_getphdr.c
@@ -34,10 +34,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
-#include 
 #include "libelfP.h"
 #include "common.h"
 
diff --git a/libelf/elf32_getshdr.c b/libelf/elf32_getshdr.c
index 237d9122..fc696302 100644
--- a/libelf/elf32_getshdr.c
+++ b/libelf/elf32_getshdr.c
@@ -34,9 +34,7 @@
 #include 
 #include 
 #include 
-#include 
 
-#include 
 #include "libelfP.h"
 #include "common.h"
 
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 1ff58900..46afa1f4 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -37,10 +37,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 
-#include 
 #include "libelfP.h"
 
 
diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
index d0d4d1eb..6c06e5e4 100644
--- a/libelf/elf32_updatenull.c
+++ b/libelf/elf32_updatenull.c
@@ -32,12 +32,10 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
 
-#include 
 #include "libelfP.h"
 #include "elf-knowledge.h"
 
diff --git a/libelf/elf32_xlatetof.c b/libelf/elf32_xlatetof.c
index 082d833f..377659c8 100644
--- a/libelf/elf32_xlatetof.c
+++ b/libelf/elf32_xlatetof.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 
 #include "libelfP.h"
diff --git a/libelf/elf32_xlatetom.c b/libelf/elf32_xlatetom.c
index cb0bb8d5..fa3dc9a7 100644
--- a/libelf/elf32_xlatetom.c
+++ b/libelf/elf32_xlatetom.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 
 #include "libelfP.h"
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 71eb3594..fe8c640a 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -39,11 +39,8 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
-#include 
 #include "libelfP.h"
 #include "common.h"
 
diff --git a/libelf/elf_cntl.c b/libelf/elf_cntl.c
index fd681789..04aa9132 100644
--- a/libelf/elf_cntl.c
+++ b/libelf/elf_cntl.c
@@ -31,8 +31,6 @@
 # include 
 #endif
 
-#include 
-
 #include "libelfP.h"
 
 
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index df0144e8..d7f53af2 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -31,14 +31,12 @@
 #endif
 
 #include 
-#include 
 #include "libelfP.h"
 #include "common.h"
 
 #include 
 #include 
 #include 
-#include 
 #include 
 
 /* Cleanup and return result.  Don't leak memory.  */
diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 160f0b88..5c451f36 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "libelfP.h"
 
diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
index 05ebf6a9..2203521f 100644
--- a/libelf/elf_getarsym.c
+++ b/libelf/elf_getarsym.c
@@ -32,16 +32,12 @@
 #endif
 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 
-#include 
 #include 
 #include "libe

[PATCH v2 0/7] Enable building libelf of elfutils on win32

2022-10-15 Thread Yonggang Luo via Elfutils-devel
After these changes, now libelf can be build with mingw/gcc and msvc/clang

v1 -> v2

Do no modify libebl in commit move platform depended include into system.h of 
libelf
Add commit Move the #include  into eu-config.h to

Yonggang Luo (7):
  Rename 'hello2.spec.' -> 'hello2.spec' 'hello3.spec.' -> 'hello3.spec'
  move platform depended include into system.h of libelf
  Move the #include  into eu-config.h
  lib: Use NOT_HAVE_LIBINTL to guard #include 
  Strip __ prefix from __BYTE_ORDER __LITTLE_ENDIAN and __BIG_ENDIAN
  Fixes building with msvc/clang mingw/gcc
  Add CMake build files

 .gitignore|   1 +
 CMakeLists.txt|  47 +
 configure.ac  |   1 +
 debuginfod/debuginfod.cxx |   1 -
 lib/color.c   |   1 -
 lib/eu-config.h   |   8 +
 lib/printversion.c|   1 -
 lib/system.h  |  74 ++-
 lib/system_win32.c| 162 +++
 lib/xasprintf.c   |   1 -
 lib/xmalloc.c |   1 -
 libasm/asm_end.c  |   1 -
 libasm/asm_error.c|   1 -
 libasm/asm_newscn.c   |   1 -
 libcpu/i386_disasm.c  |   2 +-
 libcpu/i386_lex.l |   1 -
 libcpu/i386_parse.y   |   1 -
 libcpu/memory-access.h|  26 +--
 libcpu/riscv_disasm.c |   2 +-
 libdw/libdwP.h|   1 -
 libdw/memory-access.h |   8 +-
 libdwfl/argp-std.c|   1 -
 libdwfl/dwfl_error.c  |   1 -
 libdwfl/dwfl_segment_report_module.c  |   2 +-
 libebl/libeblP.h  |   1 -
 libelf/CMakeLists.txt | 192 ++
 libelf/common.h   |   5 +-
 libelf/config-cmake/config.h  |  27 +++
 libelf/elf32_checksum.c   |   5 +-
 libelf/elf32_getphdr.c|   2 -
 libelf/elf32_getshdr.c|   2 -
 libelf/elf32_updatefile.c |   6 +-
 libelf/elf32_updatenull.c |   2 -
 libelf/elf32_xlatetof.c   |   5 +-
 libelf/elf32_xlatetom.c   |   1 -
 libelf/elf_begin.c|  10 +-
 libelf/elf_cntl.c |   2 -
 libelf/elf_compress.c |   2 -
 libelf/elf_end.c  |   3 +-
 libelf/elf_error.c|   1 -
 libelf/elf_getarsym.c |  10 +-
 libelf/elf_getdata.c  |   2 -
 libelf/elf_getdata_rawchunk.c |   2 -
 libelf/elf_getshdrstrndx.c|   2 -
 libelf/elf_readall.c  |   2 -
 libelf/elf_update.c   |   7 +-
 libelf/gelf_xlate.c   |   1 -
 libelf/libelf.h   |   6 +
 libelf/libelfP.h  |   5 +
 libelf/nlist.c|   1 -
 lib/xasprintf.c => libelf/win32/ar.h  | 104 +-
 src/addr2line.c   |   1 -
 src/ar.c  |   1 -
 src/arlib-argp.c  |   1 -
 src/arlib.c   |   1 -
 src/arlib.h   |   2 +-
 src/arlib2.c  |   1 -
 src/elfcmp.c  |   1 -
 src/elflint.c |   1 -
 src/findtextrel.c |   1 -
 src/nm.c  |   1 -
 src/objdump.c |   1 -
 src/ranlib.c  |   1 -
 src/readelf.c |   1 -
 src/size.c|   1 -
 src/strings.c |   1 -
 src/strip.c   |   1 -
 src/unstrip.c |   1 -
 tests/Makefile.am |   2 +-
 .../{hello2.spec. => hello2.spec} |   0
 .../{hello3.spec. => hello3.spec} |   0
 71 files changed, 612 insertions(+), 162 deletions(-)
 create mode 100644 CMakeLists.txt
 create mode 100644 lib/system_win32.c
 create mode 100644 libelf/CMakeLists.txt
 create mode 100644 libelf/config-cmake/config.h
 copy lib/xasprintf.c => libelf/win32/ar.h (66%)
 rename tests/debuginfod-rpms/{hello2.spec. => hello2.spec} (100%)
 rename tests/debuginfod-rpms/{hello3.spec. => hello3.spec} (100%)

-- 
2.36.1.windows.1



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

2022-10-15 Thread Yonggang Luo via Elfutils-devel
So we do not need include in each file.
And indeed the macro
#define _(Str) dgettext ("elfutils", Str)
access libintl function dgettext, so it's make more sense
#include  in file eu-config.h

Signed-off-by: Yonggang Luo 
---
 debuginfod/debuginfod.cxx | 1 -
 lib/color.c   | 1 -
 lib/eu-config.h   | 1 +
 lib/printversion.c| 1 -
 lib/xasprintf.c   | 1 -
 lib/xmalloc.c | 1 -
 libasm/asm_end.c  | 1 -
 libasm/asm_error.c| 1 -
 libasm/asm_newscn.c   | 1 -
 libcpu/i386_lex.l | 1 -
 libcpu/i386_parse.y   | 1 -
 libdw/libdwP.h| 1 -
 libdwfl/argp-std.c| 1 -
 libdwfl/dwfl_error.c  | 1 -
 libebl/libeblP.h  | 1 -
 libelf/elf_error.c| 1 -
 src/addr2line.c   | 1 -
 src/ar.c  | 1 -
 src/arlib-argp.c  | 1 -
 src/arlib.c   | 1 -
 src/arlib2.c  | 1 -
 src/elfcmp.c  | 1 -
 src/elflint.c | 1 -
 src/findtextrel.c | 1 -
 src/nm.c  | 1 -
 src/objdump.c | 1 -
 src/ranlib.c  | 1 -
 src/readelf.c | 1 -
 src/size.c| 1 -
 src/strings.c | 1 -
 src/strip.c   | 1 -
 src/unstrip.c | 1 -
 32 files changed, 1 insertion(+), 31 deletions(-)

diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 000a41c4..8e7ee499 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -47,7 +47,6 @@ extern "C" {
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/lib/color.c b/lib/color.c
index e43b6143..bd105ec2 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/lib/eu-config.h b/lib/eu-config.h
index c7d7cbb2..78a5c4fe 100644
--- a/lib/eu-config.h
+++ b/lib/eu-config.h
@@ -52,6 +52,7 @@
 # define rwlock_unlock(lock) ((void) (lock))
 #endif /* USE_LOCKS */
 
+#include 
 /* gettext helper macros.  */
 #define N_(Str) Str
 #define _(Str) dgettext ("elfutils", Str)
diff --git a/lib/printversion.c b/lib/printversion.c
index f657329c..7d31fa83 100644
--- a/lib/printversion.c
+++ b/lib/printversion.c
@@ -30,7 +30,6 @@
 # include 
 #endif
 
-#include 
 #include "printversion.h"
 
 void
diff --git a/lib/xasprintf.c b/lib/xasprintf.c
index 179ea2e8..d61fad90 100644
--- a/lib/xasprintf.c
+++ b/lib/xasprintf.c
@@ -33,7 +33,6 @@
 #include 
 #include 
 #include 
-#include 
 #include "libeu.h"
 #include "system.h"
 
diff --git a/lib/xmalloc.c b/lib/xmalloc.c
index 7c094985..de7211f1 100644
--- a/lib/xmalloc.c
+++ b/lib/xmalloc.c
@@ -30,7 +30,6 @@
 # include 
 #endif
 
-#include 
 #include 
 #include 
 #include 
diff --git a/libasm/asm_end.c b/libasm/asm_end.c
index 077d2aa5..a26120f2 100644
--- a/libasm/asm_end.c
+++ b/libasm/asm_end.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/libasm/asm_error.c b/libasm/asm_error.c
index cc3e660b..2b769395 100644
--- a/libasm/asm_error.c
+++ b/libasm/asm_error.c
@@ -31,7 +31,6 @@
 # include 
 #endif
 
-#include 
 #include 
 #include 
 
diff --git a/libasm/asm_newscn.c b/libasm/asm_newscn.c
index 1150015f..d258d969 100644
--- a/libasm/asm_newscn.c
+++ b/libasm/asm_newscn.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/libcpu/i386_lex.l b/libcpu/i386_lex.l
index b6ec0f87..9b33ed95 100644
--- a/libcpu/i386_lex.l
+++ b/libcpu/i386_lex.l
@@ -31,7 +31,6 @@
 #endif
 
 #include 
-#include 
 
 #include 
 #include "system.h"
diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y
index 9a92c2e0..d2236d59 100644
--- a/libcpu/i386_parse.y
+++ b/libcpu/i386_parse.y
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index 56b388c1..961fa4e7 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -29,7 +29,6 @@
 #ifndef _LIBDWP_H
 #define _LIBDWP_H 1
 
-#include 
 #include 
 #include 
 
diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 01ec18e2..bc013aa0 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
index a5c683a9..43fa1dcc 100644
--- a/libdwfl/dwfl_error.c
+++ b/libdwfl/dwfl_error.c
@@ -31,7 +31,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/libebl/libeblP.h b/libebl/libeblP.h
index fa1c2c9f..c408ed97 100644
--- a/libebl/libeblP.h
+++ b/libebl/libeblP.h
@@ -32,7 +32,6 @@
 #include 
 #include 
 #include 
-#include 
 
 
 /* Backend handle.  */
diff --git a/libelf/elf_error.c b/libelf/elf_error.c
index 5364e685..e596108d 100644
--- a/libelf/elf_error.c
+++ b/libelf/elf_error.c
@@ -32,7 +32,6 @@
 #endif
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/src/addr2line.c b/src/addr2line.c
index 25db2926..7768b2

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

2022-10-15 Thread Yonggang Luo via Elfutils-devel
Add NOT_HAVE_LIBINTL macro to disable internationalization,
sometimes we have don't want access internationalization such as MSVC,
so the macro NOT_HAVE_LIBINTL can help that.

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

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



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

2022-10-15 Thread Yonggang Luo
OK, updated in v2

On Sat, Oct 15, 2022 at 5:16 AM Mark Wielaard  wrote:
>
> On Tue, Sep 20, 2022 at 04:43:02PM +0800, Yonggang Luo via Elfutils-devel
wrote:
> > All of these files either #include  directly or #include
"libelfP.h"
> > And now "libelfP.h also #include , so the platform depended
include
> > can be moved to system.h safely
>
> I like this in theory since it cleans up some of the includes.
> But it doesn't work as is.
>
> libebl/eblobjnotetypename.c only included system.h so now doesn't
> compile anymore.  And libintl.h is removed from libelf/elf_error.c
> which really is necessary.
>
> Cheers,
>
> Mark



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