freebsd-src/libexec/rtld-elf
R. Christian McDonald 98fd69f009 rtld/arm: fix initial-exec (IE) thread-local storage relocation
net/frr[89] revealed an interesting edge-case on arm when dynamically
linking a shared library that declares more than one static TLS variable
with at least one  using the "initial-exec" TLS model. In the case
of frr[89], this library was libfrr.so which essentially does the
following:

	#include <stdio.h>

	#include "lib.h"

	static __thread int *a
		__attribute__((tls_model("initial-exec")));

	void lib_test()
	{
		static __thread int b = -1;

		printf("&a = %p\n", &a);
		printf(" a = %p\n", a);

		printf("\n");

		printf("&b = %p\n", &b);
		printf(" b = %d\n", b);
	}

Allocates a file scoped `static __thread` pointer with
tls_model("initial-exec") and later a block scoped TLS int. Notice in
the above minimal reproducer, `b == -1`. The relocation process does
the wrong thing and ends up pointing both `a` and `b` at the same place
in memory.

The output of the above in the broken state is:

	&a = 0x4009c018
	 a = 0xffffffff

	&b = 0x4009c018
	 b = -1

With the patch applied, the output becomes:

	&a = 0x4009c01c
	 a = 0x0

	&b = 0x4009c018
	 b = -1

Reviewed by:	kib
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42415/
2023-11-03 22:43:40 +01:00
..
aarch64 rtld: Teach rtld about the BTI elf note 2023-10-30 17:55:44 +00:00
amd64 rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
arm rtld/arm: fix initial-exec (IE) thread-local storage relocation 2023-11-03 22:43:40 +01:00
i386 rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
powerpc rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
powerpc64 rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
riscv rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
rtld-libc ino64: Remove 'forward compat' code for this 2023-10-31 15:26:44 -06:00
tests Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
debug.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
debug.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
libmap.c Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:23 -06:00
libmap.conf Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
libmap.h Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:23 -06:00
Makefile Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
Makefile.depend Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
map_object.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld.1 rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
rtld.c rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
rtld.h rtld: introduce STATIC_TLS_EXTRA 2023-10-30 13:42:05 -04:00
rtld_lock.c Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:23 -06:00
rtld_lock.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_malloc.c Purge more stray embedded $FreeBSD$ strings 2023-09-25 07:54:56 -07:00
rtld_malloc.h rtld_malloc: add __crt_aligned_alloc_offset() 2023-08-21 17:16:42 +03:00
rtld_paths.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_printf.c Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_printf.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_tls.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
rtld_utrace.h Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
Symbol.map Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:23 -06:00
xmalloc.c rtld: switch from malloc_aligned() to __crt_aligned_alloc() 2023-08-21 17:16:42 +03:00