From: Akihiko Odaki Date: Tue, 11 Oct 2016 14:06:48 +0000 (+0900) Subject: lib: Provide MAX and MIN in system.h X-Git-Tag: elfutils-0.168~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=60b2bf1b08c621492410b24e469b2bdf58d167d5;p=thirdparty%2Felfutils.git lib: Provide MAX and MIN in system.h This change also creates a new header file libeu.h to provide the prototypes for the function of libeu. That hides the definition of function crc32, which can conflict with zlib, from libelf. It also prevents mistakes to refer those functions from a component which doesn't link with libeu, such as libelf. Signed-off-by: Akihiko Odaki --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 76b5753d7..88c71c9aa 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,17 @@ +2015-10-11 Akihiko Odaki + + * Makefile.am (noinst_HEADERS): Add libeu.h. + * color.c: Remove system.h include, add libeu.h include. + * crc32_file.c: Likewise. + * fixedsizehash.h: Remove sys/param.h include. + * libeu.h: New file. + * system.h: Include sys/param.h. + (xmalloc, xcalloc, xrealloc, xstrdup, xstrndup, crc32, crc32_file, + color_argp, color_enum, color_*): Move definitions to libeu.h. + * xstrdup.c: Remove system.h include, add libeu.h include. + * xstrndup.c: Remove system.h include, add libeu.h and stdint.h + includes. + 2015-09-24 Jose E. Marchesi * Makefile.am (AM_CFLAGS): Use -fPIC instead of -fpic to avoid relocation diff --git a/lib/Makefile.am b/lib/Makefile.am index 2219eaa4e..7ca2bd417 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -37,8 +37,8 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ crc32.c crc32_file.c md5.c sha1.c \ color.c -noinst_HEADERS = fixedsizehash.h system.h dynamicsizehash.h list.h md5.h \ - sha1.h eu-config.h +noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ + md5.h sha1.h eu-config.h EXTRA_DIST = dynamicsizehash.c if !GPROF diff --git a/lib/color.c b/lib/color.c index d1309ed73..fde2d9de2 100644 --- a/lib/color.c +++ b/lib/color.c @@ -37,7 +37,7 @@ #include #include #include -#include "system.h" +#include "libeu.h" /* Prototype for option handler. */ diff --git a/lib/crc32_file.c b/lib/crc32_file.c index c0b18e91d..a8434d428 100644 --- a/lib/crc32_file.c +++ b/lib/crc32_file.c @@ -30,7 +30,7 @@ # include #endif -#include "system.h" +#include "libeu.h" #include #include #include diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h index 06ce6a25a..18921a44b 100644 --- a/lib/fixedsizehash.h +++ b/lib/fixedsizehash.h @@ -31,7 +31,6 @@ #include #include #include -#include #include diff --git a/lib/libeu.h b/lib/libeu.h new file mode 100644 index 000000000..69fe3d7f3 --- /dev/null +++ b/lib/libeu.h @@ -0,0 +1,78 @@ +/* Declarations for the common library. + Copyright (C) 2006-2011 Red Hat, Inc. + 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 LIBEU_H +#define LIBEU_H + +#include +#include + +extern void *xmalloc (size_t) __attribute__ ((__malloc__)); +extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__)); +extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__)); + +extern char *xstrdup (const char *) __attribute__ ((__malloc__)); +extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__)); + + +extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len); +extern int crc32_file (int fd, uint32_t *resp); + + +/* Color handling. */ + +/* Command line parser. */ +extern const struct argp color_argp; + +/* Coloring mode. */ +enum color_enum + { + color_never = 0, + color_always, + color_auto + } __attribute__ ((packed)); +extern enum color_enum color_mode; + +/* Colors to use for the various components. */ +extern char *color_address; +extern char *color_bytes; +extern char *color_mnemonic; +extern char *color_operand1; +extern char *color_operand2; +extern char *color_operand3; +extern char *color_label; +extern char *color_undef; +extern char *color_undef_tls; +extern char *color_undef_weak; +extern char *color_symbol; +extern char *color_tls; +extern char *color_weak; + +extern const char color_off[]; + +#endif diff --git a/lib/system.h b/lib/system.h index f31cfd03e..ec387c31b 100644 --- a/lib/system.h +++ b/lib/system.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -50,16 +51,14 @@ # error "Unknown byte order" #endif -extern void *xmalloc (size_t) __attribute__ ((__malloc__)); -extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__)); -extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__)); - -extern char *xstrdup (const char *) __attribute__ ((__malloc__)); -extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__)); +#ifndef MAX +#define MAX(m, n) ((m) < (n) ? (n) : (m)) +#endif +#ifndef MIN +#define MIN(m, n) ((m) < (n) ? (m) : (n)) +#endif -extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len); -extern int crc32_file (int fd, uint32_t *resp); /* A special gettext function we use if the strings are too short. */ #define sgettext(Str) \ @@ -142,39 +141,6 @@ pread_retry (int fd, void *buf, size_t len, off_t off) extern char *__cxa_demangle (const char *mangled_name, char *output_buffer, size_t *length, int *status); - - -/* Color handling. */ - -/* Command line parser. */ -extern const struct argp color_argp; - -/* Coloring mode. */ -enum color_enum - { - color_never = 0, - color_always, - color_auto - } __attribute__ ((packed)); -extern enum color_enum color_mode; - -/* Colors to use for the various components. */ -extern char *color_address; -extern char *color_bytes; -extern char *color_mnemonic; -extern char *color_operand1; -extern char *color_operand2; -extern char *color_operand3; -extern char *color_label; -extern char *color_undef; -extern char *color_undef_tls; -extern char *color_undef_weak; -extern char *color_symbol; -extern char *color_tls; -extern char *color_weak; - -extern const char color_off[]; - /* A static assertion. This will cause a compile-time error if EXPR, which must be a compile-time constant, is false. */ diff --git a/lib/xstrdup.c b/lib/xstrdup.c index aa10352ac..ff1e3d4f8 100644 --- a/lib/xstrdup.c +++ b/lib/xstrdup.c @@ -31,7 +31,7 @@ #endif #include -#include "system.h" +#include "libeu.h" /* Return a newly allocated copy of STRING. */ diff --git a/lib/xstrndup.c b/lib/xstrndup.c index 92b79c17e..d43e3b9e1 100644 --- a/lib/xstrndup.c +++ b/lib/xstrndup.c @@ -30,8 +30,9 @@ # include #endif +#include #include -#include "system.h" +#include "libeu.h" /* Return a newly allocated copy of STRING. */ diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 4c6cb2869..fe06007e9 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2015-10-11 Akihiko Odaki + + * asm_align.c: Remove sys/param.h include. + 2016-07-08 Mark Wielaard * Makefile.am (AM_CPPFLAGS): Add libdwelf. diff --git a/libasm/asm_align.c b/libasm/asm_align.c index 6631c4d73..e59a070ea 100644 --- a/libasm/asm_align.c +++ b/libasm/asm_align.c @@ -33,7 +33,6 @@ #include #include -#include #include #include diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index 9cce4e726..fff1d96a8 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,9 @@ +2015-10-11 Akihiko Odaki + + * i386_lex.l: Remove system.h include, add libeu.h include. + * i386_parse.y: Remove sys/param.h include, add libeu.h include. + * i386_disasm.c: Remove sys/param.h. + 2016-09-05 Mark Wielaard * bpf_disasm.c: Define BPF_PSEUDO_MAP_FD if undefined. diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c index ceb5164f0..699dd6199 100644 --- a/libcpu/i386_disasm.c +++ b/libcpu/i386_disasm.c @@ -41,7 +41,6 @@ #include #include #include -#include #include "../libebl/libeblP.h" diff --git a/libcpu/i386_lex.l b/libcpu/i386_lex.l index 1e10dd767..ef1b53b68 100644 --- a/libcpu/i386_lex.l +++ b/libcpu/i386_lex.l @@ -34,7 +34,7 @@ #include #include -#include +#include #include "i386_parse.h" diff --git a/libcpu/i386_parse.y b/libcpu/i386_parse.y index 689ba222b..15a72b1f0 100644 --- a/libcpu/i386_parse.y +++ b/libcpu/i386_parse.y @@ -44,8 +44,8 @@ #include #include #include -#include +#include #include #define obstack_chunk_alloc xmalloc diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 8071fc14a..c2f25ea62 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2015-10-11 Akihiko Odaki + + * dwarf_getpubnames.c: Remove sys/param.h include, add system.h. + * libdw_alloc.c: Likewise. + 2016-07-08 Mark Wielaard * libdw.map (ELFUTILS_0.167): New. Add dwelf_strtab_init, diff --git a/libdw/dwarf_getpubnames.c b/libdw/dwarf_getpubnames.c index 462b6ff03..25600f33c 100644 --- a/libdw/dwarf_getpubnames.c +++ b/libdw/dwarf_getpubnames.c @@ -34,10 +34,10 @@ #include #include #include -#include #include #include +#include static int diff --git a/libdw/libdw_alloc.c b/libdw/libdw_alloc.c index a3b7958fb..28a8cf6e4 100644 --- a/libdw/libdw_alloc.c +++ b/libdw/libdw_alloc.c @@ -34,8 +34,8 @@ #include #include #include -#include #include "libdwP.h" +#include "system.h" void * diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog index 4211023c9..a3326556d 100644 --- a/libdwelf/ChangeLog +++ b/libdwelf/ChangeLog @@ -1,3 +1,8 @@ +2015-10-11 Akihiko Odaki + + * dwelf_strtab.c: Remove sys/param.h include. + (MIN): Remove definition. + 2016-07-08 Mark Wielaard * Makefile.am (libdwelf_a_SOURCES): Add dwelf_strtab.c. diff --git a/libdwelf/dwelf_strtab.c b/libdwelf/dwelf_strtab.c index c1b93d4ab..01e091c87 100644 --- a/libdwelf/dwelf_strtab.c +++ b/libdwelf/dwelf_strtab.c @@ -38,15 +38,10 @@ #include #include #include -#include #include "libdwelfP.h" #include -#ifndef MIN -# define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - struct Dwelf_Strent { diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 3332db7ae..27c5d6ef3 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,13 @@ +2015-10-11 Akihiko Odaki + + * core-file.c: Remove sys/param.h. + * dwfl_segment_report_module.c: Likewise. Add system.h include. + (MAX): Remove definition. + * frame_unwind.c: Add system.h include. + (MAX): Remove definition. + * linux-core-attach.c (MIN): Remove definition. + * linux-pid-attach.c (MAX): Likewise. + 2016-08-12 Mark Wielaard * link_map.c (dwfl_link_map_report): Fix assert, set in.d_size. diff --git a/libdwfl/core-file.c b/libdwfl/core-file.c index 67684c9a8..84cb89acc 100644 --- a/libdwfl/core-file.c +++ b/libdwfl/core-file.c @@ -32,7 +32,6 @@ #include "libdwflP.h" #include -#include #include #include #include diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 40553c948..207a2573a 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -35,11 +35,12 @@ #include #include #include -#include #include #include #include +#include + /* A good size for the initial read from memory, if it's not too costly. This more than covers the phdrs and note segment in the average 64-bit @@ -53,10 +54,6 @@ # define MY_ELFDATA ELFDATA2MSB #endif -#ifndef MAX -# define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - /* Return user segment index closest to ADDR but not above it. If NEXT, return the closest to ADDR but not below it. */ diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c index a885446fc..fb42c1a78 100644 --- a/libdwfl/frame_unwind.c +++ b/libdwfl/frame_unwind.c @@ -35,6 +35,7 @@ #include "libdwflP.h" #include "../libdw/dwarf.h" #include +#include /* Maximum number of DWARF expression stack slots before returning an error. */ #define DWARF_EXPR_STACK_MAX 0x100 @@ -43,10 +44,6 @@ error. */ #define DWARF_EXPR_STEPS_MAX 0x1000 -#ifndef MAX -# define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - bool internal_function __libdwfl_frame_reg_get (Dwfl_Frame *state, unsigned regno, Dwarf_Addr *val) diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c index 5a7b3b3da..93d0e46eb 100644 --- a/libdwfl/linux-core-attach.c +++ b/libdwfl/linux-core-attach.c @@ -32,10 +32,6 @@ #include "../libdw/memory-access.h" -#ifndef MIN -# define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif - struct core_arg { Elf *core; diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index c13f2b62a..adfc7f818 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c @@ -37,10 +37,6 @@ #include #include -#ifndef MAX -# define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - #ifdef __linux__ static bool diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 779914460..cf672bf2a 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,11 @@ +2015-10-11 Akihiko Odaki + + * elf32_updatefile.c: Remove sys/param.h include. + * elf32_updatenull.c: Likewise. Add system.h include. + * elf_begin.c: Remove sys/param.h. + * elf_compress: Likewise. Add system.h include. + (MAX): Remove definition. + 2016-08-07 Mark Wielaard * elf_compress.c (__libelf_reset_rawdata): Check scn->flags and diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index d0fabb16c..8dd85d1a8 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "libelfP.h" diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c index 939aa13eb..d83c0b3f0 100644 --- a/libelf/elf32_updatenull.c +++ b/libelf/elf32_updatenull.c @@ -36,8 +36,8 @@ #include #include #include -#include +#include #include "libelfP.h" #include "elf-knowledge.h" diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index 147f5f4b1..8fdb37645 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -40,7 +40,6 @@ #include #include #include -#include #include #include diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c index 3aebe8202..dac0ac6d0 100644 --- a/libelf/elf_compress.c +++ b/libelf/elf_compress.c @@ -31,20 +31,16 @@ #endif #include +#include #include "libelfP.h" #include "common.h" #include #include #include -#include #include #include -#ifndef MAX -# define MAX(a, b) ((a) > (b) ? (a) : (b)) -#endif - /* Cleanup and return result. Don't leak memory. */ static void * do_deflate_cleanup (void *result, z_stream *z, void *out_buf, diff --git a/src/ChangeLog b/src/ChangeLog index 70d11f2ec..68baa2e7f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2015-10-11 Akihiko Odaki + + * arlib.c: Remove system.h include, add libeu.h include. + * arlib2.c: Remove sys/param.h include. + * elfcompress.c: Add libeu.h include. + * elflint.c: Remove sys/param.h include, add libeu.h include. + * nm.c: Likewise. + * objdump.c: Likewise. + * ranlib.c: Likewise. + * readelf.c: Likewise. + * size.c: Remove sys/param.h include. + * strings.c: Likewise, add libeu.h include. + * strip.c: Likewise. + * unstrip.c: Likewise. + 2016-10-06 Mark Wielaard * strip.c (handle_elf): Don't remove real symbols from allocated diff --git a/src/arlib.c b/src/arlib.c index 43a9145b7..c3cf47f84 100644 --- a/src/arlib.c +++ b/src/arlib.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include "arlib.h" diff --git a/src/arlib2.c b/src/arlib2.c index 7998fc6c8..553fc57b9 100644 --- a/src/arlib2.c +++ b/src/arlib2.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "arlib.h" diff --git a/src/elfcompress.c b/src/elfcompress.c index 86cc71654..7392cb763 100644 --- a/src/elfcompress.c +++ b/src/elfcompress.c @@ -34,6 +34,7 @@ #include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(dwelf) #include +#include "libeu.h" #include "system.h" /* Name and version of program. */ diff --git a/src/elflint.c b/src/elflint.c index 8c298c935..8b52ee2b1 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -35,9 +35,9 @@ #include #include #include -#include #include +#include #include #include "../libelf/libelfP.h" #include "../libelf/common.h" diff --git a/src/nm.c b/src/nm.c index 010469daf..37e54bff4 100644 --- a/src/nm.c +++ b/src/nm.c @@ -41,8 +41,8 @@ #include #include #include -#include +#include #include #include "../libebl/libeblP.h" #include "../libdwfl/libdwflP.h" diff --git a/src/objdump.c b/src/objdump.c index 0aa41e89c..1afcd573b 100644 --- a/src/objdump.c +++ b/src/objdump.c @@ -32,8 +32,8 @@ #include #include #include -#include +#include #include #include "../libebl/libeblP.h" diff --git a/src/ranlib.c b/src/ranlib.c index c93c5ac8e..455de0d60 100644 --- a/src/ranlib.c +++ b/src/ranlib.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include diff --git a/src/readelf.c b/src/readelf.c index f1572906b..204aeecb2 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -40,10 +40,10 @@ #include #include #include -#include #include #include +#include #include #include "../libelf/libelfP.h" #include "../libelf/common.h" diff --git a/src/size.c b/src/size.c index 7c03ccef7..b98674ca5 100644 --- a/src/size.c +++ b/src/size.c @@ -34,7 +34,6 @@ #include #include #include -#include #include diff --git a/src/strings.c b/src/strings.c index c1d63cd6f..a4ffcbee9 100644 --- a/src/strings.c +++ b/src/strings.c @@ -38,9 +38,9 @@ #include #include #include -#include #include +#include #include #ifndef MAP_POPULATE diff --git a/src/strip.c b/src/strip.c index 819b67e89..64ef84d37 100644 --- a/src/strip.c +++ b/src/strip.c @@ -36,13 +36,13 @@ #include #include #include -#include #include #include #include #include #include "libdwelf.h" +#include #include typedef uint8_t GElf_Byte; diff --git a/src/unstrip.c b/src/unstrip.c index 467373813..3bf4b192b 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -49,6 +49,7 @@ #include #include #include "libdwelf.h" +#include "libeu.h" #include "system.h" #ifndef _ diff --git a/tests/ChangeLog b/tests/ChangeLog index a0eb4c6ba..31904e768 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2015-10-11 Akihiko Odaki + + * arextract.c: Remove sys/param.h include, add system.h include. + 2016-08-30 Mark Wielaard * Makefile.am (asm_tst?_LDADD): Add libdw. diff --git a/tests/arextract.c b/tests/arextract.c index 21850b6c2..2c4dc7583 100644 --- a/tests/arextract.c +++ b/tests/arextract.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include int