Skip to contentSkip to conversation

linux-user: Implement VDSOs

PATCH Superseded Richard Henderson 6 participants 43 messages Aug 29, 2023 – Sep 19, 2023

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover linux-user: Implement VDSOs

Changes for v5:
* Integrated cross-compile, via new build-vdso.sh and meson rules. However, keep the binaries in the tree for hosts which do not have all of the cross-compile machinery.
* Update our loongarch64 docker image to avoid a binutils bug.

Changes for v4:
* Force all vdso to have a single load segment.
This will prevent problems with varying host/guest page size.
* Tidy some of the assembly with macros.
* Implement loongarch, ppc, s390x.

Just in case the list eats a binary:
https://gitlab.com/rth7680/qemu/-/tree/lu-vdso

r~

Richard Henderson (20):
tests/docker: Update docker-loongarch-cross toolchain
linux-user: Introduce imgsrc_read, imgsrc_read_alloc
linux-user: Tidy loader_exec
linux-user: Do not clobber bprm_buf swapping ehdr
linux-user: Use ImageSource in load_elf_image
linux-user: Use ImageSource in load_symbols
linux-user: Replace bprm->fd with bprm->src.fd
linux-user: Load vdso image if available
linux-user: Add gen-vdso tool
linux-user: Add build-vdso.sh tool
linux-user/i386: Add vdso
linux-user/x86_64: Add vdso
linux-user/aarch64: Add vdso
linux-user/arm: Add vdso
linux-user/hppa: Add vdso
linux-user/riscv: Add vdso
linux-user/loongarch64: Add vdso
linux-user/ppc: Add vdso
linux-user/s390x: Rename __SIGNAL_FRAMESIZE to STACK_FRAME_OVERHEAD linux-user/s390x: Add vdso

 linux-user/hppa/vdso-asmoffset.h              |  12 +
 linux-user/i386/vdso-asmoffset.h              |   6 +
 linux-user/loader.h                           |  60 ++-
 linux-user/loongarch64/vdso-asmoffset.h       |   8 +
 linux-user/ppc/vdso-asmoffset.h               |  20 +
 linux-user/riscv/vdso-asmoffset.h             |   9 +
 linux-user/s390x/vdso-asmoffset.h             |   2 +
 linux-user/arm/signal.c                       |  28 +-
 linux-user/elfload.c                          | 361 +++++++++++-------
 linux-user/flatload.c                         |   8 +-
 linux-user/gen-vdso.c                         | 223 +++++++++++
 linux-user/hppa/signal.c                      |  24 +-
 linux-user/i386/signal.c                      |  11 +
 linux-user/linuxload.c                        | 137 +++++--
 linux-user/loongarch64/signal.c               |  17 +-
 linux-user/ppc/signal.c                       |  31 +-
 linux-user/riscv/signal.c                     |   8 +
 linux-user/s390x/signal.c                     |   7 +-
 linux-user/gen-vdso-elfn.c.inc                | 314 +++++++++++++++
 linux-user/aarch64/meson.build                |  33 ++
 linux-user/aarch64/vdso-be.so                 | Bin 0 -> 3216 bytes
 linux-user/aarch64/vdso-le.so                 | Bin 0 -> 3216 bytes
 linux-user/aarch64/vdso.S                     |  73 ++++
 linux-user/aarch64/vdso.ld                    |  72 ++++
 linux-user/arm/meson.build                    |  35 ++
 linux-user/arm/vdso-be.so                     | Bin 0 -> 2680 bytes
 linux-user/arm/vdso-le.so                     | Bin 0 -> 2680 bytes
 linux-user/arm/vdso.S                         | 177 +++++++++
 linux-user/arm/vdso.ld                        |  67 ++++
 linux-user/build-vdso.sh                      |  31 ++
 linux-user/hppa/meson.build                   |  23 ++
 linux-user/hppa/vdso.S                        | 165 ++++++++
 linux-user/hppa/vdso.ld                       |  77 ++++
 linux-user/hppa/vdso.so                       | Bin 0 -> 2104 bytes
 linux-user/i386/meson.build                   |  24 ++
 linux-user/i386/vdso.S                        | 143 +++++++
 linux-user/i386/vdso.ld                       |  76 ++++
 linux-user/i386/vdso.so                       | Bin 0 -> 2672 bytes
 linux-user/loongarch64/meson.build            |  21 +
 linux-user/loongarch64/vdso.S                 | 130 +++++++
 linux-user/loongarch64/vdso.ld                |  73 ++++
 linux-user/loongarch64/vdso.so                | Bin 0 -> 3560 bytes
 linux-user/meson.build                        |  10 +-
 linux-user/ppc/Makefile.vdso                  |  18 +
 linux-user/ppc/meson.build                    |  12 +
 linux-user/ppc/vdso-32.ld                     |  70 ++++
 linux-user/ppc/vdso-32.so                     | Bin 0 -> 3020 bytes
 linux-user/ppc/vdso-64.ld                     |  68 ++++
 linux-user/ppc/vdso-64.so                     | Bin 0 -> 3896 bytes
 linux-user/ppc/vdso-64le.so                   | Bin 0 -> 3896 bytes
 linux-user/ppc/vdso.S                         | 239 ++++++++++++
 linux-user/riscv/meson.build                  |  30 ++
 linux-user/riscv/vdso-32.so                   | Bin 0 -> 2888 bytes
 linux-user/riscv/vdso-64.so                   | Bin 0 -> 3840 bytes
 linux-user/riscv/vdso.S                       | 186 +++++++++
 linux-user/riscv/vdso.ld                      |  74 ++++
 linux-user/s390x/meson.build                  |  24 ++
 linux-user/s390x/vdso.S                       |  61 +++
 linux-user/s390x/vdso.ld                      |  69 ++++
 linux-user/s390x/vdso.so                      | Bin 0 -> 3464 bytes
 linux-user/x86_64/meson.build                 |  20 +
 linux-user/x86_64/vdso.S                      |  78 ++++
 linux-user/x86_64/vdso.ld                     |  73 ++++
 linux-user/x86_64/vdso.so                     | Bin 0 -> 2968 bytes
 .../dockerfiles/debian-loongarch-cross.docker |   2 +-
 65 files changed, 3329 insertions(+), 211 deletions(-)
 create mode 100644 linux-user/hppa/vdso-asmoffset.h
 create mode 100644 linux-user/i386/vdso-asmoffset.h
 create mode 100644 linux-user/loongarch64/vdso-asmoffset.h
 create mode 100644 linux-user/ppc/vdso-asmoffset.h
 create mode 100644 linux-user/riscv/vdso-asmoffset.h
 create mode 100644 linux-user/s390x/vdso-asmoffset.h
 create mode 100644 linux-user/gen-vdso.c
 create mode 100644 linux-user/gen-vdso-elfn.c.inc
 create mode 100644 linux-user/aarch64/meson.build
 create mode 100755 linux-user/aarch64/vdso-be.so
 create mode 100755 linux-user/aarch64/vdso-le.so
 create mode 100644 linux-user/aarch64/vdso.S
 create mode 100644 linux-user/aarch64/vdso.ld
 create mode 100755 linux-user/arm/vdso-be.so
 create mode 100755 linux-user/arm/vdso-le.so
 create mode 100644 linux-user/arm/vdso.S
 create mode 100644 linux-user/arm/vdso.ld
 create mode 100755 linux-user/build-vdso.sh
 create mode 100644 linux-user/hppa/vdso.S
 create mode 100644 linux-user/hppa/vdso.ld
 create mode 100755 linux-user/hppa/vdso.so
 create mode 100644 linux-user/i386/vdso.S
 create mode 100644 linux-user/i386/vdso.ld
 create mode 100755 linux-user/i386/vdso.so
 create mode 100644 linux-user/loongarch64/meson.build
 create mode 100644 linux-user/loongarch64/vdso.S
 create mode 100644 linux-user/loongarch64/vdso.ld
 create mode 100755 linux-user/loongarch64/vdso.so
 create mode 100644 linux-user/ppc/Makefile.vdso
 create mode 100644 linux-user/ppc/vdso-32.ld
 create mode 100755 linux-user/ppc/vdso-32.so
 create mode 100644 linux-user/ppc/vdso-64.ld
 create mode 100755 linux-user/ppc/vdso-64.so
 create mode 100755 linux-user/ppc/vdso-64le.so
 create mode 100644 linux-user/ppc/vdso.S
 create mode 100644 linux-user/riscv/meson.build
 create mode 100755 linux-user/riscv/vdso-32.so
 create mode 100755 linux-user/riscv/vdso-64.so
 create mode 100644 linux-user/riscv/vdso.S
 create mode 100644 linux-user/riscv/vdso.ld
 create mode 100644 linux-user/s390x/vdso.S
 create mode 100644 linux-user/s390x/vdso.ld
 create mode 100755 linux-user/s390x/vdso.so
 create mode 100644 linux-user/x86_64/vdso.S
 create mode 100644 linux-user/x86_64/vdso.ld
 create mode 100755 linux-user/x86_64/vdso.so
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/20 tests/docker: Update docker-loongarch-cross toolchain

Update from clfs 5.0 to clfs 8.1, which includes updates to binutils 2.41, gcc 13.2, and glibc 2.38.

See https://github.com/loongson/build-tools

---
 tests/docker/dockerfiles/debian-loongarch-cross.docker | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/docker/dockerfiles/debian-loongarch-cross.docker +1 -1
index 9d957547b5..b4bf265717 100644
@@ -20,7 +20,7 @@ RUN apt-get update && \
         git \
         python3-minimal
 
-RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-5.0-cross-tools-gcc-glibc.tar.xz \
+RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2023.08.08/CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz \
     | tar -xJC /opt
 
 ENV PATH $PATH:/opt/cross-tools/bin
Signature · 1 line
2.34.1
Reviewed-by on v5 1/20
#2 lore raw

Re: [PATCH v5 01/20] tests/docker: Update docker-loongarch-cross toolchain

Quoted 16 lines · Richard Henderson

Update from clfs 5.0 to clfs 8.1, which includes updates to binutils 2.41, gcc 13.2, and glibc 2.38.

See https://github.com/loongson/build-tools

---
  tests/docker/dockerfiles/debian-loongarch-cross.docker | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/docker/dockerfiles/debian-loongarch-cross.docker +0 -0
index 9d957547b5..b4bf265717 100644

tests/docker/dockerfiles/debian-loongarch-cross.docker RUN apt-get update && \ · line 26

Quoted 8 lines
tests/docker/dockerfiles/debian-loongarch-cross.docker +1 -1
@@ -20,7 +20,7 @@ RUN apt-get update && \
          git \
          python3-minimal
 
-RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-5.0-cross-tools-gcc-glibc.tar.xz \
+RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2023.08.08/CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz \
      | tar -xJC /opt
 
  ENV PATH $PATH:/opt/cross-tools/bin

Thanks.
Song Gao

Reviewed-by on v5 1/20
#3 lore raw

Re: [PATCH v5 01/20] tests/docker: Update docker-loongarch-cross toolchain

In reply to Richard Henderson
Quoted 6 lines · Richard Henderson

Update from clfs 5.0 to clfs 8.1, which includes updates to binutils 2.41, gcc 13.2, and glibc 2.38.

See https://github.com/loongson/build-tools

Do you want this queued ahead of a vdso series?

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#4 lore raw

Re: [PATCH v5 01/20] tests/docker: Update docker-loongarch-cross toolchain

Quoted 6 lines · Alex Bennée
Quoted 3 lines · Richard Henderson

Update from clfs 5.0 to clfs 8.1, which includes updates to binutils 2.41, gcc 13.2, and glibc 2.38.

Quoted 7 lines
Quoted 3 lines

See https://github.com/loongson/build-tools

Do you want this queued ahead of a vdso series?

Yes, please.

r~

#5 lore raw

Re: [PATCH v5 01/20] tests/docker: Update docker-loongarch-cross toolchain

In reply to Richard Henderson
Quoted 15 lines · Richard Henderson

Update from clfs 5.0 to clfs 8.1, which includes updates to binutils 2.41, gcc 13.2, and glibc 2.38.

See https://github.com/loongson/build-tools

---
 tests/docker/dockerfiles/debian-loongarch-cross.docker | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/docker/dockerfiles/debian-loongarch-cross.docker +0 -0
index 9d957547b5..b4bf265717 100644

tests/docker/dockerfiles/debian-loongarch-cross.docker RUN apt-get update && \ · line 26

Quoted 8 lines
tests/docker/dockerfiles/debian-loongarch-cross.docker +1 -1
@@ -20,7 +20,7 @@ RUN apt-get update && \
         git \
         python3-minimal
 
-RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-5.0-cross-tools-gcc-glibc.tar.xz \
+RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2023.08.08/CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz \
     | tar -xJC /opt
 
 ENV PATH $PATH:/opt/cross-tools/bin

Queued to testing/next, thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#6 lore raw

PATCH v5 2/20 linux-user: Introduce imgsrc_read, imgsrc_read_alloc

In reply to Richard Henderson

Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE.

---
 linux-user/loader.h    | 61 +++++++++++++++++++++++-----
 linux-user/linuxload.c | 90 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+), 9 deletions(-)
linux-user/loader.h +52 -9
index 59cbeacf24..311d20f5d1 100644
@@ -18,6 +18,48 @@
 #ifndef LINUX_USER_LOADER_H
 #define LINUX_USER_LOADER_H
 
+typedef struct {
+    const void *cache;
+    unsigned int cache_size;
+    int fd;
+} ImageSource;
+
+/**
+ * imgsrc_read: Read from ImageSource
+ * @dst: destination for read
+ * @offset: offset within file for read
+ * @len: size of the read
+ * @img: ImageSource to read from
+ * @errp: Error details.
+ *
+ * Read into @dst, using the cache when possible.
+ */
+bool imgsrc_read(void *dst, off_t offset, size_t len,
+                 const ImageSource *img, Error **errp);
+
+/**
+ * imgsrc_read_alloc: Read from ImageSource
+ * @offset: offset within file for read
+ * @size: size of the read
+ * @img: ImageSource to read from
+ * @errp: Error details.
+ *
+ * Read into newly allocated memory, using the cache when possible.
+ */
+void *imgsrc_read_alloc(off_t offset, size_t len,
+                        const ImageSource *img, Error **errp);
+
+/**
+ * imgsrc_mmap: Map from ImageSource
+ *
+ * If @src has a file descriptor, pass on to target_mmap.  Otherwise,
+ * this is "mapping" from a host buffer, which resolves to memcpy.
+ * Therefore, flags must be MAP_PRIVATE | MAP_FIXED; the argument is
+ * retained for clarity.
+ */
+abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot,
+                     int flags, const ImageSource *src, abi_ulong offset);
+
 /*
  * Read a good amount of data initially, to hopefully get all the
  * program headers loaded.
@@ -29,15 +71,16 @@
  * used when loading binaries.
  */
 struct linux_binprm {
-        char buf[BPRM_BUF_SIZE] __attribute__((aligned));
-        abi_ulong p;
-        int fd;
-        int e_uid, e_gid;
-        int argc, envc;
-        char **argv;
-        char **envp;
-        char *filename;        /* Name of binary */
-        int (*core_dump)(int, const CPUArchState *); /* coredump routine */
+    char buf[BPRM_BUF_SIZE] __attribute__((aligned));
+    ImageSource src;
+    abi_ulong p;
+    int fd;
+    int e_uid, e_gid;
+    int argc, envc;
+    char **argv;
+    char **envp;
+    char *filename;        /* Name of binary */
+    int (*core_dump)(int, const CPUArchState *); /* coredump routine */
 };
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
linux-user/linuxload.c +90 -0

112 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v5 2/20
#7 lore raw

Re: [PATCH v5 02/20] linux-user: Introduce imgsrc_read, imgsrc_read_alloc

Quoted 5 lines · Richard Henderson

Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#8 lore raw

PATCH v5 3/20 linux-user: Tidy loader_exec

In reply to Richard Henderson

Reorg the if cases to reduce indentation.
Test for 4 bytes in the file before checking the signatures.

---
 linux-user/linuxload.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
linux-user/linuxload.c +21 -21
index 3536dd8104..5b7e9ab983 100644
@@ -154,31 +154,31 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
 
     retval = prepare_binprm(bprm);
 
