Re: Compile elfutils with Clang

2017-09-12 Thread Dmitry Golovin
Hi Ulf,

Forgot to include it. I believe this file was also written by Chih-hung.

Regards,
Dmitry

12.09.2017, 17:32, "Ulf Hermann" :
> Hi Dmitry,
>
> I would love to know how you implemented INLINE_NESTED_FUNC, but 
> nested_func.h seems to be missing from your patch. Can you please double 
> check this?
>
> regards,
> Ulf/* Copyright (C) 2015 Red Hat, Inc.
   This file is part of elfutils.
   Written by Chih-Hung Hsieh , 2015.

   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 _NESTED_FUNC_H
#define _NESTED_FUNC_H 1

#if __clang__

  #define __BLOCK __block

  #define NESTED_FUNC(return_type, function_name, \
  arg_types, arg_types_and_names) \
return_type (^function_name) arg_types = \
^ return_type arg_types_and_names

  /* Clang does not like inline keyword before a block variable. */
  #define INLINE_NESTED_FUNC(r, f, t, a) \
NESTED_FUNC (r, f, t, a)

  #define INLINE_INTUSE_NESTED_FUNC(r, f, t, a) \
NESTED_FUNC (r, INTUSE(f), t, a)

  /* Recrusive blocks need to be declared before used. */
  #define RECURSIVE_NESTED_FUNC(return_type, function_name, \
  arg_types, arg_types_and_names) \
__BLOCK return_type (^function_name) arg_types; \
function_name = ^ return_type arg_types_and_names

  #define INLINE_RECURSIVE_NESTED_FUNC(r, f, t, a) \
RECURSIVE_NESTED_FUNC (r, f, t, a)

  #define INLINE_INTUSE_RECURSIVE_NESTED_FUNC(r, f, t, a) \
RECURSIVE_NESTED_FUNC (r, INTUSE(f), t, a)

#else /* gcc nested function */

  #define __BLOCK

  #define NESTED_FUNC(return_type, function_name, \
  arg_types, arg_types_and_names) \
return_type function_name arg_types_and_names

  #define INLINE_NESTED_FUNC(r, f, t, a) \
inline NESTED_FUNC (r, f, t, a)

  #define INLINE_INTUSE_NESTED_FUNC(r, f, t, a) \
inline NESTED_FUNC (r, INTUSE(f), t, a)

  #define RECURSIVE_NESTED_FUNC(r, f, t, a) \
NESTED_FUNC (r, f, t, a)

  #define INLINE_RECURSIVE_NESTED_FUNC(r, f, t, a) \
inline RECURSIVE_NESTED_FUNC (r, f, t, a)

  #define INLINE_INTUSE_RECURSIVE_NESTED_FUNC(r, f, t, a) \
INLINE_RECURSIVE_NESTED_FUNC (r, INTUSE(f), t, a)

#endif

#endif /* _NESTED_FUNC_H */


Re: Compile elfutils with Clang

2017-09-12 Thread Ulf Hermann
Hi Dmitry,

I would love to know how you implemented INLINE_NESTED_FUNC, but nested_func.h 
seems to be missing from your patch. Can you please double check this?

regards,
Ulf


Re: Compile elfutils with Clang

2017-09-12 Thread Dmitry Golovin
Hi Chih-hung,
 
I have added clang support to elfutils 0.170, the work is mostly based on your 
patches. So I'm attaching it and posting it to the mailing list in case someone 
else wants to compile it with clang.

(sending it again, because the first message was not accepted by the mailing 
list contene filter)
 
Regards,
Dmitry

11.09.2017, 19:34, "Chih-hung Hsieh" :
> Dimitry, I made a few changes to compile some libraries in elfutils that were 
> needed by Android.
> I don't have a separate branch.
>
> On Sat, Sep 9, 2017 at 3:52 AM, Dmitry Golovin  wrote:
>> Hello,
>>
>> I've been trying to compile elfutils with clang for a while now and I'm 
>> wondering maybe someone else is also working on it?
>> I found some useful patches written by Chih-Hung Hsieh, but they seem to be 
>> written over 2 years ago and not maintained.
>> Is there a fork or a branch of elfutils that can be compiled with clang?
>>
>> Regards,
>> Dmitrydiff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 207a257..c3d7f88 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -31,6 +31,7 @@
 #undef	_
 #include "libdwflP.h"
 #include "common.h"
