[PATCH] D26146: [ThinLTO] Prevent exporting of locals used/defined in module level asm

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 13:31:25 PDT 2016


tejohnson added a comment.

In https://reviews.llvm.org/D26146#585130, @mehdi_amini wrote:

> > All global values defined in normal IR and used in module level asm should be included on either the llvm.used or llvm.compiler.used global.
>
> Can you clarify where this requirement comes from?


For inline asm, according to http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable:
"This is commonly used to represent references from inline asms and other things the compiler cannot “see”, and corresponds to “attribute((used))” in GNU C."

And for module level asm, I got this info from you =). It was via the conversation we had on the Chromium build issue that discussed this fix:

On Thu, Oct 27, 2016 at 8:08 AM, Mehdi Amini <mehdi.amini at apple.com> wrote:

> On Oct 27, 2016, at 6:51 AM, Teresa Johnson <tejohnson at google.com> wrote:
> 
>> On Tue, Oct 25, 2016 at 8:31 PM, Mehdi Amini <mehdi.amini at apple.com> wrote:
>> 
>>> On Oct 25, 2016, at 11:06 AM, Teresa Johnson <tejohnson at google.com> wrote:
>>> 
>>>> I have a draft set of fixes in https://reviews.llvm.org/D25951 (WIP, not for review). I've done some testing using the regression tests and one I added for module asm, but it needs cleanup and more testing. Feel free to give it a try.
>>>> 
>>>> I'm going to split it up and send various parts for review separately - it was a bit more involved than I expected.
>>>> 
>>>> Also, I have attempted to handle the case where a local value is used in module level asm. E.g.:
>>>> 
>>>>  -------------------
>>>> 
>>>> @b = internal global i32 1, align 4
>>>> 
>>>> module asm "\09.text"
>>>>  module asm "\09.type\09foo, at function"
>>>>  module asm "foo:"
>>>>  module asm "\09movl    b, %eax"
>>>>  module asm "\09ret "
>>>>  module asm "\09.size\09foo, .-foo"
>>>>  module asm “"
>>> 
>>> The frontend is responsible to add @b to llvm.compiler_used.
>> 
>> Ok, adding the llvm.compiler.used containing @b fixes the opt -O2 build of this case. This will simplify the patch as I don't need to look for uses within module asm blocks (just defs). I can simply flag all values within both llvm.used and llvm.compiler.used as non-renamable.
>> 
>> For inline asm we assume the uses are added to llvm.used, not llvm.compiler.used - I guess this is because they are user inserted? I do see in CGObjCMac.cpp where there are a bunch of calls to add to the compiler used, but that seems to be when CGObjCMac is synthesizing module assembly. In the Chromium case the module level asm is generated from file scope asm() calls - I assume it is therefore the user's responsibility to mark any uses within those with “attribute((used))”, just as one would for inline asm (asm added within a function), right?
> 
> Right.
> 
>> Mehdi




https://reviews.llvm.org/D26146





More information about the llvm-commits mailing list