-    if (retval >= 0) {
-        if (bprm->buf[0] == 0x7f
-                && bprm->buf[1] == 'E'
-                && bprm->buf[2] == 'L'
-                && bprm->buf[3] == 'F') {
-            retval = load_elf_binary(bprm, infop);
-#if defined(TARGET_HAS_BFLT)
-        } else if (bprm->buf[0] == 'b'
-                && bprm->buf[1] == 'F'
-                && bprm->buf[2] == 'L'
-                && bprm->buf[3] == 'T') {
-            retval = load_flt_binary(bprm, infop);
-#endif
-        } else {
-            return -ENOEXEC;
-        }
+    if (retval < 4) {
+        return -ENOEXEC;
     }
-
-    if (retval >= 0) {
-        /* success.  Initialize important registers */
-        do_init_thread(regs, infop);
+    if (bprm->buf[0] == 0x7f
+        && bprm->buf[1] == 'E'
+        && bprm->buf[2] == 'L'
+        && bprm->buf[3] == 'F') {
+        retval = load_elf_binary(bprm, infop);
+#if defined(TARGET_HAS_BFLT)
+    } else if (bprm->buf[0] == 'b'
+               && bprm->buf[1] == 'F'
+               && bprm->buf[2] == 'L'
+               && bprm->buf[3] == 'T') {
+        retval = load_flt_binary(bprm, infop);
+#endif
+    } else {
+        return -ENOEXEC;
+    }
+    if (retval < 0) {
         return retval;
     }
 
-    return retval;
+    /* Success.  Initialize important registers. */
+    do_init_thread(regs, infop);
+    return 0;
 }
 
 bool imgsrc_read(void *dst, off_t offset, size_t len,
Signature · 1 line
2.34.1
#10 lore raw

PATCH v5 4/20 linux-user: Do not clobber bprm_buf swapping ehdr

In reply to Richard Henderson

Rearrange the allocation of storage for ehdr between load_elf_image and load_elf_binary. The same set of copies are done, but we don't modify bprm_buf, which will be important later.

---
 linux-user/elfload.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
linux-user/elfload.c +14 -11
index 92b981c445..4d3b25ed14 100644
@@ -3020,16 +3020,17 @@ static bool parse_elf_properties(int image_fd,
    On return: INFO values will be filled in, as necessary or available.  */
 
 static void load_elf_image(const char *image_name, int image_fd,
-                           struct image_info *info, char **pinterp_name,
+                           struct image_info *info, struct elfhdr *ehdr,
+                           char **pinterp_name,
                            char bprm_buf[BPRM_BUF_SIZE])
 {
-    struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
     struct elf_phdr *phdr;
     abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
     int i, retval, prot_exec;
     Error *err = NULL;
 
     /* First of all, some simple consistency checks */
+    memcpy(ehdr, bprm_buf, sizeof(*ehdr));
     if (!elf_check_ident(ehdr)) {
         error_setg(&err, "Invalid ELF image for this architecture");
         goto exit_errmsg;
@@ -3344,6 +3345,7 @@ static void load_elf_image(const char *image_name, int image_fd,
 static void load_elf_interp(const char *filename, struct image_info *info,
                             char bprm_buf[BPRM_BUF_SIZE])
 {
+    struct elfhdr ehdr;
     int fd, retval;
     Error *err = NULL;
 
@@ -3365,7 +3367,7 @@ static void load_elf_interp(const char *filename, struct image_info *info,
         memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval);
     }
 
-    load_elf_image(filename, fd, info, NULL, bprm_buf);
+    load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf);
 }
 
 static int symfind(const void *s0, const void *s1)
@@ -3558,8 +3560,14 @@ uint32_t get_elf_eflags(int fd)
 
 int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
 {
+    /*
+     * We need a copy of the elf header for passing to create_elf_tables.
+     * We will have overwritten the original when we re-use bprm->buf
+     * while loading the interpreter.  Allocate the storage for this now
+     * and let elf_load_image do any swapping that may be required.
+     */
+    struct elfhdr ehdr;
     struct image_info interp_info;
-    struct elfhdr elf_ex;
     char *elf_interpreter = NULL;
     char *scratch;
 
@@ -3571,12 +3579,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
     info->start_mmap = (abi_ulong)ELF_START_MMAP;
 
     load_elf_image(bprm->filename, bprm->fd, info,
-                   &elf_interpreter, bprm->buf);
-
-    /* ??? We need a copy of the elf header for passing to create_elf_tables.
-       If we do nothing, we'll have overwritten this when we re-use bprm->buf
-       when we load the interpreter.  */
-    elf_ex = *(struct elfhdr *)bprm->buf;
+                   &ehdr, &elf_interpreter, bprm->buf);
 
     /* Do this so that we can load the interpreter, if need be.  We will
        change some of these later */
@@ -3663,7 +3666,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
         target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC);
     }
 
-    bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex,
+    bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr,
                                 info, (elf_interpreter ? &interp_info : NULL));
     info->start_stack = bprm->p;
 
Signature · 1 line
2.34.1
Reviewed-by on v5 4/20
#11 lore raw

Re: [PATCH v5 04/20] linux-user: Do not clobber bprm_buf swapping ehdr

Quoted 6 lines · Richard Henderson

Rearrange the allocation of storage for ehdr between load_elf_image and load_elf_binary. The same set of copies are done, but we don't modify bprm_buf, which will be important later.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#12 lore raw

PATCH v5 5/20 linux-user: Use ImageSource in load_elf_image

In reply to Richard Henderson

Change parse_elf_properties as well, as the bprm_buf argument ties the two functions closely.

---
 linux-user/elfload.c | 128 +++++++++++++++++--------------------------
 1 file changed, 49 insertions(+), 79 deletions(-)
linux-user/elfload.c +49 -79
index 4d3b25ed14..833c22da25 100644
@@ -2923,10 +2923,9 @@ static bool parse_elf_property(const uint32_t *data, int *off, int datasz,
 }
 
 /* Process NT_GNU_PROPERTY_TYPE_0. */
-static bool parse_elf_properties(int image_fd,
+static bool parse_elf_properties(const ImageSource *src,
                                  struct image_info *info,
                                  const struct elf_phdr *phdr,
-                                 char bprm_buf[BPRM_BUF_SIZE],
                                  Error **errp)
 {
     union {
@@ -2954,14 +2953,8 @@ static bool parse_elf_properties(int image_fd,
         return false;
     }
 
-    if (phdr->p_offset + n <= BPRM_BUF_SIZE) {
-        memcpy(&note, bprm_buf + phdr->p_offset, n);
-    } else {
-        ssize_t len = pread(image_fd, &note, n, phdr->p_offset);
-        if (len != n) {
-            error_setg_errno(errp, errno, "Error reading file header");
-            return false;
-        }
+    if (!imgsrc_read(&note, phdr->p_offset, n, src, errp)) {
+        return false;
     }
 
     /*
@@ -3007,30 +3000,34 @@ static bool parse_elf_properties(int image_fd,
     }
 }
 
-/* Load an ELF image into the address space.
+/**
+ * load_elf_image: Load an ELF image into the address space.
+ * @image_name: the filename of the image, to use in error messages.
+ * @src: the ImageSource from which to read.
+ * @info: info collected from the loaded image.
+ * @ehdr: the ELF header, not yet bswapped.
+ * @pinterp_name: record any PT_INTERP string found.
+ *
+ * On return: @info values will be filled in, as necessary or available.
+ */
 
-   IMAGE_NAME is the filename of the image, to use in error messages.
-   IMAGE_FD is the open file descriptor for the image.
-
-   BPRM_BUF is a copy of the beginning of the file; this of course
-   contains the elf file header at offset 0.  It is assumed that this
-   buffer is sufficiently aligned to present no problems to the host
-   in accessing data at aligned offsets within the buffer.
-
-   On return: INFO values will be filled in, as necessary or available.  */
-
-static void load_elf_image(const char *image_name, int image_fd,
+static void load_elf_image(const char *image_name, const ImageSource *src,
                            struct image_info *info, struct elfhdr *ehdr,
-                           char **pinterp_name,
-                           char bprm_buf[BPRM_BUF_SIZE])
+                           char **pinterp_name)
 {
-    struct elf_phdr *phdr;
+    g_autofree struct elf_phdr *phdr = NULL;
     abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
-    int i, retval, prot_exec;
+    int i, prot_exec;
     Error *err = NULL;
 
-    /* First of all, some simple consistency checks */
-    memcpy(ehdr, bprm_buf, sizeof(*ehdr));
+    /*
+     * First of all, some simple consistency checks.
+     * Note that we rely on the bswapped ehdr staying in bprm_buf,
+     * for later use by load_elf_binary and create_elf_tables.
+     */
+    if (!imgsrc_read(ehdr, 0, sizeof(*ehdr), src, &err)) {
+        goto exit_errmsg;
+    }
     if (!elf_check_ident(ehdr)) {
         error_setg(&err, "Invalid ELF image for this architecture");
         goto exit_errmsg;
@@ -3041,15 +3038,11 @@ static void load_elf_image(const char *image_name, int image_fd,
         goto exit_errmsg;
     }
 
-    i = ehdr->e_phnum * sizeof(struct elf_phdr);
-    if (ehdr->e_phoff + i <= BPRM_BUF_SIZE) {
-        phdr = (struct elf_phdr *)(bprm_buf + ehdr->e_phoff);
-    } else {
-        phdr = (struct elf_phdr *) alloca(i);
-        retval = pread(image_fd, phdr, i, ehdr->e_phoff);
-        if (retval != i) {
-            goto exit_read;
-        }
+    phdr = imgsrc_read_alloc(ehdr->e_phoff,
+                             ehdr->e_phnum * sizeof(struct elf_phdr),
+                             src, &err);
+    if (phdr == NULL) {
+        goto exit_errmsg;
     }
     bswap_phdr(phdr, ehdr->e_phnum);
 
@@ -3086,17 +3079,10 @@ static void load_elf_image(const char *image_name, int image_fd,
                 goto exit_errmsg;
             }
 
-            interp_name = g_malloc(eppnt->p_filesz);
-
-            if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
-                memcpy(interp_name, bprm_buf + eppnt->p_offset,
-                       eppnt->p_filesz);
-            } else {
-                retval = pread(image_fd, interp_name, eppnt->p_filesz,
-                               eppnt->p_offset);
-                if (retval != eppnt->p_filesz) {
-                    goto exit_read;
-                }
+            interp_name = imgsrc_read_alloc(eppnt->p_offset, eppnt->p_filesz,
+                                            src, &err);
+            if (interp_name == NULL) {
+                goto exit_errmsg;
             }
             if (interp_name[eppnt->p_filesz - 1] != 0) {
                 error_setg(&err, "Invalid PT_INTERP entry");
@@ -3104,7 +3090,7 @@ static void load_elf_image(const char *image_name, int image_fd,
             }
             *pinterp_name = g_steal_pointer(&interp_name);
         } else if (eppnt->p_type == PT_GNU_PROPERTY) {
-            if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) {
+            if (!parse_elf_properties(src, info, eppnt, &err)) {
                 goto exit_errmsg;
             }
         } else if (eppnt->p_type == PT_GNU_STACK) {
@@ -3257,9 +3243,9 @@ static void load_elf_image(const char *image_name, int image_fd,
              * but no backing file segment.
              */
             if (eppnt->p_filesz != 0) {
-                error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po,
+                error = imgsrc_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po,
                                     elf_prot, MAP_PRIVATE | MAP_FIXED,
-                                    image_fd, eppnt->p_offset - vaddr_po);
+                                    src, eppnt->p_offset - vaddr_po);
                 if (error == -1) {
                     goto exit_mmap;
                 }
@@ -3291,20 +3277,11 @@ static void load_elf_image(const char *image_name, int image_fd,
 #ifdef TARGET_MIPS
         } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
             Mips_elf_abiflags_v0 abiflags;
-            if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) {
-                error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry");
+
+            if (!imgsrc_read(&abiflags, eppnt->p_offset, sizeof(abiflags),
+                             src, &err)) {
                 goto exit_errmsg;
             }
-            if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
-                memcpy(&abiflags, bprm_buf + eppnt->p_offset,
-                       sizeof(Mips_elf_abiflags_v0));
-            } else {
-                retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0),
-                               eppnt->p_offset);
-                if (retval != sizeof(Mips_elf_abiflags_v0)) {
-                    goto exit_read;
-                }
-            }
             bswap_mips_abiflags(&abiflags);
             info->fp_abi = abiflags.fp_abi;
 #endif
@@ -3317,23 +3294,16 @@ static void load_elf_image(const char *image_name, int image_fd,
     }
 
     if (qemu_log_enabled()) {
-        load_symbols(ehdr, image_fd, load_bias);
+        load_symbols(ehdr, src->fd, load_bias);
     }
 
-    debuginfo_report_elf(image_name, image_fd, load_bias);
+    debuginfo_report_elf(image_name, src->fd, load_bias);
 
     mmap_unlock();
 
-    close(image_fd);
+    close(src->fd);
     return;
 
- exit_read:
-    if (retval >= 0) {
-        error_setg(&err, "Incomplete read of file header");
-    } else {
-        error_setg_errno(&err, errno, "Error reading file header");
-    }
-    goto exit_errmsg;
  exit_mmap:
     error_setg_errno(&err, errno, "Error mapping file");
     goto exit_errmsg;
@@ -3346,6 +3316,7 @@ static void load_elf_interp(const char *filename, struct image_info *info,
                             char bprm_buf[BPRM_BUF_SIZE])
 {
     struct elfhdr ehdr;
+    ImageSource src;
     int fd, retval;
     Error *err = NULL;
 
@@ -3363,11 +3334,11 @@ static void load_elf_interp(const char *filename, struct image_info *info,
         exit(-1);
     }
 
-    if (retval < BPRM_BUF_SIZE) {
-        memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval);
-    }
+    src.fd = fd;
+    src.cache = bprm_buf;
+    src.cache_size = retval;
 
-    load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf);
+    load_elf_image(filename, &src, info, &ehdr, NULL);
 }
 
 static int symfind(const void *s0, const void *s1)
@@ -3578,8 +3549,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
 
     info->start_mmap = (abi_ulong)ELF_START_MMAP;
 
-    load_elf_image(bprm->filename, bprm->fd, info,
-                   &ehdr, &elf_interpreter, bprm->buf);
+    load_elf_image(bprm->filename, &bprm->src, info, &ehdr, &elf_interpreter);
 
     /* Do this so that we can load the interpreter, if need be.  We will
        change some of these later */
Signature · 1 line
2.34.1
#13 lore raw

PATCH v5 6/20 linux-user: Use ImageSource in load_symbols

In reply to Richard Henderson

Aside from the section headers, we're unlikely to hit the ImageSource cache on guest executables. But the interface for imgsrc_read_* is better.

---
 linux-user/elfload.c | 87 ++++++++++++++++++++++++--------------------
 1 file changed, 48 insertions(+), 39 deletions(-)
linux-user/elfload.c +48 -39
index 833c22da25..f34fb64c0c 100644
@@ -2049,7 +2049,8 @@ static inline void bswap_mips_abiflags(Mips_elf_abiflags_v0 *abiflags) { }
 #ifdef USE_ELF_CORE_DUMP
 static int elf_core_dump(int, const CPUArchState *);
 #endif /* USE_ELF_CORE_DUMP */
-static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias);
+static void load_symbols(struct elfhdr *hdr, const ImageSource *src,
+                         abi_ulong load_bias);
 
 /* Verify the portions of EHDR within E_IDENT for the target.
    This can be performed before bswapping the entire header.  */
@@ -3294,7 +3295,7 @@ static void load_elf_image(const char *image_name, const ImageSource *src,
     }
 
     if (qemu_log_enabled()) {
-        load_symbols(ehdr, src->fd, load_bias);
+        load_symbols(ehdr, src, load_bias);
     }
 
     debuginfo_report_elf(image_name, src->fd, load_bias);
@@ -3385,19 +3386,20 @@ static int symcmp(const void *s0, const void *s1)
 }
 
 /* Best attempt to load symbols from this ELF object. */
-static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
+static void load_symbols(struct elfhdr *hdr, const ImageSource *src,
+                         abi_ulong load_bias)
 {
     int i, shnum, nsyms, sym_idx = 0, str_idx = 0;
-    uint64_t segsz;
-    struct elf_shdr *shdr;
+    g_autofree struct elf_shdr *shdr = NULL;
     char *strings = NULL;
-    struct syminfo *s = NULL;
-    struct elf_sym *new_syms, *syms = NULL;
+    struct elf_sym *syms = NULL;
+    struct elf_sym *new_syms;
+    uint64_t segsz;
 
     shnum = hdr->e_shnum;
-    i = shnum * sizeof(struct elf_shdr);
-    shdr = (struct elf_shdr *)alloca(i);
-    if (pread(fd, shdr, i, hdr->e_shoff) != i) {
+    shdr = imgsrc_read_alloc(hdr->e_shoff, shnum * sizeof(struct elf_shdr),
+                             src, NULL);
+    if (shdr == NULL) {
         return;
     }
 
@@ -3415,31 +3417,33 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
 
  found:
     /* Now know where the strtab and symtab are.  Snarf them.  */
-    s = g_try_new(struct syminfo, 1);
-    if (!s) {
-        goto give_up;
-    }
 
     segsz = shdr[str_idx].sh_size;
-    s->disas_strtab = strings = g_try_malloc(segsz);
-    if (!strings ||
-        pread(fd, strings, segsz, shdr[str_idx].sh_offset) != segsz) {
+    strings = g_try_malloc(segsz);
+    if (!strings) {
+        goto give_up;
+    }
+    if (!imgsrc_read(strings, shdr[str_idx].sh_offset, segsz, src, NULL)) {
         goto give_up;
     }
 
     segsz = shdr[sym_idx].sh_size;
-    syms = g_try_malloc(segsz);
-    if (!syms || pread(fd, syms, segsz, shdr[sym_idx].sh_offset) != segsz) {
-        goto give_up;
-    }
-
     if (segsz / sizeof(struct elf_sym) > INT_MAX) {
-        /* Implausibly large symbol table: give up rather than ploughing
-         * on with the number of symbols calculation overflowing
+        /*
+         * Implausibly large symbol table: give up rather than ploughing
+         * on with the number of symbols calculation overflowing.
          */
         goto give_up;
     }
     nsyms = segsz / sizeof(struct elf_sym);
+    syms = g_try_malloc(segsz);
+    if (!syms) {
+        goto give_up;
+    }
+    if (!imgsrc_read(syms, shdr[sym_idx].sh_offset, segsz, src, NULL)) {
+        goto give_up;
+    }
+
     for (i = 0; i < nsyms; ) {
         bswap_sym(syms + i);
         /* Throw away entries which we do not need.  */
@@ -3464,10 +3468,12 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
         goto give_up;
     }
 
-    /* Attempt to free the storage associated with the local symbols
-       that we threw away.  Whether or not this has any effect on the
-       memory allocation depends on the malloc implementation and how
-       many symbols we managed to discard.  */
+    /*
+     * Attempt to free the storage associated with the local symbols
+     * that we threw away.  Whether or not this has any effect on the
+     * memory allocation depends on the malloc implementation and how
+     * many symbols we managed to discard.
+     */
     new_syms = g_try_renew(struct elf_sym, syms, nsyms);
     if (new_syms == NULL) {
         goto give_up;
@@ -3476,20 +3482,23 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
 
     qsort(syms, nsyms, sizeof(*syms), symcmp);
 
-    s->disas_num_syms = nsyms;
-#if ELF_CLASS == ELFCLASS32
-    s->disas_symtab.elf32 = syms;
-#else
-    s->disas_symtab.elf64 = syms;
-#endif
-    s->lookup_symbol = lookup_symbolxx;
-    s->next = syminfos;
-    syminfos = s;
+    {
+        struct syminfo *s = g_new(struct syminfo, 1);
 
+        s->disas_strtab = strings;
+        s->disas_num_syms = nsyms;
+#if ELF_CLASS == ELFCLASS32
+        s->disas_symtab.elf32 = syms;
+#else
+        s->disas_symtab.elf64 = syms;
+#endif
+        s->lookup_symbol = lookup_symbolxx;
+        s->next = syminfos;
+        syminfos = s;
+    }
     return;
 
-give_up:
-    g_free(s);
+ give_up:
     g_free(strings);
     g_free(syms);
 }
Signature · 1 line
2.34.1
#14 lore raw

PATCH v5 7/20 linux-user: Replace bprm->fd with bprm->src.fd

In reply to Richard Henderson

There are only a couple of uses of bprm->fd remaining. Migrate to the other field.

---
 linux-user/loader.h    | 1 -
 linux-user/flatload.c  | 8 ++++----
 linux-user/linuxload.c | 5 ++---
 3 files changed, 6 insertions(+), 8 deletions(-)
linux-user/loader.h +0 -1
index 311d20f5d1..5b4cdddd50 100644
@@ -74,7 +74,6 @@ struct linux_binprm {
     char buf[BPRM_BUF_SIZE] __attribute__((aligned));
     ImageSource src;
     abi_ulong p;
-    int fd;
     int e_uid, e_gid;
     int argc, envc;
     char **argv;
linux-user/flatload.c +4 -4
index 8f5e9f489b..15e3ec5f6b 100644
@@ -463,7 +463,7 @@ static int load_flat_file(struct linux_binprm * bprm,
         DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n");
 
         textpos = target_mmap(0, text_len, PROT_READ|PROT_EXEC,
-                              MAP_PRIVATE, bprm->fd, 0);
+                              MAP_PRIVATE, bprm->src.fd, 0);
         if (textpos == -1) {
             fprintf(stderr, "Unable to mmap process text\n");
             return -1;
@@ -490,7 +490,7 @@ static int load_flat_file(struct linux_binprm * bprm,
         } else
 #endif
         {
-            result = target_pread(bprm->fd, datapos,
+            result = target_pread(bprm->src.fd, datapos,
                                   data_len + (relocs * sizeof(abi_ulong)),
                                   fpos);
         }
@@ -540,10 +540,10 @@ static int load_flat_file(struct linux_binprm * bprm,
         else
 #endif
         {
-            result = target_pread(bprm->fd, textpos,
+            result = target_pread(bprm->src.fd, textpos,
                                   text_len, 0);
             if (result >= 0) {
-                result = target_pread(bprm->fd, datapos,
+                result = target_pread(bprm->src.fd, datapos,
                     data_len + (relocs * sizeof(abi_ulong)),
                     ntohl(hdr->data_start));
             }
linux-user/linuxload.c +2 -3
index 5b7e9ab983..4a794f8cea 100644
@@ -39,7 +39,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
     int mode;
     int retval;
 
-    if (fstat(bprm->fd, &st) < 0) {
+    if (fstat(bprm->src.fd, &st) < 0) {
         return -errno;
     }
 
@@ -69,7 +69,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
         bprm->e_gid = st.st_gid;
     }
 
-    retval = read(bprm->fd, bprm->buf, BPRM_BUF_SIZE);
+    retval = read(bprm->src.fd, bprm->buf, BPRM_BUF_SIZE);
     if (retval < 0) {
         perror("prepare_binprm");
         exit(-1);
@@ -144,7 +144,6 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
 {
     int retval;
 
-    bprm->fd = fdexec;
     bprm->src.fd = fdexec;
     bprm->filename = (char *)filename;
     bprm->argc = count(argv);
Signature · 1 line
2.34.1
#15 lore raw

PATCH v5 8/20 linux-user: Load vdso image if available

In reply to Richard Henderson

The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines.

---
 linux-user/elfload.c | 87 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 78 insertions(+), 9 deletions(-)
linux-user/elfload.c +78 -9
index f34fb64c0c..2a6adebb4a 100644
@@ -33,6 +33,19 @@
 #undef ELF_ARCH
 #endif
 
+#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0
+#endif
+
+typedef struct {
+    const uint8_t *image;
+    const uint32_t *relocs;
+    unsigned image_size;
+    unsigned reloc_count;
+    unsigned sigreturn_ofs;
+    unsigned rt_sigreturn_ofs;
+} VdsoImageInfo;
+
 #define ELF_OSABI   ELFOSABI_SYSV
 
 /* from personality.h */
@@ -2292,7 +2305,8 @@ static abi_ulong loader_build_fdpic_loadmap(struct image_info *info, abi_ulong s
 static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
                                    struct elfhdr *exec,
                                    struct image_info *info,
-                                   struct image_info *interp_info)
+                                   struct image_info *interp_info,
+                                   struct image_info *vdso_info)
 {
     abi_ulong sp;
     abi_ulong u_argc, u_argv, u_envp, u_auxv;
@@ -2380,10 +2394,15 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     }
 
     size = (DLINFO_ITEMS + 1) * 2;
-    if (k_base_platform)
+    if (k_base_platform) {
         size += 2;
-    if (k_platform)
+    }
+    if (k_platform) {
         size += 2;
+    }
+    if (vdso_info) {
+        size += 2;
+    }
 #ifdef DLINFO_ARCH_ITEMS
     size += DLINFO_ARCH_ITEMS * 2;
 #endif
@@ -2465,6 +2484,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     if (u_platform) {
         NEW_AUX_ENT(AT_PLATFORM, u_platform);
     }
+    if (vdso_info) {
+        NEW_AUX_ENT(AT_SYSINFO_EHDR, vdso_info->load_addr);
+    }
     NEW_AUX_ENT (AT_NULL, 0);
 #undef NEW_AUX_ENT
 
@@ -3342,6 +3364,49 @@ static void load_elf_interp(const char *filename, struct image_info *info,
     load_elf_image(filename, &src, info, &ehdr, NULL);
 }
 
+#ifndef vdso_image_info
+#define vdso_image_info()    NULL
+#endif
+
+static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso)
+{
+    ImageSource src;
+    struct elfhdr ehdr;
+    abi_ulong load_bias, load_addr;
+
+    src.fd = -1;
+    src.cache = vdso->image;
+    src.cache_size = vdso->image_size;
+
+    load_elf_image("<internal-vdso>", &src, info, &ehdr, NULL);
+    load_addr = info->load_addr;
+    load_bias = info->load_bias;
+
+    /*
+     * We need to relocate the VDSO image.  The one built into the kernel
+     * is built for a fixed address.  The one built for QEMU is not, since
+     * that requires close control of the guest address space.
+     * We pre-processed the image to locate all of the addresses that need
+     * to be updated.
+     */
+    for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) {
+        abi_ulong *addr = g2h_untagged(load_addr + vdso->relocs[i]);
+        *addr = tswapal(tswapal(*addr) + load_bias);
+    }
+
+    /* Install signal trampolines, if present. */
+    if (vdso->sigreturn_ofs) {
+        default_sigreturn = load_addr + vdso->sigreturn_ofs;
+    }
+    if (vdso->rt_sigreturn_ofs) {
+        default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs;
+    }
+
+    /* Remove write from VDSO segment. */
+    target_mprotect(info->start_data, info->end_data - info->start_data,
+                    PROT_READ | PROT_EXEC);
+}
+
 static int symfind(const void *s0, const void *s1)
 {
     struct elf_sym *sym = (struct elf_sym *)s1;
@@ -3547,7 +3612,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
      * and let elf_load_image do any swapping that may be required.
      */
     struct elfhdr ehdr;
-    struct image_info interp_info;
+    struct image_info interp_info, vdso_info;
     char *elf_interpreter = NULL;
     char *scratch;
 
@@ -3630,10 +3695,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
     }
 
     /*
-     * TODO: load a vdso, which would also contain the signal trampolines.
-     * Otherwise, allocate a private page to hold them.
+     * Load a vdso if available, which will amongst other things contain the
+     * signal trampolines.  Otherwise, allocate a separate page for them.
      */
-    if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) {
+    const VdsoImageInfo *vdso = vdso_image_info();
+    if (vdso) {
+        load_elf_vdso(&vdso_info, vdso);
+    } else if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) {
         abi_long tramp_page = target_mmap(0, TARGET_PAGE_SIZE,
                                           PROT_READ | PROT_WRITE,
                                           MAP_PRIVATE | MAP_ANON, -1, 0);
@@ -3645,8 +3713,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
         target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC);
     }
 
-    bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr,
-                                info, (elf_interpreter ? &interp_info : NULL));
+    bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info,
+                                elf_interpreter ? &interp_info : NULL,
+                                vdso ? &vdso_info : NULL);
     info->start_stack = bprm->p;
 
     /* If we have an interpreter, set that as the program's entry point.
Signature · 1 line
2.34.1
Reviewed-by on v5 8/20
#16 lore raw

Re: [PATCH v5 08/20] linux-user: Load vdso image if available

Hi Richard,

Quoted 14 lines · Richard Henderson

The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines.

---
  linux-user/elfload.c | 87 +++++++++++++++++++++++++++++++++++++++-----
  1 file changed, 78 insertions(+), 9 deletions(-)
linux-user/elfload.c +0 -0
index f34fb64c0c..2a6adebb4a 100644

linux-user/elfload.c line 37

Quoted 5 lines
linux-user/elfload.c +2 -0
@@ -33,6 +33,19 @@
  #undef ELF_ARCH
  #endif
 
+#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0

I'd rather #error here so new targets are added with a clearly defined TARGET_ARCH_HAS_SIGTRAMP_PAGE.

Quoted 30 lines
linux-user/elfload.c +27 -0
+#endif
+
+typedef struct {
+    const uint8_t *image;
+    const uint32_t *relocs;
+    unsigned image_size;
+    unsigned reloc_count;
+    unsigned sigreturn_ofs;
+    unsigned rt_sigreturn_ofs;
+} VdsoImageInfo;
+
  #define ELF_OSABI   ELFOSABI_SYSV
 
 
+#ifndef vdso_image_info
+#define vdso_image_info()    NULL
+#endif
+
+static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso)
+{
+    ImageSource src;
+    struct elfhdr ehdr;
+    abi_ulong load_bias, load_addr;
+
+    src.fd = -1;
+    src.cache = vdso->image;
+    src.cache_size = vdso->image_size;
+
+    load_elf_image("<internal-vdso>", &src, info, &ehdr, NULL);
+    load_addr = info->load_addr;

linux-user/elfload.c

Quoted 10 lines
linux-user/elfload.c +10 -0
+    load_bias = info->load_bias;
+
+    /*
+     * We need to relocate the VDSO image.  The one built into the kernel
+     * is built for a fixed address.  The one built for QEMU is not, since
+     * that requires close control of the guest address space.
+     * We pre-processed the image to locate all of the addresses that need
+     * to be updated.
+     */
+    for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) {

Do we really need 'n'?

Quoted 6 lines
linux-user/elfload.c +6 -0
+        abi_ulong *addr = g2h_untagged(load_addr + vdso->relocs[i]);
+        *addr = tswapal(tswapal(*addr) + load_bias);
+    }
+
+    /* Install signal trampolines, if present. */
+    if (vdso->sigreturn_ofs) {

linux-user/elfload.c static void load_elf_interp(const char *filename, struct image_info *info, · line 3408

Quoted 10 lines
linux-user/elfload.c +10 -0
+        default_sigreturn = load_addr + vdso->sigreturn_ofs;
+    }
+    if (vdso->rt_sigreturn_ofs) {
+        default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs;
+    }
+
+    /* Remove write from VDSO segment. */
+    target_mprotect(info->start_data, info->end_data - info->start_data,
+                    PROT_READ | PROT_EXEC);
+}
#17 lore raw

Re: [PATCH v5 08/20] linux-user: Load vdso image if available

Quoted 12 lines · Philippe Mathieu-Daudé

Hi Richard,

Quoted 9 lines · Richard Henderson

The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines.

---
  linux-user/elfload.c | 87 +++++++++++++++++++++++++++++++++++++++-----

  1 file changed, 78 insertions(+), 9 deletions(-)
Quoted 12 lines

linux-user/elfload.c line 36

Quoted 9 lines
linux-user/elfload.c +2 -0
index f34fb64c0c..2a6adebb4a 100644
@@ -33,6 +33,19 @@
   #undef ELF_ARCH
   #endif
+#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0

I'd rather #error here so new targets are added with a clearly defined TARGET_ARCH_HAS_SIGTRAMP_PAGE.

The next step after adding vdso's is to remove TARGET_ARCH_HAS_SIGTRAMP_PAGE.

Quoted 3 lines

linux-user/elfload.c static void load_elf_interp(const char *filename, struct image_info *info, · line 3392

Quoted 1 line
linux-user/elfload.c +1 -0
+    for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) {

Do we really need 'n'?

You should always have an loop invariant condition if possible.

r~

#18 lore raw

Re: [PATCH v5 08/20] linux-user: Load vdso image if available

Quoted 26 lines · Richard Henderson
Quoted 12 lines · Philippe Mathieu-Daudé

Hi Richard,

Quoted 9 lines · Richard Henderson

The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines.

---
  linux-user/elfload.c | 87 +++++++++++++++++++++++++++++++++++++++-----

  1 file changed, 78 insertions(+), 9 deletions(-)
Quoted 12 lines

linux-user/elfload.c line 36

Quoted 9 lines
linux-user/elfload.c +2 -0
index f34fb64c0c..2a6adebb4a 100644
@@ -33,6 +33,19 @@
   #undef ELF_ARCH
   #endif
+#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0

I'd rather #error here so new targets are added with a clearly defined TARGET_ARCH_HAS_SIGTRAMP_PAGE.

Quoted 1 line

The next step after adding vdso's is to remove TARGET_ARCH_HAS_SIGTRAMP_PAGE.

Ah great.

Quoted 5 lines
Quoted 3 lines

linux-user/elfload.c static void load_elf_interp(const char *filename, struct image_info *info, · line 3392

Quoted 1 line
linux-user/elfload.c +1 -0
+    for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) {

Do we really need 'n'?

You should always have an loop invariant condition if possible.

vdso->reloc_count doesn't seem updated, but I get your point.

#19 lore raw

Re: [PATCH v5 08/20] linux-user: Load vdso image if available

Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+    for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) {

Do we really need 'n'?

You should always have an loop invariant condition if possible.

vdso->reloc_count doesn't seem updated, but I get your point.

But the compiler doesn't know that -- it must assume that the store to *addr may overlap reloc_count.

r~

#20 lore raw

PATCH v5 9/20 linux-user: Add gen-vdso tool

In reply to Richard Henderson

This tool will be used for post-processing the linked vdso image, turning it into something that is easy to include into elfload.c.

---
 linux-user/gen-vdso.c          | 223 ++++++++++++++++++++++++
 linux-user/gen-vdso-elfn.c.inc | 307 +++++++++++++++++++++++++++++++++
 linux-user/meson.build         |   6 +-
 3 files changed, 535 insertions(+), 1 deletion(-)
 create mode 100644 linux-user/gen-vdso.c
 create mode 100644 linux-user/gen-vdso-elfn.c.inc
linux-user/gen-vdso.c new file +223 -0
new file mode 100644
index 0000000000..a6c61d2f6e
@@ -0,0 +1,223 @@
+/*
+ * Post-process a vdso elf image for inclusion into qemu.
+ *
+ * Copyright 2023 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <endian.h>
+#include <unistd.h>
+#include "elf.h"
+
+
+#define bswap_(p)  _Generic(*(p), \
+                            uint16_t: __builtin_bswap16,       \
+                            uint32_t: __builtin_bswap32,       \
+                            uint64_t: __builtin_bswap64,       \
+                            int16_t: __builtin_bswap16,        \
+                            int32_t: __builtin_bswap32,        \
+                            int64_t: __builtin_bswap64)
+#define bswaps(p) (*(p) = bswap_(p)(*(p)))
+
+static void output_reloc(FILE *outf, void *buf, void *loc)
+{
+    fprintf(outf, "    0x%08lx,\n", (unsigned long)(loc - buf));
+}
+
+static const char *sigreturn_sym;
+static const char *rt_sigreturn_sym;
+
+static unsigned sigreturn_addr;
+static unsigned rt_sigreturn_addr;
+
+#define N 32
+#define elfN(x)  elf32_##x
+#define ElfN(x)  Elf32_##x
+#include "gen-vdso-elfn.c.inc"
+#undef N
+#undef elfN
+#undef ElfN
+
+#define N 64
+#define elfN(x)  elf64_##x
+#define ElfN(x)  Elf64_##x
+#include "gen-vdso-elfn.c.inc"
+#undef N
+#undef elfN
+#undef ElfN
+
+
+int main(int argc, char **argv)
+{
+    FILE *inf, *outf;
+    long total_len;
+    const char *prefix = "vdso";
+    const char *inf_name;
+    const char *outf_name = NULL;
+    unsigned char *buf;
+    bool need_bswap;
+
+    while (1) {
+        int opt = getopt(argc, argv, "o:p:r:s:");
+        if (opt < 0) {
+            break;
+        }
+        switch (opt) {
+        case 'o':
+            outf_name = optarg;
+            break;
+        case 'p':
+            prefix = optarg;
+            break;
+        case 'r':
+            rt_sigreturn_sym = optarg;
+            break;
+        case 's':
+            sigreturn_sym = optarg;
+            break;
+        default:
+        usage:
+            fprintf(stderr, "usage: [-p prefix] [-r rt-sigreturn-name] "
+                    "[-s sigreturn-name] -o output-file input-file\n");
+            return EXIT_FAILURE;
+        }
+    }
+
+    if (optind >= argc || outf_name == NULL) {
+        goto usage;
+    }
+    inf_name = argv[optind];
+
+    /*
+     * Open the input and output files.
+     */
+    inf = fopen(inf_name, "rb");
+    if (inf == NULL) {
+        goto perror_inf;
+    }
+    outf = fopen(outf_name, "w");
+    if (outf == NULL) {
+        goto perror_outf;
+    }
+
+    /*
+     * Read the input file into a buffer.
+     * We expect the vdso to be small, on the order of one page,
+     * therefore we do not expect a partial read.
+     */
+    fseek(inf, 0, SEEK_END);
+    total_len = ftell(inf);
+    fseek(inf, 0, SEEK_SET);
+
+    buf = malloc(total_len);
+    if (buf == NULL) {
+        goto perror_inf;
+    }
+
+    errno = 0;
+    if (fread(buf, 1, total_len, inf) != total_len) {
+        if (errno) {
+            goto perror_inf;
+        }
+        fprintf(stderr, "%s: incomplete read\n", inf_name);
+        return EXIT_FAILURE;
+    }
+    fclose(inf);
+
+    /*
+     * Write out the vdso image now, before we make local changes.
+     */
+
+    fprintf(outf,
+            "/* Automatically generated from linux-user/gen-vdso.c. */\n"
+            "\n"
+            "static const uint8_t %s_image[] = {",
+            prefix);
+    for (long i = 0; i < total_len; ++i) {
+        if (i % 12 == 0) {
+            fputs("\n   ", outf);
+        }
+        fprintf(outf, " 0x%02x,", buf[i]);
+    }
+    fprintf(outf, "\n};\n\n");
+
+    /*
+     * Identify which elf flavor we're processing.
+     * The first 16 bytes of the file are e_ident.
+     */
+
+    if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1 ||
+        buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3) {
+        fprintf(stderr, "%s: not an elf file\n", inf_name);
+        return EXIT_FAILURE;
+    }
+    switch (buf[EI_DATA]) {
+    case ELFDATA2LSB:
+        need_bswap = BYTE_ORDER != LITTLE_ENDIAN;
+        break;
+    case ELFDATA2MSB:
+        need_bswap = BYTE_ORDER != BIG_ENDIAN;
+        break;
+    default:
+        fprintf(stderr, "%s: invalid elf EI_DATA (%u)\n",
+                inf_name, buf[EI_DATA]);
+        return EXIT_FAILURE;
+    }
+
+    /*
+     * We need to relocate the VDSO image.  The one built into the kernel
+     * is built for a fixed address.  The one we built for QEMU is not,
+     * since that requires close control of the guest address space.
+     *
+     * Output relocation addresses as we go.
+     */
+
+    fprintf(outf, "static const unsigned %s_relocs[] = {\n", prefix);
+
+    switch (buf[EI_CLASS]) {
+    case ELFCLASS32:
+        elf32_process(outf, buf, need_bswap);
+        break;
+    case ELFCLASS64:
+        elf64_process(outf, buf, need_bswap);
+        break;
+    default:
+        fprintf(stderr, "%s: invalid elf EI_CLASS (%u)\n",
+                inf_name, buf[EI_CLASS]);
+        return EXIT_FAILURE;
+    }
+
+    fprintf(outf, "};\n\n");   /* end vdso_relocs. */
+
+    fprintf(outf, "static const VdsoImageInfo %s_image_info = {\n", prefix);
+    fprintf(outf, "    .image = %s_image,\n", prefix);
+    fprintf(outf, "    .relocs = %s_relocs,\n", prefix);
+    fprintf(outf, "    .image_size = sizeof(%s_image),\n", prefix);
+    fprintf(outf, "    .reloc_count = ARRAY_SIZE(%s_relocs),\n", prefix);
+    fprintf(outf, "    .sigreturn_ofs = 0x%x,\n", sigreturn_addr);
+    fprintf(outf, "    .rt_sigreturn_ofs = 0x%x,\n", rt_sigreturn_addr);
+    fprintf(outf, "};\n");
+
+    /*
+     * Everything should have gone well.
+     */
+    if (fclose(outf)) {
+        goto perror_outf;
+    }
+    return EXIT_SUCCESS;
+
+ perror_inf:
+    perror(inf_name);
+    return EXIT_FAILURE;
+
+ perror_outf:
+    perror(outf_name);
+    return EXIT_FAILURE;
+}
linux-user/gen-vdso-elfn.c.inc new file +307 -0

307 lines not on this page · raw message

linux-user/meson.build +5 -1
index 7171dc60be..e4cb70ed2d 100644
@@ -28,9 +28,13 @@ linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c'))
 linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c'))
 linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('semihost.c'))
 
-
 syscall_nr_generators = {}
 
+gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c',
+                          native: true, build_by_default: false)
+gen_vdso = generator(gen_vdso_exe, output: '@[email protected]',
+                     arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@'])
+
 subdir('alpha')
 subdir('arm')
 subdir('hppa')
Signature · 1 line
2.34.1
#21 lore raw

PATCH v5 10/20 linux-user: Add build-vdso.sh tool

In reply to Richard Henderson

A shell script to build the vdso using the cross-compiler makefile fragment. If none detected, fall back to copying the pre-build vdso from the source directory.

---
 linux-user/build-vdso.sh | 31 +++++++++++++++++++++++++++++++
 linux-user/meson.build   |  1 +
 2 files changed, 32 insertions(+)
 create mode 100755 linux-user/build-vdso.sh
linux-user/build-vdso.sh new file +31 -0
new file mode 100755
index 0000000000..489088737f
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Build vdso using cross tools
+
+build_dir=error
+source_dir=error
+target_dir=error
+output=error
+
+while test $# -gt 0; do
+  opt="$1"
+  shift
+  case "$opt" in
+    -B) build_dir=$1; shift;;
+    -C) source_dir=$1; shift;;
+    -T) target_dir=$1; shift;;
+    -o) output=$1; shift;;
+    --) break;;
+  esac
+done
+
+frag="${build_dir}/tests/tcg/${target_dir}/config-target.mak"
+if ! test -f "$frag"; then
+  # No cross-compiler available
+  # Copy pre-build image into build tree
+  cp "${source_dir}/$(basename ${output})" "${output}"
+  exit $?
+fi
+
+# Extract cross-compiler from the makefile fragment, and build.
+CC=$(grep CC= "$frag" | sed s/CC=//)
+exec $CC -o "$output" $@
linux-user/meson.build +1 -0
index e4cb70ed2d..099e5c4fe0 100644
@@ -30,6 +30,7 @@ linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('sem
 
 syscall_nr_generators = {}
 
+build_vdso_cmd = find_program('build-vdso.sh')
 gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c',
                           native: true, build_by_default: false)
 gen_vdso = generator(gen_vdso_exe, output: '@[email protected]',
Signature · 1 line
2.34.1
#22 lore raw

PATCH v5 11/20 linux-user/i386: Add vdso

In reply to Richard Henderson

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1267

---
 linux-user/i386/vdso-asmoffset.h |   6 ++
 linux-user/elfload.c             |  16 +++-
 linux-user/i386/signal.c         |  11 +++
 linux-user/i386/meson.build      |  24 ++++++
 linux-user/i386/vdso.S           | 143 +++++++++++++++++++++++++++++++
 linux-user/i386/vdso.ld          |  76 ++++++++++++++++
 linux-user/i386/vdso.so          | Bin 0 -> 2672 bytes
 7 files changed, 274 insertions(+), 2 deletions(-)
 create mode 100644 linux-user/i386/vdso-asmoffset.h
 create mode 100644 linux-user/i386/vdso.S
 create mode 100644 linux-user/i386/vdso.ld
 create mode 100755 linux-user/i386/vdso.so
linux-user/i386/vdso-asmoffset.h new file +6 -0
new file mode 100644
index 0000000000..4e5ee0dd49
@@ -0,0 +1,6 @@
+/*
+ * offsetof(struct sigframe, sc.eip)
+ * offsetof(struct rt_sigframe, uc.tuc_mcontext.eip)
+ */
+#define SIGFRAME_SIGCONTEXT_eip      64
+#define RT_SIGFRAME_SIGCONTEXT_eip  220
linux-user/elfload.c +14 -2
index 2a6adebb4a..fb876ae30a 100644
@@ -309,12 +309,24 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
     (*regs)[15] = tswapreg(env->regs[R_ESP]);
     (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff);
 }
-#endif
+
+/*
+ * i386 is the only target which supplies AT_SYSINFO for the vdso.
+ * All others only supply AT_SYSINFO_EHDR.
+ */
+#define DLINFO_ARCH_ITEMS 1
+#define ARCH_DLINFO       NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry);
+
+#include "vdso.c.inc"
+
+#define vdso_image_info()    &vdso_image_info
+
+#endif /* TARGET_X86_64 */
 
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
-#endif
+#endif /* TARGET_I386 */
 
 #ifdef TARGET_ARM
 
linux-user/i386/signal.c +11 -0
index 60fa07d6f9..bc5d45302e 100644
@@ -214,6 +214,17 @@ struct rt_sigframe {
 };
 #define TARGET_RT_SIGFRAME_FXSAVE_OFFSET (                                 \
     offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET)
