aboutsummaryrefslogtreecommitdiffstats
path: root/linux-user/elfload.c
AgeCommit message (Collapse)AuthorFilesLines
2012-02-02linux-user: save auxv lengthAlexander Graf1-11/+4
We create our own AUXV segment on stack and save a pointer to it. However we don't save the length of it, so any code that wants to do anything useful with it later on has to walk it again. Instead, let's remember the length of our AUXV segment. This simplifies later uses by a lot. (edited by Riku to apply to qemu HEAD) Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
2012-01-10elf: Improve symbol lookup (optimize, fix for bsd-user)Stefan Weil1-7/+4
Coverity complained about local variable key which was only partially initiated. Only key.st_value was set. As this was also the only part of key which was used in function symfind, the code could be optimized by directly passing a pointer to orig_addr. In bsd-user/elfload.c, fix ec822001a2f26eef8701194714f6482b6d852de2 was missing. This was a simple replacement of > by >= in symfind, so I fixed it here without creating an additional patch. Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
2011-12-02fix spelling in linux-user sub directoryDong Xu Wang1-1/+1
Cc: Riku Voipio <riku.voipio@iki.fi> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-11-11linux-user/elfload.c: Don't memset(NULL..) if malloc() failedPeter Maydell1-3/+2
If a malloc() in copy_elf_strings() failed we would call memset() before the "did malloc fail?" check. Fix this by moving to the glib alloc/free routines for this memory so we can use g_try_malloc0 rather than having a separate memset(). Spotted by Coverity (see bug 887883). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-27ppc64-linux-user: Properly interpret the entry function descriptor.Richard Henderson1-4/+4
Don't confuse the load address with the load bias. They're equal for ET_DYN objects (i.e. ld.so) but different for ET_EXEC objects (i.e. statically linked). Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2011-09-09linux-user: Implement new ARM 64 bit cmpxchg kernel helperDr. David Alan Gilbert1-2/+54
linux-user: Implement new ARM 64 bit cmpxchg kernel helper Linux 3.1 will have a new kernel-page helper for ARM implementing 64 bit cmpxchg. Implement this helper in QEMU linux-user mode: * Provide kernel helper emulation for 64bit cmpxchg * Allow guest to object to guest offset to ensure it can map a page * Populate page with kernel helper version Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Dr. David Alan Gilbert <david.gilbert@linaro.org>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-13/+13
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-14set ELF_HWCAP for SPARC and SPARC64Artyom Tarasenko1-2/+4
setting ELF_HWCAP fixes dynamic library loading for Linux/sparc64 This patch allows loading busybox from Debian 6 initrd Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-06-21linux-user: Define AT_RANDOM to support target stack protection mechanism.Laurent ALFONSI1-1/+20
The dynamic linker from the GNU C library v2.10+ uses the ELF auxiliary vector AT_RANDOM [1] as a pointer to 16 bytes with random values to initialize the stack protection mechanism. Technically the emulated GNU dynamic linker crashes due to a NULL pointer derefencement if it is built with stack protection enabled and if AT_RANDOM is not defined by the QEMU ELF loader. [1] This ELF auxiliary vector was introduced in Linux v2.6.29. This patch can be tested with the code above: #include <elf.h> /* Elf*_auxv_t, AT_RANDOM, */ #include <stdio.h> /* printf(3), */ #include <stdlib.h> /* exit(3), EXIT_*, */ #include <stdint.h> /* uint8_t, */ #include <string.h> /* memcpy(3), */ #if defined(__LP64__) || defined(__ILP64__) || defined(__LLP64__) # define Elf_auxv_t Elf64_auxv_t #else # define Elf_auxv_t Elf32_auxv_t #endif main(int argc, char* argv[], char* envp[]) { Elf_auxv_t *auxv; /* *envp = NULL marks end of envp. */ while (*envp++ != NULL); /* auxv->a_type = AT_NULL marks the end of auxv. */ for (auxv = (Elf_auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) { if (auxv->a_type == AT_RANDOM) { int i; uint8_t rand_bytes[16]; printf("AT_RANDOM is: 0x%x\n", auxv->a_un.a_val); memcpy(rand_bytes, (const uint8_t *)auxv->a_un.a_val, sizeof(rand_bytes)); printf("it points to: "); for (i = 0; i < 16; i++) { printf("0x%02x ", rand_bytes[i]); } printf("\n"); exit(EXIT_SUCCESS); } } exit(EXIT_FAILURE); } Changes introduced in v2 and v3: * Fix typos + thinko (AT_RANDOM is used for stack canary, not for ASLR) * AT_RANDOM points to 16 random bytes stored inside the user stack. * Add a small test program. Signed-off-by: Cédric VINCENT <cedric.vincent@st.com> Signed-off-by: Laurent ALFONSI <laurent.alfonsi@st.com> Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
2011-06-21linux-user: Handle images where lowest vaddr is not page alignedPeter Maydell1-57/+73
Fix a bug in the linux-user ELF loader code where it was not correctly handling images where the lowest vaddr to be loaded was not page aligned. The problem was that the code to probe for a suitable guest base address was changing the 'loaddr' variable (by rounding it to a page boundary), which meant that the load bias would then be incorrectly calculated unless loaddr happened to already be page-aligned. Binaries generated by gcc with the default linker script do start with a loadable segment at a page-aligned vaddr, so were unaffected. This bug was noticed with a binary created by the Google Go toolchain for ARM. We fix the bug by refactoring the "probe for guest base" code out into its own self-contained function. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
2011-06-21linux-user: Fix the load of ELF files that have no "useful" symbolCédric VINCENT1-15/+19
This patch fixes a "double free()" due to "realloc(syms, 0)" in the loader when the ELF file has no "useful" symbol, as with the following example (compiled with "sh4-linux-gcc -nostdlib"): .text .align 1 .global _start _start: mov #1, r3 trapa #40 // syscall(__NR_exit) nop The bug appears when the log (option "-d") is enabled. Signed-off-by: Cédric VINCENT <cedric.vincent@st.com> Signed-off-by: Yves JANIN <yves.janin@st.com> Signed-off-by: Riku Voipio <riku.voipio@iki.fi> Reviewed-by: Richard Henderson <rth@twiddle.net>
2011-05-20s390x: s390x-linux-user supportUlrich Hecht1-0/+19
This patch adds support for running s390x binaries in the linux-user emulation code. Signed-off-by: Ulrich Hecht <uli@suse.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2011-04-12unicore32: necessary modifications for other files to support unicore32Guan Xuetao1-0/+74
Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2011-02-17linux-user: correct core dump formatLaurent Vivier1-16/+18
This patch allows to really use the core dumped by qemu with guest architecture tools. - it adds a missing bswap_phdr() for the program headers of memory regions. "objdump -x" sample: BEFORE: 0x1000000 off 0x00200000 vaddr 0x00000400 paddr 0x00000000 align 2**21 filesz 0x00000000 memsz 0x00100000 flags --- 0x1000000 off 0x00200000 vaddr 0x00100400 paddr 0x00000000 align 2**21 filesz 0x00000000 memsz 0x00080000 flags --- 6000000 AFTER: LOAD off 0x00002000 vaddr 0x00040000 paddr 0x00000000 align 2**13 filesz 0x00000000 memsz 0x00001000 flags --- LOAD off 0x00002000 vaddr 0x00041000 paddr 0x00000000 align 2**13 filesz 0x00000000 memsz 0x00000800 flags rw- - it doesn't pad the note size to sizeof(int32_t). On m68k the NT_PRSTATUS note size is 154 and must not be rounded up to 156, because this value is checked by objdump and gdb. "gdb" symptoms: "warning: Couldn't find general-purpose registers in core file." "objdump -x" sample: BEFORE: Sections: Idx Name Size VMA LMA File off Algn 0 note0 000001c4 00000000 00000000 000003b4 2**0 CONTENTS, READONLY 1 .auxv 00000070 00000000 00000000 00000508 2**2 CONTENTS 2 proc1 00100000 00000400 00000000 00200000 2**10 READONLY AFTER: Sections: Idx Name Size VMA LMA File off Algn 0 note0 000001c4 00000000 00000000 000003b4 2**0 CONTENTS, READONLY 1 .reg/19022 00000050 00000000 00000000 0000040e 2**2 CONTENTS 2 .reg 00000050 00000000 00000000 0000040e 2**2 CONTENTS 3 .auxv 00000070 00000000 00000000 00000508 2**2 CONTENTS 4 load1 00000000 00040000 00000000 00002000 2**13 ALLOC, READONLY Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
2011-02-09linux-user/elfload: add FDPIC supportMike Frysinger1-0/+71
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
2011-02-09linux-user: Fix possible realloc memory leakStefan Weil1-3/+5
Extract from "man realloc": "If realloc() fails the original block is left untouched; it is not freed or moved." Fix a possible memory leak (reported by cppcheck). Cc: Riku Voipio <riku.voipio@iki.fi> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Riku Voipio <riku.voipio@nokia.com>
2010-07-29linux-user: Protect against allocation failure in load_symbols.Richard Henderson1-0/+10
Cc: malc <av1474@comtv.ru> Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: malc <av1474@comtv.ru>
2010-07-29linux-user: Re-use load_elf_image for the main binary.Richard Henderson1-277/+103
This requires moving the PT_INTERP extraction and GUEST_BASE handling into load_elf_image. Key this off a non-null pointer argument to receive the interpreter name. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Extract load_elf_image from load_elf_interp.Richard Henderson1-174/+167
Moving toward a single copy of the elf binary loading code. Fill in the details of the loaded image into a struct image_info. Adjust create_elf_tables to read from such structures instead of from a collection of passed arguments. Don't return error values from load_elf_interp; always exit(-1) with a message to stderr. Collect elf_interpreter handling in load_elf_binary to a common spot. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Remove partial support for a.out interpreters.Richard Henderson1-70/+9
At the bottom of the a.out support was the unimplemented load_aout_interp function. There were other portions of the support that didn't look right; when I went to look in the Linux kernel for clarification, I found that the support for such interpreters has been removed from binfmt_elf. There doesn't seem to be any reason to keep this broken support in qemu. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Put the stack guard page at the top.Richard Henderson1-14/+17
There are no supported stack-grows-up targets. We were putting the guard page at the highest address, i.e. the bottom of the stack. Use the maximum of host and guest page size for the guard size. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Improve consistency checking in elf headers.Richard Henderson1-24/+33
Validate more fields of the elf header. Extract those checks into two common functions to be used in both load_elf_interp and load_elf_binary. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Load symbols from the interpreter.Richard Henderson1-88/+101
First, adjust load_symbols to accept a load_bias parameter. At the same time, read the entire section header table in one go, use pread instead f lseek+read for the symbol and string tables, and properly free allocated structures on error exit paths. Second, adjust load_elf_interp to compute load_bias. This requires finding out the built-in load addresses. Which allows us to honor a pre-linked interpreter image when possible, and eliminate the hard-coded INTERP_MAP_SIZE value. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Clean up byte-swapping in elfload.c.Richard Henderson1-71/+48
Remove ifdefs from code by defining empty inline functions when byte swapping isn't needed. Push loops over swapping arrays of structures into the swapping functions. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Define ELF_DATA generically.Richard Henderson1-24/+6
The only consideration on this value is the target endianness. The existing defines were incorrect for alpha and sh4eb. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Reduce lseek+reads while loading elf files.Richard Henderson1-60/+44
Define BPRM_BUF_SIZE to 1k and read that amount initially. If the data we want from the binary is in this buffer, use it instead of reading from the file again. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Reindent elfload.c.Richard Henderson1-510/+518
Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29Add more DT_* and AT_* constants to qemu's copy of elf.h.Richard Henderson1-9/+0
Moving some PPC AT_* constants from elfload.c at the same time. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-07-29linux-user: Handle filesz < memsz for any PT_LOAD segment.Richard Henderson1-97/+55
I caught padzero not properly initializing the .bss segment on a statically linked Alpha program. Rather than a minimal patch, replace the gross code with a single mmap+memset. Share more code between load_elf_interp and load_elf_binary. Legally, an ELF program need not have just a single .bss; and PT_LOAD segment can have memsz > filesz. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-06-16Usermode exec-stack fixPaul Brook1-0/+1
When loading a shared library that requires an executable stack, glibc uses the mprotext PROT_GROWSDOWN flag to achieve this. We don't support PROT_GROWSDOWN. Add a special case to handle changing the stack permissions in this way. Signed-off-by: Paul Brook <paul@codesourcery.com>
2010-05-29Pre-allocate guest address spacePaul Brook1-1/+1
Allow pre-allocation of the guest virtual address space in usermode emulation. Signed-off-by: Paul Brook <paul@codesourcery.com>
2010-05-19microblaze: Update elf machine nums.Edgar E. Iglesias1-2/+2
189 was allocated in upstream binutils. 0xbaab was the old temporary value. Still used by some tools and the linux kernel. I've seen 115 in older gdb versions, but lets ignore that one. Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-05-19microblaze: Add linux-user core dumping support.Edgar E. Iglesias1-0/+18
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2010-05-05Better default guest_basePaul Brook1-6/+67
Avoid loading linux-user applications in address space already used/reserved by the host. Signed-off-by: Paul Brook <paul@codesourcery.com>
2010-05-05Remove PAGE_RESERVEDPaul Brook1-6/+0
The usermode PAGE_RESERVED code is not required by the current mmap implementation, and is already broken when guest_base != 0. Unfortunately the bsd emulation still uses the old mmap implementation, so we can't rip it out altogether. Signed-off-by: Paul Brook <paul@codesourcery.com>
2010-03-28linux-user/ppc: use the Linux register layoutRob Landley1-21/+2
The dynamic linker converts the Linux layout to the AIX layout and is reentrant so it won't do it a second time if it's already been converted. In short it work just fine with either register layout. OTOH, statically linked binaries expect a Linux layout. Remove code converting the Linux layout to AIX layout so that all binaries are presented the Linux Layout. Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-03-27linux-user: Use RLIMIT_STACK for default stack size.Richard Henderson1-1/+1
The current default stack limit of 512kB is far too small; a fair number of gcc testsuite failures (for all guests) are directly attributable to this. Using the -s option in every invocation of the emulator is annoying to say the least. A reasonable compromise seems to be to honor the system rlimit. At least on two Linux distributions, this is set to 8MB and 10MB respectively. If the system does not limit the stack, then we're no worse off than before. At the same time, rename the variable from x86_stack_size and change the ultimate fallback size from 512kB to 8MB. Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2010-03-12Fix usermode virtual address typePaul Brook1-2/+2
Usermode virtual addresses are abi_ulong, not target_ulong. Signed-off-by: Paul Brook <paul@codesourcery.com>
2010-03-01Disassembler symbol lookup fixPaul Brook1-2/+2
Fix function signature for userspace disassembler symbol lookup. Signed-off-by: Paul Brook <paul@codesourcery.com>
2010-01-17fix linux-user microblaze ELF_ARCH definitionMike Frysinger1-1/+1
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
2009-12-19linux-user: add core dump support for SHNathan Froyd1-0/+33
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: add core dump support for M68KNathan Froyd1-0/+29
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: add core dump support for MIPSNathan Froyd1-0/+46
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: add core dump support for PPCNathan Froyd1-0/+26
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: fix ARM core dumps on opposite-endian hostsNathan Froyd1-19/+19
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: commonify definitions of target typedefsNathan Froyd1-22/+10
There's no sense in separately declaring target_{elf_greg,uid,gid,pid}_t for every architecture. Just declare them once with appropriate USE_UID16 handling. Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: fix ELF_USE_CORE_DUMP/USE_ELF_CORE_DUMP confusionNathan Froyd1-1/+1
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-19linux-user: use TARGET_ABI_FMT_lx to print abi_ulong typesAurelien Jarno1-1/+1
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-12-13target-alpha: Drop bogus UNIQ initial value on Linux.Richard Henderson1-3/+0
Signed-off-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2009-10-16linux-user: Update ARM hwcapsRiku Voipio1-1/+8
Update ARM hwcaps to match Linux kernel 2.6.31 state Signed-off-by: Riku Voipio <riku.voipio@iki.fi>