Re: [RFC] libdw: prepend current directory in read_srclines

2017-05-03 Thread Torsten Polle
Hi Mark,

> Am 29.03.2017 um 22:15 schrieb Torsten Polle :
> 
> Hi Mark,
> 
>> Am 27.03.2017 um 22:45 schrieb Mark Wielaard :
>> 
>> Hi Torsten,
>> 
>> On Sun, Mar 26, 2017 at 08:35:50PM +0200, Torsten Polle wrote:
>>> I observed that readelf and elfutils sometimes report different results.
>> 
>> Do you have an example of this? It would be good to have a testcase.
>> 
>>> PFA a patch that corrects this. I’m not sure whether the way I tackled
>>> the problem is acceptable.
>> 
>> I see why you are proposing this. The DWARF spec does say about the
>> include_directories "Each path entry is either a full path name or is
>> relative to the current directory of the compilation". So your patch
>> does make sense.
>> 
>> But it does depend on what users of dwarf_getsrclines expect.
>> Or any use of Dwarf_Line/Dwarf_Files. I think those users expect that
>> the returned file names can be relative. And that they should make them
>> absolute using index zero or the comp_dir themselves.
>> 
>> So if you do have an example where the expected output isn't what you
>> believe it should be we should examine if there is some other way to
>> do the right thing.
>> 
>> Cheers,
>> Mark
> 
> thanks for the answer. I’ll come back with an example, which is SystemTap 
> based. :-)
> 
> Please allow for some delay. I expect to provide an example in about two 
> weeks.
> 
> Regards,
> Torsten

Sorry for coming back so late. Please find attached my reproduction.

I compile the simple program relative.c:

int main()
{
  return 0;
}

with the command "gcc -g ../2017-05-03-elfutils/relative.c -o relative“.

When I run systemtap with the command
/opt/tooling/adit/systemtap/bin/stap -g -a i386 -B 
CROSS_COMPILE=i586-poky-linux- -r 
/home/polle/work/build/poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.8.12+gitAUTOINC+926c93ae07_021b4aef55-r0/build
 
--sysroot=/home/polle/work/build/poky/build/tmp/work/qemux86-poky-linux/core-image-sato/1.0-r0/rootfs
 -L 'process("/bin/relative").function("main").call‘

I get the following output:
process("/bin/relative").function("main@../2017-05-03-elfutils/relative.c:1").call

But running nm returns the following.
nm -l | grep relative
080483eb T main 
/home/polle/work/issues/2017-05-03-elfutils/../2017-05-03-elfutils/relative.c:1

I hope this helps.

Kind Regards,
Torsten

[PATCH] Add replacement endian.h and byteswap.h to libgnu

2017-05-03 Thread Ulf Hermann
Some systems don't provide endian.h and byteswap.h. The required
functions are trivial to define using sys/param.h and gcc builtins,
though.

Also, include endian.h in dwelf_scn_gnu_compressed_size.c as that uses
be64toh().

Signed-off-by: Ulf Hermann 
---
 ChangeLog|  4 ++
 configure.ac |  6 +++
 libdwelf/ChangeLog   |  4 ++
 libdwelf/dwelf_scn_gnu_compressed_size.c |  1 +
 libgnu/ChangeLog |  6 +++
 libgnu/Makefile.am   | 17 +++-
 libgnu/byteswap.in.h | 38 
 libgnu/endian.in.h   | 75 
 8 files changed, 150 insertions(+), 1 deletion(-)
 create mode 100644 libgnu/ChangeLog
 create mode 100644 libgnu/byteswap.in.h
 create mode 100644 libgnu/endian.in.h

diff --git a/ChangeLog b/ChangeLog
index d43eeb6..01f3197 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-03  Ulf Hermann  
+
+   * configure.ac: Check if endian.h and byteswap.h are available.
+
 2017-04-28  Ulf Hermann  
 
* configure.ac: Determine the binary format we're building natively.
diff --git a/configure.ac b/configure.ac
index a854013..1e6c844 100644
--- a/configure.ac
+++ b/configure.ac
@@ -544,6 +544,12 @@ else
 fi
 AC_SUBST([intl_LDADD])
 