+
+/*
+ * Verify that vdso-asmoffset.h constants match.
+ */
+#include "i386/vdso-asmoffset.h"
+
+QEMU_BUILD_BUG_ON(offsetof(struct sigframe, sc.eip)
+                  != SIGFRAME_SIGCONTEXT_eip);
+QEMU_BUILD_BUG_ON(offsetof(struct rt_sigframe, uc.tuc_mcontext.eip)
+                  != RT_SIGFRAME_SIGCONTEXT_eip);
+
 #else
 
 struct rt_sigframe {
linux-user/i386/meson.build +24 -0
index ee523019a5..d858bf1d77 100644
@@ -3,3 +3,27 @@ syscall_nr_generators += {
                     arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                     output: '@BASENAME@_nr.h')
 }
+
+vdso_so = custom_target(output: 'vdso.so',
+                        input: files('vdso.S', 'vdso.ld'),
+                        depend_files: files('vdso-asmoffset.h'),
+                        command: [
+                            build_vdso_cmd,
+                            '-B', meson.project_build_root(),
+                            '-C', meson.current_source_dir(),
+                            '-T', 'i386-linux-user',
+                            '-o', '@OUTPUT@',
+	                    '--', '-m32', '-nostdlib', '-shared',
+	                    '-Wl,-h,linux-gate.so.1',
+                            '-Wl,--build-id=sha1',
+                            '-Wl,--hash-style=both',
+                            '-Wl,-T,@INPUT1@',
+                            '@INPUT0@'
+                        ])
+
+vdso_inc = gen_vdso.process(vdso_so, extra_args: [
+                                '-s', '__kernel_sigreturn',
+                                '-r', '__kernel_rt_sigreturn'
+                            ])
+
+linux_user_ss.add(when: 'TARGET_I386', if_true: vdso_inc)
linux-user/i386/vdso.S new file +143 -0

