Commit Graph

1069 Commits

Author SHA1 Message Date
riastradh eeb15e760e ld.elf_so: Split hash functions into a separate file.
This way we can test them in isolation.

No functional change intended.
2023-07-30 09:20:14 +00:00
riastradh b1509f1b68 ld.elf_so: Sort SRCS.
No functional change intended.
2023-07-30 09:19:19 +00:00
riastradh 26121a0094 ld.elf_so: Split SRCS onto multiple lines.
Makes updates easier.

No functional change intended.
2023-07-30 09:19:10 +00:00
joerg cc08a85a25 TLS variant I archs need to fudge the offset by the size of the TCB. 2023-06-07 13:50:04 +00:00
riastradh 1c55978778 ld.elf_so: Sprinkle more debug messages on dlopen and error.
PR pkg/57445
2023-06-04 23:42:38 +00:00
martin 35e060692e Avoid using uninitialized variable "symnum" when building with DEBUG
enabled by borrowing the rdbg_symname() macro from arch/x86_64.
2023-06-04 20:02:29 +00:00
joerg 3caa8dc735 Fix interactions of initial-exec TLS model and dlopen
(1) If an initial-exec relocation was used for a non-local symbol
(i.e. the definition of the symbol is in a different DSO), the
computation of the static TLS offset used the wrong DSO.
This would effectively mean the wrong address was computed
(PR toolchain/50277, PR pkg/57445).

Fix this by forcing the computation of the correct DSO (the one defining
the symbol).

This code uses __UNCONST to avoid the vast interface changes for this
special case.

(2) If symbols from a DSO loaded via dlopen are used with both
global-dynamic/local-dynamic and initial-exec relocations AND
a initial-exec relocation was resolved first in a thread, a split brain
situation could exist where the dynamic relocations would use one memory
block (separate allocation) and the initial-exec relocations the static
per-thread TLS space.

(3) If the initial-exec relocation in (2) is seen after any thread has
already used a GD/LD allocation, bail out. Since IE relocations are used
only in the GOT, this will prevent the dlopen. This is a bit more
aggressive than necessary, but a full blown reference counting doesn't
seem to be justified.
2023-06-04 01:24:56 +00:00
andvar cb40c69b16 follow the steps of Andrew Doran (ad) commit and fix more s/loose/lose/ typos.
also s/beyound/beyond/ and few others along the way, mainly in comments.
2023-06-02 08:51:46 +00:00
riastradh 78e97c0a70 ld.elf_so: Make tls alloc debug messages more detailed and greppable.
XXX pullup-10
2023-06-01 08:20:10 +00:00
riastradh 3e105dc2be ld.elf_so: Sprinkle tls debug messages.
XXX pullup-10
2023-05-31 18:44:39 +00:00
skrll 75b842b847 RISC-V support that works on QEMU with a single hart.
Thanks for Simon Burge for plic(4).
2023-05-07 12:41:45 +00:00
riastradh b8bbdc68a0 dlopen(3): Read _rtld_objtail under the lock.
XXX pullup-8
XXX pullup-9
XXX pullup-10
2023-04-23 11:53:00 +00:00
christos 6d8ba4b8b8 Oops wrong mask. 2023-04-18 22:42:52 +00:00
christos 5eb593004f The SysV ABI specifies that the symbol hash function should return only 32
bits of hash. Unfortunately due to an implementation bu and the fact that
the return type is unsigned long which is 64 bits in LP64, this can fail
in some cases: "\xff\x0f\x0f\x0f\x0f\x0f\x12". See:
    https://maskray.me/blog/2023-04-12-elf-hash-function
From Ed Maste @ FreeBSD:
    https://cgit.freebsd.org/src/commit/\
	?id=29e3a06510823edbb91667d21f530d3ec778116d
Need to write Unit Tests for this.
2023-04-18 16:48:45 +00:00
chs 916c1920bc ld.elf_so powerpc: remove bogus ldscript
This ldscript is not needed and actually makes things worse by putting
everything in one LOAD section, which then needs to have rwx permission.
Remove it so that we get two LOAD sections with better permissions.
Fixes PR 57323.
2023-04-09 17:24:48 +00:00
skrll 1fe403d437 Alignment. NFCI. 2023-02-10 08:12:48 +00:00
christos 2f8ed368a1 fix the ldd build 2023-01-12 19:17:11 +00:00
christos 5550906484 Handle program headers properly; fixes c++ exceptions on arm32. 2023-01-12 18:52:47 +00:00
christos acf7fb3abf Remove the limitation of only being able to load binaries with 2 PT_LOAD
sections, like the kernel can. From FreeBSD.
2023-01-06 15:33:47 +00:00
christos 7d5e3ea3ec comment out a function that is only used in rtld 2023-01-04 01:37:24 +00:00
christos 6f661f3b8e make the what argument size_t since we are passing in size_t 2023-01-04 01:37:00 +00:00
skrll 40505c9552 Use the SZREG symbol instead of __SIZEOF_POINTER__ as its shorter. Assert
that they're the same just in case.

Sprinkle some KNF whitespace while I'm here.
2022-12-05 07:33:43 +00:00
skrll d9992aa755 RISC-V is RELA 2022-12-05 07:26:25 +00:00
skrll 1beb9ce90d Consistently use the 'mv' instrucation (which is itself an alias) instead
of the (old) alternative alias 'move'.
2022-12-04 17:04:06 +00:00
skrll 7893424154 Trailing whitespace 2022-12-03 09:38:53 +00:00
skrll b9abccc917 Whitespace. NFC. 2022-12-03 09:10:40 +00:00
riastradh 65715c6162 ld.elf_so(8): Make fork take a shared, not exclusive, lock.
We only need to ensure that there are no concurrent modifications to
the rtld data structures in flight, since the threads that began
those modifications will not exist in the child and will therefore be
unable to complete them in the child.

