Skip to contentSkip to conversation

linux-user/sh4: add VDSO support for sh4 and sh4eb

PATCH In review Matt Turner 3 participants 4 messages May 23 – Jul 16 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/sh4: add VDSO support for sh4 and sh4eb

Provides replacement VDSO with sigreturn trampolines (__kernel_sigreturn, __kernel_rt_sigreturn) and syscall stubs (clock_gettime, clock_gettime64, clock_getres, gettimeofday).

Both LE and BE blobs are committed and selected at compile time via TARGET_BIG_ENDIAN. The BE variant requires an sh4eb-unknown-linux-gnu toolchain; sh4-unknown-linux-gnu does not support -mb.

CFI register numbers follow GCC's SH_DEBUGGER_REGNO:
PR=17, GBR=18, MACH=20, MACL=21, FPUL=23, FPSCR=24, FR0-15=25-40.

---
 linux-user/sh4/Makefile.vdso    |  18 ++++
 linux-user/sh4/elfload.c        |  14 ++++
 linux-user/sh4/meson.build      |  12 +++
 linux-user/sh4/target_elf.h     |   1 +
 linux-user/sh4/vdso-asmoffset.h |  45 ++++++++++
 linux-user/sh4/vdso-be.so       | Bin 0 -> 2704 bytes
 linux-user/sh4/vdso-le.so       | Bin 0 -> 2704 bytes
 linux-user/sh4/vdso.S           | 142 ++++++++++++++++++++++++++++++++
 linux-user/sh4/vdso.ld          |  67 +++++++++++++++
 9 files changed, 299 insertions(+)
 create mode 100644 linux-user/sh4/Makefile.vdso
 create mode 100644 linux-user/sh4/vdso-asmoffset.h
 create mode 100755 linux-user/sh4/vdso-be.so
 create mode 100755 linux-user/sh4/vdso-le.so
 create mode 100644 linux-user/sh4/vdso.S
 create mode 100644 linux-user/sh4/vdso.ld
linux-user/sh4/Makefile.vdso new file +18 -0
new file mode 100644
index 0000000000..272c5d262d
@@ -0,0 +1,18 @@
+include $(BUILD_DIR)/tests/tcg/sh4-linux-user/config-target.mak
+
+SUBDIR = $(SRC_PATH)/linux-user/sh4
+VPATH += $(SUBDIR)
+
+all: $(SUBDIR)/vdso-le.so $(SUBDIR)/vdso-be.so
+
+LDFLAGS = -nostdlib -shared -Wl,-h,linux-gate.so.1 \
+	  -Wl,--build-id=sha1 -Wl,--hash-style=both \
+	  -Wl,-T,$(SUBDIR)/vdso.ld
+
+$(SUBDIR)/vdso-le.so: vdso.S vdso.ld vdso-asmoffset.h
+	$(CC) -o $@ $(LDFLAGS) -ml $<
+
+CC_BE = sh4eb-unknown-linux-gnu-gcc
+
+$(SUBDIR)/vdso-be.so: vdso.S vdso.ld vdso-asmoffset.h
+	$(CC_BE) -o $@ $(LDFLAGS) $<
linux-user/sh4/elfload.c +14 -0
index ddf2aaaed7..f03ce49e7d 100644
@@ -5,6 +5,20 @@
 #include "loader.h"
 #include "target_elf.h"
 
+#if TARGET_BIG_ENDIAN
+# include "vdso-be.c.inc"
+#else
+# include "vdso-le.c.inc"
+#endif
+
+const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags G_GNUC_UNUSED)
+{
+#if TARGET_BIG_ENDIAN
+    return &vdso_be_image_info;
+#else
+    return &vdso_le_image_info;
+#endif
+}
 
 const char *get_elf_cpu_model(uint32_t eflags)
 {
linux-user/sh4/meson.build +12 -0
index 3bc3a6924a..611bce050b 100644
@@ -3,3 +3,15 @@ syscall_nr_generators += {
                    arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ],
                    output: '@BASENAME@_nr.h')
 }
+
+vdso_le_inc = gen_vdso.process('vdso-le.so',
+                               extra_args: ['-s', '__kernel_sigreturn',
+                                            '-r', '__kernel_rt_sigreturn',
+                                            '-p', 'vdso_le'])
+
+vdso_be_inc = gen_vdso.process('vdso-be.so',
+                               extra_args: ['-s', '__kernel_sigreturn',
+                                            '-r', '__kernel_rt_sigreturn',
+                                            '-p', 'vdso_be'])
+
+linux_user_ss.add(when: 'TARGET_SH4', if_true: [vdso_le_inc, vdso_be_inc])
linux-user/sh4/target_elf.h +1 -0
index d9e253d425..3fcb63d409 100644
@@ -15,6 +15,7 @@
 
 #define HAVE_ELF_HWCAP          1
 #define HAVE_ELF_CORE_DUMP      1
