diff mbox

[v6,1/3] loader: Allow ELF loader to auto-detect the ELF arch

Message ID 61ce2ea7fe4c1df986c50fe881c9635ed1ef80fa.1463077144.git.alistair.francis@xilinx.com
State New
Headers show

Commit Message

Alistair Francis May 13, 2016, 8:37 p.m. UTC
If the caller didn't specify an architecture for the ELF machine
the load_elf() function will auto detect it based on the ELF file.

Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---

 hw/core/loader.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Cleber Rosa May 24, 2016, 10:08 p.m. UTC | #1
On 05/13/2016 05:37 PM, Alistair Francis wrote:
>
> +    if (elf_machine < 1) {
> +        /* The caller didn't specify and ARCH, we can figure it out */

Spotted a comment typo: s/and/an/

> +        lseek(fd, 0x12, SEEK_SET);
> +        if (read(fd, &e_machine, sizeof(e_machine)) != sizeof(e_machine)) {
> +            goto fail;
> +        }
> +        elf_machine = e_machine;
> +    }
> +
Alistair Francis May 25, 2016, 6:22 p.m. UTC | #2
On Tue, May 24, 2016 at 3:08 PM, Cleber Rosa <crosa@redhat.com> wrote:
>
> On 05/13/2016 05:37 PM, Alistair Francis wrote:
>>
>>
>> +    if (elf_machine < 1) {
>> +        /* The caller didn't specify and ARCH, we can figure it out */
>
>
> Spotted a comment typo: s/and/an/

Thanks, sending a version 7 with it fixed.

Thanks,

Alistair

>
>
>> +        lseek(fd, 0x12, SEEK_SET);
>> +        if (read(fd, &e_machine, sizeof(e_machine)) != sizeof(e_machine))
>> {
>> +            goto fail;
>> +        }
>> +        elf_machine = e_machine;
>> +    }
>> +
>
>
> --
> Cleber Rosa
> [ Sr Software Engineer - Virtualization Team - Red Hat ]
> [ Avocado Test Framework - avocado-framework.github.io ]
>
diff mbox

Patch

diff --git a/hw/core/loader.c b/hw/core/loader.c
index c049957..6b8be6b 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -419,6 +419,7 @@  int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
 {
     int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED;
     uint8_t e_ident[EI_NIDENT];
+    uint16_t e_machine;
 
     fd = open(filename, O_RDONLY | O_BINARY);
     if (fd < 0) {
@@ -451,6 +452,15 @@  int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
         goto fail;
     }
 
+    if (elf_machine < 1) {
+        /* The caller didn't specify and ARCH, we can figure it out */
+        lseek(fd, 0x12, SEEK_SET);
+        if (read(fd, &e_machine, sizeof(e_machine)) != sizeof(e_machine)) {
+            goto fail;
+        }
+        elf_machine = e_machine;
+    }
+
     lseek(fd, 0, SEEK_SET);
     if (e_ident[EI_CLASS] == ELFCLASS64) {
         ret = load_elf64(filename, fd, translate_fn, translate_opaque, must_swab,