[patch] Don't rauw an alias in llvm.used (v2)

Nick Lewycky nicholas at mxc.ca
Sun May 5 17:48:34 PDT 2013


Rafael EspĂ­ndola wrote:
> Clang has recently started producing internal but llvm.used aliases as
> a backward compatibility hack for static functions declared in an
> extern C context.
>
> This found an interesting bug in GlobalOpt: It would replace the alias
> with the function in the initialization of llvm.used, allowing llvm to
> drop the alias.
>
> One option would be to just not call replaceAllUsesWith if the alias
> is in llvm.used. We would lose some optimizations and I am afraid of
> making it possible for users to add __attribute__((used)) to get this
> side effect. What we should do is replace all other users.
>
> I ended implementing two options. The first one (add-back.patch)
> looked the simplest at first: Just call replaceAllUsesWith and patch
> llvm.used back to its previous state. The main problem in here is
> detecting if any other changes were made. We have to walk the
> constant's uses to find out.
>
> Since we ale walking the uses anyway, another option (cow.patch) is to
> duplicate a bit of the copy on write logic in replaceAllUsesWith to
> special case use chains that end up in llvm.used. In the end I think I
> like this one a bit more. What do you think?

Yes, I also prefer cow.patch. Thanks for looking into this!

Nick



More information about the llvm-commits mailing list