Commit graph

79 commits

Author SHA1 Message Date
Jinoh Kang
966233aee6 loader: Set the visibility of symbols in preloader to "hidden".
Today, the preloader is linked with -fPIE in spite of the fact that the
preloader is a non-PIE statically linked binary.  This is due to a
limitation in tools/makedep that makes it difficult to specify CFLAGS
for each individual object file's recipe.

This can seemingly cause problems with some GOTPCREL(X) relocations
inside the preloader. Since preloader does not link to the system
library directly, there is no need for a Global Offset Table (GOT).
However, a few extern (non-static) function symbols are declared, the
use of which makes GCC emit instructions that references those symbols
by indirection through GOT.  The linker then tries to optimize such
instructions to eliminate GOT references, which can fail due to various
reasons.

This stands in contradiction with Jinoh Kang's suggestion (in bug 55050)
that "-fPIE is harmless even when applied to an object linked into
non-PIE executables." The claim is theoretically true since
position-independent code can in principle be relocated to any address
(fixed or dynamic); however, it fails due to some peculiar practical
issues, which is arguably a limitation in the linker's implementation
(since it can be worked around with -Wl,--no-relax without issues).

Fix this by eliminating GOT usage by setting the default visibility of
non-static declarations to "hidden". Assuming GCC's medium code model
(-mcmodel=medium; default code model for x86_64), this suppresses any
unnecessary PLT or GOT relocations for defined symbols, and provides
opportunity for GCC to optimize the code better.

Fixes: 78ed343842
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55091
2023-06-20 20:27:45 +02:00
Alexandre Julliard
ac1761d1da loader: Build the preloader as PIE on 64-bit. 2023-06-19 17:32:24 +02:00
Tim Clem
6b0836e3f1 loader: Reserve some space for 32-bit top-down allocations on 64-bit. 2023-05-31 22:50:10 +02:00
Martin Storsjö
f760976803 ntdll: Add ARM EHABI unwind instructions in assembly functions.
On most ELF platforms on ARM, ARM EHABI is the unwind info
format normally used, instead of DWARF like on most other platforms.

Currently, when unwinding through ELF objects with libunwind, the
libraries don't have any .eh_frame section mapped at runtime (since
DWARF isn't used for unwinding). Instead, what happens is that
libunwind ends up loading .debug_frame from the libraries on disk
instead.

Therefore, currently, ELF unwinding relies on the .so files not being
stripped.

This patch adds the necessary EHABI unwinding instructions in the
assembly functions that currently have DWARF CFI instructions.

EHABI isn't signaled via any specific preprocessor macro, but
is signaled by the absence of other unwind mechanisms (such
as __ARM_DWARF_EH__ and __SEH__, or maybe SjLj).

Mark the asm functions in the preloaders as .cantunwind, to avoid
undefined references to __aeabi_unwind_cpp_pr* functions.

Also mark other assembly functions as .cantunwind; for
signal_exit_thread this is essential if the function is marked
with .fnstart/.fnend - otherwise exiting threads does hang.
(pthread_exit internally calls _Unwind_ForcedUnwind, which would
hang if signal_exit_thread had .fnstart without any matching unwind
info).

