1 From b77db7fa6cd00e1412fdd186180996f8d622b275 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Sun, 7 Sep 2014 12:21:04 +0200
4 Subject: [PATCH 5/5] ld_iscsi: fix largefile related issues
6 This commit fixes two related issues in the ld_iscsi example with
9 The first issue appears when building libiscsi against the glibc C
10 library, with the flags -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
11 -D_FILE_OFFSET_BITS=64:
13 {standard input}: Assembler messages:
14 {standard input}:2774: Error: symbol `__fxstat64' is already defined
15 {standard input}:2850: Error: symbol `__lxstat64' is already defined
16 {standard input}:2938: Error: symbol `__xstat64' is already defined
18 This is due to the fact that when _FILE_OFFSET_BITS=64 is passed, the
19 *64() functions are defined by the C library as aliases to the
20 non-64*() functions, because those ones directly support large files
23 The second issue appears when building libiscsi against the uClibc C
24 library, in a configuration that doesn't have largefile support. In
25 this case, the ld_iscsi that tries to use stat64 or some other *64()
26 functions cannot build, because such functions are not provided by the
27 C library. Of course, ld_iscsi does not need to wrap the *64()
28 functions in such a situation, because they do not exist.
30 This commit fixes those problems by enclosing the *64() related code
31 of ld_iscsi in the following compile time conditional:
33 This ensures that the *64() function handling is here only if
34 largefile support is available and enabled (_LARGEFILE_SOURCE64) and
35 if non-*64() functions are not already 64 bits capable (in which case
36 the 64*() functions are just aliases for the non-64*() ones).
39 http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
40 for more details about the meaning of those macros.
42 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
44 examples/ld_iscsi.c | 4 ++++
45 1 file changed, 4 insertions(+)
47 diff --git a/examples/ld_iscsi.c b/examples/ld_iscsi.c
48 index 0cf2724..02f9d25 100644
49 --- a/examples/ld_iscsi.c
50 +++ b/examples/ld_iscsi.c
51 @@ -543,6 +543,7 @@ int dup2(int oldfd, int newfd)
52 return real_dup2(oldfd, newfd);
55 +#if defined(_LARGEFILE64_SOURCE) && _FILE_OFFSET_BITS != 64
57 int (*real_fxstat64)(int ver, int fd, struct stat64 *buf);
59 @@ -591,6 +592,7 @@ int __xstat64(int ver, const char *path, struct stat64 *buf)
60 return __lxstat64(ver, path, buf);
65 static void __attribute__((constructor)) _init(void)
67 @@ -669,6 +671,7 @@ static void __attribute__((constructor)) _init(void)
71 +#if defined(_LARGEFILE64_SOURCE) && _FILE_OFFSET_BITS != 64
72 real_fxstat64 = dlsym(RTLD_NEXT, "__fxstat64");
73 if (real_fxstat64 == NULL) {
74 LD_ISCSI_DPRINTF(0,"Failed to dlsym(__fxstat64)");
75 @@ -683,4 +686,5 @@ static void __attribute__((constructor)) _init(void)
76 if (real_xstat64 == NULL) {
77 LD_ISCSI_DPRINTF(0,"Failed to dlsym(__xstat64)");