On amd64, arm64 dlopen()ing a .so with TLS vars succeeds but vars are not initialized; see kib@'s https://reviews.freebsd.org/D19072 for a patch to address that. On (32-bit) arm dlopen() of the TLS .so fails, with or without kib's patch. Test code: https://github.com/emaste/test-tls-initial-exec On amd64 or arm64 without the patch: % make test LD_LIBRARY_PATH. ./app-link foo: 2016 ./app-dlopen *** Signal 11 Stop. On amd64 or arm64 with the patch: % make test LD_LIBRARY_PATH. ./app-link foo: 2016 ./app-dlopen foo: 2016 On armv7 with or without the patch (tested on BeagleBone Black): % make test LD_LIBRARY_PATH. ./app-link foo: 2016 ./app-dlopen dlopen: dlerror() returned NULL, huh?
So I'm looking at rtld-elf/arm/reloc.c and this bit stands out: case R_ARM_TLS_TPOFF32: def = find_symdef(symnum, obj, &defobj, flags, cache, lockstate); if (def == NULL) return -1; if (!defobj->tls_done && allocate_tls_offset(obj)) return -1; Surely allocate_tls_offset returns true on success? isn't this condition backwards?
A commit references this bug: Author: emaste Date: Fri Mar 29 14:35:23 UTC 2019 New revision: 345693 URL: https://svnweb.freebsd.org/changeset/base/345693 Log: rtld: attempt to fix reloc_nonplt_object TLS allocation allocate_tls_offset returns true on success. This still needs more testing and review, but this change is consistent with other archs. PR: 236880 Reported by: Andrew Gierth <andrew@tao11.riddles.org.uk> MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Changes: head/libexec/rtld-elf/arm/reloc.c
Same issue exists on MIPS; all other archs test !allocate_tls_offset() for error.
A commit references this bug: Author: emaste Date: Fri Mar 29 15:07:00 UTC 2019 New revision: 345694 URL: https://svnweb.freebsd.org/changeset/base/345694 Log: rtld: attempt to fix reloc_non_plt TLS allocation on MIPS allocate_tls_offset returns true on success. The same issue existed on arm and was fixed in r345693. PR: 236880 MFC after: 1 month Sponsored by: The FreeBSD Foundation Changes: head/libexec/rtld-elf/mips/reloc.c
arm-specific issue fixed in commit referenced above and init-exec TLS for dlopened .so now fixed by r345703
A commit references this bug: Author: emaste Date: Fri Apr 12 00:31:23 UTC 2019 New revision: 346142 URL: https://svnweb.freebsd.org/changeset/base/346142 Log: MFC r345693, 345694: rtld: attempt to fix reloc_nonplt_object TLS allocation on arm and mips allocate_tls_offset returns true on success. This still needs more testing and review, but this change is consistent with other archs. PR: 236880 Reported by: Andrew Gierth <andrew@tao11.riddles.org.uk> (arm) Sponsored by: The FreeBSD Foundation Changes: _U stable/12/ stable/12/libexec/rtld-elf/arm/reloc.c stable/12/libexec/rtld-elf/mips/reloc.c