sysdeps/unix/sysv/linux/lseek.c on ILP32 question

Steve Ellcey sellcey@caviumnetworks.com
Tue Feb 21 18:22:00 GMT 2017


I am looking at a glibc bug in the ILP32 aarch implementation that I am
working on and have a question about lseek.  The failure I am looking
at comes from the LTP testsuite and involves calling lseek with a
negative offset argument.

I am looking at sysdeps/unix/sysv/linux/lseek.c and the code for when
__NR__llseek is defined.  It has:

  int rc = INLINE_SYSCALL_CALL (_llseek, fd,
                                (long) (((uint64_t) (offset)) >> 32),
                                (long) offset, &res, whence);

And I am not sure the conversion from offset to the two llseek
arguments is correct for both LP64 and ILP32 modes when offset is
negative.  For example if I run the following program on x86_64:

#include <stdio.h>
void foo(long long i)
{
  printf("%ld %ld\n",
	(long) (((unsigned long long) (i)) >> 32),
	(long) i);
}
int main()
{
  foo(3);
  foo(-3);
}

I get this result when compiling in 64 bit mode:

0 3
4294967295 -3

And I get this result when compiling in 32 bit mode:

0 3
-1 -3

I have also attached the cutdown version of the original LTP test. On
my LP64 aarch64 system it prints:

fd = 3
val(1) = 0
val(2) = 40
val(3) = 0
val(4) = 40
val(5) = 0

When compiled in ILP32 mode on aarch64, it prints:

fd = 3
val(1) = 0
val(2) = 40
val(3) = 0
val(4) = 0
Gee, let's write something in the file!


41
val(5) = 0


Steve Ellcey
sellcey@cavium.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 1021 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20170221/af961e2a/attachment.bin>


More information about the Libc-alpha mailing list