+#include "nested_func.h"
 
 #include 
 #include 
@@ -233,15 +234,18 @@ invalid_elf (Elf *elf, bool disk_file_has_build_id,
 }
 
 int
-dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
-			Dwfl_Memory_Callback *memory_callback,
-			void *memory_callback_arg,
-			Dwfl_Module_Callback *read_eagerly,
-			void *read_eagerly_arg,
-			const void *note_file, size_t note_file_size,
-			const struct r_debug_info *r_debug_info)
+dwfl_segment_report_module (Dwfl *dwfl, int const ndx_in, const char* const name_in,
+			Dwfl_Memory_Callback* const memory_callback,
+			void* const memory_callback_arg,
+			Dwfl_Module_Callback * const read_eagerly,
+			void* const read_eagerly_arg,
+			const void* const note_file, size_t const note_file_size,
+			const struct r_debug_info* const r_debug_info)
 {
-  size_t segment = ndx;
+  __BLOCK int ndx = ndx_in;
+  __BLOCK const char *name = name_in;
+
+  __BLOCK size_t segment = ndx;
 
   if (segment >= dwfl->lookup_elts)
 segment = dwfl->lookup_elts - 1;
@@ -255,34 +259,38 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 if (++segment == dwfl->lookup_elts)
   return 0;
 
-  GElf_Addr start = dwfl->lookup_addr[segment];
+  __BLOCK GElf_Addr start = dwfl->lookup_addr[segment];
 
-  inline bool segment_read (int segndx,
-			void **buffer, size_t *buffer_available,
-			GElf_Addr addr, size_t minread)
+  INLINE_NESTED_FUNC (bool, segment_read,
+  (int , void **, size_t *, GElf_Addr, size_t),
+  (int segndx,
+   void **buffer, size_t *buffer_available,
+   GElf_Addr addr, size_t minread))
   {
 return ! (*memory_callback) (dwfl, segndx, buffer, buffer_available,
  addr, minread, memory_callback_arg);
-  }
+  };
 
-  inline void release_buffer (void **buffer, size_t *buffer_available)
+  INLINE_NESTED_FUNC (void, release_buffer,
+  (void **, size_t *),
+  (void **buffer, size_t *buffer_available))
   {
 if (*buffer != NULL)
   (void) segment_read (-1, buffer, buffer_available, 0, 0);
-  }
+  };
 
   /* First read in the file header and check its sanity.  */
 
-  void *buffer = NULL;
-  size_t buffer_available = INITIAL_READ;
-  Elf *elf = NULL;
-  int fd = -1;
+  __BLOCK void *buffer = NULL;
+  __BLOCK size_t buffer_available = INITIAL_READ;
+  __BLOCK Elf *elf = NULL;
+  __BLOCK int fd = -1;
 
   /* We might have to reserve some memory for the phdrs.  Set to NULL
  here so we can always safely free it.  */
-  void *phdrsp = NULL;
+  __BLOCK void *phdrsp = NULL;
 
-  inline int finish (void)
+  INLINE_NESTED_FUNC (int, finish, (void), (void))
   {
 free (phdrsp);
 release_buffer (, _available);
@@ -291,15 +299,17 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 if (fd != -1)
   close (fd);
 return ndx;
-  }
+  };
 
   if (segment_read (ndx, , _available,
 		start, sizeof (Elf64_Ehdr))
   || memcmp (buffer, ELFMAG, SELFMAG) != 0)
 return finish ();
 
-  inline bool read_portion (void **data, size_t *data_size,
-			GElf_Addr vaddr, size_t filesz)
+  INLINE_NESTED_FUNC (bool, read_portion,
+  (void **, size_t *, GElf_Addr, size_t),
+  (void **data, size_t *data_size,
+   GElf_Addr vaddr, size_t filesz))
   {
 if (vaddr - start + filesz > buffer_available
 	/* If we're in string mode, then don't consider the buffer we have
@@ -317,35 +327,37 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 *data = vaddr - start + buffer;
 *data_size = 0;
 return false;
-  }
+  };
 
-