[v2,1/2] linux-user: Add ELF_PLATFORM for arm

Message ID 20190212074840.13542-2-richard.henderson@linaro.org
State New
Headers show
Series
  • linux-user: Fix AT_PLATFORM for arm
Related show

Commit Message

Richard Henderson Feb. 12, 2019, 7:48 a.m.
The 32-bit kernel has strings for v4, v5, v6, v7, v7m.
The 64-bit kernel, in compat mode, has strings for v8.

Fixes: https://bugs.launchpad.net/bugs/1813034
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v2: Include v8.
---
 linux-user/elfload.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Laurent Vivier Feb. 12, 2019, 8:31 a.m. | #1
On 12/02/2019 08:48, Richard Henderson wrote:
> The 32-bit kernel has strings for v4, v5, v6, v7, v7m.
> The 64-bit kernel, in compat mode, has strings for v8.
> 
> Fixes: https://bugs.launchpad.net/bugs/1813034
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> v2: Include v8.
> ---
>  linux-user/elfload.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 775a36ccdd..d796d51ec6 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -500,6 +500,37 @@ static uint32_t get_elf_hwcap2(void)
>  #undef GET_FEATURE
>  #undef GET_FEATURE_ID
>  
> +#define ELF_PLATFORM get_elf_platform()
> +
> +static const char *get_elf_platform(void)
> +{
> +    CPUARMState *env = thread_cpu->env_ptr;
> +
> +#ifdef TARGET_WORDS_BIGENDIAN
> +# define END  "b"
> +#else
> +# define END  "l"
> +#endif
> +
> +    if (arm_feature(env, ARM_FEATURE_V8)) {
> +        return "v8" END;
> +    } else if (arm_feature(env, ARM_FEATURE_V7)) {
> +        if (arm_feature(env, ARM_FEATURE_M)) {
> +            return "v7m" END;
> +        } else {
> +            return "v7" END;
> +        }
> +    } else if (arm_feature(env, ARM_FEATURE_V6)) {
> +        return "v6" END;
> +    } else if (arm_feature(env, ARM_FEATURE_V5)) {
> +        return "v5" END;
> +    } else {
> +        return "v4" END;
> +    }

I know nothing about ARM, but in kernel we have also a "v5t"
(cpu_elf_name) and in QEMU we have a ARM_FEATURE_V4T which is set with
ARM_FEATURE_V5. Is it related?

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

Thanks,
Laurent
Richard Henderson Feb. 12, 2019, 9:44 p.m. | #2
On 2/12/19 12:31 AM, Laurent Vivier wrote:
> I know nothing about ARM, but in kernel we have also a "v5t"
> (cpu_elf_name) and in QEMU we have a ARM_FEATURE_V4T which is set with
> ARM_FEATURE_V5. Is it related?

>From the ARM ARM (DDI 0406C, page A1-30):

The valid variants of ARMv4, ARMv5, and ARMv6 are as follows:
ARMv4, ARMv4T, ARMv5T, ARMv5TE, ARMv5TEJ, ARMv6, ARMv6K, ARMv6T2

So all v5 are "t".  The use of "v5t" within the kernel seems to be an outlier
and perhaps a bug to be squashed:

$ grep -r cpu_elf_name . | grep v5
./mm/proc-xsc3.S:	string	cpu_elf_name, "v5"
./mm/proc-arm1020.S:	string	cpu_elf_name, "v5"
./mm/proc-arm946.S:	string	cpu_elf_name, "v5t"
./mm/proc-arm1020e.S:	string	cpu_elf_name, "v5"
./mm/proc-arm1022.S:	string	cpu_elf_name, "v5"
./mm/proc-feroceon.S:	string	cpu_elf_name, "v5"
./mm/proc-xscale.S:	string	cpu_elf_name, "v5"
./mm/proc-mohawk.S:	string	cpu_elf_name, "v5"
./mm/proc-arm926.S:	string	cpu_elf_name, "v5"
./mm/proc-arm1026.S:	string	cpu_elf_name, "v5"


r~
Laurent Vivier Feb. 14, 2019, 9:25 a.m. | #3
On 12/02/2019 08:48, Richard Henderson wrote:
> The 32-bit kernel has strings for v4, v5, v6, v7, v7m.
> The 64-bit kernel, in compat mode, has strings for v8.
> 
> Fixes: https://bugs.launchpad.net/bugs/1813034
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> v2: Include v8.
> ---
>  linux-user/elfload.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)

Applied to my linux-user branch.

Thanks,
Laurent

Patch

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 775a36ccdd..d796d51ec6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -500,6 +500,37 @@  static uint32_t get_elf_hwcap2(void)
 #undef GET_FEATURE
 #undef GET_FEATURE_ID
 
+#define ELF_PLATFORM get_elf_platform()
+
+static const char *get_elf_platform(void)
+{
+    CPUARMState *env = thread_cpu->env_ptr;
+
+#ifdef TARGET_WORDS_BIGENDIAN
+# define END  "b"
+#else
+# define END  "l"
+#endif
+
+    if (arm_feature(env, ARM_FEATURE_V8)) {
+        return "v8" END;
+    } else if (arm_feature(env, ARM_FEATURE_V7)) {
+        if (arm_feature(env, ARM_FEATURE_M)) {
+            return "v7m" END;
+        } else {
+            return "v7" END;
+        }
+    } else if (arm_feature(env, ARM_FEATURE_V6)) {
+        return "v6" END;
+    } else if (arm_feature(env, ARM_FEATURE_V5)) {
+        return "v5" END;
+    } else {
+        return "v4" END;
+    }
+
+#undef END
+}
+
 #else
 /* 64 bit ARM definitions */
 #define ELF_START_MMAP 0x80000000