143 lines not on this page · raw message

linux-user/i386/vdso.ld new file +76 -0

76 lines not on this page · raw message

linux-user/i386/vdso.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..bdece5dfcf8da036d013262d4e37208350283cfa
GIT binary patch
Signature · 1 line
2.34.1
#23 lore raw

PATCH v5 12/20 linux-user/x86_64: Add vdso

In reply to Richard Henderson
---
 linux-user/elfload.c          |   4 +-
 linux-user/x86_64/meson.build |  20 +++++++++
 linux-user/x86_64/vdso.S      |  78 ++++++++++++++++++++++++++++++++++
 linux-user/x86_64/vdso.ld     |  73 +++++++++++++++++++++++++++++++
 linux-user/x86_64/vdso.so     | Bin 0 -> 2968 bytes
 5 files changed, 173 insertions(+), 2 deletions(-)
 create mode 100644 linux-user/x86_64/vdso.S
 create mode 100644 linux-user/x86_64/vdso.ld
 create mode 100755 linux-user/x86_64/vdso.so
linux-user/elfload.c +2 -2
index fb876ae30a..b421f04675 100644
@@ -317,12 +317,12 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
 #define DLINFO_ARCH_ITEMS 1
 #define ARCH_DLINFO       NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry);
 
+#endif /* TARGET_X86_64 */
+
 #include "vdso.c.inc"
 
 #define vdso_image_info()    &vdso_image_info
 
-#endif /* TARGET_X86_64 */
-
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
linux-user/x86_64/meson.build +20 -0
index 203af9a60c..6744563a11 100644
@@ -3,3 +3,23 @@ syscall_nr_generators += {
                       arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                       output: '@BASENAME@_nr.h')
 }
+
+vdso_so = custom_target(output: 'vdso.so',
+                        input: files('vdso.S', 'vdso.ld'),
+                        command: [
+                            build_vdso_cmd,
+                            '-B', meson.project_build_root(),
+                            '-C', meson.current_source_dir(),
+                            '-T', 'x86_64-linux-user',
+                            '-o', '@OUTPUT@',
+	                    '--', '-nostdlib', '-shared',
+	                    '-Wl,-h,linux-vdso.so.1',
+                            '-Wl,--build-id=sha1',
+                            '-Wl,--hash-style=both',
+                            '-Wl,-T,@INPUT1@',
+                            '@INPUT0@'
+                        ])
+
+vdso_inc = gen_vdso.process(vdso_so)
+
+linux_user_ss.add(when: 'TARGET_X86_64', if_true: vdso_inc)
linux-user/x86_64/vdso.S new file +78 -0

78 lines not on this page · raw message

linux-user/x86_64/vdso.ld new file +73 -0

73 lines not on this page · raw message

linux-user/x86_64/vdso.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..c873d6ea580b393825506d2ffbddcf9827d89e14
GIT binary patch
Signature · 1 line
2.34.1
#24 lore raw

PATCH v5 13/20 linux-user/aarch64: Add vdso

In reply to Richard Henderson
---
 linux-user/elfload.c           |   7 ++++
 linux-user/aarch64/meson.build |  33 +++++++++++++++
 linux-user/aarch64/vdso-be.so  | Bin 0 -> 3216 bytes
 linux-user/aarch64/vdso-le.so  | Bin 0 -> 3216 bytes
 linux-user/aarch64/vdso.S      |  73 +++++++++++++++++++++++++++++++++
 linux-user/aarch64/vdso.ld     |  72 ++++++++++++++++++++++++++++++++
 linux-user/meson.build         |   1 +
 7 files changed, 186 insertions(+)
 create mode 100644 linux-user/aarch64/meson.build
 create mode 100755 linux-user/aarch64/vdso-be.so
 create mode 100755 linux-user/aarch64/vdso-le.so
 create mode 100644 linux-user/aarch64/vdso.S
 create mode 100644 linux-user/aarch64/vdso.ld
linux-user/elfload.c +7 -0
index b421f04675..8316868bd2 100644
@@ -768,6 +768,13 @@ static uint32_t get_elf_hwcap2(void)
 
 #undef GET_FEATURE_ID
 
+#if TARGET_BIG_ENDIAN
+# include "vdso-be.c.inc"
+#else
+# include "vdso-le.c.inc"
+#endif
+#define vdso_image_info()    &vdso_image_info
+
 #endif /* not TARGET_AARCH64 */
 #endif /* TARGET_ARM */
 
linux-user/aarch64/meson.build new file +33 -0
new file mode 100644
index 0000000000..b769c87570
@@ -0,0 +1,33 @@
+# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it
+# is always true as far as source_set.apply() is concerned.  Always build
+# both header files and include the right one via #if.
+
+vdso_cmd = [
+    build_vdso_cmd,
+    '-B', meson.project_build_root(),
+    '-C', meson.current_source_dir(),
+    '-T', 'aarch64-linux-user',
+    '-o', '@OUTPUT@',
+    '--',
+    '-nostdlib', '-shared',
+    '-Wl,-h,linux-vdso.so.1',
+    '-Wl,--build-id=sha1',
+    '-Wl,--hash-style=both',
+    '-Wl,-T,@INPUT1@',
+    '@INPUT0@'
+]
+
+vdso_le_so = custom_target(output: 'vdso-le.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           command: vdso_cmd + ['-mlittle-endian'])
+
+vdso_be_so = custom_target(output: 'vdso-be.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           command: vdso_cmd + ['-mbig-endian'])
+
+gen = [
+  gen_vdso.process(vdso_le_so, extra_args: ['-r', '__kernel_rt_sigreturn']),
+  gen_vdso.process(vdso_be_so, extra_args: ['-r', '__kernel_rt_sigreturn']),
+]
+
+linux_user_ss.add(when: 'TARGET_AARCH64', if_true: gen)
linux-user/aarch64/vdso-be.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..b19563b648cc3e33a45b9394695d747f55c11db7
GIT binary patch
linux-user/aarch64/vdso-le.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..4bd7bf1587b9dc652784efc34f67be6514f46a10
GIT binary patch
linux-user/aarch64/vdso.S new file +73 -0

73 lines not on this page · raw message

linux-user/aarch64/vdso.ld new file +72 -0

72 lines not on this page · raw message

linux-user/meson.build +1 -0
index 099e5c4fe0..1b265ed365 100644
@@ -36,6 +36,7 @@ gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c',
 gen_vdso = generator(gen_vdso_exe, output: '@[email protected]',
                      arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@'])
 
+subdir('aarch64')
 subdir('alpha')
 subdir('arm')
 subdir('hppa')
Signature · 1 line
2.34.1
#25 lore raw

PATCH v5 14/20 linux-user/arm: Add vdso

In reply to Richard Henderson
---
 linux-user/arm/signal.c    |  28 +++---
 linux-user/elfload.c       |   3 +-
 linux-user/arm/meson.build |  35 ++++++++
 linux-user/arm/vdso-be.so  | Bin 0 -> 2680 bytes
 linux-user/arm/vdso-le.so  | Bin 0 -> 2680 bytes
 linux-user/arm/vdso.S      | 177 +++++++++++++++++++++++++++++++++++++
 linux-user/arm/vdso.ld     |  67 ++++++++++++++
 7 files changed, 293 insertions(+), 17 deletions(-)
 create mode 100755 linux-user/arm/vdso-be.so
 create mode 100755 linux-user/arm/vdso-le.so
 create mode 100644 linux-user/arm/vdso.S
 create mode 100644 linux-user/arm/vdso.ld
linux-user/arm/signal.c +12 -16
index cf99fd7b8a..c328d31081 100644
@@ -167,9 +167,8 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig,
     abi_ulong handler = 0;
     abi_ulong handler_fdpic_GOT = 0;
     abi_ulong retcode;
-    int thumb, retcode_idx;
+    int thumb;
     int is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info);
-    bool copy_retcode;
 
     if (is_fdpic) {
         /* In FDPIC mode, ka->_sa_handler points to a function
@@ -184,9 +183,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig,
     } else {
         handler = ka->_sa_handler;
     }
-
     thumb = handler & 1;
-    retcode_idx = thumb + (ka->sa_flags & TARGET_SA_SIGINFO ? 2 : 0);
 
     uint32_t cpsr = cpsr_read(env);
 
@@ -202,24 +199,23 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig,
         cpsr &= ~CPSR_E;
     }
 
+    /* Our vdso default_sigreturn label is a table of entry points. */
+    int idx = is_fdpic * 2 + ((ka->sa_flags & TARGET_SA_SIGINFO) != 0);
+    retcode = default_sigreturn + idx * 16;
+
+    /*
+     * Put the sigreturn code on the stack no matter which return
+     * mechanism we use in order to remain ABI compliant.
+     */
+    memcpy(frame->retcode, g2h_untagged(retcode & ~1), 16);
+
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         if (is_fdpic) {
+            /* Place the function descriptor in slot 3. */
             __put_user((abi_ulong)ka->sa_restorer, &frame->retcode[3]);
-            retcode = (sigreturn_fdpic_tramp +
-                       retcode_idx * RETCODE_BYTES + thumb);
-            copy_retcode = true;
         } else {
             retcode = ka->sa_restorer;
-            copy_retcode = false;
         }
-    } else {
-        retcode = default_sigreturn + retcode_idx * RETCODE_BYTES + thumb;
-        copy_retcode = true;
-    }
-
-    /* Copy the code to the stack slot for ABI compatibility. */
-    if (copy_retcode) {
-        memcpy(frame->retcode, g2h_untagged(retcode & ~1), RETCODE_BYTES);
     }
 
     env->regs[0] = usig;
linux-user/elfload.c +2 -1
index 8316868bd2..cd2ab4292c 100644
@@ -768,6 +768,8 @@ static uint32_t get_elf_hwcap2(void)
 
 #undef GET_FEATURE_ID
 
+#endif /* not TARGET_AARCH64 */
+
 #if TARGET_BIG_ENDIAN
 # include "vdso-be.c.inc"
 #else
@@ -775,7 +777,6 @@ static uint32_t get_elf_hwcap2(void)
 #endif
 #define vdso_image_info()    &vdso_image_info
 
-#endif /* not TARGET_AARCH64 */
 #endif /* TARGET_ARM */
 
 #ifdef TARGET_SPARC
linux-user/arm/meson.build +35 -0
index 5a93c925cf..6a8ce075c3 100644
@@ -5,3 +5,38 @@ syscall_nr_generators += {
                    arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                    output: '@BASENAME@_nr.h')
 }
+
+# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it
+# is always true as far as source_set.apply() is concerned.  Always build
+# both header files and include the right one via #if.
+
+vdso_cmd = [
+    build_vdso_cmd,
+    '-B', meson.project_build_root(),
+    '-C', meson.current_source_dir(),
+    '-T', 'arm-linux-user',
+    '-o', '@OUTPUT@',
+    '--',
+    '-nostdlib', '-shared',
+    '-Wl,-use-blx',
+    '-Wl,-h,linux-vdso.so.1',
+    '-Wl,--build-id=sha1',
+    '-Wl,--hash-style=both',
+    '-Wl,-T,@INPUT1@',
+    '@INPUT0@'
+]
+
+vdso_le_so = custom_target(output: 'vdso-le.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           command: vdso_cmd + ['-mlittle-endian'])
+
+vdso_be_so = custom_target(output: 'vdso-be.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           command: vdso_cmd + ['-mbig-endian'])
+
+gen = [
+  gen_vdso.process(vdso_be_so, extra_args: ['-s', 'sigreturn_codes']),
+  gen_vdso.process(vdso_le_so, extra_args: ['-s', 'sigreturn_codes'])
+]
+
+linux_user_ss.add(when: 'TARGET_ARM', if_true: gen)
linux-user/arm/vdso-be.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..591db80fe47540707e5c627443ac566d7f2c7c60
GIT binary patch
linux-user/arm/vdso-le.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..8077fa5608d3d2539ec19e8b097cf812fcc41ef8
GIT binary patch
linux-user/arm/vdso.S new file +177 -0

177 lines not on this page · raw message

linux-user/arm/vdso.ld new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.34.1
#26 lore raw

PATCH v5 15/20 linux-user/hppa: Add vdso

In reply to Richard Henderson
---
 linux-user/hppa/vdso-asmoffset.h |  12 +++
 linux-user/elfload.c             |   4 +
 linux-user/hppa/signal.c         |  24 +++--
 linux-user/hppa/meson.build      |  23 +++++
 linux-user/hppa/vdso.S           | 165 +++++++++++++++++++++++++++++++
 linux-user/hppa/vdso.ld          |  77 +++++++++++++++
 linux-user/hppa/vdso.so          | Bin 0 -> 2104 bytes
 7 files changed, 295 insertions(+), 10 deletions(-)
 create mode 100644 linux-user/hppa/vdso-asmoffset.h
 create mode 100644 linux-user/hppa/vdso.S
 create mode 100644 linux-user/hppa/vdso.ld
 create mode 100755 linux-user/hppa/vdso.so
linux-user/hppa/vdso-asmoffset.h new file +12 -0
new file mode 100644
index 0000000000..c8b40c0332
@@ -0,0 +1,12 @@
+#define sizeof_rt_sigframe              584
+#define offsetof_sigcontext             160
+#define offsetof_sigcontext_gr          0x4
+#define offsetof_sigcontext_fr          0x88
+#define offsetof_sigcontext_iaoq        0x190
+#define offsetof_sigcontext_sar         0x198
+
+/* arch/parisc/include/asm/rt_sigframe.h */
+#define SIGFRAME                        64
+#define FUNCTIONCALLFRAME               48
+#define PARISC_RT_SIGFRAME_SIZE32 \
+    (((sizeof_rt_sigframe) + FUNCTIONCALLFRAME + SIGFRAME) & -SIGFRAME)
linux-user/elfload.c +4 -0
index cd2ab4292c..eb22a17e0e 100644
@@ -1771,6 +1771,10 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define STACK_GROWS_DOWN 0
 #define STACK_ALIGNMENT  64
 
+#include "vdso.c.inc"
+
+#define vdso_image_info()    &vdso_image_info
+
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
linux-user/hppa/signal.c +14 -10
index f253a15864..ada22556c1 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "vdso-asmoffset.h"
 
 struct target_sigcontext {
     abi_ulong sc_flags;
@@ -47,6 +48,19 @@ struct target_rt_sigframe {
     /* hidden location of upper halves of pa2.0 64-bit gregs */
 };
 
+QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe) != sizeof_rt_sigframe);
+QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.tuc_mcontext)
+                  != offsetof_sigcontext);
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_gr)
+                  != offsetof_sigcontext_gr);
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_fr)
+                  != offsetof_sigcontext_fr);
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_iaoq)
+                  != offsetof_sigcontext_iaoq);
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_sar)
+                  != offsetof_sigcontext_sar);
+
+
 static void setup_sigcontext(struct target_sigcontext *sc, CPUArchState *env)
 {
     int i;
@@ -91,16 +105,6 @@ static void restore_sigcontext(CPUArchState *env, struct target_sigcontext *sc)
     __get_user(env->cr[CR_SAR], &sc->sc_sar);
 }
 
