At the start of bfd_check_format_matches, we have this read of_bfd_section_id:
...
unsigned int initial_section_id = _bfd_section_id;
...
In order to access the variable, it is required to hold the global BFD lock.
The function already contains code acquiring the lock:
...
/* Locking is required here in order to manage _bfd_section_id. */
if (!bfd_lock ())
{
bfd_cache_set_uncloseable (abfd, old_in_format_matches, NULL);
free (matching_vector);
return false;
}
...
so fix this by moving the read after it.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33826
const bfd_target *fail_targ;
int match_count, best_count, best_match;
int ar_match_index;
- unsigned int initial_section_id = _bfd_section_id;
+ unsigned int initial_section_id;
struct bfd_preserve preserve, preserve_match;
bfd_cleanup cleanup = NULL;
struct per_xvec_messages messages = { abfd, PER_XVEC_NO_TARGET, NULL, NULL };
free (matching_vector);
return false;
}
+ initial_section_id = _bfd_section_id;
/* Presume the answer is yes. */
abfd->format = format;