Bug 173720 - initializeThreading() [first] causes WTFCrash due to maxSingleAllocationSize not being initialized
Summary: initializeThreading() [first] causes WTFCrash due to maxSingleAllocationSize ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-22 09:38 PDT by Vladimir Vukicevic
Modified: 2017-06-25 14:41 PDT (History)
10 users (show)

See Also:


Attachments
Patch (1.65 KB, patch)
2017-06-23 01:55 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Vukicevic 2017-06-22 09:38:52 PDT
This is probably an edge case, but -- in a JSC static build that gets linked into another DLL, and that DLL does some dumb stuff from static constructors, such as JSClassCreate, I get this crash because maxSingleAllocationSize is still 0 (it's set by Options::initialize() which hasn't been called yet by initializeThreading()) -- lambdas and other junk omitted from stack:

WTFCrash()
WTF::fastMalloc(unsigned __int64 n)
WTF::Lock::operator new(unsigned __int64 size)
std::make_unique<WTF::Lock>()
WTF::threadMap()
WTF::ThreadHolder::initializeOnce()
WTF::initializeThreading()
JSC::initializeThreading::__l2::<lambda>()
JSC::initializeThreading()
JSClassCreate(const JSClassDefinition * definition)
...

I don't know if this is valid (to do stuff like JSClassCreate from constructors without doing explicit engine initialization), but it worked on older versions of jscore.
Comment 1 Vladimir Vukicevic 2017-06-22 09:40:43 PDT
Actually, now that I look closer.. I don't get how it's not initialized to size_t::max(), but is 0, other than static initializer order goop since it's initialized using 'std::numeric_limits<size_t>::max();' ?
Comment 2 Vladimir Vukicevic 2017-06-22 09:49:38 PDT
Yep, changing the static initializer to a simple "= SIZE_MAX;" fixes this.
Comment 3 Vladimir Vukicevic 2017-06-22 09:59:08 PDT
VS 2017 (cl 19.10.25019). max() is constexpr, so, I dunno why!
Comment 4 Yusuke Suzuki 2017-06-23 01:49:39 PDT
(In reply to Vladimir Vukicevic from comment #3)
> VS 2017 (cl 19.10.25019). max() is constexpr, so, I dunno why!

Hmmmmm, yeah, that is strange. In the meantime, we just use SIZE_MAX.
Comment 5 Yusuke Suzuki 2017-06-23 01:51:02 PDT
(In reply to Vladimir Vukicevic from comment #0)
> This is probably an edge case, but -- in a JSC static build that gets linked
> into another DLL, and that DLL does some dumb stuff from static
> constructors, such as JSClassCreate, I get this crash because
> maxSingleAllocationSize is still 0 (it's set by Options::initialize() which
> hasn't been called yet by initializeThreading()) -- lambdas and other junk
> omitted from stack:
> 
> WTFCrash()
> WTF::fastMalloc(unsigned __int64 n)
> WTF::Lock::operator new(unsigned __int64 size)
> std::make_unique<WTF::Lock>()
> WTF::threadMap()
> WTF::ThreadHolder::initializeOnce()
> WTF::initializeThreading()
> JSC::initializeThreading::__l2::<lambda>()
> JSC::initializeThreading()
> JSClassCreate(const JSClassDefinition * definition)
> ...
> 
> I don't know if this is valid (to do stuff like JSClassCreate from
> constructors without doing explicit engine initialization), but it worked on
> older versions of jscore.

Basically, we do not allow static constructors in WebKit.
If we use static constructors, mac build with clang will fail due to the option restricting static constructors.
Comment 6 Yusuke Suzuki 2017-06-23 01:55:39 PDT
Created attachment 313700 [details]
Patch
Comment 7 Mark Lam 2017-06-25 14:11:53 PDT
Comment on attachment 313700 [details]
Patch

r=me
Comment 8 Yusuke Suzuki 2017-06-25 14:14:29 PDT
Comment on attachment 313700 [details]
Patch

Thanks!
Comment 9 WebKit Commit Bot 2017-06-25 14:41:54 PDT
Comment on attachment 313700 [details]
Patch

Clearing flags on attachment: 313700

Committed r218800: <http://trac.webkit.org/changeset/218800>
Comment 10 WebKit Commit Bot 2017-06-25 14:41:56 PDT
All reviewed patches have been landed.  Closing bug.