public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] skip testing time before epoch on mips
@ 2021-03-10  3:31 Chen Li
  0 siblings, 0 replies; 5+ messages in thread
From: Chen Li @ 2021-03-10  3:31 UTC (permalink / raw)
  To: gcc-patches, libstdc++


When execute libstdc++ testcases on mips, I notice that last_write_time
alawys failed, and the failed VERIFY is  "VERIFY(
approx_equal(last_write_time(f.path), time) );" where testing time before
than epoch.

Below is the minimal case:

```
// gcc a.c
int main()
{
        struct timespec times[2] = {{1, UTIME_OMIT}, {-1201, 985000000}};
        utimensat(AT_FDCWD, "test", times, 0);

}
```

$ touch test && gcc a.c && ./a.out && stat test
  File: test
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d      Inode: 1056841     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  deepin)   Gid: ( 1000/  deepin)
Access: 2021-03-08 13:52:55.966354501 +0800
Modify: 2106-02-07 14:08:15.985000000 +0800
Change: 2021-03-08 13:52:56.907782193 +0800
 Birth: -

Undoubtedly, mtime's type is unsigned somewhere on mips.

After debuging kernel, it turns out that mtime is always -1201 in
ext4_setattr, cp_new_stat, newlstat and etc, so the problem should not
occur in kernel space.

go back to user space via copy_to_user, I finally found mips used
"unsigned int st_mtime_sec;" in struct kernel_stat, which is used to
receive -1201 from kernel.

Maybe sparc also suffers from this problem, but I have no machine to
verify.
---
 .../testsuite/27_io/filesystem/operations/last_write_time.cc    | 2 ++
 .../experimental/filesystem/operations/last_write_time.cc       | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
index 6ae64c482b6..72272d4e781 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
@@ -200,11 +200,13 @@ test02()
   VERIFY( approx_equal(last_write_time(f.path), time) );

   ec = bad_ec;
+  #ifndef __mips__
   // A time before than the epoch
   time -= chrono::milliseconds(1000 * 60 * 20 + 15);
   last_write_time(f.path, time, ec);
   VERIFY( !ec );
   VERIFY( approx_equal(last_write_time(f.path), time) );
+  #endif
 }

 int
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
index 536ab1f28f6..6fb490a6bc3 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
@@ -165,11 +165,13 @@ test02()
   VERIFY( !ec );
   VERIFY( approx_equal(last_write_time(f.path), time) );

+  #ifndef __mips__
   ec = bad_ec;
   time -= chrono::milliseconds(1000 * 60 * 10 + 15);
   last_write_time(f.path, time, ec);
   VERIFY( !ec );
   VERIFY( approx_equal(last_write_time(f.path), time) );
+  #endif
 }

 int
--
2.30.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] skip testing time before epoch on mips
  2021-03-08 10:57 ` Jonathan Wakely
@ 2021-03-08 11:15   ` YunQiang Su
  0 siblings, 0 replies; 5+ messages in thread
From: YunQiang Su @ 2021-03-08 11:15 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Chen Li, libstdc++, gcc-patches

Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> 于2021年3月8日周一 下午6:57写道:
>
> On 08/03/21 14:35 +0800, Chen Li wrote:
> >
> >When execute libstdc++ testcases on mips, I notice that last_write_time
> >alawys failed, and the failed VERIFY is  "VERIFY(
> >approx_equal(last_write_time(f.path), time) );" where testing time before
> >than epoch.
> >
> >Below is the minimal case:
> >
> >```
> >// gcc a.c
> >int main()
> >{
> >        struct timespec times[2] = {{1, UTIME_OMIT}, {-1201, 985000000}};
> >        utimensat(AT_FDCWD, "test", times, 0);
> >
> >}
> >```
> >
> >$ touch test && gcc a.c && ./a.out && stat test
> >  File: test
> >  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
> >Device: 805h/2053d      Inode: 1056841     Links: 1
> >Access: (0644/-rw-r--r--)  Uid: ( 1000/  deepin)   Gid: ( 1000/  deepin)
> >Access: 2021-03-08 13:52:55.966354501 +0800
> >Modify: 2106-02-07 14:08:15.985000000 +0800
> >Change: 2021-03-08 13:52:56.907782193 +0800
> > Birth: -
> >
> >Undoubtedly, mtime's type is unsigned somewhere on mips.
> >
> >After debuging kernel, it turns out that mtime is always -1201 in
> >ext4_setattr, cp_new_stat, newlstat and etc, so the problem should not
> >occur in kernel space.
> >
> >go back to user space via copy_to_user, I finally found mips used
> >"unsigned int st_mtime_sec;" in struct kernel_stat, which is used to
> >receive -1201 from kernel.
>
> I can't reproduce this on a mips64 machine:
>
> jwakely@erpro8-fsf2:~$ uname -a
> Linux erpro8-fsf2 4.1.4 #1 SMP PREEMPT Mon Aug 3 14:22:54 PDT 2015 mips64 GNU/Linux
> jwakely@erpro8-fsf2:~$ apt list libc6
> Listing... Done
> libc6/oldstable,now 2.19-18+deb8u10 mipsel [installed]

it is mips32, not mips64. Here mips64 we mean userland, not the kernel.

> jwakely@erpro8-fsf2:~$ touch test && ./a.out && TZ= stat test
>    File: ‘test’
>    Size: 0               Blocks: 0          IO Block: 131072 regular empty file
> Device: 21h/33d Inode: 36596524    Links: 1
> Access: (0644/-rw-r--r--)  Uid: ( 1049/ jwakely)   Gid: ( 1049/ jwakely)
> Access: 2021-03-08 10:52:06.855991946 +0000
> Modify: 1969-12-31 23:39:59.985000000 +0000
> Change: 2021-03-08 10:52:06.859992051 +0000
>   Birth: -
>
> This is an ext4 filesystem.
>
> Do I need to compile a 64-bit executable?
>

Yes. you need 64bit userland.

> In any case, shouldn't this be fixed in glibc to return EINVAL instead
> of setting a bogus time? That would make the std::filesystem library
> report an error.
>

Since kernel has introduced statx(2), so we can use statx to implemente stat(3).

>
> >Maybe sparc also suffers from this problem, but I have no machine to
> >verify.
>
> Your test case works correctly for me on sparc-linux (both 32-bit and
> 64-bit on ext4 and xfs filesystems):
>
> $ uname -a
> Linux gcc202 5.10.0-4-sparc64-smp #1 SMP Debian 5.10.19-1 (2021-03-02) sparc64 GNU/Linux
> $ apt list libc6
> Listing... Done
> libc6/unstable,now 2.31-4 sparc64 [installed]
> $ ./a.out
> $ TZ= stat test
>    File: test
>    Size: 0               Blocks: 0          IO Block: 8192   regular empty file
> Device: fd01h/64769d    Inode: 657291843   Links: 1
> Access: (0644/-rw-r--r--)  Uid: ( 1049/ jwakely)   Gid: ( 1049/ jwakely)
> Access: 2021-03-08 10:25:43.593819539 +0000
> Modify: 1969-12-31 23:39:59.985000000 +0000
> Change: 2021-03-08 10:34:13.711287778 +0000
>   Birth: 2021-03-08 10:24:27.106598699 +0000
>


-- 
YunQiang Su

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] skip testing time before epoch on mips
  2021-03-08  6:35 Chen Li
  2021-03-08  6:41 ` YunQiang Su
@ 2021-03-08 10:57 ` Jonathan Wakely
  2021-03-08 11:15   ` YunQiang Su
  1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2021-03-08 10:57 UTC (permalink / raw)
  To: Chen Li; +Cc: gcc-patches, libstdc++

On 08/03/21 14:35 +0800, Chen Li wrote:
>
>When execute libstdc++ testcases on mips, I notice that last_write_time
>alawys failed, and the failed VERIFY is  "VERIFY(
>approx_equal(last_write_time(f.path), time) );" where testing time before
>than epoch.
>
>Below is the minimal case:
>
>```
>// gcc a.c
>int main()
>{
>        struct timespec times[2] = {{1, UTIME_OMIT}, {-1201, 985000000}};
>        utimensat(AT_FDCWD, "test", times, 0);
>
>}
>```
>
>$ touch test && gcc a.c && ./a.out && stat test
>  File: test
>  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
>Device: 805h/2053d      Inode: 1056841     Links: 1
>Access: (0644/-rw-r--r--)  Uid: ( 1000/  deepin)   Gid: ( 1000/  deepin)
>Access: 2021-03-08 13:52:55.966354501 +0800
>Modify: 2106-02-07 14:08:15.985000000 +0800
>Change: 2021-03-08 13:52:56.907782193 +0800
> Birth: -
>
>Undoubtedly, mtime's type is unsigned somewhere on mips.
>
>After debuging kernel, it turns out that mtime is always -1201 in
>ext4_setattr, cp_new_stat, newlstat and etc, so the problem should not
>occur in kernel space.
>
>go back to user space via copy_to_user, I finally found mips used
>"unsigned int st_mtime_sec;" in struct kernel_stat, which is used to
>receive -1201 from kernel.

I can't reproduce this on a mips64 machine:

jwakely@erpro8-fsf2:~$ uname -a
Linux erpro8-fsf2 4.1.4 #1 SMP PREEMPT Mon Aug 3 14:22:54 PDT 2015 mips64 GNU/Linux
jwakely@erpro8-fsf2:~$ apt list libc6
Listing... Done
libc6/oldstable,now 2.19-18+deb8u10 mipsel [installed]
jwakely@erpro8-fsf2:~$ touch test && ./a.out && TZ= stat test
   File: ‘test’
   Size: 0               Blocks: 0          IO Block: 131072 regular empty file
Device: 21h/33d Inode: 36596524    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1049/ jwakely)   Gid: ( 1049/ jwakely)
Access: 2021-03-08 10:52:06.855991946 +0000
Modify: 1969-12-31 23:39:59.985000000 +0000
Change: 2021-03-08 10:52:06.859992051 +0000
  Birth: -

This is an ext4 filesystem.

Do I need to compile a 64-bit executable? 

In any case, shouldn't this be fixed in glibc to return EINVAL instead
of setting a bogus time? That would make the std::filesystem library
report an error.


>Maybe sparc also suffers from this problem, but I have no machine to
>verify.

Your test case works correctly for me on sparc-linux (both 32-bit and
64-bit on ext4 and xfs filesystems):

$ uname -a
Linux gcc202 5.10.0-4-sparc64-smp #1 SMP Debian 5.10.19-1 (2021-03-02) sparc64 GNU/Linux
$ apt list libc6
Listing... Done
libc6/unstable,now 2.31-4 sparc64 [installed]
$ ./a.out
$ TZ= stat test
   File: test
   Size: 0               Blocks: 0          IO Block: 8192   regular empty file
Device: fd01h/64769d    Inode: 657291843   Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1049/ jwakely)   Gid: ( 1049/ jwakely)
Access: 2021-03-08 10:25:43.593819539 +0000
Modify: 1969-12-31 23:39:59.985000000 +0000
Change: 2021-03-08 10:34:13.711287778 +0000
  Birth: 2021-03-08 10:24:27.106598699 +0000


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] skip testing time before epoch on mips
  2021-03-08  6:35 Chen Li
@ 2021-03-08  6:41 ` YunQiang Su
  2021-03-08 10:57 ` Jonathan Wakely
  1 sibling, 0 replies; 5+ messages in thread
From: YunQiang Su @ 2021-03-08  6:41 UTC (permalink / raw)
  To: Chen Li; +Cc: gcc-patches, libstdc++

Chen Li <chenli@uniontech.com> 于2021年3月8日周一 下午2:35写道:
>
>
> When execute libstdc++ testcases on mips, I notice that last_write_time
> alawys failed, and the failed VERIFY is  "VERIFY(
> approx_equal(last_write_time(f.path), time) );" where testing time before
> than epoch.
>
> Below is the minimal case:
>
> ```
> // gcc a.c
> int main()
> {
>         struct timespec times[2] = {{1, UTIME_OMIT}, {-1201, 985000000}};
>         utimensat(AT_FDCWD, "test", times, 0);
>
> }
> ```
>
> $ touch test && gcc a.c && ./a.out && stat test
>   File: test
>   Size: 0               Blocks: 0          IO Block: 4096   regular empty file
> Device: 805h/2053d      Inode: 1056841     Links: 1
> Access: (0644/-rw-r--r--)  Uid: ( 1000/  deepin)   Gid: ( 1000/  deepin)
> Access: 2021-03-08 13:52:55.966354501 +0800
> Modify: 2106-02-07 14:08:15.985000000 +0800
> Change: 2021-03-08 13:52:56.907782193 +0800
>  Birth: -
>
> Undoubtedly, mtime's type is unsigned somewhere on mips.
>

It only has this problem on mips64.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=983769

> After debuging kernel, it turns out that mtime is always -1201 in
> ext4_setattr, cp_new_stat, newlstat and etc, so the problem should not
> occur in kernel space.
>
> go back to user space via copy_to_user, I finally found mips used
> "unsigned int st_mtime_sec;" in struct kernel_stat, which is used to
> receive -1201 from kernel.
>
> Maybe sparc also suffers from this problem, but I have no machine to
> verify.
> ---
>  .../testsuite/27_io/filesystem/operations/last_write_time.cc    | 2 ++
>  .../experimental/filesystem/operations/last_write_time.cc       | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
> index 6ae64c482b6..72272d4e781 100644
> --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
> +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
> @@ -200,11 +200,13 @@ test02()
>    VERIFY( approx_equal(last_write_time(f.path), time) );
>
>    ec = bad_ec;
> +  #ifndef __mips__
>    // A time before than the epoch
>    time -= chrono::milliseconds(1000 * 60 * 20 + 15);
>    last_write_time(f.path, time, ec);
>    VERIFY( !ec );
>    VERIFY( approx_equal(last_write_time(f.path), time) );
> +  #endif
>  }
>
>  int
> diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
> index 536ab1f28f6..6fb490a6bc3 100644
> --- a/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
> +++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
> @@ -165,11 +165,13 @@ test02()
>    VERIFY( !ec );
>    VERIFY( approx_equal(last_write_time(f.path), time) );
>
> +  #ifndef __mips__
>    ec = bad_ec;
>    time -= chrono::milliseconds(1000 * 60 * 10 + 15);
>    last_write_time(f.path, time, ec);
>    VERIFY( !ec );
>    VERIFY( approx_equal(last_write_time(f.path), time) );
> +  #endif
>  }
>
>  int
> --
> 2.30.0
>
>
>


-- 
YunQiang Su

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] skip testing time before epoch on mips
@ 2021-03-08  6:35 Chen Li
  2021-03-08  6:41 ` YunQiang Su
  2021-03-08 10:57 ` Jonathan Wakely
  0 siblings, 2 replies; 5+ messages in thread
From: Chen Li @ 2021-03-08  6:35 UTC (permalink / raw)
  To: gcc-patches, libstdc++


When execute libstdc++ testcases on mips, I notice that last_write_time
alawys failed, and the failed VERIFY is  "VERIFY(
approx_equal(last_write_time(f.path), time) );" where testing time before
than epoch.

Below is the minimal case:

```
// gcc a.c
int main()
{
        struct timespec times[2] = {{1, UTIME_OMIT}, {-1201, 985000000}};
        utimensat(AT_FDCWD, "test", times, 0);

}
```

$ touch test && gcc a.c && ./a.out && stat test
  File: test
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d      Inode: 1056841     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  deepin)   Gid: ( 1000/  deepin)
Access: 2021-03-08 13:52:55.966354501 +0800
Modify: 2106-02-07 14:08:15.985000000 +0800
Change: 2021-03-08 13:52:56.907782193 +0800
 Birth: -

Undoubtedly, mtime's type is unsigned somewhere on mips.

After debuging kernel, it turns out that mtime is always -1201 in
ext4_setattr, cp_new_stat, newlstat and etc, so the problem should not
occur in kernel space.

go back to user space via copy_to_user, I finally found mips used
"unsigned int st_mtime_sec;" in struct kernel_stat, which is used to
receive -1201 from kernel.

Maybe sparc also suffers from this problem, but I have no machine to
verify.
---
 .../testsuite/27_io/filesystem/operations/last_write_time.cc    | 2 ++
 .../experimental/filesystem/operations/last_write_time.cc       | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
index 6ae64c482b6..72272d4e781 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc
@@ -200,11 +200,13 @@ test02()
   VERIFY( approx_equal(last_write_time(f.path), time) );
 
   ec = bad_ec;
+  #ifndef __mips__
   // A time before than the epoch
   time -= chrono::milliseconds(1000 * 60 * 20 + 15);
   last_write_time(f.path, time, ec);
   VERIFY( !ec );
   VERIFY( approx_equal(last_write_time(f.path), time) );
+  #endif
 }
 
 int
diff --git a/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc b/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
index 536ab1f28f6..6fb490a6bc3 100644
--- a/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
+++ b/libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
@@ -165,11 +165,13 @@ test02()
   VERIFY( !ec );
   VERIFY( approx_equal(last_write_time(f.path), time) );
 
+  #ifndef __mips__
   ec = bad_ec;
   time -= chrono::milliseconds(1000 * 60 * 10 + 15);
   last_write_time(f.path, time, ec);
   VERIFY( !ec );
   VERIFY( approx_equal(last_write_time(f.path), time) );
+  #endif
 }
 
 int
-- 
2.30.0




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-10  3:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10  3:31 [PATCH] skip testing time before epoch on mips Chen Li
  -- strict thread matches above, loose matches on Subject: below --
2021-03-08  6:35 Chen Li
2021-03-08  6:41 ` YunQiang Su
2021-03-08 10:57 ` Jonathan Wakely
2021-03-08 11:15   ` YunQiang Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).