This would, in principle, allow unwinding through these functions with
libunwind, for versions of libunwind that can parse the EHABI unwind
info - see e.g.
4d779f55c0.
(This commit isn't yet in any current release AFAIK). Unwinding with
EHABI via libunwind would require a few tweaks to the libunwind interface
usage in unix/signal_arm.c though, since e.g. the unw_get_proc_info call
fails if there's no .eh_frame or .debug_frame available.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-11-07 10:28:18 +01:00
Jinoh Kang
38dfa2f455 loader: Fix return type of get_auxiliary().
This is required for fetching pointer-valued vectors (e.g.
AT_SYSINFO_EHDR).

Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com>
2022-07-04 20:14:02 +02:00
Alexandre Julliard
e3001b6a7c configure: Assume that sys/mman.h is available on Unix.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-12-09 18:43:51 +01:00
Alexandre Julliard
28d7d5ba93 loader: Avoid including wine/port.h.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-10-20 16:16:07 +02:00
Martin Storsjö
29922c2276 loader: Add support for ARM linux in the preloader.
Since 28fe84da45, the main exe image
must be mappable at its desired base address, which essentially
requires the preloader.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51539
Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-08-05 23:11:23 +02:00
Alexandre Julliard
d5a372abbb include: Move inline assembly definitions to a new wine/asm.h header.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2019-05-14 13:45:07 +02:00
Alexandre Julliard
df8c5a37ec loader: Duplicate some preloader code instead of trying to share it.
This mostly reverts bd2d795240.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2018-12-05 22:33:43 +01:00
Sebastian Lackner
a0ab2a7b0c loader: Implement preloader for macOS.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2018-12-04 11:10:09 +01:00
Ken Thomases
bd2d795240 loader: Move some code in preparation for adding the Mac preloader.
Signed-off-by: Ken Thomases <ken@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2018-12-04 11:03:46 +01:00
Alexandre Julliard
a2d76cb43f loader: Don't add the AT_UID entries if they don't already exist.
geteuid() etc. are broken on Android.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2018-10-30 18:04:48 +01:00
André Hentschel
c08e5560c4 loader: Setup the TLS register on ARM64.
Signed-off-by: André Hentschel <nerv@dawncrow.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-11-16 14:04:10 +01:00
André Hentschel
ebcac6d8f1 loader: Remove dead code.
Signed-off-by: André Hentschel <nerv@dawncrow.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-11-16 14:03:48 +01:00
Austin English
039d267b09 preloader: Fix a typo in error message.
Signed-off-by: Austin English <austinenglish@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-11-01 23:16:08 +01:00
André Hentschel
0ad8bb4ecf loader: Don't warn for limited user address space on ARM64.
Signed-off-by: André Hentschel <nerv@dawncrow.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-10-25 10:26:48 +02:00
André Hentschel
27e92e550c loader: Build the preloader for ARM64.
Signed-off-by: André Hentschel <nerv@dawncrow.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-10-25 10:26:18 +02:00
Alexandre Julliard
9f06a197c8 preloader: Add a fallback to the old mmap syscall just in case.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-05-02 20:06:25 +02:00
Alexandre Julliard
60fb3d4b64 preloader: Fix symbol lookup for dynamic libraries.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-04-27 15:04:51 +02:00
Alexandre Julliard
45a632ee81 preloader: Use the SYS_mmap2 system call instead of the old SYS_mmap one.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-04-27 15:04:03 +02:00
Alexandre Julliard
1172754fcb preloader: Add a debug option to dump memory maps.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-04-27 15:03:46 +02:00
Keno Fischer
5f38bfed7c preloader: Add proper CFI instructions to _start functions.
Signed-off-by: Keno Fischer <keno@juliacomputing.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-16 23:26:11 +09:00
Qian Hong
33765285c5 loader: Fix wld_prctl prototype.
Spotted by Robert O'Callahan.

Signed-off-by: Qian Hong <qhong@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-04-04 13:13:31 +09:00
Alexandre Julliard
8b4ed00b59 loader: Avoid ELF32_ST_INFO macro that is missing on Android. 2014-07-24 20:34:39 +02:00
Alexandre Julliard
1ecfff38bd loader: ELF hash table entries are always 32-bit on Linux. 2013-07-30 14:43:33 +02:00
Alexandre Julliard
097867debd loader: Rename the elf_hash function to avoid conflicts. 2013-02-13 17:19:43 +01:00
Alexandre Julliard
3b8ab28c40 loader: Define our own auxv structure. 2013-02-13 17:19:42 +01:00
Alexandre Julliard
6f1932dbca loader: Hardcode Linux syscall numbers. 2013-01-21 16:00:07 +01:00
Eric Pouech
7b544af170 loader: Protect preloader against ELF file without loadable segments (clang). 2011-03-28 17:24:53 +02:00
Alexandre Julliard
7e112c2917 loader: Setup the TLS register on x86-64 for stack protector checks. 2010-12-21 19:38:27 +01:00
Alexandre Julliard
61d2d80795 loader: Define asm functions instead of inlines for x86-64 syscalls to avoid trouble with register constraints. 2010-12-18 12:33:29 +01:00
Alexandre Julliard
0a0862001b loader: Build the preloader for x86-64. 2010-12-16 17:59:24 +01:00
Alexandre Julliard
fe031c937d loader: Use long instead of int in the preloader for anything that can store a pointer. 2010-12-16 16:53:24 +01:00
Alexandre Julliard
144cb78dba loader: Make sure the new stack is 16-byte aligned in the preloader. 2010-12-16 16:52:02 +01:00
Harald Hoyer
2bea45dd0a preloader: Fix moving of auxiliary values. 2010-07-29 17:33:35 +02:00
Austin English
df9fda760e loader: Remove mapat from map_so_lib, where it is unused. 2010-05-28 12:31:12 +02:00
Alexandre Julliard
fa6ffb4d5d Fix empty function prototypes. 2009-10-07 12:24:53 +02:00
Alexandre Julliard
4d35f3f270 preloader: Reserve addresses only up to 0x68000000, that should be enough for ole32. 2009-07-01 16:03:56 +02:00
Alexandre Julliard
8d833ee2e7 loader: Reserve some more memory to cover the native ole32 addresses. 2009-06-25 14:34:11 +02:00
Stefan Reimer
3dcd1285f1 loader: Fix build with gcc-4.3 and ssp. 2009-01-04 13:33:01 +01:00
Alexandre Julliard
912e4d4def loader: Reserve some space for the virtual heap too. 2008-11-07 11:05:38 +01:00
Alexandre Julliard
7a4d575029 preloader: Silence the warning for the low 64k. 2008-05-05 19:46:15 +02:00
Alexandre Julliard
195ca1e85f preloader: Reserve low memory areas in separate chunks. 2008-04-14 20:38:17 +02:00
Francois Gouget
d8c41a25da Spelling fix in the ldt bitfields. 2008-04-14 12:40:22 +02:00
Joris Huizer
e1e54d1ee7 preloader: sign-compare fix. 2007-03-05 15:31:56 +01:00
Alexandre Julliard
092ac1fbf5 preloader: Added printf format checking and fix some formats. 2007-01-11 12:46:06 +01:00
Alexandre Julliard
13029a2536 preloader: Remove reserved ranges that we failed to allocate. 2007-01-11 12:35:42 +01:00
Alexandre Julliard
4d9f3dfae1 preloader: Reset both AT_SYSINFO and AT_SYSINFO_EHDR when one of them conflicts. 2007-01-02 12:21:45 +01:00
Alexandre Julliard
4c4094e86e preloader: Clear %gs again before calling the interpreter entry point. 2006-11-04 20:25:06 +01:00