[Bug 221337] -fsanitize=address (asan) fails on i386

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Sun Oct 22 21:57:31 UTC 2017


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221337

Dimitry Andric <dim at FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|freebsd-bugs at FreeBSD.org    |dim at FreeBSD.org
             Status|Open                        |In Progress

--- Comment #10 from Dimitry Andric <dim at FreeBSD.org> ---
Created attachment 187379
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=187379&action=edit
Ensure alignment of jemalloc's TSD is 8 bytes on 32-bit platforms

Here is a possible way of fixing this issue: it ensures that the big tsd_t
struct in contrib/jemalloc/src/tsd.c is aligned to 8 bytes, on !LP64 platforms
(i.e. i386, but it could also apply to arm or mips, if AddressSanitizer ever
gets to work there).

Before r319971, on i386 the TLS items in libc.so.7 added up to 80 bytes of
storage (a multiple of 8 bytes), assuming __je_tsd_initialized is aligned at 4
bytes:

$ readelf -sW /usr/obj/head-r319970/usr/src/lib/libc/libc.so.7|grep -w TLS
  1139: 00000058     4 TLS     GLOBAL DEFAULT   17 _ThreadRuneLocale@@FBSD_1.3
   547: 00000054     4 TLS     LOCAL  DEFAULT   17 __thread_locale
   607: 00000000    64 TLS     LOCAL  DEFAULT   16 __je_tsd_tls
   608: 0000004c     1 TLS     LOCAL  DEFAULT   17 __je_tsd_initialized
  3088: 00000058     4 TLS     GLOBAL DEFAULT   17 _ThreadRuneLocale

With r319971, this increased quite a lot, to 2404 bytes (which is not a
multiple of 8 bytes anymore, unfortunately):

$ readelf -sW /usr/obj/head-r319971/usr/src/lib/libc/libc.so.7|grep -w TLS
  1139: 0000096c     4 TLS     GLOBAL DEFAULT   17 _ThreadRuneLocale@@FBSD_1.3
   441: 00000968     4 TLS     LOCAL  DEFAULT   17 __thread_locale
   500: 00000000  2388 TLS     LOCAL  DEFAULT   16 __je_tsd_tls
   502: 00000960     1 TLS     LOCAL  DEFAULT   17 __je_tsd_initialized
  2845: 0000096c     4 TLS     GLOBAL DEFAULT   17 _ThreadRuneLocale

All the growth is in the __je_tsd_tls struct, as you can see.  If this struct
is forced to align to 8 bytes, the total amount of TLS data also becomes
aligned to 8 bytes.

An alternative would be to unconditionally align the struct at, say, 16 bytes,
and get rid of the #ifdef.

Yet another alternative would be to place some bogus padding 4 byte entity
somewhere else in libc.so to ensure the TLS data is a multiple of 8 bytes. 
Suggestions as to where are welcome. :)

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list