Fix build and tests on non-Linux (Hurd)

Pino Toscano toscano.pino at tiscali.it
Sat Jun 27 07:36:24 UTC 2015


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Reduce-scope-of-some-includes.patch
Type: text/x-patch
Size: 3158 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/elfutils-devel/attachments/20150627/adda3569/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-tests-Mark-an-unused-argument-as-such.patch
Type: text/x-patch
Size: 1181 bytes
Desc: not available
URL: <https://lists.fedorahosted.org/pipermail/elfutils-devel/attachments/20150627/adda3569/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 811 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.fedorahosted.org/pipermail/elfutils-devel/attachments/20150627/adda3569/attachment.sig>


More information about the elfutils-devel mailing list