+#define HAVE_VDSO_IMAGE_INFO    1
 
 /*
  * See linux kernel: arch/sh/include/asm/elf.h, where
linux-user/sh4/vdso-asmoffset.h new file +45 -0

45 lines not on this page · raw message

./linux-user/sh4/vdso-be.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..4f50143f8284ab63693c1117e68f3efa886155e3
GIT binary patch
./linux-user/sh4/vdso-le.so new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..c41cb5831b9e5883a64564da8b2149a33e199f4f
GIT binary patch
linux-user/sh4/vdso.S new file +142 -0

142 lines not on this page · raw message

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

67 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw
Quoted 21 lines · Matt Turner

Provides replacement VDSO with sigreturn trampolines (__kernel_sigreturn, __kernel_rt_sigreturn) and syscall stubs (clock_gettime, clock_gettime64, clock_getres, gettimeofday).

Both LE and BE blobs are committed and selected at compile time via TARGET_BIG_ENDIAN. The BE variant requires an sh4eb-unknown-linux-gnu toolchain; sh4-unknown-linux-gnu does not support -mb.

CFI register numbers follow GCC's SH_DEBUGGER_REGNO:
PR=17, GBR=18, MACH=20, MACL=21, FPUL=23, FPSCR=24, FR0-15=25-40.

---
  linux-user/sh4/Makefile.vdso    |  18 ++++
  linux-user/sh4/elfload.c        |  14 ++++
  linux-user/sh4/meson.build      |  12 +++
  linux-user/sh4/target_elf.h     |   1 +
  linux-user/sh4/vdso-asmoffset.h |  45 ++++++++++
  linux-user/sh4/vdso-be.so       | Bin 0 -> 2704 bytes
  linux-user/sh4/vdso-le.so       | Bin 0 -> 2704 bytes
  linux-user/sh4/vdso.S           | 142 ++++++++++++++++++++++++++++++++
  linux-user/sh4/vdso.ld          |  67 +++++++++++++++
  9 files changed, 299 insertions(+)
Quoted 6 lines

create mode 100644 linux-user/sh4/Makefile.vdso create mode 100644 linux-user/sh4/vdso-asmoffset.h create mode 100755 linux-user/sh4/vdso-be.so create mode 100755 linux-user/sh4/vdso-le.so create mode 100644 linux-user/sh4/vdso.S create mode 100644 linux-user/sh4/vdso.ld

I added the missing

and added the patch to linux-user-next git tree.

Thanks!
Helge

#2 lore raw
In reply to Matt Turner
Quoted 42 lines · Matt Turner

Provides replacement VDSO with sigreturn trampolines (__kernel_sigreturn, __kernel_rt_sigreturn) and syscall stubs (clock_gettime, clock_gettime64, clock_getres, gettimeofday).

Both LE and BE blobs are committed and selected at compile time via TARGET_BIG_ENDIAN. The BE variant requires an sh4eb-unknown-linux-gnu toolchain; sh4-unknown-linux-gnu does not support -mb.

CFI register numbers follow GCC's SH_DEBUGGER_REGNO:
PR=17, GBR=18, MACH=20, MACL=21, FPUL=23, FPSCR=24, FR0-15=25-40.

---
  linux-user/sh4/Makefile.vdso    |  18 ++++
  linux-user/sh4/elfload.c        |  14 ++++
  linux-user/sh4/meson.build      |  12 +++
  linux-user/sh4/target_elf.h     |   1 +
  linux-user/sh4/vdso-asmoffset.h |  45 ++++++++++
  linux-user/sh4/vdso-be.so       | Bin 0 -> 2704 bytes
  linux-user/sh4/vdso-le.so       | Bin 0 -> 2704 bytes
  linux-user/sh4/vdso.S           | 142 ++++++++++++++++++++++++++++++++
  linux-user/sh4/vdso.ld          |  67 +++++++++++++++
  9 files changed, 299 insertions(+)

create mode 100644 linux-user/sh4/Makefile.vdso create mode 100644 linux-user/sh4/vdso-asmoffset.h create mode 100755 linux-user/sh4/vdso-be.so create mode 100755 linux-user/sh4/vdso-le.so create mode 100644 linux-user/sh4/vdso.S create mode 100644 linux-user/sh4/vdso.ld

linux-user/sh4/Makefile.vdso new file +8 -0
new file mode 100644
index 0000000000..272c5d262d
@@ -0,0 +1,18 @@
+include $(BUILD_DIR)/tests/tcg/sh4-linux-user/config-target.mak
+
+SUBDIR = $(SRC_PATH)/linux-user/sh4
+VPATH += $(SUBDIR)
+
+all: $(SUBDIR)/vdso-le.so $(SUBDIR)/vdso-be.so
+
+LDFLAGS = -nostdlib -shared -Wl,-h,linux-gate.so.1 \

linux-user/sh4/Makefile.vdso line 18

Quoted 10 lines
linux-user/sh4/Makefile.vdso new file +10 -0
+	  -Wl,--build-id=sha1 -Wl,--hash-style=both \
+	  -Wl,-T,$(SUBDIR)/vdso.ld
+
+$(SUBDIR)/vdso-le.so: vdso.S vdso.ld vdso-asmoffset.h
+	$(CC) -o $@ $(LDFLAGS) -ml $<
+
+CC_BE = sh4eb-unknown-linux-gnu-gcc
+
+$(SUBDIR)/vdso-be.so: vdso.S vdso.ld vdso-asmoffset.h
+	$(CC_BE) -o $@ $(LDFLAGS) $<

Where this sh4eb-unknown-linux-gnu-gcc comes from? For one, we don't have it in debian. Can the same be produced with

sh4-linux-gnu-gcc -Wl,-EB -Wa,--big

instead? (Or -gcc -mb, which does not work on debian currenly). I can pass this on command like as CC_BE="..".

But I know nothing about sh4, so dunno if this is the right thing to do. It builds, but I don't have any sh4eb binary to test against.

Thanks,

/mjt

#3 lore raw
Quoted 49 lines · Michael Tokarev
Quoted 47 lines · Matt Turner

Provides replacement VDSO with sigreturn trampolines (__kernel_sigreturn, __kernel_rt_sigreturn) and syscall stubs (clock_gettime, clock_gettime64, clock_getres, gettimeofday).

Both LE and BE blobs are committed and selected at compile time via TARGET_BIG_ENDIAN. The BE variant requires an sh4eb-unknown-linux-gnu toolchain; sh4-unknown-linux-gnu does not support -mb.

CFI register numbers follow GCC's SH_DEBUGGER_REGNO:
PR=17, GBR=18, MACH=20, MACL=21, FPUL=23, FPSCR=24, FR0-15=25-40.

---
  linux-user/sh4/Makefile.vdso    |  18 ++++
  linux-user/sh4/elfload.c        |  14 ++++
  linux-user/sh4/meson.build      |  12 +++
  linux-user/sh4/target_elf.h     |   1 +
  linux-user/sh4/vdso-asmoffset.h |  45 ++++++++++
  linux-user/sh4/vdso-be.so       | Bin 0 -> 2704 bytes
  linux-user/sh4/vdso-le.so       | Bin 0 -> 2704 bytes
  linux-user/sh4/vdso.S           | 142 ++++++++++++++++++++++++++++++++
  linux-user/sh4/vdso.ld          |  67 +++++++++++++++
  9 files changed, 299 insertions(+)

create mode 100644 linux-user/sh4/Makefile.vdso create mode 100644 linux-user/sh4/vdso-asmoffset.h create mode 100755 linux-user/sh4/vdso-be.so create mode 100755 linux-user/sh4/vdso-le.so create mode 100644 linux-user/sh4/vdso.S create mode 100644 linux-user/sh4/vdso.ld

linux-user/sh4/Makefile.vdso new file +13 -0
new file mode 100644
index 0000000000..272c5d262d
@@ -0,0 +1,18 @@
+include $(BUILD_DIR)/tests/tcg/sh4-linux-user/config-target.mak
+
+SUBDIR = $(SRC_PATH)/linux-user/sh4
+VPATH += $(SUBDIR)
+
+all: $(SUBDIR)/vdso-le.so $(SUBDIR)/vdso-be.so
+
+LDFLAGS = -nostdlib -shared -Wl,-h,linux-gate.so.1 \
+       -Wl,--build-id=sha1 -Wl,--hash-style=both \
+       -Wl,-T,$(SUBDIR)/vdso.ld
+
+$(SUBDIR)/vdso-le.so: vdso.S vdso.ld vdso-asmoffset.h
+     $(CC) -o $@ $(LDFLAGS) -ml $<
Quoted 8 lines

linux-user/sh4/Makefile.vdso line 18

Quoted 5 lines
linux-user/sh4/Makefile.vdso new file +5 -0
+
+CC_BE = sh4eb-unknown-linux-gnu-gcc
+
+$(SUBDIR)/vdso-be.so: vdso.S vdso.ld vdso-asmoffset.h
+     $(CC_BE) -o $@ $(LDFLAGS) $<

Where this sh4eb-unknown-linux-gnu-gcc comes from? For one, we don't have it in debian. Can the same be produced with

I built it locally with Gentoo's crossdev tool.

Quoted 3 lines

sh4-linux-gnu-gcc -Wl,-EB -Wa,--big

instead? (Or -gcc -mb, which does not work on debian currenly).

I believe I ran into this as well, which led me to build a cross toolchain myself. I didn't think to try -Wl,-EB -Wa,--big, but if that works then it could have saved me some time :)

Quoted 5 lines

I can pass this on command like as CC_BE="..".

But I know nothing about sh4, so dunno if this is the right thing to do. It builds, but I don't have any sh4eb binary to test against.

I'm not anywhere near an expert in sh4, but it seems that big-endian sh4 is super niche and uncommon. I wasn't even sure whether I should bother implementing big-endian support here.