This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix build and tests on non-Linux (Hurd)


Hi,

I've worked to make elfutils from git be able to build again on
non-Linux OSes, and hopefully have all the tests passing.
My reference OS for this was GNU/Hurd, although most of the problems
and the proposed fixes apply to any other non-Linux OS.

Attached there are git commits for the issues trivial hopefully enough.
For the issues that I'm describing below, I'm happy to provide more
patches, after agreeing on the best way to fix each.

* Build

With the provided commits, most of sources (including tests) build 
again.

The remaining issue is in src/strings.c, the unconditional usage of
MAP_POPULATE. which is Linux-only. A local workaround of defining it
to 0 if not already defined seemed to not cause further issues.

* Tests

Most of the tests pass, and what does not are the following:

| FAIL: run-native-test.sh
| FAIL: dwfl-bug-fd-leak
| SKIP: run-backtrace-native.sh
| SKIP: run-backtrace-data.sh
| SKIP: run-backtrace-dwarf.sh
| SKIP: run-backtrace-native-biarch.sh
| SKIP: run-backtrace-native-core.sh
| SKIP: run-backtrace-native-core-biarch.sh
| SKIP: run-backtrace-core-x86_64.sh
| SKIP: run-backtrace-core-x32.sh
| SKIP: run-backtrace-core-i386.sh
| SKIP: run-backtrace-core-ppc.sh
| SKIP: run-backtrace-core-s390x.sh
| SKIP: run-backtrace-core-s390.sh
| SKIP: run-backtrace-core-aarch64.sh
| FAIL: run-deleted.sh
| SKIP: vdsosyms

The skipped tests look correct though. Let's analyze the failing tests:

| FAIL: run-native-test.sh
| ========================
|
| SRCDIR/tests/allregs: dwfl_module_register_names: no error

allregs relies on the kernel modules handling, which is non-functional
since there are no "kernel modules" on the Hurd (microkernel with
userspace servers). I get a clearer error message about this with:

diff --git a/tests/allregs.c b/tests/allregs.c
index 901d4e8..d3d459e 100644
--- a/tests/allregs.c
+++ b/tests/allregs.c
@@ -158,6 +158,8 @@ main (int argc, char **argv)
   Dwfl_Module *mod = NULL;
   if (dwfl_getmodules (dwfl, &first_module, &mod, 0) < 0)
     error (EXIT_FAILURE, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1));
+  if (mod == NULL)
+    error (EXIT_FAILURE, 0, "dwfl_getmodules: module not found");
 
   if (remaining == argc)
     {

Also, if I comment out the usage of allregs from run-native-test.sh,
the test passes.

| FAIL: dwfl-bug-fd-leak
| ======================
|
| (empty)

This test actually crashes on Hurd, as the dwfl_addrmodule() at
dwfl-bug-fd-leak.c:68 returns null. This is most probably due to our
procfs emulation not showing yet filenames in /proc/$pid/maps files.
At least the patch below avoids the segfault of the test, still leaving
the failure:

diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c
index 170a61a..f992b7a 100644
--- a/tests/dwfl-bug-fd-leak.c
+++ b/tests/dwfl-bug-fd-leak.c
@@ -65,7 +65,10 @@ elfutils_open (pid_t pid, Dwarf_Addr address)
     }
   else
     {
-      Elf *elf = dwfl_module_getelf (dwfl_addrmodule (dwfl, address), 
&bias);
+      Dwfl_Module *module = dwfl_addrmodule (dwfl, address);
+      if (module == NULL)
+       error (2, 0, "dwfl_addrmodule: no module available for 0x%llx", 
address);
+      Elf *elf = dwfl_module_getelf (module, &bias);
       if (elf == NULL)
        error (2, 0, "dwfl_module_getelf: %s", dwfl_errmsg (-1));
     }

| FAIL: run-deleted.sh
| ====================
|
| SRCDIR/src/stack: dwfl_linux_proc_attach pid 1491: Function not 
implemented

This is because dwfl_linux_proc_attach is implemented only on Linux,
returning ENOSYS everywhere else. I made the test skipped with the 
following:

diff --git a/tests/backtrace-subr.sh b/tests/backtrace-subr.sh
index 790b4f4..bb306c0 100644
--- a/tests/backtrace-subr.sh
+++ b/tests/backtrace-subr.sh
@@ -74,6 +74,10 @@ check_unsupported()
     echo >&2 $testname: arch not supported
     exit 77
   fi
+  if grep -q -E ': dwfl_linux_proc_attach pid ([[:digit:]]+): Function 
not implemented$' $err; then
+    echo >&2 $testname: OS not supported
+    exit 77
+  fi
 }
 
 check_native_unsupported()

but I'm not sure that would be the correct way (especially that it
relies on the string representation of ENOSYS).


As said above, I'm available for further patches.

