reason of pwritev01_64 failure on 32-bit arm
Hi,
I've reproduced and analyzed failure of pwritev01_64 described at [1]
[1] http://lists.linux.it/pipermail/ltp/2016-March/001201.html
pwritev01_64 fail is an LTP issue
pwrite01 and pwrite01_64 are built from the same source, pwrite01.c 64-bit version is built with additional define, -D_FILE_OFFSET_BITS=64, which causes 'off_t' type defined by glibc to become 64-bit.
Problem is that both pwrite01.o and pwrite01_64.o link against the same utility library, libltp
From this library, a routine called safe_pread() is used. One of arguments of this routine has type off_t.
This means that ABI for this routine is different when built with -D_FILE_OFFSET_BITS=64 and without it.
Library is built without -D_FILE_OFFSET_BITS=64, thus on 32-bit platform safe_pread() inside library expects ABI with 32-bit 'off_t'. And pwrite01_64.o, built with -D_FILE_OFFSET_BITS=64, uses different ABI.
If a copy of safe_pread() is injected inside pwrite01.c (and compile issue is resolved), test passes.
In general, it is not safe to link together object files built with and without -D_FILE_OFFSET_BITS=64, since that code is not always binary-compatible.
On 64-bit platform, sizeof(off_t) is 8 both with and without -D_FILE_OFFSET_BITS=64, this issue does not show.
WBR,
Nikita Yushchenko
----- Original Message -----
Quoted 32 lines
From: "Nikita Yushchenko" <[email protected]>
To: [email protected]
Cc: "arusalin" <[email protected]>
Sent: Friday, 2 September, 2016 5:58:51 PM
Subject: [LTP] reason ofpwritev01_64failure on 32-bit armHi,
I've reproduced and analyzed failure of
pwritev01_64described at [1][1] http://lists.linux.it/pipermail/ltp/2016-March/001201.html
pwritev01_64fail is an LTP issuepwrite01 and
pwrite01_64are built from the same source,pwrite01.c64-bit version is built with additional define, -D_FILE_OFFSET_BITS=64, which causes 'off_t' type defined by glibc to become 64-bit.Problem is that both pwrite01.o and pwrite01_64.o link against the same utility library, libltp
From this library, a routine calledsafe_pread()is used. One of arguments of this routine has typeoff_t.
This means that ABI for this routine is different when built with -D_FILE_OFFSET_BITS=64 and without it.
Library is built without -D_FILE_OFFSET_BITS=64, thus on 32-bit platformsafe_pread()inside library expects ABI with 32-bit 'off_t'. And pwrite01_64.o, built with -D_FILE_OFFSET_BITS=64, uses different ABI.If a copy of
safe_pread()is injected insidepwrite01.c(and compile issue is resolved), test passes.
Quoted 7 lines
In general, it is not safe to link together object files built with and without -D_FILE_OFFSET_BITS=64, since that code is not always binary-compatible.
On 64-bit platform,
sizeof(off_t)is 8 both with and without -D_FILE_OFFSET_BITS=64, this issue does not show.
Hi,
Thanks for following up on this. Looks like we should do same thing for pread/pwrite as we already do for lseek, that is to move these from lib to headers as inline functions:
$ grep -B2 off_t -r lib/*.c lib/safe_macros.c-ssize_t safe_pread(const char *file, const int lineno, void (*cleanup_fn)(void), lib/safe_macros.c- char len_strict, int fildes, void *buf, size_t nbyte, lib/safe_macros.c: off_t offset) -- lib/safe_macros.c-ssize_t safe_pwrite(const char *file, const int lineno, lib/safe_macros.c- void (cleanup_fn) (void), char len_strict, int fildes, lib/safe_macros.c: const void *buf, size_t nbyte, off_t offset)
Are you planning to submit a patch?
Regards,
Jan
Quoted 7 lines
WBR,
Nikita Yushchenko--
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/1 safe_macros: make safe_pread() and safe_pwrite() inline
These routines have an argument of type off_t, which has size dependent on compile options on 32-bit builds. Thus having there rotines compiled inside library cause ABI issues.
--- include/old/safe_macros.h | 39 +++++++++++++++++++++++++++++++++++++++ include/safe_macros_fn.h | 8 -------- include/tst_safe_macros.h | 39 +++++++++++++++++++++++++++++++++++++++ lib/safe_macros.c | 32 -------------------------------- 4 files changed, 78 insertions(+), 40 deletions(-)
include/old/safe_macros.h +39 -0
@@ -70,6 +70,26 @@safe_read (__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags + */ +static inline ssize_t safe_pread (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pread (fildes, buf, nbyte, offset); + +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pread(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PREAD (cleanup_fn, len_strict, fildes, buf, nbyte, offset) \ safe_pread(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte), (offset))
@@ -112,6 +132,25 @@safe_write (__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags + */ +static inline ssize_t safe_pwrite (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,const void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pwrite (fildes, buf, nbyte, offset); +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pwrite(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PWRITE (cleanup_fn, len_strict, fildes, buf, nbyte, offset) \ safe_pwrite(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte), (offset))
include/safe_macros_fn.h +0 -8
@@ -71,10 +71,6 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn)(void), char len_strict, int fildes, void *buf, size_t nbyte); -ssize_t safe_pread (const char *file,const int lineno, -void (*cleanup_fn)(void ),char len_strict, -int fildes,void *buf,size_t nbyte,off_t offset); -int safe_setegid (const char *file,const int lineno,void (*cleanup_fn)(void ),gid_t egid);
@@ -118,10 +114,6 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn)(void), char len_strict, int fildes, const void *buf, size_t nbyte); -ssize_t safe_pwrite (const char *file,const int lineno, -void (cleanup_fn )(void ),char len_strict,int fildes, -const void *buf,size_t nbyte,off_t offset); -long safe_strtol (const char *file,const int lineno,void (cleanup_fn )(void ),char *str,long min,long max);
include/tst_safe_macros.h +39 -0
@@ -97,6 +97,26 @@ static inline int safe_dup(const char *file, const int lineno,#define SAFE_READ (len_strict, fildes, buf, nbyte) \ safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags +*/ +static inline ssize_t safe_pread (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pread (fildes, buf, nbyte, offset); + +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pread(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PREAD (len_strict, fildes, buf, nbyte, offset) \ safe_pread(__FILE__, __LINE__, NULL, (len_strict), (fildes), \ (buf), (nbyte), (offset))
@@ -170,6 +190,25 @@ static inline pid_t safe_getpgid(const char *file, const int lineno,#define SAFE_WRITE (len_strict, fildes, buf, nbyte) \ safe_write(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags +*/ +static inline ssize_t safe_pwrite (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,const void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pwrite (fildes, buf, nbyte, offset); +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pwrite(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PWRITE (len_strict, fildes, buf, nbyte, offset) \ safe_pwrite(__FILE__, __LINE__, NULL, (len_strict), (fildes), \ (buf), (nbyte), (offset))
lib/safe_macros.c +0 -32
@@ -252,22 +252,6 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),return rval; } -ssize_t safe_pread (const char *file,const int lineno,void (*cleanup_fn)(void ), -char len_strict,int fildes,void *buf,size_t nbyte, -off_t offset) -{ -ssize_t rval; - - rval =pread (fildes, buf, nbyte, offset); -if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { -tst_brkm (TBROK |TERRNO , cleanup_fn, -"%s:%d: read(%d,%p,%zu,%ld) failed, returned %zd" , - file, lineno, fildes, buf, nbyte, offset, rval); - } - -return rval; -} -int safe_setegid (const char *file,const int lineno,void (*cleanup_fn) (void ),gid_t egid) {
@@ -458,22 +442,6 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),return rval; } -ssize_t safe_pwrite (const char *file,const int lineno, -void (cleanup_fn ) (void ),char len_strict,int fildes, -const void *buf,size_t nbyte,off_t offset) -{ -ssize_t rval; - - rval =pwrite (fildes, buf, nbyte, offset); -if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { -tst_brkm (TBROK |TERRNO , cleanup_fn, -"%s:%d: pwrite(%d,%p,%zu,%ld) failed" , - file, lineno, fildes, buf, rval, offset); - } - -return rval; -} -long safe_strtol (const char *file,const int lineno,void (cleanup_fn ) (void ),char *str,long min,long max) {
Signature · 1 line
2.1.4
PATCH 1/1 safe_macros: make safe_pread() and safe_pwrite() inline
Hi!
Quoted 32 lines
include/tst_safe_macros.h +20
-0@@ -97,6 +97,26 @@ static inline int safe_dup(const char *file, const int lineno,#define SAFE_READ (len_strict, fildes, buf, nbyte) \ safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags +*/ +static inline ssize_t safe_pread (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pread (fildes, buf, nbyte, offset); + +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pread(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PREAD (len_strict, fildes, buf, nbyte, offset) \ safe_pread(__FILE__, __LINE__, NULL, (len_strict), (fildes), \ (buf), (nbyte), (offset))
include/tst_safe_macros.h static inline pid_t safe_getpgid(const char *file, const int lineno, · line 195
Quoted 6 lines
include/tst_safe_macros.h +3
-0@@ -170,6 +190,25 @@ static inline pid_t safe_getpgid(const char *file, const int lineno,#define SAFE_WRITE (len_strict, fildes, buf, nbyte) \ safe_write(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags +*/
We already have a comment in this file explaining why there are a few inline functions so I would omit these.
Quoted 9 lines
include/tst_safe_macros.h +9
-0+static inline ssize_t safe_pwrite (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,const void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pwrite (fildes, buf, nbyte, offset); +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { + tst_brkm(TBROK | TERRNO, cleanup_fn,
include/tst_safe_macros.h static inline pid_t safe_getpgid(const char *file, const int lineno, · line 214
Quoted 10 lines
include/tst_safe_macros.h +7
-0+"%s:%d: pwrite(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PWRITE (len_strict, fildes, buf, nbyte, offset) \ safe_pwrite(__FILE__, __LINE__, NULL, (len_strict), (fildes), \ (buf), (nbyte), (offset))
These newlib inline function should omit the cleanup_fn parameter and use tst_brk_() instead.
Otherwise it looks fine.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 safe_macros: make safe_pread() and safe_pwrite() inline
These routines have an argument of type off_t, which has size dependent on compile options on 32-bit builds. Thus having there rotines compiled inside library cause ABI issues.
--- include/old/safe_macros.h | 39 +++++++++++++++++++++++++++++++++++++++ include/safe_macros_fn.h | 8 -------- include/tst_safe_macros.h | 38 ++++++++++++++++++++++++++++++++++++-- lib/safe_macros.c | 32 -------------------------------- 4 files changed, 75 insertions(+), 42 deletions(-)
include/old/safe_macros.h +39 -0
@@ -70,6 +70,26 @@safe_read (__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags + */ +static inline ssize_t safe_pread (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pread (fildes, buf, nbyte, offset); + +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pread(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PREAD (cleanup_fn, len_strict, fildes, buf, nbyte, offset) \ safe_pread(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte), (offset))
@@ -112,6 +132,25 @@safe_write (__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags + */ +static inline ssize_t safe_pwrite (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,const void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pwrite (fildes, buf, nbyte, offset); +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pwrite(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PWRITE (cleanup_fn, len_strict, fildes, buf, nbyte, offset) \ safe_pwrite(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte), (offset))
include/safe_macros_fn.h +0 -8
@@ -71,10 +71,6 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn)(void), char len_strict, int fildes, void *buf, size_t nbyte); -ssize_t safe_pread (const char *file,const int lineno, -void (*cleanup_fn)(void ),char len_strict, -int fildes,void *buf,size_t nbyte,off_t offset); -int safe_setegid (const char *file,const int lineno,void (*cleanup_fn)(void ),gid_t egid);
@@ -118,10 +114,6 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn)(void), char len_strict, int fildes, const void *buf, size_t nbyte); -ssize_t safe_pwrite (const char *file,const int lineno, -void (cleanup_fn )(void ),char len_strict,int fildes, -const void *buf,size_t nbyte,off_t offset); -long safe_strtol (const char *file,const int lineno,void (cleanup_fn )(void ),char *str,long min,long max);
include/tst_safe_macros.h +36 -2
@@ -97,8 +97,27 @@ static inline int safe_dup(const char *file, const int lineno,#define SAFE_READ (len_strict, fildes, buf, nbyte) \ safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags +*/ +static inline ssize_t safe_pread (const char *file,const int lineno, +char len_strict,int fildes,void *buf,size_t nbyte, +off_t offset) +{ +ssize_t rval; + + rval =pread (fildes, buf, nbyte, offset); + +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"pread(%d,%p,%zu,%lld) failed" , + fildes, buf, nbyte, (long long )offset); + } + +return rval; +}#define SAFE_PREAD (len_strict, fildes, buf, nbyte, offset) \ - safe_pread(__FILE__, __LINE__, NULL, (len_strict), (fildes), \ + safe_pread(__FILE__, __LINE__, (len_strict), (fildes), \ (buf), (nbyte), (offset))#define SAFE_SETEGID (egid) \
@@ -170,8 +189,23 @@ static inline pid_t safe_getpgid(const char *file, const int lineno,#define SAFE_WRITE (len_strict, fildes, buf, nbyte) \ safe_write(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte)) +static inline ssize_t safe_pwrite (const char *file,const int lineno, +char len_strict,int fildes,const void *buf,size_t nbyte, +off_t offset) +{ +ssize_t rval; + + rval =pwrite (fildes, buf, nbyte, offset); +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"pwrite(%d,%p,%zu,%lld) failed" , + fildes, buf, nbyte, (long long )offset); + } + +return rval; +}#define SAFE_PWRITE (len_strict, fildes, buf, nbyte, offset) \ - safe_pwrite(__FILE__, __LINE__, NULL, (len_strict), (fildes), \ + safe_pwrite(__FILE__, __LINE__, (len_strict), (fildes), \ (buf), (nbyte), (offset))#define SAFE_STRTOL (str, min, max) \
lib/safe_macros.c +0 -32
@@ -252,22 +252,6 @@ ssize_t safe_read(const char *file, const int lineno, void (*cleanup_fn) (void),return rval; } -ssize_t safe_pread (const char *file,const int lineno,void (*cleanup_fn)(void ), -char len_strict,int fildes,void *buf,size_t nbyte, -off_t offset) -{ -ssize_t rval; - - rval =pread (fildes, buf, nbyte, offset); -if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { -tst_brkm (TBROK |TERRNO , cleanup_fn, -"%s:%d: read(%d,%p,%zu,%ld) failed, returned %zd" , - file, lineno, fildes, buf, nbyte, offset, rval); - } - -return rval; -} -int safe_setegid (const char *file,const int lineno,void (*cleanup_fn) (void ),gid_t egid) {
@@ -458,22 +442,6 @@ ssize_t safe_write(const char *file, const int lineno, void (cleanup_fn) (void),return rval; } -ssize_t safe_pwrite (const char *file,const int lineno, -void (cleanup_fn ) (void ),char len_strict,int fildes, -const void *buf,size_t nbyte,off_t offset) -{ -ssize_t rval; - - rval =pwrite (fildes, buf, nbyte, offset); -if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { -tst_brkm (TBROK |TERRNO , cleanup_fn, -"%s:%d: pwrite(%d,%p,%zu,%ld) failed" , - file, lineno, fildes, buf, rval, offset); - } - -return rval; -} -long safe_strtol (const char *file,const int lineno,void (cleanup_fn ) (void ),char *str,long min,long max) {
Signature · 1 line
2.1.4
PATCH 1/1 safe_macros: make safe_pread() and safe_pwrite() inline
Hi!
Quoted 32 lines
include/old/safe_macros.h +20
-0@@ -70,6 +70,26 @@safe_read (__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte)) +/* +* inline function that uses off_t since sizeof(off_t) depends on compile flags + */ +static inline ssize_t safe_pread (const char *file,const int lineno, +void (*cleanup_fn)(void ),char len_strict, +int fildes,void *buf,size_t nbyte,off_t offset) +{ +ssize_t rval; + + rval =pread (fildes, buf, nbyte, offset); + +if (rval ==-1 || (len_strict && (size_t )rval != nbyte)) { +tst_brkm (TBROK |TERRNO , cleanup_fn, +"%s:%d: pread(%d,%p,%zu,%lld) failed, returned %zd" , + file, lineno, fildes, buf, nbyte, (long long )offset, + rval); + } + +return rval; +}#define SAFE_PREAD (cleanup_fn, len_strict, fildes, buf, nbyte, offset) \ safe_pread(__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte), (offset))
include/old/safe_macros.h line 134
Quoted 3 lines
include/old/safe_macros.h +0
-0@@ -112,6 +132,25 @@safe_write (__FILE__, __LINE__, cleanup_fn, (len_strict), (fildes), \ (buf), (nbyte))
I've removed this part (SAFE_PREAD in old library headers), since the old library is deprecated and there are more users for this function.
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]