+AC_CHECK_DECLS([BYTE_ORDER], [], [], [[#include ]])
+AM_CONDITIONAL(HAVE_ENDIAN_H, [test "x$ac_cv_have_decl_BYTE_ORDER" = "xyes"])
+
+AC_CHECK_DECLS([bswap_32], [], [], [[#include ]])
+AM_CONDITIONAL(HAVE_BYTESWAP_H, [test "x$ac_cv_have_decl_bswap_32" = "xyes"])
+
 dnl Check if we have  for EM_BPF disassembly.
 AC_CHECK_HEADERS(linux/bpf.h)
 AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"])
diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index a332655..29af410 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-03  Ulf Hermann  
+
+   * dwelf_scn_gnu_compressed_size.c: Include endian.h.
+
 2015-10-11  Akihiko Odaki  
 
* dwelf_strtab.c: Remove sys/param.h include.
diff --git a/libdwelf/dwelf_scn_gnu_compressed_size.c 
b/libdwelf/dwelf_scn_gnu_compressed_size.c
index d39b702..6bad8af 100644
--- a/libdwelf/dwelf_scn_gnu_compressed_size.c
+++ b/libdwelf/dwelf_scn_gnu_compressed_size.c
@@ -30,6 +30,7 @@
 # include 
 #endif
 
+#include 
 #include "libdwelfP.h"
 #include "libelfP.h"
 
diff --git a/libgnu/ChangeLog b/libgnu/ChangeLog
new file mode 100644
index 000..ca38be2
--- /dev/null
+++ b/libgnu/ChangeLog
@@ -0,0 +1,6 @@
+2017-05-03  Ulf Hermann  
+
+   * Makefile.am: Make endian.h and byteswap.h available if they don't
+   exist.
+   * byteswap.in.h: New file.
+   * endian.in.h: New file.
diff --git a/libgnu/Makefile.am b/libgnu/Makefile.am
index 0d31e69..37fdb9c 100644
--- a/libgnu/Makefile.am
+++ b/libgnu/Makefile.am
@@ -35,7 +35,22 @@ noinst_LIBRARIES =
 MOSTLYCLEANFILES =
 MOSTLYCLEANDIRS =
 BUILT_SOURCES =
-EXTRA_DIST =
+EXTRA_DIST = endian.in.h byteswap.in.h
 CLEANFILES =
 SUFFIXES =
+
+if !HAVE_ENDIAN_H
+endian.h: endian.in.h
+   $(AM_V_GEN)rm -f $@ && cat $< > $@
+BUILT_SOURCES += endian.h
+MOSTLYCLEANFILES += endian.h
+endif
+
+if !HAVE_BYTESWAP_H
+byteswap.h: byteswap.in.h
+   $(AM_V_GEN)rm -f $@ && cat $< > $@
+BUILT_SOURCES += byteswap.h
+MOSTLYCLEANFILES += byteswap.h
+endif
+
 include gnulib.am
diff --git a/libgnu/byteswap.in.h b/libgnu/byteswap.in.h
new file mode 100644
index 000..e7b4f29
--- /dev/null
+++ b/libgnu/byteswap.in.h
@@ -0,0 +1,38 @@
+/* Byteswapping functions for windows
+   Copyright (C) 2017 The Qt Company Ltd.
+   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 .  */
+
+#ifndef LIB_BYTESWAP_H
+#define LIB_BYTESWAP_H 1
+
+#include 
+
+#define bswap_16(x) __builtin_bswap16(x)
+#define bswap_32(x) __builtin_bswap32(x)
+#define bswap_64(x) __builtin_bswap64(x)
+
+#endif
diff --git a/libgnu/endian.in.h 

[PATCH] If f(un)lockfile is unavailable define it away

2017-05-03 Thread Ulf Hermann
Sometimes _POSIX_THREAD_SAFE_FUNCTIONS is still set in this case, which
in turn leads to build problems in getopt.c (which would define the
functions to nop anyway if it knew they aren't present).

Signed-off-by: Ulf Hermann 
---
 lib/ChangeLog   | 5 +
 lib/eu-config.h | 7 +++
 2 files changed, 12 insertions(+)

diff --git a/lib/ChangeLog b/lib/ChangeLog
index ecc6179..58ee43f 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-03  Ulf Hermann  
+
+   * eu-config.h: Define flockfile and funlockfile away if gnulib hasn't
+   detected them.
+
 2017-04-27  Ulf Hermann  
 
* eu-config.h: Define attribute_hidden to be empty if the compiler
diff --git a/lib/eu-config.h b/lib/eu-config.h
index 135803e..e69b213 100644
--- a/lib/eu-config.h
+++ b/lib/eu-config.h
@@ -198,5 +198,12 @@ asm (".section predict_data, \"aw\"; .previous\n"
 # define COMPAT_VERSION(name, version, prefix) error "should use #ifdef 
SYMBOL_VERSIONING"
 #endif
 
+#if !HAVE_FLOCKFILE
+# define flockfile(fp) /* nop */
+#endif
+
+#if !HAVE_FUNLOCKFILE
+# define funlockfile(fp) /* nop */
+#endif
 
 #endif /* eu-config.h */
-- 
2.1.4



[PATCH v2] Detect if symbol versioning is supported (was "Disable symbol versioning if .symver doesn't work")

2017-05-03 Thread Ulf Hermann
If not, throw an error unless symbol versioning was explicitly
disabled.

Signed-off-by: Ulf Hermann 
---
 ChangeLog|  4 
 configure.ac | 15 +++
 2 files changed, 19 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 01f88f3..22c46c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-03  Ulf Hermann  
+
+   * configure.ac: Test if symbol versioning is supported.
+
 2017-04-27  Ulf Hermann  
 
* configure.ac: Check if the compiler supports
diff --git a/configure.ac b/configure.ac
index 0266a36..48b06de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -376,6 +376,21 @@ AS_IF([test "x$enable_textrelcheck" != "xno"],
 AC_ARG_ENABLE([symbol-versioning],
 AS_HELP_STRING([--disable-symbol-versioning],
[Disable symbol versioning in shared objects]))
+
+AC_CACHE_CHECK([whether symbol versioning is supported], 
ac_cv_symbol_versioning, [dnl
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+#define NEW_VERSION(name, version) \
+  asm (".symver " #name "," #name "@@@" #version);
+int foo(int x) { return x + 1; }
+NEW_VERSION (foo, ELFUTILS_12.12)
+])], ac_cv_symbol_versioning=yes, ac_cv_symbol_versioning=no)])
+if test "$ac_cv_symbol_versioning" = "no"; then
+if test "x$enable_symbol_versioning" != "xno"; then
+AC_MSG_ERROR([Symbol versioning is not supported.
+  Use --disable-symbol-versioning to build without.])
+fi
+fi
+
 AM_CONDITIONAL(SYMBOL_VERSIONING, [test "x$enable_symbol_versioning" != "xno"])
 AS_IF([test "x$enable_symbol_versioning" = "xno"],
   [AC_MSG_WARN([Disabling symbol versioning breaks ABI compatibility.])
-- 
2.1.4



Re: pending patches

2017-05-03 Thread Ulf Hermann
> - Check for -z,defs, -z,relro, -fPIC, -fPIE before using them
>   There are actually two versions, I haven't looked yet how they differ.
> - Check if gcc complains about __attribute__ (visibility(..))
> - Disable symbol versioning if .symver doesn't work
> - Check if rpath is supported before setting it
> 
> In all of the above cases checking for support is a good thing.
> But I am a little hesitant about automatically disabling support.
> For example our binary compatibility depends on having symbol versioning
> support. It seems bad to "silently" break that. And without rpath
> support backends aren't found and stuff will mysteriously break. So I
> think I prefer configure to error out and have an explicit override
> option someone would have to use indicating they are building a broken
> elfutils.

That can be done. I will post new versions of the patches to add a configure 
switch.

My problem right now is that I have about 50 more patches pending locally and I 
will be gone from May 12th to sometime in August. So, I probably won't manage 
to post and fix all of them here before autumn. Yet, I still need them for the 
Qt Creator (and perfparser) 4.4 release, for which the feature freeze will 
happen when I'm gone.

To deal with this, right now I have a fork of elfutils at 
http://code.qt.io/cgit/qt-creator/elfutils.git/ which receives the patches 
before they get here. This is not great and I want to merge it eventually, but 
I can't clone myself.

> - Check if we need -lintl for linking gettext
>   This looks OK, but I don't know much about gettext support.

It's just that mingw doesn't really have a libc and msvcrt.dll doesn't have 
gettext. So we need to link libintl.a or libintl.dll (as provided by mingw) 
separately.

> - Generalize library names
>   This looks like a nice cleanup, but I don't know anything about how
>   non-gnu/linux systems do library sonames (I also use a local hack
>   sometimes to explicitly set a different version that I should upstream
>   myself).

Well, not at all. It's called dll hell :(. The patch provides binaries with the 
version encoded into the file name, which can make things somewhat better. 
However, as dw.dll (and dw1.dll and dw-0.168.dll) link against plain elf.dll, 
extra hackery is required if you want to use the files with versions encoded. 
Also you cannot do "-lelf" then, but rather "-lelf1".

Ulf


pending patches

2017-05-03 Thread Mark Wielaard
Hi Ulf,

Here are some short comments on the pending patches that I would like to
deal with after the 0.169 release. I believe what we have now on master
is a good set of fixes that look OK on Fedora 25/RHEL7 x86_64. I'll run
some tests on other distros and supported Fedora/RHEL architectures in
the next days. And if no show-stoppers pop up I'll like to do a release
on Friday. Then next week we return to these patches.

- Add gnulub modules to replace missing libc functionality.
  The big one. I am surprised that actually made it to the list.
  I haven't tried it out yet, but it looks basically sane.
  What is missing is a description/script to run for updates.
  I have to add something like that for some other special files
  (elf.h, po files) too so anybody can easily run it before a
  release.

- Drop handrolled or #ifdef'ed libc replacement.
  Right, should go in right after the above.

- Check for -z,defs, -z,relro, -fPIC, -fPIE before using them
  There are actually two versions, I haven't looked yet how they differ.
- Check if gcc complains about __attribute__ (visibility(..))
- Disable symbol versioning if .symver doesn't work
- Check if rpath is supported before setting it

In all of the above cases checking for support is a good thing.
But I am a little hesitant about automatically disabling support.
For example our binary compatibility depends on having symbol versioning
support. It seems bad to "silently" break that. And without rpath
support backends aren't found and stuff will mysteriously break. So I
think I prefer configure to error out and have an explicit override
option someone would have to use indicating they are building a broken
elfutils.

- Check if we need -lintl for linking gettext
  This looks OK, but I don't know much about gettext support.

- Generalize library names
  This looks like a nice cleanup, but I don't know anything about how
  non-gnu/linux systems do library sonames (I also use a local hack
  sometimes to explicitly set a different version that I should upstream
  myself).

- Check native binary format
  Yes, running self-test/checks on non-ELF binaries is not going to
  work.

Cheers,

Mark


[PATCH] Check if gcc supports -rdynamic and don't use it if not

2017-05-03 Thread Ulf Hermann
On some platforms the symbols are automatically exported and -rdynamic 
will produce a warning.

Signed-off-by: Ulf Hermann 
---
 ChangeLog |  4 
 configure.ac  | 11 +++
 tests/ChangeLog   |  5 +
 tests/Makefile.am |  2 +-
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index d43eeb6..eaea959 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-03  Ulf Hermann  
+
+   * configure.ac: Add check for -rdynamic.
+
 2017-04-28  Ulf Hermann  
 
* configure.ac: Determine the binary format we're building natively.
diff --git a/configure.ac b/configure.ac
index 18ef6d6..e45584e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,6 +237,17 @@ fi
 
 AC_SUBST([dso_LDFLAGS])
 
+rdynamic_LDFLAGS="-rdynamic"
+AC_CACHE_CHECK([whether gcc supports $rdynamic_LDFLAGS], ac_cv_rdynamic, [dnl
+save_LDFLAGS="$LDFLAGS"
+LDFLAGS="$rdynamic_LDFLAGS $save_LDFLAGS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_rdynamic=yes, ac_cv_rdynamic=no)
+LDFLAGS="$save_LDFLAGS"
+])
+if test "$ac_cv_rdynamic" = "no"; then
+   rdynamic_LDFLAGS=""
+fi
+
 AC_CACHE_CHECK([for rpath support], ac_cv_rpath, [dnl
 save_LDFLAGS="$LDFLAGS"
 LDFLAGS="$save_LDFLAGS -Wl,--enable-new-dtags,-rpath,/foo/bar"
diff --git a/tests/ChangeLog b/tests/ChangeLog
index ab1a3788..b00c848 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-03  Ulf Hermann  
+
+   * Makefile.am: Skip -rdynamic when compiling deleted-lib.so with a
+   compiler that doesn't support it.
+
 2017-04-28  Ulf Hermann  
 
* run-disasm-x86-64.sh: Disable if the native binary format is not
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 943c694..114ab7a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -520,7 +520,7 @@ endif
 system_elf_libelf_test_LDADD = $(libelf) $(libgnu)
 
 deleted-lib$(LIBEXT): deleted-lib.c $(libgnu)
-   $(AM_V_CCLD)$(COMPILE) $(fpic_CFLAGS) -fasynchronous-unwind-tables 
-shared -rdynamic -o $@ $^
+   $(AM_V_CCLD)$(COMPILE) $(fpic_CFLAGS) -fasynchronous-unwind-tables 
-shared $(rdynamic_LDFLAGS) -o $@ $^
 
 if GCOV
 check: check-am coverage
-- 
2.1.4