Thanks,
-- 
Pino Toscano
>From 8010c3e5049b955a687cea1316c427730aff435c Mon Sep 17 00:00:00 2001
From: Pino Toscano <toscano.pino@tiscali.it>
Date: Fri, 26 Jun 2015 20:36:01 +0200
Subject: [PATCH] Reduce scope of some includes

Use some includes only according to the #ifdef block of the respective
code, or matching the fact they are Linux-only.  This way, includes
potentially unportable are not unconditionally used.

Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
---
 backends/ChangeLog      | 4 ++++
 backends/i386_initreg.c | 2 +-
 tests/ChangeLog         | 7 +++++++
 tests/backtrace-data.c  | 2 ++
 tests/backtrace.c       | 2 ++
 tests/deleted.c         | 2 ++
 6 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index fe61d9c..c95e80f 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,7 @@
+2015-06-26  Pino Toscano  <toscano.pino@tiscali.it>
+
+	* i386_initreg.c: Reduce scope of some includes to match their usage.
+
 2015-04-28  Mark Wielaard  <mjw@redhat.com>
 
 	* aarch64_reloc.def: Drop "64" from TLS_DTPMOD64, TLS_DTPREL64 and
diff --git a/backends/i386_initreg.c b/backends/i386_initreg.c
index 51fd9ea..c344282 100644
--- a/backends/i386_initreg.c
+++ b/backends/i386_initreg.c
@@ -30,7 +30,7 @@
 # include <config.h>
 #endif
 
-#if defined __i386__ || defined __x86_64__
+#if (defined __i386__ || defined __x86_64__) && defined(__linux__)
 # include <sys/types.h>
 # include <sys/user.h>
 # include <sys/ptrace.h>
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 34f89cc..3a7d312 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2015-06-26  Pino Toscano  <toscano.pino@tiscali.it>
+
+	* tests/backtrace-data.c: Reduce scope of some includes to match their
+	usage.
+	* tests/backtrace.c: Likewise.
+	* tests/deleted.c: Likewise.
+
 2015-06-16  Mark Wielaard  <mjw@redhat.com>
 
 	* run-strip-test.sh: Add strip-in-place (eu-strip without -o) test
diff --git a/tests/backtrace-data.c b/tests/backtrace-data.c
index 5a93a9c..bc5ceba 100644
--- a/tests/backtrace-data.c
+++ b/tests/backtrace-data.c
@@ -30,6 +30,7 @@
 #include <error.h>
 #include <unistd.h>
 #include <dwarf.h>
+#if defined(__x86_64__) && defined(__linux__)
 #include <sys/resource.h>
 #include <sys/ptrace.h>
 #include <signal.h>
@@ -39,6 +40,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include ELFUTILS_HEADER(dwfl)
+#endif
 
 #if !defined(__x86_64__) || !defined(__linux__)
 
diff --git a/tests/backtrace.c b/tests/backtrace.c
index abd56ab..1247643 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -27,6 +27,7 @@
 #include <error.h>
 #include <unistd.h>
 #include <dwarf.h>
+#ifdef __linux__
 #include <sys/resource.h>
 #include <sys/ptrace.h>
 #include <signal.h>
@@ -37,6 +38,7 @@
 #include <string.h>
 #include <argp.h>
 #include ELFUTILS_HEADER(dwfl)
+#endif
 
 #ifndef __linux__
 
diff --git a/tests/deleted.c b/tests/deleted.c
index d071bf7..6be35bc 100644
--- a/tests/deleted.c
+++ b/tests/deleted.c
@@ -23,7 +23,9 @@
 #include <stdio.h>
 #include <error.h>
 #include <errno.h>
+#ifdef __linux__
 #include <sys/prctl.h>
+#endif
 
 extern void libfunc (void);
 
-- 
2.1.4

>From 598a2af3003b131cbaa710f98489e8876d3ed48f Mon Sep 17 00:00:00 2001
From: Pino Toscano <toscano.pino@tiscali.it>
Date: Fri, 26 Jun 2015 20:38:31 +0200
Subject: [PATCH] tests: Mark an unused argument as such

Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
---
 tests/ChangeLog  | 4 ++++
 tests/vdsosyms.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 3a7d312..3461168 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,9 @@
 2015-06-26  Pino Toscano  <toscano.pino@tiscali.it>
 
+	* tests/vdsosyms.c [!__linux__] (main): Mark argv as unused.
+
+2015-06-26  Pino Toscano  <toscano.pino@tiscali.it>
+
 	* tests/backtrace-data.c: Reduce scope of some includes to match their
 	usage.
 	* tests/backtrace.c: Likewise.
diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c
index 4f12b9a..b876c10 100644
--- a/tests/vdsosyms.c
+++ b/tests/vdsosyms.c
@@ -28,7 +28,7 @@
 
 #ifndef __linux__
 int
-main (int argc __attribute__ ((unused)), char **argv)
+main (int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)))
 {
   printf ("Getting the vdso is unsupported.\n");
   return 77;
-- 
2.1.4

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]