MATLAB Error: Cannot load any more object with static TLS

by Pavel Holoborodko on February 22, 2016

UPDATE (December 2, 2017): We have found a workaround for the issue and included it into toolbox, this error shouldn’t appear for toolbox versions starting from 4.4.5.



Lately we have been receiving increasing number of reports from users who encounter the following error when trying to use toolbox on GNU Linux version of MATLAB:

>> addpath('/home/user/Documents/AdvanpixMCT-3.9.1.10015');
>> mp.Info
Invalid MEX-file '/home/user/Documents/AdvanpixMCT-3.9.1.10015/mpimpl.mexa64':
dlopen: cannot load any more object with static TLS
 
Error in mp.Info (line 196)
            mpimpl(4);

The error has no relation to our toolbox – it is long standing issue with MATLAB itself, known at least since R2012b release. Overview of the problem can be found on stackoverflow or in our brief explanation below[1].

Here we focus on how to fix the issue in few simple steps.

  1. Navigate to the first folder on the search path of MATLAB:
    >> u = userpath;
    >> cd(u(1:end-1));
  2. Create startup.m file in the folder (by using the mouse or command edit). Add there following lines:
    % path to toolbox - edit for your version:
    addpath('/home/user/Documents/AdvanpixMCT-3.9.1.10015');
     
    % run some command from toolbox so that MATLAB has to load it BEFORE any other MEX.
    mp('pi');

    From now on, on every start, MATLAB will load toolbox before any other MEX.

  3. Restart MATLAB and check if toolbox is loaded and ready to work:
  4. >> mp.Info;
    ---------------------------------------------------------------------
    Multiprecision Computing Toolbox, (c) 2008-2016 Advanpix LLC.
    Version :  3.9.1 Build 10015
    Platform:  64-bit (GNU Linux)
    Release :  2016-01-30
     
    .....
    ---------------------------------------------------------------------

These instructions are not specific to toolbox and can be used to prioritize loading of any MEX.

Update (October 30, 2016).
If instructions above did not fix the issue – try doing the following.

– Find matlabrc.m file in matlabroot/toolbox/local directory. This is the main script which MATLAB runs on startup.

– Place contents of our startup.m (see 2nd step above) directly into matlabrc.m as early as possible, before the lines:

% Execute startup MATLAB script, if it exists.
if (exist('startup','file') == 2) ||...
        (exist('startup','file') == 6)
   startup
end

– Restart MATLAB and check if this helps.


The TLS issue
Every MEX module requires system resources when it is being loaded into memory. The most aggressive MEX is the one compiled with TLS feature (needed for safe multi-threading).

MATLAB and its toolboxes use MEX dynamic libraries a lot. For example, the R2014b installation on GNU Linux contains 1888 MEX files in total!

At some point, when more and more MEX libraries are requested by MATLAB, allowed limit is reached and system loader restricts MATLAB from loading another MEX.

The most obvious solution would be to use TLS only where needed – most of the MEX in MATLAB do not use multi-threaded computations and no TLS is required. Probably if developers at TheMathWorks would use TLS more selectively – we would not see the issue at all.

{ 6 comments… read them below or add one }

Tolentee March 15, 2016 at 9:11 pm

Having similar problem loading a different mex-file package. Follow similar steps as above. Can you provide code/command to run toolbox before an other MEX.

Reply

Pavel Holoborodko March 16, 2016 at 12:00 am

Just call some command from your MEX in startup.m

Reply

Tolentee March 16, 2016 at 12:37 am

Yes! Got it working now. Besides I was using multi-thread in my case (when compiling mex-), which probably does not work. Once I disabled it for multi-thread, everything now works fine.
Thanks for the help as well.

Reply

Tanushree April 21, 2016 at 5:34 am

Thanks a lot! That worked for me!

Reply

Wonseok Jeon May 11, 2016 at 6:30 am

This doesn’t work for me 🙁

And, I found a simple way to use the toolbox in Ubuntu14.04 (with MATLAB 2016a).

Open the matlab in the terminal window with

matlab -nojvm

and use addpath command in the terminal window.

Then, the toolbox is usable in MATLAB, but in this case, the problem is that ‘plot’ command is not usable.

Reply

Pavel Holoborodko May 11, 2016 at 7:08 am

Thank you for sharing the workaround! Hopefully MATLAB developers will fix this issue in next releases.

Reply

Leave a Comment

Previous post:

Next post: