Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 872821 - sys-process/psinfo: it stuck on RISC-V ARCH
Summary: sys-process/psinfo: it stuck on RISC-V ARCH
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Shell Tools project
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2022-09-25 12:15 UTC by Yixun Lan
Modified: 2022-09-26 12:27 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
psinfo-0.12-int.patch (psinfo-0.12-int.patch,1.01 KB, patch)
2022-09-25 12:17 UTC, Yixun Lan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yixun Lan archtester gentoo-dev 2022-09-25 12:15:22 UTC
I'm able to build this app, but it stuck if try to run it

while I use gdb to trace, and found it have problem to truncate int to char

       #include <unistd.h>

       int getopt(int argc, char *const argv[],
                  const char *optstring);

       int fgetc(FILE *stream);

the attached patch will just fix the problem

Reproducible: Always
Comment 1 Yixun Lan archtester gentoo-dev 2022-09-25 12:17:22 UTC
Created attachment 814120 [details, diff]
psinfo-0.12-int.patch
Comment 2 Yixun Lan archtester gentoo-dev 2022-09-26 06:12:32 UTC
this problem also exist at arm64 platform

while according to RISC-V psAbi manual[1], "char" is equivalent to "unsigned char", so in RISC-V/ARM64 the following code will always print out false, while in X86_64 will print out true

test() {
  char val = EOF;
  printf("%s", val == EOF ? "true" : "false");
}

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc

C/C++ type representations

char is unsigned.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-09-26 06:16:55 UTC
(Just commit it at your leisure)

Good find!
Comment 4 Yixun Lan archtester gentoo-dev 2022-09-26 12:20:54 UTC
From 0bceea42308cb1cf5faa9665511a8e8468c491e5 Mon Sep 17 00:00:00 2001
From: Yixun Lan <dlan@gentoo.org>
Date: Mon, 26 Sep 2022 20:08:08 +0800
Subject: [PATCH] fix 'char' issue in RISC-V (also Arm64) platform

According to RISC-V psAbi manual[1], "char" is equivalent to "unsigned char",
so in RISC-V/ARM64 the following code will always print out 'false',
while in X86_64 it will print out 'true'

test() {
  char val = EOF;
  printf("%s", val == EOF ? "true" : "false");
}

According to man page, the following two function return value is 'int':
       int getopt(int argc, char *const argv[],
                  const char *optstring);
       int fgetc(FILE *stream);

so, we use 'int' variable and then convert to 'char' if nencessary

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc
snip of description:
   C/C++ type representations
   char is unsigned.

Bug: https://bugs.gentoo.org/872821

Signed-off-by: Yixun Lan <dlan@gentoo.org>


I'll also try to report this to upstream (not sure if he can be reachable)..
Comment 5 Larry the Git Cow gentoo-dev 2022-09-26 12:22:51 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8d87286759fdff1a4ed2b9a36f7a1818e031e841

commit 8d87286759fdff1a4ed2b9a36f7a1818e031e841
Author:     Yixun Lan <dlan@gentoo.org>
AuthorDate: 2022-09-26 12:18:17 +0000
Commit:     Yixun Lan <dlan@gentoo.org>
CommitDate: 2022-09-26 12:21:35 +0000

    sys-process/psinfo: fix 'unsigned char' issue in RISC-V/ARM64 platform
    
    Closes: https://bugs.gentoo.org/872821
    Signed-off-by: Yixun Lan <dlan@gentoo.org>

 sys-process/psinfo/files/psinfo-0.12-char.patch | 65 +++++++++++++++++++++++++
 sys-process/psinfo/psinfo-0.12-r1.ebuild        |  3 +-
 2 files changed, 67 insertions(+), 1 deletion(-)
Comment 6 Larry the Git Cow gentoo-dev 2022-09-26 12:27:32 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2e82ad643d809c8ac1cb5b92e46c10344e3c6be5

commit 2e82ad643d809c8ac1cb5b92e46c10344e3c6be5
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-09-26 12:26:14 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-09-26 12:26:14 +0000

    sys-process/psinfo: revbump for unsigned char fix
    
    it's only keyworded on amd64/x86, but it affects runtime and it'll
    avoid confusion if any say, arm users have been using it (or trying to).
    
    Closes: https://bugs.gentoo.org/872821
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-process/psinfo/psinfo-0.12-r1.ebuild |  1 -
 sys-process/psinfo/psinfo-0.12-r2.ebuild | 24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)