[Libre-soc-bugs] [Bug 982] Support PowerPC ABI in ISACaller

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Tue Sep 5 18:20:35 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=982

--- Comment #6 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Luke Kenneth Casson Leighton from comment #4)
> (In reply to Jacob Lifshay from comment #2)
> > note that the list of actual syscalls that are needed to run a simple
> > program are a bit different:
> > I tested the following program on ppc64le:
> > gcc -x c - -static <<'EOF'
> > #include <stdio.h>
> > int main() {
> >     FILE *f;
> >     f = fopen("/proc/cmdline", "r");
> 
> it's very important to avoid fopen at the early phase, and just do
> read open write and close.  ("man 2 open")

that doesn't help much:
strace ./a.out > out.txt
execve("./a.out", ["./a.out"], 0x7fffed669f60 /* 18 vars */) = 0
brk(NULL)                               = 0x1001a000000
brk(0x1001a000fe4)                      = 0x1001a000fe4
uname({sysname="Linux", nodename="75-224-155-23", ...}) = 0
readlink("/proc/self/exe", "/home/jacob/a.out", 4096) = 17
brk(0x1001a030fe4)                      = 0x1001a030fe4
brk(0x1001a040000)                      = 0x1001a040000
openat(AT_FDCWD, "/proc/cmdline", O_RDONLY|O_CLOEXEC) = 3
read(3, "root=UUID=0ff31a9e-7434-4c47-b03"..., 4096) = 86
write(1, "root=UUID=0ff31a9e-7434-4c47-b03"..., 86) = 86
read(3, "", 4096)                       = 0
exit_group(0)                           = ?
+++ exited with 0 +++


I used this program:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>

#define BUFSZ 4096

#define RETRY_SYSCALL(retval, call) \
do { \
    retval = (call); \
} while(retval == -1 && errno == EINTR)

int main() {
    unsigned char buf[BUFSZ];
    int fd;
    RETRY_SYSCALL(fd, open("/proc/cmdline", O_RDONLY | O_CLOEXEC));
    if(fd == -1)
        return 1;

    while(1) {
        ssize_t read_count;
        RETRY_SYSCALL(read_count, read(fd, buf, sizeof(buf)));
        if(read_count == -1)
            return 1;
        if(read_count == 0)
            break;
        ssize_t pos = 0;
        while(pos < read_count) {
            ssize_t write_count, left = read_count - pos;
            RETRY_SYSCALL(write_count, write(STDOUT_FILENO, &buf[pos], left));
            if(write_count == -1)
                return 1;
            pos += write_count;
        }
    }

    // close(fd);

    return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list