-#if TARGET_ABI_BITS == 32
-#define SIGFRAME                64
-#define FUNCTIONCALLFRAME       48
-#else
-#define SIGFRAME                128
-#define FUNCTIONCALLFRAME       96
-#endif
-#define PARISC_RT_SIGFRAME_SIZE32 \
-    ((sizeof(struct target_rt_sigframe) + FUNCTIONCALLFRAME + SIGFRAME) & -SIGFRAME)
-
 void setup_rt_frame(int sig, struct target_sigaction *ka,
                     target_siginfo_t *info,
                     target_sigset_t *set, CPUArchState *env)
linux-user/hppa/meson.build +23 -0
index 4709508a09..e13ea4e9ab 100644
@@ -3,3 +3,26 @@ syscall_nr_generators += {
                     arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                     output: '@BASENAME@_nr.h')
 }
+
+vdso_so = custom_target(output: 'vdso.so',
+                        input: files('vdso.S', 'vdso.ld'),
+                        depend_files: files('vdso-asmoffset.h'),
+                        command: [
+                            build_vdso_cmd,
+                            '-B', meson.project_build_root(),
+                            '-C', meson.current_source_dir(),
+                            '-T', 'hppa-linux-user',
+                            '-o', '@OUTPUT@',
+	                    '--', '-nostdlib', '-shared',
+	                    '-Wl,-h,linux-vdso32.so.1',
+                            '-Wl,--build-id=sha1',
+                            '-Wl,--hash-style=both',
+                            '-Wl,-T,@INPUT1@',
+                            '@INPUT0@'
+                        ])
+
+vdso_inc = gen_vdso.process(vdso_so, extra_args: [
+                                '-r', '__kernel_sigtramp_rt'
+                            ])
+
+linux_user_ss.add(when: 'TARGET_HPPA', if_true: vdso_inc)
linux-user/hppa/vdso.S new file +165 -0

165 lines not on this page · raw message

linux-user/hppa/vdso.ld new file +77 -0

77 lines not on this page · raw message

linux-user/hppa/vdso.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..e1ddd70c37e9eb6871c21d538dcce0a1e736a918
GIT binary patch
Signature · 1 line
2.34.1
#27 lore raw

PATCH v5 16/20 linux-user/riscv: Add vdso

In reply to Richard Henderson
---
 linux-user/riscv/vdso-asmoffset.h |   9 ++
 linux-user/elfload.c              |   4 +
 linux-user/riscv/signal.c         |   8 ++
 linux-user/meson.build            |   1 +
 linux-user/riscv/meson.build      |  30 +++++
 linux-user/riscv/vdso-32.so       | Bin 0 -> 2888 bytes
 linux-user/riscv/vdso-64.so       | Bin 0 -> 3840 bytes
 linux-user/riscv/vdso.S           | 186 ++++++++++++++++++++++++++++++
 linux-user/riscv/vdso.ld          |  74 ++++++++++++
 9 files changed, 312 insertions(+)
 create mode 100644 linux-user/riscv/vdso-asmoffset.h
 create mode 100644 linux-user/riscv/meson.build
 create mode 100755 linux-user/riscv/vdso-32.so
 create mode 100755 linux-user/riscv/vdso-64.so
 create mode 100644 linux-user/riscv/vdso.S
 create mode 100644 linux-user/riscv/vdso.ld
linux-user/riscv/vdso-asmoffset.h new file +9 -0
new file mode 100644
index 0000000000..123902ef61
@@ -0,0 +1,9 @@
+#ifdef TARGET_ABI32
+# define sizeof_rt_sigframe     0x2b0
+# define offsetof_uc_mcontext   0x120
+# define offsetof_freg0         0x80
+#else
+# define sizeof_rt_sigframe     0x340
+# define offsetof_uc_mcontext   0x130
+# define offsetof_freg0         0x100
+#endif
linux-user/elfload.c +4 -0
index eb22a17e0e..8f902bb427 100644
@@ -1733,8 +1733,10 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 
 #ifdef TARGET_RISCV32
 #define ELF_CLASS ELFCLASS32
+#include "vdso-32.c.inc"
 #else
 #define ELF_CLASS ELFCLASS64
+#include "vdso-64.c.inc"
 #endif
 
 #define ELF_HWCAP get_elf_hwcap()
@@ -1751,6 +1753,8 @@ static uint32_t get_elf_hwcap(void)
 #undef MISA_BIT
 }
 
+#define vdso_image_info()    &vdso_image_info
+
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
linux-user/riscv/signal.c +8 -0
index eaa168199a..5449c7618a 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "vdso-asmoffset.h"
 
 /* Signal handler invocation must be transparent for the code being
    interrupted. Complete CPU (hart) state is saved on entry and restored
@@ -37,6 +38,8 @@ struct target_sigcontext {
     uint32_t fcsr;
 }; /* cf. riscv-linux:arch/riscv/include/uapi/asm/ptrace.h */
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, fpr) != offsetof_freg0);
+
 struct target_ucontext {
     unsigned long uc_flags;
     struct target_ucontext *uc_link;
@@ -51,6 +54,11 @@ struct target_rt_sigframe {
     struct target_ucontext uc;
 };
 
+QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe)
+                  != sizeof_rt_sigframe);
+QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.uc_mcontext)
+                  != offsetof_uc_mcontext);
+
 static abi_ulong get_sigframe(struct target_sigaction *ka,
                               CPURISCVState *regs, size_t framesize)
 {
linux-user/meson.build +1 -0
index 1b265ed365..3aa967b27c 100644
@@ -46,6 +46,7 @@ subdir('microblaze')
 subdir('mips64')
 subdir('mips')
 subdir('ppc')
+subdir('riscv')
 subdir('s390x')
 subdir('sh4')
 subdir('sparc')
linux-user/riscv/meson.build new file +30 -0
new file mode 100644
index 0000000000..0a00cae9fd
@@ -0,0 +1,30 @@
+vdso_cmd = [
+    build_vdso_cmd,
+    '-B', meson.project_build_root(),
+    '-C', meson.current_source_dir(),
+    '-T', 'riscv64-linux-user',
+    '-o', '@OUTPUT@',
+    '--',
+    '-nostdlib', '-shared', '-fpic',
+    '-Wl,-h,linux-vdso.so.1',
+    '-Wl,--build-id=sha1',
+    '-Wl,--hash-style=both',
+    '-Wl,-T,@INPUT1@',
+    '@INPUT0@'
+]
+
+vdso_32_so = custom_target(output: 'vdso-32.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           depend_files: files('vdso-asmoffset.h'),
+                           command: vdso_cmd + ['-mabi=ilp32d', '-march=rv32g'])
+
+vdso_64_so = custom_target(output: 'vdso-64.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           depend_files: files('vdso-asmoffset.h'),
+                           command: vdso_cmd + ['-mabi=lp64d', '-march=rv64g'])
+
+vdso_32_inc = gen_vdso.process(vdso_32_so, extra_args: ['-r', '__vdso_rt_sigreturn'])
+vdso_64_inc = gen_vdso.process(vdso_64_so, extra_args: ['-r', '__vdso_rt_sigreturn'])
+
+linux_user_ss.add(when: 'TARGET_RISCV32', if_true: vdso_32_inc)
+linux_user_ss.add(when: 'TARGET_RISCV64', if_true: vdso_64_inc)
linux-user/riscv/vdso-32.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..189e2f49e78f158cf49e6092edf7ece8cf7e8a25
GIT binary patch
linux-user/riscv/vdso-64.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..3c3b3a8cc579649e5108402b706bf7f741efd2e4
GIT binary patch
linux-user/riscv/vdso.S new file +186 -0

186 lines not on this page · raw message

linux-user/riscv/vdso.ld new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.34.1
Acked-by on v5 16/20
#28 lore raw

Re: [PATCH v5 16/20] linux-user/riscv: Add vdso

Quoted 2 lines · Richard Henderson

Alistair

Quoted 489 lines
---
 linux-user/riscv/vdso-asmoffset.h |   9 ++
 linux-user/elfload.c              |   4 +
 linux-user/riscv/signal.c         |   8 ++
 linux-user/meson.build            |   1 +
 linux-user/riscv/meson.build      |  30 +++++
 linux-user/riscv/vdso-32.so       | Bin 0 -> 2888 bytes
 linux-user/riscv/vdso-64.so       | Bin 0 -> 3840 bytes
 linux-user/riscv/vdso.S           | 186 ++++++++++++++++++++++++++++++
 linux-user/riscv/vdso.ld          |  74 ++++++++++++
 9 files changed, 312 insertions(+)
 create mode 100644 linux-user/riscv/vdso-asmoffset.h
 create mode 100644 linux-user/riscv/meson.build
 create mode 100755 linux-user/riscv/vdso-32.so
 create mode 100755 linux-user/riscv/vdso-64.so
 create mode 100644 linux-user/riscv/vdso.S
 create mode 100644 linux-user/riscv/vdso.ld
linux-user/riscv/vdso-asmoffset.h new file +9 -0
new file mode 100644
index 0000000000..123902ef61
@@ -0,0 +1,9 @@
+#ifdef TARGET_ABI32
+# define sizeof_rt_sigframe     0x2b0
+# define offsetof_uc_mcontext   0x120
+# define offsetof_freg0         0x80
+#else
+# define sizeof_rt_sigframe     0x340
+# define offsetof_uc_mcontext   0x130
+# define offsetof_freg0         0x100
+#endif
linux-user/elfload.c +4 -0
index eb22a17e0e..8f902bb427 100644
@@ -1733,8 +1733,10 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 
 #ifdef TARGET_RISCV32
 #define ELF_CLASS ELFCLASS32
+#include "vdso-32.c.inc"
 #else
 #define ELF_CLASS ELFCLASS64
+#include "vdso-64.c.inc"
 #endif
 
 #define ELF_HWCAP get_elf_hwcap()
@@ -1751,6 +1753,8 @@ static uint32_t get_elf_hwcap(void)
 #undef MISA_BIT
 }
 
