Bug 236880 - dlopen() of .so with tls fails on (32-bit) arm
Summary: dlopen() of .so with tls fails on (32-bit) arm
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-29 14:00 UTC by Ed Maste
Modified: 2019-04-12 00:32 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2019-03-29 14:00:54 UTC
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?
Comment 1 Andrew "RhodiumToad" Gierth 2019-03-29 14:20:09 UTC
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?
Comment 2 commit-hook freebsd_committer freebsd_triage 2019-03-29 14:35:53 UTC
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
Comment 3 Ed Maste freebsd_committer freebsd_triage 2019-03-29 15:04:43 UTC
Same issue exists on MIPS; all other archs test !allocate_tls_offset() for error.
Comment 4 commit-hook freebsd_committer freebsd_triage 2019-03-29 15:07:28 UTC
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
Comment 5 Ed Maste freebsd_committer freebsd_triage 2019-03-29 18:05:05 UTC
arm-specific issue fixed in commit referenced above and init-exec TLS for dlopened .so now fixed by r345703
Comment 6 commit-hook freebsd_committer freebsd_triage 2019-04-12 00:32:23 UTC
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