* [Qemu-devel] [PATCH] linux-user: fix ELF load alignment error
@ 2018-07-16 19:53 Laurent Vivier
2018-07-16 23:46 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Laurent Vivier @ 2018-07-16 19:53 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson, Riku Voipio, Alexander Graf, Laurent Vivier
When we try to use some targets on ppc64, it can happen the target
doesn't support the host page size to align ELF load sections and
fails with:
ELF load command alignment not page-aligned
Since commit a70daba3771 ("linux-user: Tell guest about big host
page sizes") the host page size is used to align ELF sections, but
this doesn't work if the alignment required by the load section is
smaller than the host one. For these cases, we continue to use the
TARGET_PAGE_SIZE instead of the host one.
I have tested this change on ppc64, and it fixes qemu linux-user for:
s390x, m68k, i386, arm, aarch64, hppa
and I have tested it doesn't break the following targets:
x86_64, mips64el, sh4
mips and mipsel abort, but I think for another reason.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/elfload.c | 10 +++++++++-
linux-user/qemu.h | 1 +
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 942a1b661f..3a42fbd89d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1875,7 +1875,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff));
NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr)));
NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
- NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE, getpagesize())));
+ if ((info->alignment & ~qemu_host_page_mask) != 0) {
+ /* Target doesn't support host page size alignment */
+ NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
+ } else {
+ NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE,
+ qemu_host_page_size)));
+ }
NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_info ? interp_info->load_addr : 0));
NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0);
NEW_AUX_ENT(AT_ENTRY, info->entry);
@@ -2202,6 +2208,7 @@ static void load_elf_image(const char *image_name, int image_fd,
/* Find the maximum size of the image and allocate an appropriate
amount of memory to handle that. */
loaddr = -1, hiaddr = 0;
+ info->alignment |= 0;
for (i = 0; i < ehdr->e_phnum; ++i) {
if (phdr[i].p_type == PT_LOAD) {
abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
@@ -2213,6 +2220,7 @@ static void load_elf_image(const char *image_name, int image_fd,
hiaddr = a;
}
++info->nsegs;
+ info->alignment |= phdr[i].p_align;
}
}
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index bb85c81aa4..7b16a1cdea 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -51,6 +51,7 @@ struct image_info {
abi_ulong file_string;
uint32_t elf_flags;
int personality;
+ abi_ulong alignment;
/* The fields below are used in FDPIC mode. */
abi_ulong loadmap_addr;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] linux-user: fix ELF load alignment error
2018-07-16 19:53 [Qemu-devel] [PATCH] linux-user: fix ELF load alignment error Laurent Vivier
@ 2018-07-16 23:46 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2018-07-16 23:46 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel; +Cc: Riku Voipio, Alexander Graf
On 07/16/2018 12:53 PM, Laurent Vivier wrote:
> When we try to use some targets on ppc64, it can happen the target
> doesn't support the host page size to align ELF load sections and
> fails with:
>
> ELF load command alignment not page-aligned
>
> Since commit a70daba3771 ("linux-user: Tell guest about big host
> page sizes") the host page size is used to align ELF sections, but
> this doesn't work if the alignment required by the load section is
> smaller than the host one. For these cases, we continue to use the
> TARGET_PAGE_SIZE instead of the host one.
>
> I have tested this change on ppc64, and it fixes qemu linux-user for:
> s390x, m68k, i386, arm, aarch64, hppa
> and I have tested it doesn't break the following targets:
> x86_64, mips64el, sh4
> mips and mipsel abort, but I think for another reason.
...
> loaddr = -1, hiaddr = 0;
> + info->alignment |= 0;
Plain assignment for initialization.
Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-16 23:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-16 19:53 [Qemu-devel] [PATCH] linux-user: fix ELF load alignment error Laurent Vivier
2018-07-16 23:46 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).