This is an archive of the discontinued LLVM Phabricator instance.

Fix race condition in Defined Atom ordinal computation.
AbandonedPublic

Authored by lhames on Mar 13 2015, 4:00 PM.

Details

Reviewers
ruiu
Jean-Daniel
Summary

Defined atom are allocated in multiples thread. The static counter must be atomic, else the ordinal is not guarantee to be unique (which is required by the Mach-O writer).

Diff Detail

Repository
rL LLVM

Event Timeline

Jean-Daniel retitled this revision from to Fix race condition in Defined Atom ordinal computation..
Jean-Daniel updated this object.
Jean-Daniel edited the test plan for this revision. (Show Details)
Jean-Daniel added a reviewer: ruiu.
Jean-Daniel set the repository for this revision to rL LLVM.
Jean-Daniel added a project: lld.
Jean-Daniel added a subscriber: Unknown Object (MLST).

am confused, Atoms live within a File and when the ordinals would be relative inside the file. So for your case do more than one file share the same SimpleDefinedAtom ? Am I missing some information ?

That’s true for input file, but having the same ordinal for 2 atoms raise an assert in MachO Layout Pass which is run on the generated file (that contains atom from many files)

Le 14 mars 2015 à 06:22, Shankar Kalpathi Easwaran <shankarke@gmail.com> a écrit :

am confused, Atoms live within a File and when the ordinals would be relative inside the file. So for your case do more than one file share the same SimpleDefinedAtom ? Am I missing some information ?

REPOSITORY
rL LLVM

http://reviews.llvm.org/D8336

EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/

But now that I think about it, there is just something wrong in the first place with that ordinal. It it either meaning full inside a single input file, and we shouldn’t use a static or don’t care about race condition, or it is meaningful across files and I don’t see how it can be as loading file in parallel make it indeterministic anyway.

Le 14 mars 2015 à 07:22, Jean-Daniel Dupas <mailing@xenonium.com> a écrit :

That’s true for input file, but having the same ordinal for 2 atoms raise an assert in MachO Layout Pass which is run on the generated file (that contains atom from many files)

Le 14 mars 2015 à 06:22, Shankar Kalpathi Easwaran <shankarke@gmail.com> a écrit :

am confused, Atoms live within a File and when the ordinals would be relative inside the file. So for your case do more than one file share the same SimpleDefinedAtom ? Am I missing some information ?

REPOSITORY
rL LLVM

http://reviews.llvm.org/D8336

EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/


llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

ruiu edited edge metadata.Mar 16 2015, 12:16 PM

Thank you for doing this. I wonder if we use _ordinal assigned here in the constructor. We usually assign ordinals explicitly in the reader, so I hope ordinals assigned here are overwritten in all use cases. If you change this to UINT_MAX or something and make ordinal() to abort if it's still UINT_MAX, does the linker fail with the assertion?

This change is good to mitigate the situation, so I'm OK to commit as a quick fix, but the actual fix should be assigning ordinals explicitly.

lhames added a subscriber: lhames.May 20 2015, 4:50 PM

I just hit this bug too (see http://reviews.llvm.org/D8336), and I've committed this fix in r237857.

Jean-Daniel - did you end up having any insights into the Right Way to fix this?

lhames commandeered this revision.May 22 2015, 5:04 PM
lhames added a reviewer: Jean-Daniel.

Fixed in r238072 by moving the ordinal tracking into the File class as discussed in http://reviews.llvm.org/D9927.

lhames abandoned this revision.May 22 2015, 5:04 PM