mapend = l->l_map_end | (_dl_pagesize - 1);
assert (mapend > mapstart);
- if ((mapend >= high || l == _dl_loaded) && high >= mapstart)
+ /* Prefer gaps below the main executable, note that l ==
+ _dl_loaded does not work for static binaries loading
+ e.g. libnss_*.so. */
+ if ((mapend >= high || l->l_type == lt_executable)
+ && high >= mapstart)
high = mapstart;
else if (mapend >= low && low >= mapstart)
low = mapend;