+#define vdso_image_info()    &vdso_image_info
+
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
linux-user/riscv/signal.c +8 -0
index eaa168199a..5449c7618a 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "vdso-asmoffset.h"
 
 /* Signal handler invocation must be transparent for the code being
    interrupted. Complete CPU (hart) state is saved on entry and restored
@@ -37,6 +38,8 @@ struct target_sigcontext {
     uint32_t fcsr;
 }; /* cf. riscv-linux:arch/riscv/include/uapi/asm/ptrace.h */
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, fpr) != offsetof_freg0);
+
 struct target_ucontext {
     unsigned long uc_flags;
     struct target_ucontext *uc_link;
@@ -51,6 +54,11 @@ struct target_rt_sigframe {
     struct target_ucontext uc;
 };
 
+QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe)
+                  != sizeof_rt_sigframe);
+QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.uc_mcontext)
+                  != offsetof_uc_mcontext);
+
 static abi_ulong get_sigframe(struct target_sigaction *ka,
                               CPURISCVState *regs, size_t framesize)
 {
linux-user/meson.build +1 -0
index 1b265ed365..3aa967b27c 100644
@@ -46,6 +46,7 @@ subdir('microblaze')
 subdir('mips64')
 subdir('mips')
 subdir('ppc')
+subdir('riscv')
 subdir('s390x')
 subdir('sh4')
 subdir('sparc')
linux-user/riscv/meson.build new file +30 -0
new file mode 100644
index 0000000000..0a00cae9fd
@@ -0,0 +1,30 @@
+vdso_cmd = [
+    build_vdso_cmd,
+    '-B', meson.project_build_root(),
+    '-C', meson.current_source_dir(),
+    '-T', 'riscv64-linux-user',
+    '-o', '@OUTPUT@',
+    '--',
+    '-nostdlib', '-shared', '-fpic',
+    '-Wl,-h,linux-vdso.so.1',
+    '-Wl,--build-id=sha1',
+    '-Wl,--hash-style=both',
+    '-Wl,-T,@INPUT1@',
+    '@INPUT0@'
+]
+
+vdso_32_so = custom_target(output: 'vdso-32.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           depend_files: files('vdso-asmoffset.h'),
+                           command: vdso_cmd + ['-mabi=ilp32d', '-march=rv32g'])
+
+vdso_64_so = custom_target(output: 'vdso-64.so',
+                           input: files('vdso.S', 'vdso.ld'),
+                           depend_files: files('vdso-asmoffset.h'),
+                           command: vdso_cmd + ['-mabi=lp64d', '-march=rv64g'])
+
+vdso_32_inc = gen_vdso.process(vdso_32_so, extra_args: ['-r', '__vdso_rt_sigreturn'])
+vdso_64_inc = gen_vdso.process(vdso_64_so, extra_args: ['-r', '__vdso_rt_sigreturn'])
+
+linux_user_ss.add(when: 'TARGET_RISCV32', if_true: vdso_32_inc)
+linux_user_ss.add(when: 'TARGET_RISCV64', if_true: vdso_64_inc)
linux-user/riscv/vdso-32.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..189e2f49e78f158cf49e6092edf7ece8cf7e8a25
GIT binary patch
linux-user/riscv/vdso-64.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..3c3b3a8cc579649e5108402b706bf7f741efd2e4
GIT binary patch
linux-user/riscv/vdso.S new file +186 -0
new file mode 100644
index 0000000000..70a4f710db
@@ -0,0 +1,186 @@
+/*
+ * RISC-V linux replacement vdso.
+ *
+ * Copyright 2021 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <asm/unistd.h>
+#include <asm/errno.h>
+
+#if __riscv_xlen == 32
+# define TARGET_ABI32
+#endif
+#include "vdso-asmoffset.h"
+
+       .text
+
+.macro endf name
+       .globl  \name
+       .type   \name, @function
+       .size   \name, . - \name
+.endm
+
+.macro raw_syscall nr
+       li      a7, \nr
+       ecall
+.endm
+
+.macro vdso_syscall name, nr
+\name:
+       raw_syscall \nr
+endf   \name
+.endm
+
+__vdso_gettimeofday:
+       .cfi_startproc
+#ifdef __NR_gettimeofday
+       raw_syscall __NR_gettimeofday
+       ret
+#else
+       /* No gettimeofday, fall back to clock_gettime64. */
+       beq     a1, zero, 1f
+       sw      zero, 0(a1)     /* tz->tz_minuteswest = 0 */
+       sw      zero, 4(a1)     /* tz->tz_dsttime = 0 */
+1:     addi    sp, sp, -32
+       .cfi_adjust_cfa_offset 32
+       sw      a0, 16(sp)      /* save tv */
+       mv      a0, sp
+       raw_syscall __NR_clock_gettime64
+       lw      t0, 0(sp)       /* timespec.tv_sec.low */
+       lw      t1, 4(sp)       /* timespec.tv_sec.high */
+       lw      t2, 8(sp)       /* timespec.tv_nsec.low */
+       lw      a1, 16(sp)      /* restore tv */
+       addi    sp, sp, 32
+       .cfi_adjust_cfa_offset -32
+       bne     a0, zero, 9f    /* syscall error? */
+       li      a0, -EOVERFLOW
+       bne     t1, zero, 9f    /* y2038? */
+       li      a0, 0
+       li      t3, 1000
+       divu    t2, t2, t3      /* nsec -> usec */
+       sw      t0, 0(a1)       /* tz->tv_sec */
+       sw      t2, 4(a1)       /* tz->tv_usec */
+9:     ret
+#endif
+       .cfi_endproc
+endf __vdso_gettimeofday
+
+       .cfi_startproc
+
+#ifdef __NR_clock_gettime
+vdso_syscall __vdso_clock_gettime, __NR_clock_gettime
+#else
+vdso_syscall __vdso_clock_gettime, __NR_clock_gettime64
+#endif
+
+#ifdef __NR_clock_getres
+vdso_syscall __vdso_clock_getres, __NR_clock_getres
+#else
+vdso_syscall __vdso_clock_getres, __NR_clock_getres_time64
+#endif
+
+vdso_syscall __vdso_getcpu, __NR_getcpu
+
+__vdso_flush_icache:
+       /* qemu does not need to flush the icache */
+       li      a0, 0
+       ret
+endf __vdso_flush_icache
+
+       .cfi_endproc
+
+/*
+ * Start the unwind info at least one instruction before the signal
+ * trampoline, because the unwinder will assume we are returning
+ * after a call site.
+ */
+
+       .cfi_startproc simple
+       .cfi_signal_frame
+
+#define sizeof_reg     (__riscv_xlen / 4)
+#define sizeof_freg    8
+#define B_GR   (offsetof_uc_mcontext - sizeof_rt_sigframe)
+#define B_FR   (offsetof_uc_mcontext - sizeof_rt_sigframe + offsetof_freg0)
+
+       .cfi_def_cfa    2, sizeof_rt_sigframe
+
+       /* Return address */
+       .cfi_return_column 64
+       .cfi_offset     64, B_GR + 0                    /* pc */
+
+       /* Integer registers */
+       .cfi_offset     1, B_GR + 1 * sizeof_reg        /* r1 (ra) */
+       .cfi_offset     2, B_GR + 2 * sizeof_reg        /* r2 (sp) */
+       .cfi_offset     3, B_GR + 3 * sizeof_reg
+       .cfi_offset     4, B_GR + 4 * sizeof_reg
+       .cfi_offset     5, B_GR + 5 * sizeof_reg
+       .cfi_offset     6, B_GR + 6 * sizeof_reg
+       .cfi_offset     7, B_GR + 7 * sizeof_reg
+       .cfi_offset     8, B_GR + 8 * sizeof_reg
+       .cfi_offset     9, B_GR + 9 * sizeof_reg
+       .cfi_offset     10, B_GR + 10 * sizeof_reg
+       .cfi_offset     11, B_GR + 11 * sizeof_reg
+       .cfi_offset     12, B_GR + 12 * sizeof_reg
+       .cfi_offset     13, B_GR + 13 * sizeof_reg
+       .cfi_offset     14, B_GR + 14 * sizeof_reg
+       .cfi_offset     15, B_GR + 15 * sizeof_reg
+       .cfi_offset     16, B_GR + 16 * sizeof_reg
+       .cfi_offset     17, B_GR + 17 * sizeof_reg
+       .cfi_offset     18, B_GR + 18 * sizeof_reg
+       .cfi_offset     19, B_GR + 19 * sizeof_reg
+       .cfi_offset     20, B_GR + 20 * sizeof_reg
+       .cfi_offset     21, B_GR + 21 * sizeof_reg
+       .cfi_offset     22, B_GR + 22 * sizeof_reg
+       .cfi_offset     23, B_GR + 23 * sizeof_reg
+       .cfi_offset     24, B_GR + 24 * sizeof_reg
+       .cfi_offset     25, B_GR + 25 * sizeof_reg
+       .cfi_offset     26, B_GR + 26 * sizeof_reg
+       .cfi_offset     27, B_GR + 27 * sizeof_reg
+       .cfi_offset     28, B_GR + 28 * sizeof_reg
+       .cfi_offset     29, B_GR + 29 * sizeof_reg
+       .cfi_offset     30, B_GR + 30 * sizeof_reg
+       .cfi_offset     31, B_GR + 31 * sizeof_reg      /* r31 */
+
+       .cfi_offset     32, B_FR + 0                    /* f0 */
+       .cfi_offset     33, B_FR + 1 * sizeof_freg      /* f1 */
+       .cfi_offset     34, B_FR + 2 * sizeof_freg
+       .cfi_offset     35, B_FR + 3 * sizeof_freg
+       .cfi_offset     36, B_FR + 4 * sizeof_freg
+       .cfi_offset     37, B_FR + 5 * sizeof_freg
+       .cfi_offset     38, B_FR + 6 * sizeof_freg
+       .cfi_offset     39, B_FR + 7 * sizeof_freg
+       .cfi_offset     40, B_FR + 8 * sizeof_freg
+       .cfi_offset     41, B_FR + 9 * sizeof_freg
+       .cfi_offset     42, B_FR + 10 * sizeof_freg
+       .cfi_offset     43, B_FR + 11 * sizeof_freg
+       .cfi_offset     44, B_FR + 12 * sizeof_freg
+       .cfi_offset     45, B_FR + 13 * sizeof_freg
+       .cfi_offset     46, B_FR + 14 * sizeof_freg
+       .cfi_offset     47, B_FR + 15 * sizeof_freg
+       .cfi_offset     48, B_FR + 16 * sizeof_freg
+       .cfi_offset     49, B_FR + 17 * sizeof_freg
+       .cfi_offset     50, B_FR + 18 * sizeof_freg
+       .cfi_offset     51, B_FR + 19 * sizeof_freg
+       .cfi_offset     52, B_FR + 20 * sizeof_freg
+       .cfi_offset     53, B_FR + 21 * sizeof_freg
+       .cfi_offset     54, B_FR + 22 * sizeof_freg
+       .cfi_offset     55, B_FR + 23 * sizeof_freg
+       .cfi_offset     56, B_FR + 24 * sizeof_freg
+       .cfi_offset     57, B_FR + 25 * sizeof_freg
+       .cfi_offset     58, B_FR + 26 * sizeof_freg
+       .cfi_offset     59, B_FR + 27 * sizeof_freg
+       .cfi_offset     60, B_FR + 28 * sizeof_freg
+       .cfi_offset     61, B_FR + 29 * sizeof_freg
+       .cfi_offset     62, B_FR + 30 * sizeof_freg
+       .cfi_offset     63, B_FR + 31 * sizeof_freg     /* f31 */
+
+       nop
+
+__vdso_rt_sigreturn:
+       raw_syscall __NR_rt_sigreturn
+endf __vdso_rt_sigreturn
+
+       .cfi_endproc
linux-user/riscv/vdso.ld new file +74 -1
new file mode 100644
index 0000000000..aabe2b0ab3
@@ -0,0 +1,74 @@
+/*
+ * Linker script for linux riscv replacement vdso.
+ *
+ * Copyright 2021 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+VERSION {
+        LINUX_4.15 {
+        global:
+                __vdso_rt_sigreturn;
+                __vdso_gettimeofday;
+                __vdso_clock_gettime;
+                __vdso_clock_getres;
+                __vdso_getcpu;
+                __vdso_flush_icache;
+
+        local: *;
+        };
+}
+
+
+PHDRS {
+        phdr            PT_PHDR         FLAGS(4) PHDRS;
+        load            PT_LOAD         FLAGS(7) FILEHDR PHDRS;
+        dynamic         PT_DYNAMIC      FLAGS(4);
+        eh_frame_hdr    PT_GNU_EH_FRAME;
+        note            PT_NOTE         FLAGS(4);
+}
+
+SECTIONS {
+        /*
+         * We can't prelink to any address without knowing something about
+         * the virtual memory space of the host, since that leaks over into
+         * the available memory space of the guest.
+         */
+        . = SIZEOF_HEADERS;
+
+        /*
+         * The following, including the FILEHDRS and PHDRS, are modified
+         * when we relocate the binary.  We want them to be initially
+         * writable for the relocation; we'll force them read-only after.
+         */
+        .note           : { *(.note*) }         :load :note
+        .dynamic        : { *(.dynamic) }       :load :dynamic
+        .dynsym         : { *(.dynsym) }        :load
+        /*
+         * There ought not be any real read-write data.
+         * But since we manipulated the segment layout,
+         * we have to put these sections somewhere.
+         */
+        .data           : {
+                *(.data*)
+                *(.sdata*)
+                *(.got.plt) *(.got)
+                *(.gnu.linkonce.d.*)
+                *(.bss*)
+                *(.dynbss*)
+                *(.gnu.linkonce.b.*)
+        }
+
+        .rodata         : { *(.rodata*) }
+        .hash           : { *(.hash) }
+        .gnu.hash       : { *(.gnu.hash) }
+        .dynstr         : { *(.dynstr) }
+        .gnu.version    : { *(.gnu.version) }
+        .gnu.version_d  : { *(.gnu.version_d) }
+        .gnu.version_r  : { *(.gnu.version_r) }
+        .eh_frame_hdr   : { *(.eh_frame_hdr) }  :load :eh_frame_hdr
+        .eh_frame       : { *(.eh_frame) }      :load
+
+        .text           : { *(.text*) }         :load   =0xd503201f
+}
--

2.34.1

#29 lore raw

PATCH v5 17/20 linux-user/loongarch64: Add vdso

In reply to Richard Henderson

Requires a relatively recent binutils version in order to avoid spurious R_LARCH_NONE relocations. The presence of these relocs are diagnosed by our gen-vdso tool.

---
 linux-user/loongarch64/vdso-asmoffset.h |   8 ++
 linux-user/elfload.c                    |   4 +
 linux-user/loongarch64/signal.c         |  17 +++-
 linux-user/loongarch64/meson.build      |  21 ++++
 linux-user/loongarch64/vdso.S           | 130 ++++++++++++++++++++++++
 linux-user/loongarch64/vdso.ld          |  73 +++++++++++++
 linux-user/loongarch64/vdso.so          | Bin 0 -> 3560 bytes
 linux-user/meson.build                  |   1 +
 8 files changed, 253 insertions(+), 1 deletion(-)
 create mode 100644 linux-user/loongarch64/vdso-asmoffset.h
 create mode 100644 linux-user/loongarch64/meson.build
 create mode 100644 linux-user/loongarch64/vdso.S
 create mode 100644 linux-user/loongarch64/vdso.ld
 create mode 100755 linux-user/loongarch64/vdso.so
linux-user/loongarch64/vdso-asmoffset.h new file +8 -0
new file mode 100644
index 0000000000..60d113822f
@@ -0,0 +1,8 @@
+#define sizeof_rt_sigframe         0x240
+#define sizeof_sigcontext          0x110
+#define sizeof_sctx_info           0x10
+
+#define offsetof_sigcontext        0x130
+#define offsetof_sigcontext_pc     0
+#define offsetof_sigcontext_gr     8
+#define offsetof_fpucontext_fr     0
linux-user/elfload.c +4 -0
index 8f902bb427..877727e9e7 100644
@@ -1027,6 +1027,10 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en
 
 #define elf_check_arch(x) ((x) == EM_LOONGARCH)
 
+#include "vdso.c.inc"
+
+#define vdso_image_info()    &vdso_image_info
+
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
linux-user/loongarch64/signal.c +16 -1
index bb8efb1172..b9d0a4cad7 100644
@@ -10,8 +10,8 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
-
 #include "target/loongarch/internals.h"
+#include "vdso-asmoffset.h"
 
 /* FP context was used */
 #define SC_USED_FP              (1 << 0)
@@ -23,6 +23,11 @@ struct target_sigcontext {
     uint64_t sc_extcontext[0]   QEMU_ALIGNED(16);
 };
 
+QEMU_BUILD_BUG_ON(sizeof(struct target_sigcontext) != sizeof_sigcontext);
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_pc)
+                  != offsetof_sigcontext_pc);
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigcontext, sc_regs)
+                  != offsetof_sigcontext_gr);
 
 #define FPU_CTX_MAGIC           0x46505501
 #define FPU_CTX_ALIGN           8
@@ -32,6 +37,9 @@ struct target_fpu_context {
     uint32_t fcsr;
 } QEMU_ALIGNED(FPU_CTX_ALIGN);
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_fpu_context, regs)
+                  != offsetof_fpucontext_fr);
+
 #define CONTEXT_INFO_ALIGN      16
 struct target_sctx_info {
     uint32_t magic;
@@ -39,6 +47,8 @@ struct target_sctx_info {
     uint64_t padding;
 } QEMU_ALIGNED(CONTEXT_INFO_ALIGN);
 
+QEMU_BUILD_BUG_ON(sizeof(struct target_sctx_info) != sizeof_sctx_info);
+
 struct target_ucontext {
     abi_ulong tuc_flags;
     abi_ptr tuc_link;
@@ -53,6 +63,11 @@ struct target_rt_sigframe {
     struct target_ucontext       rs_uc;
 };
 
+QEMU_BUILD_BUG_ON(sizeof(struct target_rt_sigframe)
+                  != sizeof_rt_sigframe);
+QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, rs_uc.tuc_mcontext)
+                  != offsetof_sigcontext);
+
 /*
  * These two structures are not present in guest memory, are private
  * to the signal implementation, but are largely copied from the
linux-user/loongarch64/meson.build new file +21 -0
new file mode 100644
index 0000000000..fea83312f5
@@ -0,0 +1,21 @@
+vdso_so = custom_target(output: 'vdso.so',
+                        input: files('vdso.S', 'vdso.ld'),
+                        depend_files: files('vdso-asmoffset.h'),
+                        command: [
+                            build_vdso_cmd,
+                            '-B', meson.project_build_root(),
+                            '-C', meson.current_source_dir(),
+                            '-T', 'loongarch64-linux-user',
+                            '-o', '@OUTPUT@',
+	                    '--', '-nostdlib', '-shared', '-fpic',
+	                    '-Wl,-h,linux-vdso.so.1',
+                            '-Wl,--build-id=sha1',
+                            '-Wl,--hash-style=both',
+                            '-Wl,--no-warn-rwx-segments',
+                            '-Wl,-T,@INPUT1@',
+                            '@INPUT0@'
+                        ])
+
+vdso_inc = gen_vdso.process(vdso_so, extra_args: ['-r', '__vdso_rt_sigreturn'])
+
+linux_user_ss.add(when: 'TARGET_LOONGARCH64', if_true: vdso_inc)
linux-user/loongarch64/vdso.S new file +130 -0

130 lines not on this page · raw message

linux-user/loongarch64/vdso.ld new file +73 -0

73 lines not on this page · raw message

linux-user/loongarch64/vdso.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..bfaa26f2bfe1aaa01d9a349b8b030ef6323e1f8e
GIT binary patch
linux-user/meson.build +1 -0
index 3aa967b27c..1292e50c15 100644
@@ -41,6 +41,7 @@ subdir('alpha')
 subdir('arm')
 subdir('hppa')
 subdir('i386')
+subdir('loongarch64')
 subdir('m68k')
 subdir('microblaze')
 subdir('mips64')
Signature · 1 line
2.34.1
#30 lore raw

PATCH v5 18/20 linux-user/ppc: Add vdso

In reply to Richard Henderson
---
 linux-user/ppc/vdso-asmoffset.h |  20 +++
 linux-user/elfload.c            |   9 ++
 linux-user/ppc/signal.c         |  31 +++--
 linux-user/gen-vdso-elfn.c.inc  |   7 +
 linux-user/ppc/Makefile.vdso    |  18 +++
 linux-user/ppc/meson.build      |  12 ++
 linux-user/ppc/vdso-32.ld       |  70 ++++++++++
 linux-user/ppc/vdso-32.so       | Bin 0 -> 3020 bytes
 linux-user/ppc/vdso-64.ld       |  68 +++++++++
 linux-user/ppc/vdso-64.so       | Bin 0 -> 3896 bytes
 linux-user/ppc/vdso-64le.so     | Bin 0 -> 3896 bytes
 linux-user/ppc/vdso.S           | 239 ++++++++++++++++++++++++++++++++
 12 files changed, 466 insertions(+), 8 deletions(-)
 create mode 100644 linux-user/ppc/vdso-asmoffset.h
 create mode 100644 linux-user/ppc/Makefile.vdso
 create mode 100644 linux-user/ppc/vdso-32.ld
 create mode 100755 linux-user/ppc/vdso-32.so
 create mode 100644 linux-user/ppc/vdso-64.ld
 create mode 100755 linux-user/ppc/vdso-64.so
 create mode 100755 linux-user/ppc/vdso-64le.so
 create mode 100644 linux-user/ppc/vdso.S
linux-user/ppc/vdso-asmoffset.h new file +20 -0
new file mode 100644
index 0000000000..6844c8c81c
@@ -0,0 +1,20 @@
+/*
+ * Size of dummy stack frame allocated when calling signal handler.
+ * See arch/powerpc/include/asm/ptrace.h.
+ */
+#ifdef TARGET_ABI32
+# define SIGNAL_FRAMESIZE                   64
+#else
+# define SIGNAL_FRAMESIZE                   128
+#endif
+
+#ifdef TARGET_ABI32
+# define offsetof_sigframe_mcontext         0x20
+# define offsetof_rt_sigframe_mcontext      0x140
+# define offsetof_mcontext_fregs            0xc0
+# define offsetof_mcontext_vregs            0x1d0
+#else
+# define offsetof_rt_sigframe_mcontext      0xe8
+# define offsetof_mcontext_fregs            0x180
+# define offsetof_mcontext_vregs_ptr        0x288
+#endif
linux-user/elfload.c +9 -0
index 877727e9e7..cdc517952b 100644
@@ -1015,6 +1015,15 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
+#ifndef TARGET_PPC64
+# include "vdso-32.c.inc"
+#elif TARGET_BIG_ENDIAN
+# include "vdso-64.c.inc"
+#else
+# include "vdso-64le.c.inc"
+#endif
+#define vdso_image_info()    &vdso_image_info
+
 #endif
 
 #ifdef TARGET_LOONGARCH64
linux-user/ppc/signal.c +23 -8
index a616f20efb..7e7302823b 100644
@@ -21,14 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
-
-/* Size of dummy stack frame allocated when calling signal handler.
-   See arch/powerpc/include/asm/ptrace.h.  */
-#if defined(TARGET_PPC64)
-#define SIGNAL_FRAMESIZE 128
-#else
-#define SIGNAL_FRAMESIZE 64
-#endif
+#include "vdso-asmoffset.h"
 
 /* See arch/powerpc/include/asm/ucontext.h.  Only used for 32-bit PPC;
    on 64-bit PPC, sigcontext and mcontext are one and the same.  */
@@ -73,6 +66,16 @@ struct target_mcontext {
 #endif
 };
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_mcontext, mc_fregs)
+                  != offsetof_mcontext_fregs);
+#if defined(TARGET_PPC64)
+QEMU_BUILD_BUG_ON(offsetof(struct target_mcontext, v_regs)
+                  != offsetof_mcontext_vregs_ptr);
+#else
+QEMU_BUILD_BUG_ON(offsetof(struct target_mcontext, mc_vregs)
+                  != offsetof_mcontext_vregs);
+#endif
+
 /* See arch/powerpc/include/asm/sigcontext.h.  */
 struct target_sigcontext {
     target_ulong _unused[4];
@@ -161,6 +164,7 @@ struct target_ucontext {
 #endif
 };
 
+#if !defined(TARGET_PPC64)
 /* See arch/powerpc/kernel/signal_32.c.  */
 struct target_sigframe {
     struct target_sigcontext sctx;
@@ -168,6 +172,10 @@ struct target_sigframe {
     int32_t abigap[56];
 };
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_sigframe, mctx)
+                  != offsetof_sigframe_mcontext);
+#endif
+
 #if defined(TARGET_PPC64)
 
 #define TARGET_TRAMP_SIZE 6
@@ -184,6 +192,10 @@ struct target_rt_sigframe {
     char abigap[288];
 } __attribute__((aligned(16)));
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe,
+                           uc.tuc_sigcontext.mcontext)
+                  != offsetof_rt_sigframe_mcontext);
+
 #else
 
 struct target_rt_sigframe {
@@ -192,6 +204,9 @@ struct target_rt_sigframe {
     int32_t abigap[56];
 };
 
+QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.tuc_mcontext)
+                  != offsetof_rt_sigframe_mcontext);
+
 #endif
 
 #if defined(TARGET_PPC64)
