Skip to content

Commit e22cc80

Browse files
Ulf HermannMark Wielaard
Ulf Hermann
authored and
Mark Wielaard
committed
Move print_version into printversion.{h|c}
Rename version.c so that the implementation is called after the header and the header doesn't clash with the toplevel version.h. print_version depends on argp and is only used in the tools. Signed-off-by: Ulf Hermann <[email protected]>
1 parent b3248e6 commit e22cc80

23 files changed

+103
-27
lines changed

lib/ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2017-02-16 Ulf Hermann <[email protected]>
2+
3+
* Makefile.am (libeu_a_SOURCES): Remove version.c, add printversion.c
4+
(noinst_HEADERS): Add printversion.h
5+
* version.c: Moved to printversion.c.
6+
* printversion.c: New file, moved from version.c,
7+
remove stdio.h, argp.h, system.h includes,
8+
add printversion.h include.
9+
* printversion.h: New file.
10+
* system.h: Remove argp.h include,
11+
(ARGP_PROGRAM_VERSION_HOOK_DEF, ARGP_PROGRAM_BUG_ADDRESS_DEF): Remove.
12+
(print_version): Remove.
13+
114
2017-02-15 Ulf Hermann <[email protected]>
215

316
* system.h: Provide mempcpy if it doesn't exist.

lib/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ noinst_LIBRARIES = libeu.a
3535

3636
libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
3737
crc32.c crc32_file.c md5.c sha1.c \
38-
color.c version.c
38+
color.c printversion.c
3939

4040
noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
41-
md5.h sha1.h eu-config.h color.h
41+
md5.h sha1.h eu-config.h color.h printversion.h
4242
EXTRA_DIST = dynamicsizehash.c
4343

4444
if !GPROF

lib/version.c renamed to lib/printversion.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
# include <config.h>
3131
#endif
3232

33-
#include <argp.h>
3433
#include <libintl.h>
35-
#include <stdio.h>
36-
#include "system.h"
34+
#include "printversion.h"
3735

3836
void
3937
print_version (FILE *stream, struct argp_state *state)

lib/printversion.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Common argp_print_version_hook for all tools.
2+
Copyright (C) 2017 The Qt Company Ltd.
3+
This file is part of elfutils.
4+
5+
This file is free software; you can redistribute it and/or modify
6+
it under the terms of either
7+
8+
* the GNU Lesser General Public License as published by the Free
9+
Software Foundation; either version 3 of the License, or (at
10+
your option) any later version
11+
12+
or
13+
14+
* the GNU General Public License as published by the Free
15+
Software Foundation; either version 2 of the License, or (at
16+
your option) any later version
17+
18+
or both in parallel, as here.
19+
20+
elfutils is distributed in the hope that it will be useful, but
21+
WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23+
General Public License for more details.
24+
25+
You should have received copies of the GNU General Public License and
26+
the GNU Lesser General Public License along with this program. If
27+
not, see <http://www.gnu.org/licenses/>. */
28+
29+
#ifndef PRINTVERSION_H
30+
#define PRINTVERSION_H 1
31+
32+
#include <argp.h>
33+
#include <stdio.h>
34+
35+
/* Defined in version.c. Common ARGP_PROGRAM_VERSION_HOOK_DEF. */
36+
void print_version (FILE *stream, struct argp_state *state);
37+
38+
/* We need define two variables, argp_program_version_hook and
39+
argp_program_bug_address, in all programs. argp.h declares these
40+
variables as non-const (which is correct in general). But we can
41+
do better, it is not going to change. So we want to move them into
42+
the .rodata section. Define macros to do the trick. */
43+
#define ARGP_PROGRAM_VERSION_HOOK_DEF \
44+
void (*const apvh) (FILE *, struct argp_state *) \
45+
__asm ("argp_program_version_hook")
46+
#define ARGP_PROGRAM_BUG_ADDRESS_DEF \
47+
const char *const apba__ __asm ("argp_program_bug_address")
48+
49+
#endif // PRINTVERSION_H

lib/system.h

-16
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
# include <config.h>
3434
#endif
3535

36-
#include <argp.h>
3736
#include <errno.h>
3837
#include <stddef.h>
3938
#include <stdint.h>
@@ -145,21 +144,6 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
145144
return recvd;
146145
}
147146

148-
149-
/* We need define two variables, argp_program_version_hook and
150-
argp_program_bug_address, in all programs. argp.h declares these
151-
variables as non-const (which is correct in general). But we can
152-
do better, it is not going to change. So we want to move them into
153-
the .rodata section. Define macros to do the trick. */
154-
#define ARGP_PROGRAM_VERSION_HOOK_DEF \
155-
void (*const apvh) (FILE *, struct argp_state *) \
156-
__asm ("argp_program_version_hook")
157-
#define ARGP_PROGRAM_BUG_ADDRESS_DEF \
158-
const char *const apba__ __asm ("argp_program_bug_address")
159-
160-
/* Defined in version.c. Common ARGP_PROGRAM_VERSION_HOOK_DEF. */
161-
void print_version (FILE *stream, struct argp_state *state);
162-
163147
/* The demangler from libstdc++. */
164148
extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,
165149
size_t *length, int *status);