A shared lock suffices to ensure there are no such concurrent
modifications in flight; an exclusive lock is not necessary, and can
cause deadlock if fork is executed from a signal handler, which is
explicitly allowed by POSIX (and our own sigaction(2) man page) which
marks fork as async-signal-safe.

PR lib/56979
2022-09-13 10:18:58 +00:00
martin 75fe422388 Fix copy & pasto: DTPREL relocations do not need to allocate a static
TLS index. Patch from joerg@
2022-07-06 17:35:20 +00:00
skrll f927c76aaf Support ifunc on aarch64. The tests pass at least. 2022-06-21 06:52:17 +00:00
skrll 810da4c4dd Wrap long #if defined(...) || ... and sort. NFCI. 2022-06-21 06:47:37 +00:00
andvar ff23aff6ad fix various typos in comments, documentation and messages. 2022-05-31 08:43:13 +00:00
skrll f28ba59fd0 Set DP early so that any binary functions that override others get the
right value if they're called before _start.  This is true of bash where
it provides its own getenv.

Part of port-hppa/56118: sporadic app crashes in HPPA -current
2022-05-30 17:06:34 +00:00
riastradh 207d886754 rtld: Convert membar_exit/enter to membar_release/acquire.
These are basic CAS-based locking primitives needing release and
acquire semantics, nothing fancy here -- except the membar_sync parts
which are questionable but not relevant to the present audit.
2022-04-09 23:39:07 +00:00
hannken 8324126929 _rtld_map_object(): no need to mmap an empty bss segment. 2022-03-30 08:26:45 +00:00
andvar e394a08199 s/interger/integer/ and s/Compensatin/Compensation/ in comments. 2022-03-24 12:12:00 +00:00
skrll 45f12ca261 Restore the fptr_t type of {init,fini}{,_array} that was removed when initial
support for indirect functions was added.  This fixes {init,fini}_array support
on hppa where each member of the array is (already) a plabel.

Discussed with joerg.

 4 files changed, 29 insertions(+), 39 deletions(-)
: ----------------------------------------------------------------------
2021-12-04 14:39:08 +00:00
skrll dab59e4bc1 Provide a stub _rtld_call_ifunc when a platform doesn't use one of the
common ones or doesn't provide its own.
2021-12-04 08:53:34 +00:00
skrll 741d1b8708 Add a newline 2021-12-04 08:50:41 +00:00
skrll 95123c27a8 Error if there are undefined symbols, e.g. _rtld_call_ifunc 2021-12-04 08:45:56 +00:00
riastradh 07fb20a384 ld.elf_so(1): Omit needless membar_enter.
The use of membar_enter is to separate atomic r/m/w on a lock from
the body of the critical section so two different critical sections
happen in order:

		body of previous critical section;

	exit critical section:
		membar_exit();
		atomic_r/m/w(lock stuff);

	enter critical section:
		atomic_r/m/w(lock stuff);
		membar_enter();

		body of next critical section;

_rtld_shared_enter does this, but it _also_ issued an extraneous
membar_enter before the atomic_r/m/w part, which doesn't impose any
semantically important order but may cost some performance.
2021-06-16 21:53:51 +00:00
joerg 130482d98d Don't use the return address hack with clang. 2021-05-30 02:26:08 +00:00
christos 0f1e1628dd Don't or the got object in, just assign it. Fixes cc -mabi=64 hello.c -lcrypto
Now all 64 bit binaries work, and I tested that we did not break the 32 bit
ones
XXX: That 0x80000000 seems wrong for 64 bit stuff.
2021-03-06 20:11:08 +00:00
christos d42a77727b pretend we know about %# and %j... 2021-03-06 20:09:39 +00:00
kamil f420d54c39 Correct r_ldbase valuse
It shall be the relocbase value, not linkmap.
2020-09-22 00:41:27 +00:00
kamil f3656ffa1a Upgrade the SVR4 RTLD r_debug protocol to version 1
Changes:
 - Add a new field r_ldbase in the r_debug struct.
 - Set r_version to 1.

This harmonizes the support with OpenBSD and Linux.
FreeBSD uses version 0 (or no version).
Solaris uses version 2 that is not implemented elsewhere and relies on
SVR4 specific design and interfaces.

Update the code comments as r_debug and link_map is used by other software
than GDB, namely: sanitizers, rump, LLDB.
2020-09-21 16:08:57 +00:00
joerg 5df17207d3 R_ARM_TLS_TPOFF32 needs to adjust the existing value, not blindly
overwrite it.
2020-06-16 21:02:20 +00:00
joerg 41844ca786 Honor addend for R_AARCH64_TLS_TPREL relocation. 2020-06-16 21:01:30 +00:00
macallan d4e6a9fda0 new binutils/gcc started emitting R_PPC_UADDR32 reloc entries, so for now
treat them like R_PPC_ADDR32
XXX
these relocs have been observed in the xf86-video-radeon driver, but only in
the AtomBios support code, which is unused on PowerPC. This allows the driver
to load but it's not clear if the affected parts would actually function.
2020-05-24 02:33:11 +00:00
skrll d736ede907 Fix debug build 2020-05-16 16:43:15 +00:00
skrll eeabd67ad2 Avoid compiler warnings about uninitialised symnum 2020-05-16 16:43:00 +00:00