linux-user/gen-vdso-elfn.c.inc +7 -0
index 7034c36d5e..95856eb839 100644
@@ -273,7 +273,14 @@ static void elfN(process)(FILE *outf, void *buf, bool need_bswap)
                 errors++;
                 break;
 
+            case PT_LOPROC + 3:
+                if (ehdr->e_machine == EM_PPC64) {
+                    break;  /* DT_PPC64_OPT: integer bitmask */
+                }
+                goto do_default;
+
             default:
+            do_default:
                 /* This is probably something target specific. */
                 fprintf(stderr, "VDSO has unknown DYNAMIC entry (%lx)\n",
                         (unsigned long)tag);
linux-user/ppc/Makefile.vdso new file +18 -0
new file mode 100644
index 0000000000..e9d2b16839
@@ -0,0 +1,18 @@
+CROSS_CC ?= powerpc64-linux-gnu-gcc
+
+all: vdso-32.so vdso-64.so vdso-64le.so
+
+LDFLAGS32 := -nostdlib -shared -Wl,-T,vdso-32.ld \
+	     -Wl,-h,linux-vdso32.so.1 -Wl,--hash-style=both -Wl,--build-id=sha1
+LDFLAGS64 := -nostdlib -shared -Wl,-T,vdso-64.ld \
+	     -Wl,-h,linux-vdso64.so.1 -Wl,--hash-style=both -Wl,--build-id=sha1
+
+vdso-32.so: vdso.S vdso-32.ld vdso-asmoffset.h Makefile.vdso
+	$(CROSS_CC) $(LDFLAGS32) -m32 vdso.S -o $@
+
+vdso-64.so: vdso.S vdso-64.ld vdso-asmoffset.h Makefile.vdso
+	$(CROSS_CC) $(LDFLAGS64) -mbig-endian vdso.S -o $@
+
+vdso-64le.so: vdso.S vdso-64.ld vdso-asmoffset.h Makefile.vdso
+	$(CROSS_CC) $(LDFLAGS64) -mlittle-endian vdso.S -o $@
+
linux-user/ppc/meson.build +12 -0
index 19fead7bc8..5a838f182f 100644
@@ -3,3 +3,15 @@ syscall_nr_generators += {
                    arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                    output: '@BASENAME@_nr.h')
 }
+
+gen32 = [
+  gen_vdso.process('vdso-32.so', extra_args: ['-s', '__kernel_sigtramp32',
+                                              '-r', '__kernel_sigtramp_rt32']),
+]
+linux_user_ss.add(when: 'TARGET_PPC', if_true: gen32)
+
+gen64 = [
+  gen_vdso.process('vdso-64.so', extra_args: ['-r', '__kernel_sigtramp_rt64']),
+  gen_vdso.process('vdso-64le.so', extra_args: ['-r', '__kernel_sigtramp_rt64'])
+]
+linux_user_ss.add(when: 'TARGET_PPC64', if_true: gen64)
linux-user/ppc/vdso-32.ld new file +70 -0

70 lines not on this page · raw message

linux-user/ppc/vdso-32.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..b19baafb0d38e15b4a24def5c44a6d684714be45
GIT binary patch
linux-user/ppc/vdso-64.ld new file +68 -0

68 lines not on this page · raw message

linux-user/ppc/vdso-64.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..913c831b3819fc09912b9b31f7fbe9ee311ae12f
GIT binary patch
linux-user/ppc/vdso-64le.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..258a03b807c4eca23547d978c16d1ad5ebd08bc5
GIT binary patch
linux-user/ppc/vdso.S new file +239 -0

239 lines not on this page · raw message

Signature · 1 line
2.34.1
#31 lore raw

PATCH v5 19/20 linux-user/s390x: Rename __SIGNAL_FRAMESIZE to STACK_FRAME_OVERHEAD

In reply to Richard Henderson
---
 linux-user/s390x/signal.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
linux-user/s390x/signal.c +4 -3
index f72165576f..0f8b8e04bf 100644
@@ -26,7 +26,8 @@
 #define __NUM_FPRS 16
 #define __NUM_ACRS 16
 
-#define __SIGNAL_FRAMESIZE      160 /* FIXME: 31-bit mode -> 96 */
+/* Minimum stack frame size */
+#define STACK_FRAME_OVERHEAD    160
 
 #define _SIGCONTEXT_NSIG        64
 #define _SIGCONTEXT_NSIG_BPW    64 /* FIXME: 31-bit mode -> 32 */
@@ -63,7 +64,7 @@ typedef struct {
 } target_sigcontext;
 
 typedef struct {
-    uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];
+    uint8_t callee_used_stack[STACK_FRAME_OVERHEAD];
     target_sigcontext sc;
     target_sigregs sregs;
     int signo;
@@ -83,7 +84,7 @@ struct target_ucontext {
 };
 
 typedef struct {
-    uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];
+    uint8_t callee_used_stack[STACK_FRAME_OVERHEAD];
     /*
      * This field is no longer initialized by the kernel, but it's still a part
      * of the ABI.
Signature · 1 line
2.34.1
#33 lore raw

PATCH v5 20/20 linux-user/s390x: Add vdso

In reply to Richard Henderson
---
 linux-user/s390x/vdso-asmoffset.h |   2 +
 linux-user/elfload.c              |   3 ++
 linux-user/s390x/signal.c         |   4 +-
 linux-user/s390x/meson.build      |  24 +++++++++++
 linux-user/s390x/vdso.S           |  61 ++++++++++++++++++++++++++
 linux-user/s390x/vdso.ld          |  69 ++++++++++++++++++++++++++++++
 linux-user/s390x/vdso.so          | Bin 0 -> 3464 bytes
 7 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 linux-user/s390x/vdso-asmoffset.h
 create mode 100644 linux-user/s390x/vdso.S
 create mode 100644 linux-user/s390x/vdso.ld
 create mode 100755 linux-user/s390x/vdso.so
linux-user/s390x/vdso-asmoffset.h new file +2 -0
new file mode 100644
index 0000000000..27a062d6c1
@@ -0,0 +1,2 @@
+/* Minimum stack frame size */
+#define STACK_FRAME_OVERHEAD    160
linux-user/elfload.c +3 -0
index cdc517952b..19503d8469 100644
@@ -1737,6 +1737,9 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 4096
 
+#include "vdso.c.inc"
+#define vdso_image_info()    &vdso_image_info
+
 #endif /* TARGET_S390X */
 
 #ifdef TARGET_RISCV
linux-user/s390x/signal.c +1 -3
index 0f8b8e04bf..b40f738a70 100644
@@ -21,14 +21,12 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "vdso-asmoffset.h"
 
 #define __NUM_GPRS 16
 #define __NUM_FPRS 16
 #define __NUM_ACRS 16
 
-/* Minimum stack frame size */
-#define STACK_FRAME_OVERHEAD    160
-
 #define _SIGCONTEXT_NSIG        64
 #define _SIGCONTEXT_NSIG_BPW    64 /* FIXME: 31-bit mode -> 32 */
 #define _SIGCONTEXT_NSIG_WORDS  (_SIGCONTEXT_NSIG / _SIGCONTEXT_NSIG_BPW)
linux-user/s390x/meson.build +24 -0
index 0781ccea1d..09afd98deb 100644
@@ -3,3 +3,27 @@ syscall_nr_generators += {
                      arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                      output: '@BASENAME@_nr.h')
 }
+
+vdso_so = custom_target(output: 'vdso.so',
+                        input: files('vdso.S', 'vdso.ld'),
+                        depend_files: files('vdso-asmoffset.h'),
+                        command: [
+                            build_vdso_cmd,
+                            '-B', meson.project_build_root(),
+                            '-C', meson.current_source_dir(),
+                            '-T', 's390x-linux-user',
+                            '-o', '@OUTPUT@',
+                            '--', '-nostdlib', '-shared',
+                            '-Wl,-h,linux-vdso64.so.1',
+                            '-Wl,--build-id=sha1',
+                            '-Wl,--hash-style=both',
+                            '-Wl,-T,@INPUT1@',
+                            '@INPUT0@'
+                        ])
+
+vdso_inc = gen_vdso.process('vdso.so', extra_args: [
+                                '-s', '__kernel_sigreturn',
+                                '-r', '__kernel_rt_sigreturn'
+                            ])
+
+linux_user_ss.add(when: 'TARGET_S390X', if_true: vdso_inc)
linux-user/s390x/vdso.S new file +61 -0

61 lines not on this page · raw message

linux-user/s390x/vdso.ld new file +69 -0

69 lines not on this page · raw message

linux-user/s390x/vdso.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..64130f6f335269b03291653d006225b365be9cd9
GIT binary patch
Signature · 1 line
2.34.1
#34 lore raw

Re: [PATCH v5 20/20] linux-user/s390x: Add vdso

Quoted 15 lines · Richard Henderson
---
 linux-user/s390x/vdso-asmoffset.h |   2 +
 linux-user/elfload.c              |   3 ++
 linux-user/s390x/signal.c         |   4 +-
 linux-user/s390x/meson.build      |  24 +++++++++++
 linux-user/s390x/vdso.S           |  61 ++++++++++++++++++++++++++
 linux-user/s390x/vdso.ld          |  69 ++++++++++++++++++++++++++++++
 linux-user/s390x/vdso.so          | Bin 0 -> 3464 bytes
 7 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 linux-user/s390x/vdso-asmoffset.h
 create mode 100644 linux-user/s390x/vdso.S
 create mode 100644 linux-user/s390x/vdso.ld
 create mode 100755 linux-user/s390x/vdso.so

<snip>

Quoted 21 lines
linux-user/s390x/meson.build +13 -0
index 0781ccea1d..09afd98deb 100644
@@ -3,3 +3,27 @@ syscall_nr_generators += {
                      arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                      output: '@BASENAME@_nr.h')
 }
+
+vdso_so = custom_target(output: 'vdso.so',
+                        input: files('vdso.S', 'vdso.ld'),
+                        depend_files: files('vdso-asmoffset.h'),
+                        command: [
+                            build_vdso_cmd,
+                            '-B', meson.project_build_root(),
+                            '-C', meson.current_source_dir(),
+                            '-T', 's390x-linux-user',
+                            '-o', '@OUTPUT@',
+                            '--', '-nostdlib', '-shared',
+                            '-Wl,-h,linux-vdso64.so.1',
+                            '-Wl,--build-id=sha1',

linux-user/s390x/meson.build syscall_nr_generators += { · line 28

Quoted 10 lines
linux-user/s390x/meson.build +10 -0
+                            '-Wl,--hash-style=both',
+                            '-Wl,-T,@INPUT1@',
+                            '@INPUT0@'
+                        ])
+
+vdso_inc = gen_vdso.process('vdso.so', extra_args: [
+                                '-s', '__kernel_sigreturn',
+                                '-r', '__kernel_rt_sigreturn'
+                            ])
+

Due to the b4 dropping the vdso.so in the patch this fails:

Program build-vdso.sh found: YES (/home/alex/lsrc/qemu.git/linux-user/build-vdso.sh) ../../linux-user/s390x/meson.build:24:0: ERROR: File vdso.so does not exist.
A full log can be found at /home/alex/lsrc/qemu.git/builds/all/meson-logs/meson-log.txt
FAILED: build.ninja
/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson --internal regenerate /home/alex/lsrc/qemu.git /home/alex/lsrc/qemu.git/builds/all
ninja: error: rebuilding 'build.ninja': subcommand failed
BUILD aarch64-softmmu guest-tests
tests/tcg/aarch64-softmmu: -march=armv8.3-a detected

which makes me think the dependencies are broken anyway because I have a working s390x compiler:

  ➜  cat tests/tcg/s390x-linux-user/config-target.mak 
  # Automatically generated by configure - do not modify
  TARGET_NAME=s390x
  TARGET=s390x-linux-user
  EXTRA_CFLAGS=
  CC=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  CCAS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  AR=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ar -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  AS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-as -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  LD=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ld -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  NM=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-nm -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  OBJCOPY=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-objcopy -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  RANLIB=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ranlib -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  STRIP=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-strip -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
  BUILD_STATIC=y
  QEMU=/home/alex/lsrc/qemu.git/builds/all/qemu-s390x
  HOST_GDB_SUPPORTS_ARCH=y

We really need to express the dependency on docker-image-debian-s390x-cross (when using containers) to ensure we can build the vdso.so and not rely on the copy we have.

Quoted 175 lines
linux-user/s390x/meson.build +1 -0
+linux_user_ss.add(when: 'TARGET_S390X', if_true: vdso_inc)
linux-user/s390x/vdso.S new file +61 -0
new file mode 100644
index 0000000000..3332492477
@@ -0,0 +1,61 @@
+/*
+ * s390x linux replacement vdso.
+ *
+ * Copyright 2023 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <asm/unistd.h>
+#include "vdso-asmoffset.h"
+
+.macro endf name
+	.globl	\name
+	.type	\name, @function
+	.size	\name, . - \name
+.endm
+
+.macro raw_syscall n
+        .ifne	\n < 0x100
+	svc	\n
+	.else
+	lghi	%r1, \n
+	svc	0
+        .endif
+.endm
+
+.macro vdso_syscall name, nr
+\name:
+	.cfi_startproc
+	aghi	%r15, -(STACK_FRAME_OVERHEAD + 16)
+	.cfi_adjust_cfa_offset STACK_FRAME_OVERHEAD + 16
+	stg	%r14, STACK_FRAME_OVERHEAD(%r15)
+	.cfi_rel_offset %r14, STACK_FRAME_OVERHEAD
+	raw_syscall \nr
+	lg	%r14, STACK_FRAME_OVERHEAD(%r15)
+	aghi	%r15, STACK_FRAME_OVERHEAD + 16
+	.cfi_restore %r14
+	.cfi_adjust_cfa_offset -(STACK_FRAME_OVERHEAD + 16)
+	br	%r14
+	.cfi_endproc
+endf	\name
+.endm
+
+vdso_syscall __kernel_gettimeofday, __NR_gettimeofday
+vdso_syscall __kernel_clock_gettime, __NR_clock_gettime
+vdso_syscall __kernel_clock_getres, __NR_clock_getres
+vdso_syscall __kernel_getcpu, __NR_getcpu
+
+/*
+ * TODO unwind info, though we're ok without it.
+ * The kernel supplies bogus empty unwind info, and it is likely ignored
+ * by all users.  Without it we get the fallback signal frame handling.
+ */
+
+__kernel_sigreturn:
+	raw_syscall __NR_sigreturn
+endf	__kernel_sigreturn
+
+__kernel_rt_sigreturn:
+	raw_syscall __NR_rt_sigreturn
+endf	__kernel_rt_sigreturn
linux-user/s390x/vdso.ld new file +69 -0
new file mode 100644
index 0000000000..2a30ff382a
@@ -0,0 +1,69 @@
+/*
+ * Linker script for linux x86-64 replacement vdso.
+ *
+ * Copyright 2023 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+VERSION {
+        LINUX_2.6.29 {
+        global:
+                __kernel_gettimeofday;
+                __kernel_clock_gettime;
+                __kernel_clock_getres;
+                __kernel_getcpu;
+                __kernel_restart_syscall;
+                __kernel_rt_sigreturn;
+                __kernel_sigreturn;
+        local: *;
+        };
+}
+
+
+PHDRS {
+        phdr            PT_PHDR         FLAGS(4) PHDRS;
+        load            PT_LOAD         FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */
+        dynamic         PT_DYNAMIC      FLAGS(4);
+        eh_frame_hdr    PT_GNU_EH_FRAME;
+        note            PT_NOTE         FLAGS(4);
+}
+
+SECTIONS {
+        . = SIZEOF_HEADERS;
+
+        /*
+         * The following, including the FILEHDRS and PHDRS, are modified
+         * when we relocate the binary.  We want them to be initially
+         * writable for the relocation; we'll force them read-only after.
+         */
+        .note           : { *(.note*) }         :load :note
+        .dynamic        : { *(.dynamic) }       :load :dynamic
+        .dynsym         : { *(.dynsym) }        :load
+        .data           : {
+                /*
+                 * There ought not be any real read-write data.
+                 * But since we manipulated the segment layout,
+                 * we have to put these sections somewhere.
+                 */
+                *(.data*)
+                *(.sdata*)
+                *(.got.plt) *(.got)
+                *(.gnu.linkonce.d.*)
+                *(.bss*)
+                *(.dynbss*)
+                *(.gnu.linkonce.b.*)
+        }
+
+        .rodata         : { *(.rodata*) }
+        .hash           : { *(.hash) }
+        .gnu.hash       : { *(.gnu.hash) }
+        .dynstr         : { *(.dynstr) }
+        .gnu.version    : { *(.gnu.version) }
+        .gnu.version_d  : { *(.gnu.version_d) }
+        .gnu.version_r  : { *(.gnu.version_r) }
+        .eh_frame_hdr   : { *(.eh_frame_hdr) }  :load :eh_frame_hdr
+        .eh_frame       : { *(.eh_frame) }      :load
+
+        .text           : { *(.text*) }         :load
+}
linux-user/s390x/vdso.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..64130f6f335269b03291653d006225b365be9cd9
GIT binary patch
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#35 lore raw

Re: [PATCH v5 20/20] linux-user/s390x: Add vdso

Quoted 32 lines · Alex Bennée

Due to the b4 dropping the vdso.so in the patch this fails:

Program build-vdso.sh found: YES (/home/alex/lsrc/qemu.git/linux-user/build-vdso.sh) ../../linux-user/s390x/meson.build:24:0: ERROR: File vdso.so does not exist.
A full log can be found at /home/alex/lsrc/qemu.git/builds/all/meson-logs/meson-log.txt
FAILED: build.ninja
/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson --internal regenerate /home/alex/lsrc/qemu.git /home/alex/lsrc/qemu.git/builds/all
ninja: error: rebuilding 'build.ninja': subcommand failed
BUILD aarch64-softmmu guest-tests
tests/tcg/aarch64-softmmu: -march=armv8.3-a detected

which makes me think the dependencies are broken anyway because I have a working s390x compiler:

   ➜  cat tests/tcg/s390x-linux-user/config-target.mak
   # Automatically generated by configure - do not modify
   TARGET_NAME=s390x
   TARGET=s390x-linux-user
   EXTRA_CFLAGS=
   CC=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   CCAS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   AR=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ar -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   AS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-as -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   LD=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ld -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   NM=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-nm -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   OBJCOPY=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-objcopy -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   RANLIB=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ranlib -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   STRIP=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-strip -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   BUILD_STATIC=y
   QEMU=/home/alex/lsrc/qemu.git/builds/all/qemu-s390x
   HOST_GDB_SUPPORTS_ARCH=y
Quoted 3 lines

We really need to express the dependency on docker-image-debian-s390x-cross (when using containers) to ensure we can build the vdso.so and not rely on the copy we have.

I think expressing the dependency is a mistake.

The major problem is network unreliability. I installed a new vm to build test this, and it took more than a dozen retrys to get all of the docker images built.

What we do right now is determine if docker or podman is present and works, and then *assume* we can make all of the cross-compilers work later, and so register them as cross-compilers early.

I think the only moderately reliable thing is to determine what containers are already present and working and use only those. Developers will need to manually rebuild containers periodically and then re-run configure to make those visible to the cross-build machinery. Not completely ideal, of course, but nothing else is either.

r~

#36 lore raw

