On Thu, Apr 20, 2017 at 04:31:02PM +0200, Ulf Hermann wrote:
> config.h doesn't have include guards, so including it twice is bad. We
> deal with this by checking for PACKAGE_NAME, but only in some places.
> Once we start using gnulib, we will need to include config.h before any
> gnulib-generated headers. This is problematic if we include it
> transitively through our own private headers.
> 
> In order to set a clear rule about inclusion of config.h, it is now
> included in every .c file as first header, but not in any header. This
> will definitely avoid double-inclusion and satisfy the condition that it
> has to be included before gnulib headers. It comes at the price of
> adding some redundancy, but there is no clean way to avoid this.
> 
> Signed-off-by: Ulf Hermann <ulf.herm...@qt.io>
> ---
>  lib/ChangeLog                               |  5 +++
>  lib/crc32.c                                 |  4 ++
>  lib/system.h                                |  4 --
>  libdwfl/ChangeLog                           | 58 
> +++++++++++++++++++++++++++++
>  libdwfl/argp-std.c                          |  4 ++
>  libdwfl/cu.c                                |  4 ++
>  libdwfl/derelocate.c                        |  4 ++
>  libdwfl/dwfl_addrdie.c                      |  4 ++
>  libdwfl/dwfl_addrdwarf.c                    |  4 ++
>  libdwfl/dwfl_addrmodule.c                   |  4 ++
>  libdwfl/dwfl_begin.c                        |  4 ++
>  libdwfl/dwfl_build_id_find_debuginfo.c      |  4 ++
>  libdwfl/dwfl_build_id_find_elf.c            |  4 ++
>  libdwfl/dwfl_cumodule.c                     |  4 ++
>  libdwfl/dwfl_dwarf_line.c                   |  4 ++
>  libdwfl/dwfl_end.c                          |  4 ++
>  libdwfl/dwfl_frame.c                        |  4 ++
>  libdwfl/dwfl_frame_regs.c                   |  4 ++
>  libdwfl/dwfl_getdwarf.c                     |  4 ++
>  libdwfl/dwfl_getmodules.c                   |  4 ++
>  libdwfl/dwfl_getsrc.c                       |  4 ++
>  libdwfl/dwfl_getsrclines.c                  |  4 ++
>  libdwfl/dwfl_line_comp_dir.c                |  4 ++
>  libdwfl/dwfl_linecu.c                       |  4 ++
>  libdwfl/dwfl_lineinfo.c                     |  4 ++
>  libdwfl/dwfl_linemodule.c                   |  4 ++
>  libdwfl/dwfl_module.c                       |  4 ++
>  libdwfl/dwfl_module_addrdie.c               |  4 ++
>  libdwfl/dwfl_module_addrname.c              |  4 ++
>  libdwfl/dwfl_module_addrsym.c               |  4 ++
>  libdwfl/dwfl_module_build_id.c              |  4 ++
>  libdwfl/dwfl_module_dwarf_cfi.c             |  4 ++
>  libdwfl/dwfl_module_eh_cfi.c                |  4 ++
>  libdwfl/dwfl_module_getdwarf.c              |  4 ++
>  libdwfl/dwfl_module_getelf.c                |  4 ++
>  libdwfl/dwfl_module_getsrc.c                |  4 ++
>  libdwfl/dwfl_module_getsrc_file.c           |  4 ++
>  libdwfl/dwfl_module_getsym.c                |  4 ++
>  libdwfl/dwfl_module_info.c                  |  4 ++
>  libdwfl/dwfl_module_nextcu.c                |  4 ++
>  libdwfl/dwfl_module_register_names.c        |  4 ++
>  libdwfl/dwfl_module_report_build_id.c       |  4 ++
>  libdwfl/dwfl_module_return_value_location.c |  4 ++
>  libdwfl/dwfl_nextcu.c                       |  4 ++
>  libdwfl/dwfl_onesrcline.c                   |  4 ++
>  libdwfl/dwfl_report_elf.c                   |  4 ++
>  libdwfl/dwfl_validate_address.c             |  4 ++
>  libdwfl/dwfl_version.c                      |  4 ++
>  libdwfl/find-debuginfo.c                    |  4 ++
>  libdwfl/gzip.c                              |  4 ++
>  libdwfl/image-header.c                      |  4 ++
>  libdwfl/libdwflP.h                          |  3 --
>  libdwfl/lines.c                             |  4 ++
>  libdwfl/linux-core-attach.c                 |  4 ++
>  libdwfl/linux-pid-attach.c                  |  4 ++
>  libdwfl/linux-proc-maps.c                   |  4 ++
>  libdwfl/offline.c                           |  4 ++
>  libdwfl/open.c                              |  4 ++
>  libdwfl/relocate.c                          |  4 ++
>  libdwfl/segment.c                           |  4 ++
>  libelf/ChangeLog                            |  4 ++
>  libelf/libelfP.h                            |  4 --
>  62 files changed, 291 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/ChangeLog b/lib/ChangeLog
> index 84290f7..8cac7af 100644
> --- a/lib/ChangeLog
> +++ b/lib/ChangeLog
> @@ -1,3 +1,8 @@
> +2017-04-20  Ulf Hermann  <ulf.herm...@qt.io>
> +
> +     * crc32.c: include config.h.
> +     * system.h: Don't include config.h.
> +
>  2017-02-16  Ulf Hermann  <ulf.herm...@qt.io>
>  
>       * Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c

> diff --git a/lib/crc32.c b/lib/crc32.c
> index 1a76b1b..758602e 100644
> --- a/lib/crc32.c
> +++ b/lib/crc32.c
> @@ -25,6 +25,10 @@
>     the GNU Lesser General Public License along with this program.  If
>     not, see <http://www.gnu.org/licenses/>.  */
>  
> +#if HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
>  #include <stdint.h>
>  #include "system.h"
>  
> diff --git a/lib/system.h b/lib/system.h
> index 2d05702..9203335 100644
> --- a/lib/system.h
> +++ b/lib/system.h
> @@ -29,10 +29,6 @@
>  #ifndef LIB_SYSTEM_H
>  #define LIB_SYSTEM_H 1
>  
> -#ifdef HAVE_CONFIG_H
> -# include <config.h>
> -#endif
> -
>  #include <errno.h>
>  #include <stddef.h>
>  #include <stdint.h>

I've accidentally noticed that this hunk was not correct back in 2017
because "#if HAVE_CONFIG_H" is not the same as "#ifdef HAVE_CONFIG_H".
This was not problematic for elfutils itself because HAVE_CONFIG_H is
always defined.

Note, however, that as a side effect of commit 76c84c137a82 ("handle libc
implementations which do not provide `error.h`") "system.h" now includes
<config.h> unconditionally, essentially reintroducing the original issue
of including config.h twice for all files that include both <config.h>
and "system.h".


-- 
ldv

Reply via email to