po/ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2017-02-16 Ulf Hermann <[email protected]>
2+
3+
* po/POTFILES.in: Removed lib/version.c, added lib/printversion.c.
4+
15
2016-12-27 Mark Wielaard <[email protected]>
26

37
* *.po: Update for 0.168.

po/POTFILES.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Files from the compatibility library
55
lib/color.c
6-
lib/version.c
6+
lib/printversion.c
77
lib/xmalloc.c
88

99
# Library sources

src/ChangeLog

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2017-02-16 Ulf Hermann <[email protected]>
2+
3+
* addr2line.c: Include printversion.h
4+
* ar.c: Likewise.
5+
* elflint.c: Likewise.
6+
* nm.c: Likewise.
7+
* objdump.c: Likewise.
8+
* ranlib.c: Likewise.
9+
* readelf.c: Likewise.
10+
* size.c: Likewise.
11+
* stack.c: Likewise.
12+
* strings.c: Likewise.
13+
* strip.c: Likewise.
14+
* elfcmp.c: Include printversion.h, remove system.h include.
15+
* elfcompress.c: Likewise.
16+
* findtextrel.c: Likewise.
17+
* unstrip.c: Likewise.
18+
119
2017-02-14 Ulf Hermann <[email protected]>
220

321
* nm.c: Include color.h.

src/addr2line.c

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <unistd.h>
3939

4040
#include <system.h>
41+
#include <printversion.h>
4142

4243

4344
/* Name and version of program. */

src/ar.c

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <sys/time.h>
4242

4343
#include <system.h>
44+
#include <printversion.h>
4445

4546
#include "arlib.h"
4647

src/elfcmp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <string.h>
3434
#include <unistd.h>
3535

36-
#include <system.h>
36+
#include <printversion.h>
3737
#include "../libelf/elf-knowledge.h"
3838
#include "../libebl/libeblP.h"
3939

src/elfcompress.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include ELFUTILS_HEADER(dwelf)
3636
#include <gelf.h>
3737
#include "libeu.h"
38-
#include "system.h"
38+
#include "printversion.h"
3939

4040
/* Name and version of program. */
4141
ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;

src/elflint.c

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <elf-knowledge.h>
4040
#include <libeu.h>
4141
#include <system.h>
42+
#include <printversion.h>
4243
#include "../libelf/libelfP.h"
4344
#include "../libelf/common.h"
4445
#include "../libebl/libeblP.h"

src/findtextrel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <string.h>
3737
#include <unistd.h>
3838

39-
#include <system.h>
39+
#include <printversion.h>
4040

4141

4242
struct segments

src/nm.c

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <libeu.h>
4646
#include <system.h>
4747
#include <color.h>
48+
#include <printversion.h>
4849
#include "../libebl/libeblP.h"
4950
#include "../libdwfl/libdwflP.h"
5051

src/objdump.c

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <libeu.h>
3737
#include <system.h>
3838
#include <color.h>
39+
#include <printversion.h>
3940
#include "../libebl/libeblP.h"
4041

4142

src/ranlib.c

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <sys/stat.h>
3939

4040
#include <system.h>
41+
#include <printversion.h>
4142

4243
#include "arlib.h"
4344

src/readelf.c

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include <libeu.h>
4747
#include <system.h>
48+
#include <printversion.h>
4849
#include "../libelf/libelfP.h"
4950
#include "../libelf/common.h"
5051
#include "../libebl/libeblP.h"

src/size.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <unistd.h>
3737

3838
#include <system.h>
39-
39+
#include <printversion.h>
4040

4141
/* Name and version of program. */
4242
ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;

src/stack.c

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <dwarf.h>
3232
#include <system.h>
33+
#include <printversion.h>
3334

3435
/* Name and version of program. */
3536
ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;

src/strings.c

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include <libeu.h>
4444
#include <system.h>
45+
#include <printversion.h>
4546

4647
#ifndef MAP_POPULATE
4748
# define MAP_POPULATE 0

src/strip.c

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "libdwelf.h"
4545
#include <libeu.h>
4646
#include <system.h>
47+
#include <printversion.h>
4748

4849
typedef uint8_t GElf_Byte;
4950

src/unstrip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include <libdwfl.h>
5151
#include "libdwelf.h"
5252
#include "libeu.h"
53-
#include "system.h"
53+
#include "printversion.h"
5454

5555
#ifndef _
5656
# define _(str) gettext (str)

0 commit comments

Comments
 (0)