This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with static constructor priorities on Darwin


Hi Geoff, Richard et al.,

Looks like there's a problem with the support for static constructor
priorities when targeting Darwin.

This manifests under AddressSanitizer (gcc/asan.c), which inserts an
additional static constructor with priority equal to
MAX_RESERVED_INIT_PRIORITY-1 per each module - however the constructor
ends up being the last one in the __mod_init_func section, which leads
to crashes (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55617)

Looking at gcc/config/darwin.c I suspect that this is because
machopic_asm_out_constructor() just emits a pointer into
__mod_init_func for each constructor irrespective of its priority.
This might be fine if the constructors are created by a single
compiler pass (at least non-ASan builds behave correctly - maybe
someone else takes care of the priorities), but everything stops
working if another pass tries to add its own constructor.

As a proof of concept I've modified gcc/config/darwin.c to save the
constructors in machopic_asm_out_constructor() and emit them in
reversed order in darwin_file_end() (see
http://gcc.gnu.org/bugzilla/attachment.cgi?id=29309&action=diff) -
this really changes the order of constructors and makes small ASan
tests pass, but this solution is far from a complete one.

Is my understanding of the current problem with
machopic_asm_out_constructor() correct? If so, any chance it can be
fixed?

Thanks,
Alexander Potapenko
Software Engineer
Google Moscow


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]