Re: [PATCH v5 20/20] linux-user/s390x: Add vdso

Quoted 55 lines · Richard Henderson
Quoted 50 lines · Alex Bennée

Due to the b4 dropping the vdso.so in the patch this fails:

   Program build-vdso.sh found: YES (/home/alex/lsrc/qemu.git/linux-user/build-vdso.sh) ../../linux-user/s390x/meson.build:24:0: ERROR: File vdso.so does not exist.
   A full log can be found at /home/alex/lsrc/qemu.git/builds/all/meson-logs/meson-log.txt
   FAILED: build.ninja
   /home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson --internal regenerate /home/alex/lsrc/qemu.git /home/alex/lsrc/qemu.git/builds/all
   ninja: error: rebuilding 'build.ninja': subcommand failed
     BUILD   aarch64-softmmu guest-tests
   tests/tcg/aarch64-softmmu: -march=armv8.3-a detected

which makes me think the dependencies are broken anyway because I have a working s390x compiler:

   ➜  cat tests/tcg/s390x-linux-user/config-target.mak
   # Automatically generated by configure - do not modify
   TARGET_NAME=s390x
   TARGET=s390x-linux-user
   EXTRA_CFLAGS=
   CC=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   CCAS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   AR=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ar -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   AS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-as -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   LD=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ld -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   NM=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-nm -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   OBJCOPY=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-objcopy -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   RANLIB=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ranlib -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   STRIP=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-strip -i qemu/debian-s390x-cross -s
/home/alex/lsrc/qemu.git --
   BUILD_STATIC=y
   QEMU=/home/alex/lsrc/qemu.git/builds/all/qemu-s390x
   HOST_GDB_SUPPORTS_ARCH=y

Quoted 3 lines

We really need to express the dependency on docker-image-debian-s390x-cross (when using containers) to ensure we can build the vdso.so and not rely on the copy we have.

Quoted 7 lines

I think expressing the dependency is a mistake.

The major problem is network unreliability.  I installed a new vm to build test this, and it took more than a dozen retrys to get all of the docker images built.

What we do right now is determine if docker or podman is present and works, and then *assume* we can make all of the cross-compilers work later, and so register them as cross-compilers early.

I think the only moderately reliable thing is to determine what containers are already present and working and use only those. Developers will need to manually rebuild containers periodically and then re-run configure to make those visible to the cross-build machinery.  Not completely ideal, of course, but nothing else is either.

We discussed this 1 or 2 years ago. My suggestion was when we tag a release, we also tag the gitlab docker images (with all the distro packages installed from that tag). Then those working with the release can pull the pre-installed image from the tag; since it won't need newer package, no need for network access within the image.

During the latest development cycle, we can either use the latest tagged image if sufficient, or we have to deal with the same issues you mentioned (network stability, broken package deps from time to time).

#37 lore raw

Re: [PATCH v5 20/20] linux-user/s390x: Add vdso

In reply to Richard Henderson
Quoted 37 lines · Richard Henderson
Quoted 30 lines · Alex Bennée

Due to the b4 dropping the vdso.so in the patch this fails:
Program build-vdso.sh found: YES
(/home/alex/lsrc/qemu.git/linux-user/build-vdso.sh)
../../linux-user/s390x/meson.build:24:0: ERROR: File vdso.so does not exist.
A full log can be found at /home/alex/lsrc/qemu.git/builds/all/meson-logs/meson-log.txt
FAILED: build.ninja
/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson --internal regenerate /home/alex/lsrc/qemu.git /home/alex/lsrc/qemu.git/builds/all
ninja: error: rebuilding 'build.ninja': subcommand failed
BUILD aarch64-softmmu guest-tests
tests/tcg/aarch64-softmmu: -march=armv8.3-a detected
which makes me think the dependencies are broken anyway because I
have a
working s390x compiler:

   ➜  cat tests/tcg/s390x-linux-user/config-target.mak
   # Automatically generated by configure - do not modify
   TARGET_NAME=s390x
   TARGET=s390x-linux-user
   EXTRA_CFLAGS=
   CC=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   CCAS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-gcc -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   AR=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ar -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   AS=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-as -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   LD=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ld -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   NM=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-nm -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   OBJCOPY=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-objcopy -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   RANLIB=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-ranlib -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   STRIP=/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B /home/alex/lsrc/qemu.git/tests/docker/docker.py --engine docker cc --cc s390x-linux-gnu-strip -i qemu/debian-s390x-cross -s /home/alex/lsrc/qemu.git --
   BUILD_STATIC=y
   QEMU=/home/alex/lsrc/qemu.git/builds/all/qemu-s390x
   HOST_GDB_SUPPORTS_ARCH=y
Quoted 3 lines

We really need to express the dependency on docker-image-debian-s390x-cross (when using containers) to ensure we can build the vdso.so and not rely on the copy we have.

I think expressing the dependency is a mistake.

Quoted 7 lines

The major problem is network unreliability. I installed a new vm to build test this, and it took more than a dozen retrys to get all of the docker images built.

What we do right now is determine if docker or podman is present and works, and then *assume* we can make all of the cross-compilers work later, and so register them as cross-compilers early.

Fair enough. I'm all for making the normal case easy, but then how do we express the explicit "please build the binary for me"?

Quoted 10 lines

I think the only moderately reliable thing is to determine what containers are already present and working and use only those. Developers will need to manually rebuild containers periodically and then re-run configure to make those visible to the cross-build machinery. Not completely ideal, of course, but nothing else is either.

r~

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#38 lore raw
In reply to Richard Henderson
Quoted 8 lines · Richard Henderson

Changes for v5:
* Integrated cross-compile, via new build-vdso.sh and meson rules. However, keep the binaries in the tree for hosts which do not have all of the cross-compile machinery.
* Update our loongarch64 docker image to avoid a binutils bug.

Just in case the list eats a binary:

   https://gitlab.com/rth7680/qemu/-/tree/lu-vdso

I pulled that on top of git head, and ran into the build problem below. Do I miss something?

Helge

[62/1742] Generating linux-user/aarch64/vdso-be.so with a custom command
FAILED: linux-user/aarch64/vdso-be.so
/home/cvs/qemu/qemu/linux-user/build-vdso.sh -B /srv/_build -C /home/cvs/qemu/qemu/linux-user/aarch64 -T aarch64-linux-user -o linux-user/aarch64/vdso-be.so -- -nostdlib -shared -Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 -Wl,--hash-style=both -Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld ../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S -mbig-endian
Error: short-name resolution enforced but cannot prompt without a TTY
Traceback (most recent call last):
File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 683, in <module>

    sys.exit(main())
             ^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 679, in main
    return args.cmdobj.run(args, argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 657, in run
    return Docker().run(cmd, False, quiet=args.quiet,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 370, in run
    ret = self._do_check(["run", "--rm", "--label",
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 247, in _do_check
return subprocess.check_call(self._command + cmd, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/subprocess.py", line 413, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['podman', 'run', '--rm', '--label', 'com.qemu.instance.uuid=e746f7e345ed420088a9cc30e884a7e8', '--userns=keep-id', '-u', '1000', '-w', '/srv/_build', '-v', '/srv/_build:/srv/_build:rw', '-v', '/home/cvs/qemu/qemu:/home/cvs/qemu/qemu:ro,z', 'qemu/debian-arm64-cross', 'aarch64-linux-gnu-gcc-10', '-o', 'linux-user/aarch64/vdso-be.so', '-nostdlib', '-shared', '-Wl,-h,linux-vdso.so.1', '-Wl,--build-id=sha1', '-Wl,--hash-style=both', '-Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld', '../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S', '-mbig-endian']' returned non-zero exit status 125. filter=--filter=label=com.qemu.instance.uuid=e746f7e345ed420088a9cc30e884a7e8

#39 lore raw
Quoted 7 lines · Helge Deller
Quoted 6 lines · Richard Henderson

Changes for v5:
   * Integrated cross-compile, via new build-vdso.sh and meson rules. However, keep the binaries in the tree for hosts which do not have all of the cross-compile machinery.
   * Update our loongarch64 docker image to avoid a binutils bug.

Quoted 5 lines
Quoted 2 lines

Just in case the list eats a binary:
   https://gitlab.com/rth7680/qemu/-/tree/lu-vdso

I pulled that on top of git head, and ran into the build problem below. Do I miss something?

No idea, since it worked for me. Looks like some sort of docker.py problem. Alex?

In the short term, use --disable-containers so that you only use the cross-compilers that you have locally installed.

r~

Quoted 31 lines

Helge

[62/1742] Generating linux-user/aarch64/vdso-be.so with a custom command
FAILED: linux-user/aarch64/vdso-be.so
/home/cvs/qemu/qemu/linux-user/build-vdso.sh -B /srv/_build -C /home/cvs/qemu/qemu/linux-user/aarch64 -T aarch64-linux-user -o linux-user/aarch64/vdso-be.so -- -nostdlib -shared -Wl,-h,linux-vdso.so.1

(quoted diff) +0 -2
-Wl,--build-id=sha1 -Wl,--hash-style=both 
-Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld 

../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S -mbig-endian
Error: short-name resolution enforced but cannot prompt without a TTY
Traceback (most recent call last):
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 683, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 679, in main
    return args.cmdobj.run(args, argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 657, in run
    return Docker().run(cmd, False, quiet=args.quiet,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 370, in run
    ret = self._do_check(["run", "--rm", "--label",
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 247, in _do_check
    return subprocess.check_call(self._command + cmd, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['podman', 'run', '--rm', '--label', 'com.qemu.instance.uuid=e746f7e345ed420088a9cc30e884a7e8', '--userns=keep-id', '-u', '1000', '-w', '/srv/_build', '-v', '/srv/_build:/srv/_build:rw', '-v', '/home/cvs/qemu/qemu:/home/cvs/qemu/qemu:ro,z', 'qemu/debian-arm64-cross', 'aarch64-linux-gnu-gcc-10', '-o', 'linux-user/aarch64/vdso-be.so', '-nostdlib', '-shared', '-Wl,-h,linux-vdso.so.1', '-Wl,--build-id=sha1', '-Wl,--hash-style=both', '-Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld', '../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S', '-mbig-endian']' returned non-zero exit status 125. filter=--filter=label=com.qemu.instance.uuid=e746f7e345ed420088a9cc30e884a7e8

#40 lore raw
Quoted 45 lines · Richard Henderson
Quoted 7 lines · Helge Deller
Quoted 6 lines · Richard Henderson

Changes for v5:
   * Integrated cross-compile, via new build-vdso.sh and meson rules. However, keep the binaries in the tree for hosts which do not have all of the cross-compile machinery.
   * Update our loongarch64 docker image to avoid a binutils bug.

Quoted 5 lines
Quoted 2 lines

Just in case the list eats a binary:
   https://gitlab.com/rth7680/qemu/-/tree/lu-vdso

I pulled that on top of git head, and ran into the build problem below.
Do I miss something?

No idea, since it worked for me. Looks like some sort of docker.py problem. Alex?

In the short term, use --disable-containers so that you only use the cross-compilers that you have locally installed.

r~

Quoted 23 lines

Helge
[62/1742] Generating linux-user/aarch64/vdso-be.so with a custom command
FAILED: linux-user/aarch64/vdso-be.so /home/cvs/qemu/qemu/linux-user/build-vdso.sh -B /srv/_build -C /home/cvs/qemu/qemu/linux-user/aarch64 -T aarch64-linux-user -o linux-user/aarch64/vdso-be.so -- -nostdlib -shared

(quoted diff) +0 -2
-Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 -Wl,--hash-style=both
-Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld

../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S -mbig-endian
Error: short-name resolution enforced but cannot prompt without a TTY Traceback (most recent call last):
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 683, in <module> sys.exit(main())
             ^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 679, in main return args.cmdobj.run(args, argv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 657, in run return Docker().run(cmd, False, quiet=args.quiet, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 370, in run ret = self._do_check(["run", "--rm", "--label",

Quoted 8 lines
Quoted 8 lines

          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 247, in _do_check return subprocess.check_call(self._command + cmd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/subprocess.py", line 413, in check_call raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['podman', 'run', '--rm', '--label',

It looks like it detected podman on this setup. Can you invoke the container from the command line?

Quoted 13 lines
Quoted 13 lines

'com.qemu.instance.uuid=e746f7e345ed420088a9cc30e884a7e8', '--userns=keep-id', '-u', '1000', '-w', '/srv/_build', '-v', '/srv/_build:/srv/_build:rw', '-v', '/home/cvs/qemu/qemu:/home/cvs/qemu/qemu:ro,z', 'qemu/debian-arm64-cross', 'aarch64-linux-gnu-gcc-10', '-o', 'linux-user/aarch64/vdso-be.so', '-nostdlib', '-shared', '-Wl,-h,linux-vdso.so.1', '-Wl,--build-id=sha1', '-Wl,--hash-style=both', '-Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld', '../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S', '-mbig-endian']' returned non-zero exit status 125. filter=--filter=label=com.qemu.instance.uuid=e746f7e345ed420088a9cc30e884a7e8

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#41 lore raw
Quoted 51 lines · Alex Bennée
Quoted 48 lines · Richard Henderson
Quoted 7 lines · Helge Deller
Quoted 6 lines · Richard Henderson

Changes for v5:
   * Integrated cross-compile, via new build-vdso.sh and meson rules. However, keep the binaries in the tree for hosts which do not have all of the cross-compile machinery.
   * Update our loongarch64 docker image to avoid a binutils bug.

Quoted 5 lines
Quoted 2 lines

Just in case the list eats a binary:
   https://gitlab.com/rth7680/qemu/-/tree/lu-vdso

I pulled that on top of git head, and ran into the build problem below.
Do I miss something?

No idea, since it worked for me. Looks like some sort of docker.py problem. Alex?

In the short term, use --disable-containers so that you only use the cross-compilers that you have locally installed.

r~

Quoted 26 lines

Helge
[62/1742] Generating linux-user/aarch64/vdso-be.so with a custom command
FAILED: linux-user/aarch64/vdso-be.so /home/cvs/qemu/qemu/linux-user/build-vdso.sh -B /srv/_build -C /home/cvs/qemu/qemu/linux-user/aarch64 -T aarch64-linux-user -o linux-user/aarch64/vdso-be.so -- -nostdlib -shared

(quoted diff) +0 -2
-Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 -Wl,--hash-style=both
-Wl,-T,../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.ld

../../home/cvs/qemu/qemu/linux-user/aarch64/vdso.S -mbig-endian
Error: short-name resolution enforced but cannot prompt without a TTY Traceback (most recent call last):
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 683, in <module> sys.exit(main())
             ^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 679, in main return args.cmdobj.run(args, argv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 657, in run return Docker().run(cmd, False, quiet=args.quiet, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 370, in run ret = self._do_check(["run", "--rm", "--label", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cvs/qemu/qemu/tests/docker/docker.py", line 247, in _do_check return subprocess.check_call(self._command + cmd, **kwargs)

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/subprocess.py", line 413, in check_call raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['podman', 'run', '--rm', '--label',

It looks like it detected podman on this setup. Can you invoke the container from the command line?

Yes, if I run it on the command line:

[deller@p100 _build]$ 'podman' 'run' '--rm' '--label' 'com.qemu.instance.uuid=21e1c0332a2c44b6ae94a71392c57ccf' '--userns=keep-id' '-u' '1000' '-w' '/srv/_build' '-v' '/srv/_build:/srv/_build:rw' '-v' '/home/cvs/qemu/qemu:/home/cvs/qemu/qemu:ro,z' 'qemu/debian-armhf-cross' 'arm-linux-gnueabihf-gcc' '-o' 'linux-user/arm/vdso-le.so' '-nostdlib' '-shared' '-Wl,-use-blx' '-Wl,-h,linux-vdso.so.1' '-Wl,--build-id=sha1' '-Wl,--hash-style=both' '-Wl,-T,../../home/cvs/qemu/qemu/linux-user/arm/vdso.ld' '../../home/cvs/qemu/qemu/linux-user/arm/vdso.S' '-mlittle-endian'

I get this interactive(!!!) output where I can use the cursor keys to swith up/down:

? Please select an image:
▸ registry.fedoraproject.org/qemu/debian-armhf-cross:latest
registry.access.redhat.com/qemu/debian-armhf-cross:latest docker.io/qemu/debian-armhf-cross:latest quay.io/qemu/debian-armhf-cross:latest

I assume the problem is, that we don't want interactive input at this stage?
Probably this is why I get the error message: "Error: short-name resolution enforced but cannot prompt without a TTY" ?

Helge

#42 lore raw
Quoted 22 lines · Helge Deller
Quoted 21 lines · Alex Bennée
Quoted 18 lines · Richard Henderson
Quoted 7 lines · Helge Deller
Quoted 6 lines · Richard Henderson

Changes for v5:
   * Integrated cross-compile, via new build-vdso.sh and meson rules. However, keep the binaries in the tree for hosts which do not have all of the cross-compile machinery.
   * Update our loongarch64 docker image to avoid a binutils bug.

Quoted 5 lines
Quoted 2 lines

Just in case the list eats a binary:
   https://gitlab.com/rth7680/qemu/-/tree/lu-vdso

I pulled that on top of git head, and ran into the build problem below.
Do I miss something?

No idea, since it worked for me. Looks like some sort of docker.py problem. Alex?

In the short term, use --disable-containers so that you only use the cross-compilers that you have locally installed.

<snip>

Quoted 16 lines
Quoted 3 lines

It looks like it detected podman on this setup. Can you invoke the container from the command line?

Yes, if I run it on the command line:

[deller@p100 _build]$ 'podman' 'run' '--rm' '--label' 'com.qemu.instance.uuid=21e1c0332a2c44b6ae94a71392c57ccf' '--userns=keep-id' '-u' '1000' '-w' '/srv/_build' '-v' '/srv/_build:/srv/_build:rw' '-v' '/home/cvs/qemu/qemu:/home/cvs/qemu/qemu:ro,z' 'qemu/debian-armhf-cross' 'arm-linux-gnueabihf-gcc' '-o' 'linux-user/arm/vdso-le.so' '-nostdlib' '-shared' '-Wl,-use-blx' '-Wl,-h,linux-vdso.so.1' '-Wl,--build-id=sha1' '-Wl,--hash-style=both' '-Wl,-T,../../home/cvs/qemu/qemu/linux-user/arm/vdso.ld' '../../home/cvs/qemu/qemu/linux-user/arm/vdso.S' '-mlittle-endian'

I get this interactive(!!!) output where I can use the cursor keys to swith up/down:

? Please select an image:
▸ registry.fedoraproject.org/qemu/debian-armhf-cross:latest
registry.access.redhat.com/qemu/debian-armhf-cross:latest docker.io/qemu/debian-armhf-cross:latest quay.io/qemu/debian-armhf-cross:latest

Quoted 3 lines

I assume the problem is, that we don't want interactive input at this stage? Probably this is why I get the error message: "Error: short-name resolution enforced but cannot prompt without a TTY" ?

No I think the problem is we need to add dependencies to the target to ensure the containers are built and available (if they are needed). It looks like because qemu/debian-armhf-cross isn't available on your local setup it fails and offers some guesses.

If you run:

make docker-image-debian-armhf-cross

does the target work afterwards?

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro